select.vue 3.55 KB
<template>
    <section class="select-component">
        <div class="current-material" @click="onDropdown">
            <div class="description" v-if="selecteditem.length > 0">
                <div class="name" v-text="selecteditem" />
            </div>
            <div class="description" v-else>
                <div class="placeholder" v-text="props.placeholder" />
            </div>
            <div class="dropIcon">
                <img width="24" :src="selectIcon" alt="" />
            </div>
        </div>
        <div class="selectitems" v-show="isSelectitemsVisible" @mouseleave="onMouseout">
            <div
                v-for="item in props.items"
                :key="item"
                :index="item.key"
                class="selectitem"
                @click="onSelect(item.key)"
            >
                <div class="description">
                    <div class="name" v-text="item.key" />
                </div>
            </div>
        </div>
    </section>
</template>
<script setup>
import DROPDOWNICON from '@/views/assets/images/application-field/materials/dropdown.png';
import DROPUPICON from '@/views/assets/images/application-field/materials/dropup.png';

import { ref, defineProps } from 'vue';

const isSelectitemsVisible = ref(false);
const selectIcon = ref(DROPDOWNICON);

const props = defineProps({
    items: {
        type: [],
        default: []
    },
    selecteditem: {
        type: String,
        default: ''
    },
    handleSelect: {
        type: Function
    },
    selecteditemsWidth: {
        type: String,
        default: '292.5px'
    },
    placeholder: {
        type: String,
        default: 'Please Choose'
    }
});

const onSelect = (key) => {
    props.handleSelect(key);
    isSelectitemsVisible.value = false;
    selectIcon.value = DROPDOWNICON;
};

const onDropdown = () => {
    isSelectitemsVisible.value = !isSelectitemsVisible.value;
    selectIcon.value = isSelectitemsVisible.value ? DROPUPICON : DROPDOWNICON;
};

const onMouseout = () => {
    isSelectitemsVisible.value = false;
    selectIcon.value = DROPDOWNICON;
};
</script>
<style lang="less">
.select-component {
    width: 100%;
    height: 40px;
    border: 1.5px solid @color-button-active-background;
    border-radius: 8px;
    font-weight: 300;
    .current-material,
    .selectitem {
        display: flex;
        align-items: center;
        width: 100%;
        height: 40px;
        cursor: pointer;
        .icon {
            width: 56px;
        }
        .description {
            width: -webkit-fill-available;
            width: inherit;
            margin-left: 12px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            font-size: 15px;
            .name {
            }
            .placeholder {
                color: #c0c1c2;
            }
            .size {
                color: #c0c1c2;
            }
        }
        .dropIcon {
            width: 34px;
        }
        img {
            cursor: pointer;
            .image {
                width: 48px;
                height: 72px;
            }
        }
        &:hover {
            background-color: @header-machine-hover-color;
            color: @main-color;
        }
    }
    .selectitems {
        position: absolute;
        width: 100%;
        background-color: #fff;
        border: 1px solid #eef0f2;
        border-radius: 0 0 8px 8px;
        // height: calc(35px * 943 / 1008 * 5);
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 100;
        width: v-bind('selecteditemsWidth');
    }
}
</style>