@bitrix24/b24ui-nuxt 0.5.10 → 0.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/meta.cjs +72112 -0
- package/dist/meta.d.cts +72110 -0
- package/dist/meta.d.mts +5060 -5060
- package/dist/meta.d.ts +72110 -0
- package/dist/meta.mjs +5060 -5060
- package/dist/module.cjs +63 -0
- package/dist/module.d.cts +15 -0
- package/dist/module.d.ts +15 -0
- package/dist/module.json +3 -3
- package/dist/module.mjs +1 -1
- package/dist/runtime/components/Advice.vue +54 -47
- package/dist/runtime/components/Alert.vue +96 -71
- package/dist/runtime/components/App.vue +34 -37
- package/dist/runtime/components/Avatar.vue +81 -69
- package/dist/runtime/components/AvatarGroup.vue +76 -53
- package/dist/runtime/components/Badge.vue +83 -83
- package/dist/runtime/components/Button.vue +157 -220
- package/dist/runtime/components/ButtonGroup.vue +51 -35
- package/dist/runtime/components/Calendar.vue +152 -186
- package/dist/runtime/components/Checkbox.vue +73 -84
- package/dist/runtime/components/Chip.vue +74 -59
- package/dist/runtime/components/Collapsible.vue +41 -44
- package/dist/runtime/components/Container.vue +27 -18
- package/dist/runtime/components/Countdown.vue +378 -198
- package/dist/runtime/components/DescriptionList.vue +149 -102
- package/dist/runtime/components/DropdownMenu.vue +139 -83
- package/dist/runtime/components/DropdownMenuContent.vue +84 -137
- package/dist/runtime/components/Form.vue +216 -162
- package/dist/runtime/components/FormField.vue +80 -76
- package/dist/runtime/components/Input.vue +179 -160
- package/dist/runtime/components/InputMenu.vue +380 -300
- package/dist/runtime/components/InputNumber.vue +175 -178
- package/dist/runtime/components/Kbd.vue +45 -33
- package/dist/runtime/components/Link.vue +173 -179
- package/dist/runtime/components/LinkBase.vue +42 -64
- package/dist/runtime/components/Modal.vue +127 -105
- package/dist/runtime/components/ModalDialogClose.vue +8 -4
- package/dist/runtime/components/Navbar.vue +33 -24
- package/dist/runtime/components/NavbarDivider.vue +33 -24
- package/dist/runtime/components/NavbarSection.vue +33 -24
- package/dist/runtime/components/NavbarSpacer.vue +33 -24
- package/dist/runtime/components/NavigationMenu.vue +210 -144
- package/dist/runtime/components/OverlayProvider.vue +17 -13
- package/dist/runtime/components/Popover.vue +81 -81
- package/dist/runtime/components/Progress.vue +136 -109
- package/dist/runtime/components/RadioGroup.vue +134 -120
- package/dist/runtime/components/Range.vue +85 -94
- package/dist/runtime/components/Select.vue +260 -212
- package/dist/runtime/components/SelectMenu.vue +365 -272
- package/dist/runtime/components/Separator.vue +71 -61
- package/dist/runtime/components/Sidebar.vue +33 -24
- package/dist/runtime/components/SidebarBody.vue +38 -30
- package/dist/runtime/components/SidebarFooter.vue +33 -24
- package/dist/runtime/components/SidebarHeader.vue +33 -24
- package/dist/runtime/components/SidebarHeading.vue +33 -24
- package/dist/runtime/components/SidebarLayout.vue +70 -40
- package/dist/runtime/components/SidebarSection.vue +33 -24
- package/dist/runtime/components/SidebarSpacer.vue +33 -24
- package/dist/runtime/components/Skeleton.vue +22 -17
- package/dist/runtime/components/Slideover.vue +131 -108
- package/dist/runtime/components/StackedLayout.vue +73 -40
- package/dist/runtime/components/Switch.vue +95 -100
- package/dist/runtime/components/Tabs.vue +107 -81
- package/dist/runtime/components/Textarea.vue +201 -177
- package/dist/runtime/components/Toast.vue +105 -94
- package/dist/runtime/components/Toaster.vue +116 -94
- package/dist/runtime/components/Tooltip.vue +64 -78
- package/dist/runtime/components/content/TableWrapper.vue +70 -58
- package/dist/runtime/composables/useAvatarGroup.d.ts +1 -1
- package/dist/runtime/composables/useButtonGroup.d.ts +2 -2
- package/dist/runtime/composables/useComponentIcons.d.ts +3 -3
- package/dist/runtime/composables/useFormField.d.ts +1 -1
- package/dist/runtime/prose/A.vue +23 -18
- package/dist/runtime/prose/Blockquote.vue +23 -18
- package/dist/runtime/prose/Code.vue +31 -23
- package/dist/runtime/prose/Em.vue +23 -18
- package/dist/runtime/prose/H1.vue +23 -18
- package/dist/runtime/prose/H2.vue +23 -18
- package/dist/runtime/prose/H3.vue +23 -18
- package/dist/runtime/prose/H4.vue +23 -18
- package/dist/runtime/prose/H5.vue +23 -18
- package/dist/runtime/prose/H6.vue +23 -18
- package/dist/runtime/prose/Hr.vue +19 -18
- package/dist/runtime/prose/Img.vue +23 -18
- package/dist/runtime/prose/Li.vue +23 -18
- package/dist/runtime/prose/Ol.vue +23 -18
- package/dist/runtime/prose/P.vue +23 -18
- package/dist/runtime/prose/Pre.vue +33 -28
- package/dist/runtime/prose/Strong.vue +23 -18
- package/dist/runtime/prose/Table.vue +54 -44
- package/dist/runtime/prose/Tbody.vue +23 -18
- package/dist/runtime/prose/Td.vue +23 -18
- package/dist/runtime/prose/Th.vue +23 -18
- package/dist/runtime/prose/Thead.vue +23 -18
- package/dist/runtime/prose/Tr.vue +23 -18
- package/dist/runtime/prose/Ul.vue +23 -18
- package/dist/runtime/vue/components/Link.vue +202 -201
- package/dist/shared/b24ui-nuxt.DrKwIWoc.cjs +7721 -0
- package/dist/types.d.mts +5 -3
- package/dist/types.d.ts +7 -0
- package/dist/unplugin.cjs +236 -0
- package/dist/unplugin.d.cts +33 -0
- package/dist/unplugin.d.ts +33 -0
- package/dist/vite.cjs +21 -0
- package/dist/vite.d.cts +14 -0
- package/dist/vite.d.ts +14 -0
- package/package.json +25 -13
- package/dist/runtime/components/Advice.vue.d.ts +0 -170
- package/dist/runtime/components/Alert.vue.d.ts +0 -464
- package/dist/runtime/components/App.vue.d.ts +0 -23
- package/dist/runtime/components/Avatar.vue.d.ts +0 -281
- package/dist/runtime/components/AvatarGroup.vue.d.ts +0 -204
- package/dist/runtime/components/Badge.vue.d.ts +0 -517
- package/dist/runtime/components/Button.vue.d.ts +0 -640
- package/dist/runtime/components/ButtonGroup.vue.d.ts +0 -116
- package/dist/runtime/components/Calendar.vue.d.ts +0 -437
- package/dist/runtime/components/Checkbox.vue.d.ts +0 -354
- package/dist/runtime/components/Chip.vue.d.ts +0 -271
- package/dist/runtime/components/Collapsible.vue.d.ts +0 -118
- package/dist/runtime/components/Container.vue.d.ts +0 -27
- package/dist/runtime/components/Countdown.vue.d.ts +0 -356
- package/dist/runtime/components/DescriptionList.vue.d.ts +0 -379
- package/dist/runtime/components/DropdownMenu.vue.d.ts +0 -533
- package/dist/runtime/components/DropdownMenuContent.vue.d.ts +0 -228
- package/dist/runtime/components/Form.vue.d.ts +0 -55
- package/dist/runtime/components/FormField.vue.d.ts +0 -282
- package/dist/runtime/components/Input.vue.d.ts +0 -755
- package/dist/runtime/components/InputMenu.vue.d.ts +0 -1504
- package/dist/runtime/components/InputNumber.vue.d.ts +0 -658
- package/dist/runtime/components/Kbd.vue.d.ts +0 -109
- package/dist/runtime/components/Link.vue.d.ts +0 -129
- package/dist/runtime/components/LinkBase.vue.d.ts +0 -48
- package/dist/runtime/components/Modal.vue.d.ts +0 -327
- package/dist/runtime/components/ModalDialogClose.vue.d.ts +0 -10
- package/dist/runtime/components/Navbar.vue.d.ts +0 -101
- package/dist/runtime/components/NavbarDivider.vue.d.ts +0 -101
- package/dist/runtime/components/NavbarSection.vue.d.ts +0 -101
- package/dist/runtime/components/NavbarSpacer.vue.d.ts +0 -101
- package/dist/runtime/components/NavigationMenu.vue.d.ts +0 -824
- package/dist/runtime/components/OverlayProvider.vue.d.ts +0 -2
- package/dist/runtime/components/Popover.vue.d.ts +0 -147
- package/dist/runtime/components/Progress.vue.d.ts +0 -592
- package/dist/runtime/components/RadioGroup.vue.d.ts +0 -723
- package/dist/runtime/components/Range.vue.d.ts +0 -417
- package/dist/runtime/components/Select.vue.d.ts +0 -1200
- package/dist/runtime/components/SelectMenu.vue.d.ts +0 -1298
- package/dist/runtime/components/Separator.vue.d.ts +0 -400
- package/dist/runtime/components/Sidebar.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarBody.vue.d.ts +0 -90
- package/dist/runtime/components/SidebarFooter.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarHeader.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarHeading.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarLayout.vue.d.ts +0 -222
- package/dist/runtime/components/SidebarSection.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarSpacer.vue.d.ts +0 -101
- package/dist/runtime/components/Skeleton.vue.d.ts +0 -26
- package/dist/runtime/components/Slideover.vue.d.ts +0 -360
- package/dist/runtime/components/StackedLayout.vue.d.ts +0 -192
- package/dist/runtime/components/Switch.vue.d.ts +0 -587
- package/dist/runtime/components/Tabs.vue.d.ts +0 -453
- package/dist/runtime/components/Textarea.vue.d.ts +0 -601
- package/dist/runtime/components/Toast.vue.d.ts +0 -438
- package/dist/runtime/components/Toaster.vue.d.ts +0 -219
- package/dist/runtime/components/Tooltip.vue.d.ts +0 -186
- package/dist/runtime/components/content/TableWrapper.vue.d.ts +0 -237
- package/dist/runtime/prose/A.vue.d.ts +0 -84
- package/dist/runtime/prose/Blockquote.vue.d.ts +0 -84
- package/dist/runtime/prose/Code.vue.d.ts +0 -97
- package/dist/runtime/prose/Em.vue.d.ts +0 -84
- package/dist/runtime/prose/H1.vue.d.ts +0 -97
- package/dist/runtime/prose/H2.vue.d.ts +0 -123
- package/dist/runtime/prose/H3.vue.d.ts +0 -123
- package/dist/runtime/prose/H4.vue.d.ts +0 -123
- package/dist/runtime/prose/H5.vue.d.ts +0 -123
- package/dist/runtime/prose/H6.vue.d.ts +0 -123
- package/dist/runtime/prose/Hr.vue.d.ts +0 -74
- package/dist/runtime/prose/Img.vue.d.ts +0 -77
- package/dist/runtime/prose/Li.vue.d.ts +0 -84
- package/dist/runtime/prose/Ol.vue.d.ts +0 -84
- package/dist/runtime/prose/P.vue.d.ts +0 -84
- package/dist/runtime/prose/Pre.vue.d.ts +0 -117
- package/dist/runtime/prose/Strong.vue.d.ts +0 -84
- package/dist/runtime/prose/Table.vue.d.ts +0 -144
- package/dist/runtime/prose/Tbody.vue.d.ts +0 -84
- package/dist/runtime/prose/Td.vue.d.ts +0 -84
- package/dist/runtime/prose/Th.vue.d.ts +0 -84
- package/dist/runtime/prose/Thead.vue.d.ts +0 -84
- package/dist/runtime/prose/Tr.vue.d.ts +0 -84
- package/dist/runtime/prose/Ul.vue.d.ts +0 -84
- package/dist/runtime/vue/components/Link.vue.d.ts +0 -129
|
@@ -1,178 +1,212 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { VariantProps } from 'tailwind-variants'
|
|
3
|
+
import type { SelectRootProps, SelectRootEmits, SelectContentProps, SelectContentEmits, SelectArrowProps } from 'reka-ui'
|
|
4
|
+
import type { AppConfig } from '@nuxt/schema'
|
|
5
|
+
import _appConfig from '#build/app.config'
|
|
6
|
+
import theme from '#build/b24ui/select'
|
|
7
|
+
import type { UseComponentIconsProps } from '../composables/useComponentIcons'
|
|
8
|
+
import { tv } from '../utils/tv'
|
|
9
|
+
import type { AvatarProps, ChipProps, InputProps, IconComponent } from '../types'
|
|
10
|
+
import type {
|
|
11
|
+
AcceptableValue,
|
|
12
|
+
ArrayOrNested,
|
|
13
|
+
GetItemKeys,
|
|
14
|
+
GetItemValue,
|
|
15
|
+
GetModelValue,
|
|
16
|
+
GetModelValueEmits,
|
|
17
|
+
NestedItem,
|
|
18
|
+
PartialString,
|
|
19
|
+
EmitsToProps
|
|
20
|
+
} from '../types/utils'
|
|
21
|
+
|
|
22
|
+
const appConfigSelect = _appConfig as AppConfig & { b24ui: { select: Partial<typeof theme> } }
|
|
23
|
+
|
|
24
|
+
const select = tv({ extend: tv(theme), ...(appConfigSelect.b24ui?.select || {}) })
|
|
25
|
+
|
|
26
|
+
type SelectVariants = VariantProps<typeof select>
|
|
27
|
+
|
|
28
|
+
interface SelectItemBase {
|
|
29
|
+
label?: string
|
|
30
|
+
/**
|
|
31
|
+
* Display an icon on the left side.
|
|
32
|
+
* @IconComponent
|
|
33
|
+
*/
|
|
34
|
+
icon?: IconComponent
|
|
35
|
+
avatar?: AvatarProps
|
|
36
|
+
color?: SelectVariants['color']
|
|
37
|
+
chip?: ChipProps
|
|
38
|
+
/**
|
|
39
|
+
* The item type.
|
|
40
|
+
* @defaultValue 'item'
|
|
41
|
+
*/
|
|
42
|
+
type?: 'label' | 'separator' | 'item'
|
|
43
|
+
value?: string | number
|
|
44
|
+
disabled?: boolean
|
|
45
|
+
[key: string]: any
|
|
46
|
+
}
|
|
47
|
+
export type SelectItem = SelectItemBase | AcceptableValue | boolean
|
|
48
|
+
|
|
49
|
+
export interface SelectProps<T extends ArrayOrNested<SelectItem> = ArrayOrNested<SelectItem>, VK extends GetItemKeys<T> = 'value', M extends boolean = false> extends Omit<SelectRootProps<T>, 'dir' | 'multiple' | 'modelValue' | 'defaultValue' | 'by'>, UseComponentIconsProps {
|
|
50
|
+
id?: string
|
|
51
|
+
/** The placeholder text when the select is empty. */
|
|
52
|
+
placeholder?: string
|
|
53
|
+
/**
|
|
54
|
+
* @defaultValue 'primary'
|
|
55
|
+
*/
|
|
56
|
+
color?: SelectVariants['color']
|
|
57
|
+
/**
|
|
58
|
+
* @defaultValue 'md'
|
|
59
|
+
*/
|
|
60
|
+
size?: SelectVariants['size']
|
|
61
|
+
/**
|
|
62
|
+
* Removes padding from input
|
|
63
|
+
* @defaultValue false
|
|
64
|
+
*/
|
|
65
|
+
noPadding?: boolean
|
|
66
|
+
/**
|
|
67
|
+
* Removes all borders (rings)
|
|
68
|
+
* @defaultValue false
|
|
69
|
+
*/
|
|
70
|
+
noBorder?: boolean
|
|
71
|
+
/**
|
|
72
|
+
* Removes all borders (rings) except the bottom one
|
|
73
|
+
* @defaultValue false
|
|
74
|
+
*/
|
|
75
|
+
underline?: boolean
|
|
76
|
+
/**
|
|
77
|
+
* Rounds the corners of the button
|
|
78
|
+
* @defaultValue false
|
|
79
|
+
*/
|
|
80
|
+
rounded?: boolean
|
|
81
|
+
tag?: string
|
|
82
|
+
/**
|
|
83
|
+
* @defaultValue 'primary'
|
|
84
|
+
*/
|
|
85
|
+
tagColor?: SelectVariants['tagColor']
|
|
86
|
+
/**
|
|
87
|
+
* The icon displayed to open the menu.
|
|
88
|
+
* @defaultValue icons.chevronDown
|
|
89
|
+
* @IconComponent
|
|
90
|
+
*/
|
|
91
|
+
trailingIcon?: IconComponent
|
|
92
|
+
/**
|
|
93
|
+
* The icon displayed when an item is selected.
|
|
94
|
+
* @defaultValue icons.check
|
|
95
|
+
* @IconComponent
|
|
96
|
+
*/
|
|
97
|
+
selectedIcon?: IconComponent
|
|
98
|
+
/**
|
|
99
|
+
* The content of the menu.
|
|
100
|
+
* @defaultValue { side: 'bottom', sideOffset: 8, collisionPadding: 8, position: 'popper' }
|
|
101
|
+
*/
|
|
102
|
+
content?: Omit<SelectContentProps, 'as' | 'asChild' | 'forceMount'> & Partial<EmitsToProps<SelectContentEmits>>
|
|
103
|
+
/**
|
|
104
|
+
* Display an arrow alongside the menu.
|
|
105
|
+
* @defaultValue false
|
|
106
|
+
*/
|
|
107
|
+
arrow?: boolean | Omit<SelectArrowProps, 'as' | 'asChild'>
|
|
108
|
+
/**
|
|
109
|
+
* Render the menu in a portal.
|
|
110
|
+
* @defaultValue true
|
|
111
|
+
*/
|
|
112
|
+
portal?: boolean
|
|
113
|
+
/**
|
|
114
|
+
* When `items` is an array of objects, select the field to use as the value.
|
|
115
|
+
* @defaultValue 'value'
|
|
116
|
+
*/
|
|
117
|
+
valueKey?: VK
|
|
118
|
+
/**
|
|
119
|
+
* When `items` is an array of objects, select the field to use as the label.
|
|
120
|
+
* @defaultValue 'label'
|
|
121
|
+
*/
|
|
122
|
+
labelKey?: keyof NestedItem<T>
|
|
123
|
+
items?: T
|
|
124
|
+
/**
|
|
125
|
+
* The value of the Select when initially rendered. Use when you do not need to control the state of the Select
|
|
126
|
+
*/
|
|
127
|
+
defaultValue?: GetModelValue<T, VK, M>
|
|
128
|
+
/**
|
|
129
|
+
* The controlled value of the Select. Can be bind as `v-model`
|
|
130
|
+
*/
|
|
131
|
+
modelValue?: GetModelValue<T, VK, M>
|
|
132
|
+
/**
|
|
133
|
+
* Whether multiple options can be selected or not
|
|
134
|
+
* @defaultValue false
|
|
135
|
+
*/
|
|
136
|
+
multiple?: M & boolean
|
|
137
|
+
/**
|
|
138
|
+
* Highlight the ring color like a focus state
|
|
139
|
+
* @defaultValue false
|
|
140
|
+
*/
|
|
141
|
+
highlight?: boolean
|
|
142
|
+
class?: any
|
|
143
|
+
b24ui?: PartialString<typeof select.slots>
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type SelectEmits<A extends ArrayOrNested<SelectItem>, VK extends GetItemKeys<A> | undefined, M extends boolean> = Omit<SelectRootEmits, 'update:modelValue'> & {
|
|
147
|
+
change: [payload: Event]
|
|
148
|
+
blur: [payload: FocusEvent]
|
|
149
|
+
focus: [payload: FocusEvent]
|
|
150
|
+
} & GetModelValueEmits<A, VK, M>
|
|
151
|
+
|
|
152
|
+
type SlotProps<T extends SelectItem> = (props: { item: T, index: number }) => any
|
|
153
|
+
|
|
154
|
+
export interface SelectSlots<
|
|
155
|
+
A extends ArrayOrNested<SelectItem> = ArrayOrNested<SelectItem>,
|
|
156
|
+
VK extends GetItemKeys<A> | undefined = undefined,
|
|
157
|
+
M extends boolean = false,
|
|
158
|
+
T extends NestedItem<A> = NestedItem<A>
|
|
159
|
+
> {
|
|
160
|
+
'leading'(props: { modelValue?: GetModelValue<A, VK, M>, open: boolean, b24ui: ReturnType<typeof select> }): any
|
|
161
|
+
'default'(props: { modelValue?: GetModelValue<A, VK, M>, open: boolean }): any
|
|
162
|
+
'trailing'(props: { modelValue?: GetModelValue<A, VK, M>, open: boolean, b24ui: ReturnType<typeof select> }): any
|
|
163
|
+
'item': SlotProps<T>
|
|
164
|
+
'item-leading': SlotProps<T>
|
|
165
|
+
'item-label': SlotProps<T>
|
|
166
|
+
'item-trailing': SlotProps<T>
|
|
167
|
+
}
|
|
7
168
|
</script>
|
|
8
169
|
|
|
9
|
-
<script setup>
|
|
10
|
-
import { computed, toRef } from
|
|
11
|
-
import { useForwardPropsEmits } from
|
|
12
|
-
import { defu } from
|
|
13
|
-
import { reactivePick } from
|
|
14
|
-
import { useButtonGroup } from
|
|
15
|
-
import { useComponentIcons } from
|
|
16
|
-
import { useFormField } from
|
|
17
|
-
import { compare, get, isArrayOfArray } from
|
|
18
|
-
import icons from
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
type: Boolean,
|
|
39
|
-
required: false
|
|
40
|
-
},
|
|
41
|
-
noBorder: {
|
|
42
|
-
type: Boolean,
|
|
43
|
-
required: false
|
|
44
|
-
},
|
|
45
|
-
underline: {
|
|
46
|
-
type: Boolean,
|
|
47
|
-
required: false
|
|
48
|
-
},
|
|
49
|
-
rounded: {
|
|
50
|
-
type: Boolean,
|
|
51
|
-
required: false
|
|
52
|
-
},
|
|
53
|
-
tag: {
|
|
54
|
-
type: String,
|
|
55
|
-
required: false
|
|
56
|
-
},
|
|
57
|
-
tagColor: {
|
|
58
|
-
type: null,
|
|
59
|
-
required: false
|
|
60
|
-
},
|
|
61
|
-
trailingIcon: {
|
|
62
|
-
type: [Function, Object],
|
|
63
|
-
required: false
|
|
64
|
-
},
|
|
65
|
-
selectedIcon: {
|
|
66
|
-
type: [Function, Object],
|
|
67
|
-
required: false
|
|
68
|
-
},
|
|
69
|
-
content: {
|
|
70
|
-
type: Object,
|
|
71
|
-
required: false
|
|
72
|
-
},
|
|
73
|
-
arrow: {
|
|
74
|
-
type: [Boolean, Object],
|
|
75
|
-
required: false
|
|
76
|
-
},
|
|
77
|
-
portal: {
|
|
78
|
-
type: Boolean,
|
|
79
|
-
required: false,
|
|
80
|
-
default: true
|
|
81
|
-
},
|
|
82
|
-
valueKey: {
|
|
83
|
-
type: null,
|
|
84
|
-
required: false,
|
|
85
|
-
default: "value"
|
|
86
|
-
},
|
|
87
|
-
labelKey: {
|
|
88
|
-
type: null,
|
|
89
|
-
required: false,
|
|
90
|
-
default: "label"
|
|
91
|
-
},
|
|
92
|
-
items: {
|
|
93
|
-
type: null,
|
|
94
|
-
required: false
|
|
95
|
-
},
|
|
96
|
-
defaultValue: {
|
|
97
|
-
type: null,
|
|
98
|
-
required: false
|
|
99
|
-
},
|
|
100
|
-
modelValue: {
|
|
101
|
-
type: null,
|
|
102
|
-
required: false
|
|
103
|
-
},
|
|
104
|
-
multiple: {
|
|
105
|
-
type: Boolean,
|
|
106
|
-
required: false
|
|
107
|
-
},
|
|
108
|
-
highlight: {
|
|
109
|
-
type: Boolean,
|
|
110
|
-
required: false
|
|
111
|
-
},
|
|
112
|
-
class: {
|
|
113
|
-
type: null,
|
|
114
|
-
required: false
|
|
115
|
-
},
|
|
116
|
-
b24ui: {
|
|
117
|
-
type: null,
|
|
118
|
-
required: false
|
|
119
|
-
},
|
|
120
|
-
open: {
|
|
121
|
-
type: Boolean,
|
|
122
|
-
required: false
|
|
123
|
-
},
|
|
124
|
-
defaultOpen: {
|
|
125
|
-
type: Boolean,
|
|
126
|
-
required: false
|
|
127
|
-
},
|
|
128
|
-
autocomplete: {
|
|
129
|
-
type: String,
|
|
130
|
-
required: false
|
|
131
|
-
},
|
|
132
|
-
disabled: {
|
|
133
|
-
type: Boolean,
|
|
134
|
-
required: false
|
|
135
|
-
},
|
|
136
|
-
name: {
|
|
137
|
-
type: String,
|
|
138
|
-
required: false
|
|
139
|
-
},
|
|
140
|
-
required: {
|
|
141
|
-
type: Boolean,
|
|
142
|
-
required: false
|
|
143
|
-
},
|
|
144
|
-
icon: {
|
|
145
|
-
type: [Function, Object],
|
|
146
|
-
required: false
|
|
147
|
-
},
|
|
148
|
-
avatar: {
|
|
149
|
-
type: Object,
|
|
150
|
-
required: false
|
|
151
|
-
},
|
|
152
|
-
loading: {
|
|
153
|
-
type: Boolean,
|
|
154
|
-
required: false
|
|
155
|
-
},
|
|
156
|
-
trailing: {
|
|
157
|
-
type: Boolean,
|
|
158
|
-
required: false
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
const emits = defineEmits(["update:open", "change", "blur", "focus", "update:modelValue"]);
|
|
162
|
-
const slots = defineSlots();
|
|
163
|
-
const rootProps = useForwardPropsEmits(reactivePick(props, "open", "defaultOpen", "disabled", "autocomplete", "required", "multiple"), emits);
|
|
164
|
-
const contentProps = toRef(() => defu(props.content, { side: "bottom", sideOffset: 8, collisionPadding: 8, position: "popper" }));
|
|
165
|
-
const arrowProps = toRef(() => props.arrow);
|
|
166
|
-
const { emitFormChange, emitFormInput, emitFormBlur, emitFormFocus, size: formGroupSize, color, id, name, highlight, disabled, ariaAttrs } = useFormField(props);
|
|
167
|
-
const { orientation, size: buttonGroupSize } = useButtonGroup(props);
|
|
170
|
+
<script setup lang="ts" generic="T extends ArrayOrNested<SelectItem>, VK extends GetItemKeys<T> = 'value', M extends boolean = false">
|
|
171
|
+
import { computed, toRef } from 'vue'
|
|
172
|
+
import { Primitive, SelectRoot, SelectArrow, SelectTrigger, SelectPortal, SelectContent, SelectViewport, SelectScrollUpButton, SelectScrollDownButton, SelectLabel, SelectGroup, SelectItem, SelectItemIndicator, SelectItemText, SelectSeparator, useForwardPropsEmits } from 'reka-ui'
|
|
173
|
+
import { defu } from 'defu'
|
|
174
|
+
import { reactivePick } from '@vueuse/core'
|
|
175
|
+
import { useButtonGroup } from '../composables/useButtonGroup'
|
|
176
|
+
import { useComponentIcons } from '../composables/useComponentIcons'
|
|
177
|
+
import { useFormField } from '../composables/useFormField'
|
|
178
|
+
import { compare, get, isArrayOfArray } from '../utils'
|
|
179
|
+
import icons from '../dictionary/icons'
|
|
180
|
+
import B24Avatar from './Avatar.vue'
|
|
181
|
+
import B24Chip from './Chip.vue'
|
|
182
|
+
|
|
183
|
+
defineOptions({ inheritAttrs: false })
|
|
184
|
+
|
|
185
|
+
const props = withDefaults(defineProps<SelectProps<T, VK, M>>(), {
|
|
186
|
+
valueKey: 'value' as never,
|
|
187
|
+
labelKey: 'label' as never,
|
|
188
|
+
portal: true
|
|
189
|
+
})
|
|
190
|
+
const emits = defineEmits<SelectEmits<T, VK, M>>()
|
|
191
|
+
const slots = defineSlots<SelectSlots<T, VK, M>>()
|
|
192
|
+
|
|
193
|
+
const rootProps = useForwardPropsEmits(reactivePick(props, 'open', 'defaultOpen', 'disabled', 'autocomplete', 'required', 'multiple'), emits)
|
|
194
|
+
const contentProps = toRef(() => defu(props.content, { side: 'bottom', sideOffset: 8, collisionPadding: 8, position: 'popper' }) as SelectContentProps)
|
|
195
|
+
const arrowProps = toRef(() => props.arrow as SelectArrowProps)
|
|
196
|
+
|
|
197
|
+
const { emitFormChange, emitFormInput, emitFormBlur, emitFormFocus, size: formGroupSize, color, id, name, highlight, disabled, ariaAttrs } = useFormField<InputProps>(props)
|
|
198
|
+
const { orientation, size: buttonGroupSize } = useButtonGroup<InputProps>(props)
|
|
168
199
|
const { isLeading, isTrailing, leadingIconName, trailingIconName } = useComponentIcons(toRef(() => defu(
|
|
169
200
|
props,
|
|
170
201
|
{ trailingIcon: icons.chevronDown }
|
|
171
|
-
)))
|
|
172
|
-
|
|
202
|
+
)))
|
|
203
|
+
|
|
204
|
+
const selectSize = computed(() => buttonGroupSize.value || formGroupSize.value)
|
|
205
|
+
|
|
173
206
|
const isTag = computed(() => {
|
|
174
|
-
return props.tag
|
|
175
|
-
})
|
|
207
|
+
return props.tag
|
|
208
|
+
})
|
|
209
|
+
|
|
176
210
|
const b24ui = computed(() => select({
|
|
177
211
|
color: color.value,
|
|
178
212
|
size: selectSize?.value,
|
|
@@ -186,40 +220,54 @@ const b24ui = computed(() => select({
|
|
|
186
220
|
leading: Boolean(isLeading.value || !!props.avatar || !!slots.leading),
|
|
187
221
|
trailing: Boolean(isTrailing.value || !!slots.trailing),
|
|
188
222
|
buttonGroup: orientation.value
|
|
189
|
-
}))
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
223
|
+
}))
|
|
224
|
+
|
|
225
|
+
const groups = computed<SelectItem[][]>(() =>
|
|
226
|
+
props.items?.length
|
|
227
|
+
? isArrayOfArray(props.items)
|
|
228
|
+
? props.items
|
|
229
|
+
: [props.items]
|
|
230
|
+
: []
|
|
231
|
+
)
|
|
232
|
+
// eslint-disable-next-line vue/no-dupe-keys
|
|
233
|
+
const items = computed(() => groups.value.flatMap(group => group) as T[])
|
|
234
|
+
|
|
235
|
+
function displayValue(value?: GetItemValue<T, VK> | GetItemValue<T, VK>[]): string {
|
|
195
236
|
if (props.multiple && Array.isArray(value)) {
|
|
196
|
-
return value.map(
|
|
237
|
+
return value.map(v => displayValue(v)).filter(Boolean).join(', ')
|
|
197
238
|
}
|
|
198
|
-
|
|
199
|
-
|
|
239
|
+
|
|
240
|
+
const item = items.value.find(item => compare(typeof item === 'object' ? get(item as Record<string, any>, props.valueKey as string) : item, value))
|
|
241
|
+
return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item)
|
|
200
242
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
243
|
+
|
|
244
|
+
function onUpdate(value: any) {
|
|
245
|
+
// @ts-expect-error - 'target' does not exist in type 'EventInit'
|
|
246
|
+
const event = new Event('change', { target: { value } })
|
|
247
|
+
emits('change', event)
|
|
248
|
+
|
|
249
|
+
emitFormChange()
|
|
250
|
+
emitFormInput()
|
|
206
251
|
}
|
|
207
|
-
|
|
252
|
+
|
|
253
|
+
function onUpdateOpen(value: boolean) {
|
|
208
254
|
if (!value) {
|
|
209
|
-
const event = new FocusEvent(
|
|
210
|
-
emits(
|
|
211
|
-
emitFormBlur()
|
|
255
|
+
const event = new FocusEvent('blur')
|
|
256
|
+
emits('blur', event)
|
|
257
|
+
emitFormBlur()
|
|
212
258
|
} else {
|
|
213
|
-
const event = new FocusEvent(
|
|
214
|
-
emits(
|
|
215
|
-
emitFormFocus()
|
|
259
|
+
const event = new FocusEvent('focus')
|
|
260
|
+
emits('focus', event)
|
|
261
|
+
emitFormFocus()
|
|
216
262
|
}
|
|
217
263
|
}
|
|
218
|
-
|
|
219
|
-
|
|
264
|
+
|
|
265
|
+
function isSelectItem(item: SelectItem): item is SelectItemBase {
|
|
266
|
+
return typeof item === 'object' && item !== null
|
|
220
267
|
}
|
|
221
268
|
</script>
|
|
222
269
|
|
|
270
|
+
<!-- eslint-disable vue/no-template-shadow -->
|
|
223
271
|
<template>
|
|
224
272
|
<Primitive as="div" :class="b24ui.root({ class: [props.b24ui?.root] })">
|
|
225
273
|
<SelectRoot
|
|
@@ -228,8 +276,8 @@ function isSelectItem(item) {
|
|
|
228
276
|
v-bind="rootProps"
|
|
229
277
|
:autocomplete="autocomplete"
|
|
230
278
|
:disabled="disabled"
|
|
231
|
-
:default-value="defaultValue"
|
|
232
|
-
:model-value="modelValue"
|
|
279
|
+
:default-value="(defaultValue as (AcceptableValue | AcceptableValue[]))"
|
|
280
|
+
:model-value="(modelValue as (AcceptableValue | AcceptableValue[]))"
|
|
233
281
|
@update:model-value="onUpdate"
|
|
234
282
|
@update:open="onUpdateOpen"
|
|
235
283
|
>
|
|
@@ -239,29 +287,29 @@ function isSelectItem(item) {
|
|
|
239
287
|
</div>
|
|
240
288
|
|
|
241
289
|
<span v-if="isLeading || !!avatar || !!slots.leading" :class="b24ui.leading({ class: props.b24ui?.leading })">
|
|
242
|
-
<slot name="leading" :model-value="modelValue" :open="open" :b24ui="b24ui">
|
|
290
|
+
<slot name="leading" :model-value="(modelValue as GetModelValue<T, VK, M>)" :open="open" :b24ui="b24ui">
|
|
243
291
|
<Component
|
|
244
292
|
:is="leadingIconName"
|
|
245
293
|
v-if="isLeading && leadingIconName"
|
|
246
294
|
:class="b24ui.leadingIcon({ class: props.b24ui?.leadingIcon })"
|
|
247
295
|
/>
|
|
248
|
-
<B24Avatar v-else-if="!!avatar" :size="props.b24ui?.itemLeadingAvatarSize || b24ui.itemLeadingAvatarSize()" v-bind="avatar" :class="b24ui.itemLeadingAvatar({ class: props.b24ui?.itemLeadingAvatar })" />
|
|
296
|
+
<B24Avatar v-else-if="!!avatar" :size="((props.b24ui?.itemLeadingAvatarSize || b24ui.itemLeadingAvatarSize()) as AvatarProps['size'])" v-bind="avatar" :class="b24ui.itemLeadingAvatar({ class: props.b24ui?.itemLeadingAvatar })" />
|
|
249
297
|
</slot>
|
|
250
298
|
</span>
|
|
251
299
|
|
|
252
|
-
<slot :model-value="modelValue" :open="open">
|
|
253
|
-
<template v-for="displayedModelValue in [displayValue(modelValue)]" :key="displayedModelValue">
|
|
300
|
+
<slot :model-value="(modelValue as GetModelValue<T, VK, M>)" :open="open">
|
|
301
|
+
<template v-for="displayedModelValue in [displayValue(modelValue as GetModelValue<T, VK, M>)]" :key="displayedModelValue">
|
|
254
302
|
<span v-if="displayedModelValue" :class="b24ui.value({ class: props.b24ui?.value })">
|
|
255
303
|
{{ displayedModelValue }}
|
|
256
304
|
</span>
|
|
257
305
|
<span v-else :class="b24ui.placeholder({ class: props.b24ui?.placeholder })">
|
|
258
|
-
{{ placeholder ??
|
|
306
|
+
{{ placeholder ?? ' ' }}
|
|
259
307
|
</span>
|
|
260
308
|
</template>
|
|
261
309
|
</slot>
|
|
262
310
|
|
|
263
311
|
<span v-if="isTrailing || !!slots.trailing" :class="b24ui.trailing({ class: props.b24ui?.trailing })">
|
|
264
|
-
<slot name="trailing" :model-value="modelValue" :open="open" :b24ui="b24ui">
|
|
312
|
+
<slot name="trailing" :model-value="(modelValue as GetModelValue<T, VK, M>)" :open="open" :b24ui="b24ui">
|
|
265
313
|
<Component
|
|
266
314
|
:is="trailingIconName"
|
|
267
315
|
v-if="trailingIconName"
|
|
@@ -283,28 +331,28 @@ function isSelectItem(item) {
|
|
|
283
331
|
<SelectGroup v-for="(group, groupIndex) in groups" :key="`group-${groupIndex}`" :class="b24ui.group({ class: props.b24ui?.group })">
|
|
284
332
|
<template v-for="(item, index) in group" :key="`group-${groupIndex}-${index}`">
|
|
285
333
|
<SelectLabel v-if="isSelectItem(item) && item.type === 'label'" :class="b24ui.label({ class: props.b24ui?.label })">
|
|
286
|
-
{{ get(item, props.labelKey) }}
|
|
334
|
+
{{ get(item, props.labelKey as string) }}
|
|
287
335
|
</SelectLabel>
|
|
288
336
|
|
|
289
337
|
<SelectSeparator v-else-if="isSelectItem(item) && item.type === 'separator'" :class="b24ui.separator({ class: props.b24ui?.separator })" />
|
|
290
338
|
|
|
291
339
|
<SelectItem
|
|
292
340
|
v-else
|
|
293
|
-
:class="b24ui.item({ class: props.b24ui?.item, colorItem: isSelectItem(item) ? item?.color :
|
|
341
|
+
:class="b24ui.item({ class: props.b24ui?.item, colorItem: isSelectItem(item) ? item?.color : undefined })"
|
|
294
342
|
:disabled="isSelectItem(item) && item.disabled"
|
|
295
|
-
:value="isSelectItem(item) ? get(item, props.valueKey) : item"
|
|
343
|
+
:value="isSelectItem(item) ? get(item, props.valueKey as string) : item"
|
|
296
344
|
>
|
|
297
|
-
<slot name="item" :item="item" :index="index">
|
|
298
|
-
<slot name="item-leading" :item="item" :index="index">
|
|
345
|
+
<slot name="item" :item="(item as NestedItem<T>)" :index="index">
|
|
346
|
+
<slot name="item-leading" :item="(item as NestedItem<T>)" :index="index">
|
|
299
347
|
<Component
|
|
300
348
|
:is="item.icon"
|
|
301
349
|
v-if="isSelectItem(item) && item.icon"
|
|
302
350
|
:class="b24ui.itemLeadingIcon({ class: props.b24ui?.itemLeadingIcon, colorItem: item?.color })"
|
|
303
351
|
/>
|
|
304
|
-
<B24Avatar v-else-if="isSelectItem(item) && item.avatar" :size="props.b24ui?.itemLeadingAvatarSize || b24ui.itemLeadingAvatarSize()" v-bind="item.avatar" :class="b24ui.itemLeadingAvatar({ class: props.b24ui?.itemLeadingAvatar, colorItem: item?.color })" />
|
|
352
|
+
<B24Avatar v-else-if="isSelectItem(item) && item.avatar" :size="((props.b24ui?.itemLeadingAvatarSize || b24ui.itemLeadingAvatarSize()) as AvatarProps['size'])" v-bind="item.avatar" :class="b24ui.itemLeadingAvatar({ class: props.b24ui?.itemLeadingAvatar, colorItem: item?.color })" />
|
|
305
353
|
<B24Chip
|
|
306
354
|
v-else-if="isSelectItem(item) && item.chip"
|
|
307
|
-
:size="props.b24ui?.itemLeadingChipSize || b24ui.itemLeadingChipSize()"
|
|
355
|
+
:size="((props.b24ui?.itemLeadingChipSize || b24ui.itemLeadingChipSize()) as ChipProps['size'])"
|
|
308
356
|
inset
|
|
309
357
|
standalone
|
|
310
358
|
v-bind="item.chip"
|
|
@@ -313,18 +361,18 @@ function isSelectItem(item) {
|
|
|
313
361
|
</slot>
|
|
314
362
|
|
|
315
363
|
<SelectItemText :class="b24ui.itemLabel({ class: props.b24ui?.itemLabel })">
|
|
316
|
-
<slot name="item-label" :item="item" :index="index">
|
|
317
|
-
{{ isSelectItem(item) ? get(item, props.labelKey) : item }}
|
|
364
|
+
<slot name="item-label" :item="(item as NestedItem<T>)" :index="index">
|
|
365
|
+
{{ isSelectItem(item) ? get(item, props.labelKey as string) : item }}
|
|
318
366
|
</slot>
|
|
319
367
|
</SelectItemText>
|
|
320
368
|
|
|
321
|
-
<span :class="b24ui.itemTrailing({ class: props.b24ui?.itemTrailing, colorItem: isSelectItem(item) ? item?.color :
|
|
322
|
-
<slot name="item-trailing" :item="item" :index="index" />
|
|
369
|
+
<span :class="b24ui.itemTrailing({ class: props.b24ui?.itemTrailing, colorItem: isSelectItem(item) ? item?.color : undefined })">
|
|
370
|
+
<slot name="item-trailing" :item="(item as NestedItem<T>)" :index="index" />
|
|
323
371
|
|
|
324
372
|
<SelectItemIndicator as-child>
|
|
325
373
|
<Component
|
|
326
374
|
:is="selectedIcon || icons.check"
|
|
327
|
-
:class="b24ui.itemTrailingIcon({ class: props.b24ui?.itemTrailingIcon, colorItem: isSelectItem(item) ? item?.color :
|
|
375
|
+
:class="b24ui.itemTrailingIcon({ class: props.b24ui?.itemTrailingIcon, colorItem: isSelectItem(item) ? item?.color : undefined })"
|
|
328
376
|
/>
|
|
329
377
|
</SelectItemIndicator>
|
|
330
378
|
</span>
|