-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
select-list-item.vue
69 lines (61 loc) · 1.64 KB
/
select-list-item.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
<v-divider v-if="item.divider === true" />
<v-list-item
v-else
v-show="!item.hidden"
:active="isActive"
:disabled="item.disabled"
clickable
:value="item.value"
@click="multiple ? null : $emit('update:modelValue', item.value)"
>
<v-list-item-icon v-if="multiple === false && allowOther === false && item.icon">
<v-icon :name="item.icon" />
</v-list-item-icon>
<v-list-item-content>
<span v-if="multiple === false || item.selectable === false" class="item-text">{{ item.text }}</span>
<v-checkbox
v-else
class="checkbox"
:model-value="modelValue || []"
:label="item.text"
:value="item.value"
:disabled="item.disabled"
@update:model-value="$emit('update:modelValue', $event.length > 0 ? $event : null)"
/>
</v-list-item-content>
</v-list-item>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { Option } from './types';
interface Props {
item: Option;
itemLabelFontFamily: string;
modelValue?: string | number | (string | number)[] | null;
multiple?: boolean;
allowOther?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
itemLabelFontFamily: 'var(--v-select-font-family)',
modelValue: null,
multiple: true,
allowOther: false,
});
defineEmits(['update:modelValue']);
const isActive = computed(() => {
if (props.multiple) {
if (!Array.isArray(props.modelValue) || !props.item.value) {
return false;
}
return props.modelValue.includes(props.item.value);
} else {
return props.modelValue === props.item.value;
}
});
</script>
<style scoped>
.checkbox :deep(.type-text) {
font-family: v-bind('$props.itemLabelFontFamily');
}
</style>