@byyuurin/ui 0.0.10 → 0.0.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.
Files changed (194) hide show
  1. package/README.md +2 -2
  2. package/dist/module.json +3 -3
  3. package/dist/module.mjs +1 -1
  4. package/dist/module.mjs.map +1 -1
  5. package/dist/runtime/app/injections.d.ts +388 -364
  6. package/dist/runtime/components/Accordion.vue +38 -67
  7. package/dist/runtime/components/Accordion.vue.d.ts +52 -0
  8. package/dist/runtime/components/Alert.vue +37 -75
  9. package/dist/runtime/components/Alert.vue.d.ts +59 -0
  10. package/dist/runtime/components/App.vue +25 -40
  11. package/dist/runtime/components/App.vue.d.ts +24 -0
  12. package/dist/runtime/components/Avatar.vue +31 -51
  13. package/dist/runtime/components/Avatar.vue.d.ts +25 -0
  14. package/dist/runtime/components/AvatarGroup.vue +38 -69
  15. package/dist/runtime/components/AvatarGroup.vue.d.ts +27 -0
  16. package/dist/runtime/components/Badge.vue +25 -51
  17. package/dist/runtime/components/Badge.vue.d.ts +44 -0
  18. package/dist/runtime/components/Breadcrumb.vue +36 -74
  19. package/dist/runtime/components/Breadcrumb.vue.d.ts +52 -0
  20. package/dist/runtime/components/Button.vue +62 -51
  21. package/dist/runtime/components/Button.vue.d.ts +29 -0
  22. package/dist/runtime/components/ButtonGroup.vue +17 -37
  23. package/dist/runtime/components/ButtonGroup.vue.d.ts +26 -0
  24. package/dist/runtime/components/Calendar.vue +75 -110
  25. package/dist/runtime/components/Calendar.vue.d.ts +75 -0
  26. package/dist/runtime/components/Card.vue +25 -42
  27. package/dist/runtime/components/Card.vue.d.ts +30 -0
  28. package/dist/runtime/components/Carousel.vue +118 -225
  29. package/dist/runtime/components/Carousel.vue.d.ts +104 -0
  30. package/dist/runtime/components/Checkbox.vue +46 -73
  31. package/dist/runtime/components/Checkbox.vue.d.ts +56 -0
  32. package/dist/runtime/components/Chip.vue +31 -48
  33. package/dist/runtime/components/Chip.vue.d.ts +30 -0
  34. package/dist/runtime/components/Collapsible.vue +22 -30
  35. package/dist/runtime/components/Collapsible.vue.d.ts +26 -0
  36. package/dist/runtime/components/Drawer.vue +51 -101
  37. package/dist/runtime/components/Drawer.vue.d.ts +80 -0
  38. package/dist/runtime/components/DropdownMenu.vue +37 -115
  39. package/dist/runtime/components/DropdownMenu.vue.d.ts +99 -0
  40. package/dist/runtime/components/DropdownMenuContent.vue +81 -77
  41. package/dist/runtime/components/DropdownMenuContent.vue.d.ts +39 -0
  42. package/dist/runtime/components/Form.vue +140 -254
  43. package/dist/runtime/components/Form.vue.d.ts +78 -0
  44. package/dist/runtime/components/FormItem.vue +50 -89
  45. package/dist/runtime/components/FormItem.vue.d.ts +60 -0
  46. package/dist/runtime/components/Input.vue +79 -115
  47. package/dist/runtime/components/Input.vue.d.ts +64 -0
  48. package/dist/runtime/components/InputNumber.vue +74 -117
  49. package/dist/runtime/components/InputNumber.vue.d.ts +245 -0
  50. package/dist/runtime/components/Kbd.vue +18 -39
  51. package/dist/runtime/components/Kbd.vue.d.ts +28 -0
  52. package/dist/runtime/components/Link.vue +168 -257
  53. package/dist/runtime/components/Link.vue.d.ts +95 -0
  54. package/dist/runtime/components/LinkBase.vue +36 -54
  55. package/dist/runtime/components/LinkBase.vue.d.ts +28 -0
  56. package/dist/runtime/components/Modal.vue +49 -84
  57. package/dist/runtime/components/Modal.vue.d.ts +66 -0
  58. package/dist/runtime/components/OverlayProvider.vue +10 -14
  59. package/dist/runtime/components/OverlayProvider.vue.d.ts +2 -0
  60. package/dist/runtime/components/Pagination.vue +55 -121
  61. package/dist/runtime/components/Pagination.vue.d.ts +93 -0
  62. package/dist/runtime/components/PinInput.vue +49 -58
  63. package/dist/runtime/components/PinInput.vue.d.ts +35 -0
  64. package/dist/runtime/components/Popover.vue +39 -68
  65. package/dist/runtime/components/Popover.vue.d.ts +45 -0
  66. package/dist/runtime/components/Progress.vue +68 -120
  67. package/dist/runtime/components/Progress.vue.d.ts +54 -0
  68. package/dist/runtime/components/RadioGroup.vue +67 -125
  69. package/dist/runtime/components/RadioGroup.vue.d.ts +74 -0
  70. package/dist/runtime/components/ScrollArea.vue +31 -31
  71. package/dist/runtime/components/ScrollArea.vue.d.ts +17 -0
  72. package/dist/runtime/components/Select.vue +114 -204
  73. package/dist/runtime/components/Select.vue.d.ts +119 -0
  74. package/dist/runtime/components/Separator.vue +26 -44
  75. package/dist/runtime/components/Separator.vue.d.ts +27 -0
  76. package/dist/runtime/components/Skeleton.vue +12 -21
  77. package/dist/runtime/components/Skeleton.vue.d.ts +19 -0
  78. package/dist/runtime/components/Slider.vue +52 -74
  79. package/dist/runtime/components/Slider.vue.d.ts +36 -0
  80. package/dist/runtime/components/Switch.vue +51 -71
  81. package/dist/runtime/components/Switch.vue.d.ts +49 -0
  82. package/dist/runtime/components/Table.vue +108 -194
  83. package/dist/runtime/components/Table.vue.d.ts +148 -0
  84. package/dist/runtime/components/Tabs.vue +36 -81
  85. package/dist/runtime/components/Tabs.vue.d.ts +65 -0
  86. package/dist/runtime/components/Textarea.vue +77 -124
  87. package/dist/runtime/components/Textarea.vue.d.ts +60 -0
  88. package/dist/runtime/components/Toast.vue +47 -75
  89. package/dist/runtime/components/Toast.vue.d.ts +131 -0
  90. package/dist/runtime/components/ToastProvider.vue +65 -101
  91. package/dist/runtime/components/ToastProvider.vue.d.ts +38 -0
  92. package/dist/runtime/components/Tooltip.vue +36 -47
  93. package/dist/runtime/components/Tooltip.vue.d.ts +31 -0
  94. package/dist/runtime/composables/useAvatarGroup.d.ts +1 -1
  95. package/dist/runtime/composables/useButtonGroup.d.ts +2 -2
  96. package/dist/runtime/composables/useFormItem.d.ts +2 -2
  97. package/dist/runtime/composables/useKbd.d.ts +1 -1
  98. package/dist/runtime/composables/useLocale.d.ts +3 -3
  99. package/dist/runtime/composables/useTheme.d.ts +1 -1
  100. package/dist/runtime/composables/useToast.d.ts +1 -1
  101. package/dist/runtime/locale/en.d.ts +1 -1
  102. package/dist/runtime/locale/zh-tw.d.ts +1 -1
  103. package/dist/runtime/theme/accordion.d.ts +45 -51
  104. package/dist/runtime/theme/accordion.js +1 -1
  105. package/dist/runtime/theme/alert.d.ts +115 -121
  106. package/dist/runtime/theme/alert.js +1 -1
  107. package/dist/runtime/theme/avatar-group.d.ts +42 -48
  108. package/dist/runtime/theme/avatar-group.js +1 -1
  109. package/dist/runtime/theme/avatar.d.ts +46 -52
  110. package/dist/runtime/theme/avatar.js +1 -1
  111. package/dist/runtime/theme/badge.d.ts +60 -66
  112. package/dist/runtime/theme/badge.js +1 -1
  113. package/dist/runtime/theme/breadcrumb.d.ts +52 -58
  114. package/dist/runtime/theme/breadcrumb.js +1 -1
  115. package/dist/runtime/theme/button-group.d.ts +36 -42
  116. package/dist/runtime/theme/button.d.ts +162 -168
  117. package/dist/runtime/theme/button.js +1 -1
  118. package/dist/runtime/theme/calendar.d.ts +52 -50
  119. package/dist/runtime/theme/calendar.js +20 -3
  120. package/dist/runtime/theme/card.d.ts +52 -58
  121. package/dist/runtime/theme/card.js +1 -1
  122. package/dist/runtime/theme/carousel.d.ts +98 -104
  123. package/dist/runtime/theme/carousel.js +1 -1
  124. package/dist/runtime/theme/checkbox.d.ts +77 -83
  125. package/dist/runtime/theme/checkbox.js +1 -1
  126. package/dist/runtime/theme/chip.d.ts +50 -56
  127. package/dist/runtime/theme/chip.js +1 -1
  128. package/dist/runtime/theme/collapsible.d.ts +29 -35
  129. package/dist/runtime/theme/collapsible.js +1 -1
  130. package/dist/runtime/theme/drawer.d.ts +120 -126
  131. package/dist/runtime/theme/drawer.js +1 -1
  132. package/dist/runtime/theme/dropdown-menu.d.ts +55 -61
  133. package/dist/runtime/theme/dropdown-menu.js +1 -1
  134. package/dist/runtime/theme/form-item.d.ts +63 -69
  135. package/dist/runtime/theme/form-item.js +1 -1
  136. package/dist/runtime/theme/form.d.ts +1 -7
  137. package/dist/runtime/theme/input-number.d.ts +98 -104
  138. package/dist/runtime/theme/input-number.js +1 -1
  139. package/dist/runtime/theme/input.d.ts +153 -159
  140. package/dist/runtime/theme/input.js +1 -1
  141. package/dist/runtime/theme/kbd.d.ts +30 -36
  142. package/dist/runtime/theme/link.d.ts +37 -43
  143. package/dist/runtime/theme/modal.d.ts +36 -42
  144. package/dist/runtime/theme/modal.js +1 -1
  145. package/dist/runtime/theme/pagination.d.ts +71 -77
  146. package/dist/runtime/theme/pagination.js +1 -1
  147. package/dist/runtime/theme/pinInput.d.ts +80 -86
  148. package/dist/runtime/theme/pinInput.js +1 -1
  149. package/dist/runtime/theme/popover.d.ts +29 -35
  150. package/dist/runtime/theme/popover.js +1 -1
  151. package/dist/runtime/theme/progress.d.ts +163 -169
  152. package/dist/runtime/theme/progress.js +1 -1
  153. package/dist/runtime/theme/radio-group.d.ts +99 -105
  154. package/dist/runtime/theme/radio-group.js +1 -1
  155. package/dist/runtime/theme/scroll-area.d.ts +62 -68
  156. package/dist/runtime/theme/scroll-area.js +1 -1
  157. package/dist/runtime/theme/select.d.ts +165 -171
  158. package/dist/runtime/theme/select.js +1 -1
  159. package/dist/runtime/theme/separator.d.ts +62 -68
  160. package/dist/runtime/theme/separator.js +1 -1
  161. package/dist/runtime/theme/skeleton.d.ts +1 -7
  162. package/dist/runtime/theme/slider.d.ts +62 -68
  163. package/dist/runtime/theme/slider.js +1 -1
  164. package/dist/runtime/theme/switch.d.ts +111 -117
  165. package/dist/runtime/theme/switch.js +1 -1
  166. package/dist/runtime/theme/table.d.ts +75 -81
  167. package/dist/runtime/theme/table.js +1 -1
  168. package/dist/runtime/theme/tabs.d.ts +114 -120
  169. package/dist/runtime/theme/tabs.js +1 -1
  170. package/dist/runtime/theme/textarea.d.ts +76 -82
  171. package/dist/runtime/theme/textarea.js +1 -1
  172. package/dist/runtime/theme/toast-provider.d.ts +106 -112
  173. package/dist/runtime/theme/toast-provider.js +1 -1
  174. package/dist/runtime/theme/toast.d.ts +74 -80
  175. package/dist/runtime/theme/toast.js +1 -1
  176. package/dist/runtime/theme/tooltip.d.ts +35 -41
  177. package/dist/runtime/theme/tooltip.js +1 -1
  178. package/dist/runtime/types/utils.d.ts +5 -5
  179. package/dist/runtime/utils/link.d.ts +3 -5
  180. package/dist/runtime/utils/styler.d.ts +2 -2
  181. package/dist/runtime/utils/styler.js +2 -2
  182. package/dist/shared/ui.D1BTWZFB.mjs +5 -0
  183. package/dist/shared/ui.D1BTWZFB.mjs.map +1 -0
  184. package/dist/types.d.mts +1 -1
  185. package/dist/unocss.mjs +5 -4
  186. package/dist/unocss.mjs.map +1 -1
  187. package/dist/unplugin.mjs +1 -1
  188. package/dist/unplugin.mjs.map +1 -1
  189. package/dist/vite.mjs +1 -1
  190. package/package.json +77 -75
  191. package/dist/module.cjs +0 -5
  192. package/dist/shared/ui.3e7fad19.mjs +0 -5
  193. package/dist/shared/ui.3e7fad19.mjs.map +0 -1
  194. package/dist/types.d.ts +0 -1
@@ -1,36 +1,32 @@
1
- <script lang="ts">
2
- import type { ScrollAreaRootProps } from 'reka-ui'
3
- import type { scrollArea } from '../theme'
4
- import { transitionProps } from '../theme/scroll-area'
5
- import type { ComponentAttrs } from '../types'
6
-
7
- export interface ScrollAreaProps extends ComponentAttrs<typeof scrollArea>, Pick<ScrollAreaRootProps, 'type' | 'dir' | 'scrollHideDelay'> {}
1
+ <script>
2
+ import { transitionProps } from "../theme/scroll-area";
8
3
  </script>
9
4
 
10
- <script setup lang="ts">
11
- import { reactivePick } from '@vueuse/core'
12
- import { ScrollAreaCorner, ScrollAreaRoot, ScrollAreaScrollbar, ScrollAreaThumb, ScrollAreaViewport } from 'reka-ui'
13
- import { computed, ref } from 'vue'
14
- import { useTheme } from '../composables/useTheme'
15
-
16
- const props = withDefaults(defineProps<ScrollAreaProps>(), {})
17
- const rootRef = ref<InstanceType<typeof ScrollAreaRoot>>()
18
- const rootProps = reactivePick(props, 'type', 'dir', 'scrollHideDelay')
19
-
20
- const { generateStyle } = useTheme()
21
- const style = computed(() => generateStyle('scrollArea', props))
22
-
5
+ <script setup>
6
+ import { reactivePick } from "@vueuse/core";
7
+ import { ScrollAreaCorner, ScrollAreaRoot, ScrollAreaScrollbar, ScrollAreaThumb, ScrollAreaViewport } from "reka-ui";
8
+ import { computed, ref } from "vue";
9
+ import { useTheme } from "../composables/useTheme";
10
+ const props = defineProps({
11
+ class: { type: null, required: false },
12
+ ui: { type: null, required: false },
13
+ type: { type: String, required: false },
14
+ dir: { type: String, required: false },
15
+ scrollHideDelay: { type: Number, required: false }
16
+ });
17
+ const rootRef = ref();
18
+ const rootProps = reactivePick(props, "type", "dir", "scrollHideDelay");
19
+ const { generateStyle } = useTheme();
20
+ const style = computed(() => generateStyle("scrollArea", props));
23
21
  defineExpose({
24
22
  scrollTop,
25
- scrollTopLeft,
26
- })
27
-
23
+ scrollTopLeft
24
+ });
28
25
  function scrollTop() {
29
- rootRef.value?.scrollTop()
26
+ rootRef.value?.scrollTop();
30
27
  }
31
-
32
28
  function scrollTopLeft() {
33
- rootRef.value?.scrollTopLeft()
29
+ rootRef.value?.scrollTopLeft();
34
30
  }
35
31
  </script>
36
32
 
@@ -39,29 +35,33 @@ function scrollTopLeft() {
39
35
  ref="rootRef"
40
36
  v-bind="rootProps"
41
37
  :class="style.root({ class: [props.class, props.ui?.root] })"
38
+ data-part="root"
42
39
  >
43
- <ScrollAreaViewport :class="style.viewport({ class: props.ui?.viewport })">
40
+ <ScrollAreaViewport :class="style.viewport({ class: props.ui?.viewport })" data-part="viewport">
44
41
  <slot></slot>
45
42
  </ScrollAreaViewport>
46
43
 
47
44
  <TransitionGroup v-bind="transitionProps">
48
45
  <ScrollAreaScrollbar
49
46
  key="scrollbar-horizontal"
50
- :class="style.scrollbar({ class: props.ui?.scrollbar })"
51
47
  orientation="horizontal"
48
+ :class="style.scrollbar({ class: props.ui?.scrollbar })"
49
+ data-part="scrollbar"
52
50
  >
53
- <ScrollAreaThumb :class="style.thumb({ class: props.ui?.thumb })" />
51
+ <ScrollAreaThumb :class="style.thumb({ class: props.ui?.thumb })" data-part="thumb" />
54
52
  </ScrollAreaScrollbar>
55
53
  <ScrollAreaScrollbar
56
54
  key="scrollbar-vertical"
57
- :class="style.scrollbar({ class: props.ui?.scrollbar })"
58
55
  orientation="vertical"
56
+ :class="style.scrollbar({ class: props.ui?.scrollbar })"
57
+ data-part="scrollbar"
59
58
  >
60
- <ScrollAreaThumb :class="style.thumb({ class: props.ui?.thumb })" />
59
+ <ScrollAreaThumb :class="style.thumb({ class: props.ui?.thumb })" data-part="thumb" />
61
60
  </ScrollAreaScrollbar>
62
61
  <ScrollAreaCorner
63
62
  key="corner"
64
63
  :class="style.corner({ class: props.ui?.corner })"
64
+ data-part="corner"
65
65
  />
66
66
  </TransitionGroup>
67
67
  </ScrollAreaRoot>
@@ -0,0 +1,17 @@
1
+ import type { ScrollAreaRootProps } from 'reka-ui';
2
+ import type { scrollArea } from '../theme/index.js';
3
+ import type { ComponentAttrs } from '../types/index.js';
4
+ export interface ScrollAreaProps extends ComponentAttrs<typeof scrollArea>, Pick<ScrollAreaRootProps, 'type' | 'dir' | 'scrollHideDelay'> {
5
+ }
6
+ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<ScrollAreaProps, {
7
+ scrollTop: () => void;
8
+ scrollTopLeft: () => void;
9
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<ScrollAreaProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
10
+ default?: (props: {}) => any;
11
+ }>;
12
+ export default _default;
13
+ type __VLS_WithSlots<T, S> = T & {
14
+ new (): {
15
+ $slots: S;
16
+ };
17
+ };
@@ -1,191 +1,100 @@
1
- <script lang="ts">
2
- import type { VariantProps } from '@byyuurin/ui-kit'
3
- import type { SelectArrowProps, SelectContentEmits, SelectContentProps, SelectRootEmits, SelectRootProps } from 'reka-ui'
4
- import type { UseComponentIconsProps } from '../composables/useComponentIcons'
5
- import type { select } from '../theme'
6
- import type { AcceptableValue, ArrayOrNested, ComponentAttrs, EmitsToProps, GetItemKeys, GetItemValue, GetModelValue, GetModelValueEmits, MaybeArray, NestedItem } from '../types'
1
+ <script>
7
2
 
8
- interface SelectItemBase {
9
- label?: string
10
- icon?: string
11
- /**
12
- * The option type.
13
- * @default "option"
14
- */
15
- type?: 'label' | 'separator' | 'option'
16
- value?: AcceptableValue
17
- disabled?: boolean
18
- [key: string]: any
19
- }
20
-
21
- export type SelectItem = SelectItemBase | AcceptableValue | boolean
22
-
23
- export type SelectEmits<T extends ArrayOrNested<SelectItem>, VK extends GetItemKeys<T> | undefined, M extends boolean> = Omit<SelectRootEmits, 'update:modelValue'> & {
24
- change: [payload: Event]
25
- blur: [payload: FocusEvent]
26
- focus: [payload: FocusEvent]
27
- } & GetModelValueEmits<T, VK, M>
28
-
29
- type SlotProps<T extends SelectItem> = (props: { item: T, index: number }) => any
30
-
31
- export interface SelectSlots<
32
- T extends ArrayOrNested<SelectItem> = ArrayOrNested<SelectItem>,
33
- VK extends GetItemKeys<T> | undefined = undefined,
34
- M extends boolean = false,
35
- I extends NestedItem<T> = NestedItem<T>,
36
- > {
37
- 'leading'?: (props: { modelValue?: GetModelValue<T, VK, M>, open: boolean, ui: ComponentAttrs<typeof select>['ui'] }) => any
38
- 'default'?: (props: { modelValue?: GetModelValue<T, VK, M>, open: boolean }) => any
39
- 'trailing'?: (props: { modelValue?: GetModelValue<T, VK, M>, open: boolean, ui: ComponentAttrs<typeof select>['ui'] }) => any
40
- 'item'?: SlotProps<I>
41
- 'item-leading'?: SlotProps<I>
42
- 'item-label'?: SlotProps<I>
43
- 'item-trailing'?: SlotProps<I>
44
- }
45
-
46
- type SelectVariants = VariantProps<typeof select>
47
-
48
- export interface SelectProps<
49
- T extends ArrayOrNested<SelectItem> = ArrayOrNested<SelectItem>,
50
- VK extends GetItemKeys<T> = 'value',
51
- M extends boolean = false,
52
- > extends ComponentAttrs<typeof select>, UseComponentIconsProps, Omit<SelectRootProps<T>, 'dir' | 'multiple' | 'modelValue' | 'defaultValue' | 'by'> {
53
- id?: string
54
- /** The placeholder text when the select is empty. */
55
- placeholder?: string
56
- variant?: SelectVariants['variant']
57
- size?: SelectVariants['size']
58
- /**
59
- * The icon displayed to open the menu.
60
- * @default app.icons.chevronDown
61
- */
62
- trailingIcon?: string
63
- /**
64
- * The icon displayed when an item is selected.
65
- * @default app.icons.check
66
- */
67
- selectedIcon?: string
68
- /**
69
- * The content of the menu.
70
- * @default { side: 'bottom', sideOffset: 8, collisionPadding: 8, position: 'popper' }
71
- */
72
- content?: Omit<SelectContentProps, 'as' | 'asChild' | 'forceMount'> & Partial<EmitsToProps<SelectContentEmits>>
73
- /**
74
- * Display an arrow alongside the menu.
75
- * @default false
76
- */
77
- arrow?: boolean | Omit<SelectArrowProps, 'as' | 'asChild'>
78
- /**
79
- * Render the menu in a portal.
80
- * @default true
81
- */
82
- portal?: boolean
83
- /**
84
- * When `options` is an array of objects, select the field to use as the value.
85
- * @default "value"
86
- */
87
- valueKey?: VK
88
- /**
89
- * When `options` is an array of objects, select the field to use as the label.
90
- * @default "label"
91
- */
92
- labelKey?: VK
93
- options?: T
94
- /** The value of the Select when initially rendered. Use when you do not need to control the state of the Select. */
95
- defaultValue?: GetModelValue<T, VK, M>
96
- /** The controlled value of the Select. Can be bind as `v-model`. */
97
- modelValue?: GetModelValue<T, VK, M>
98
- /** Whether multiple options can be selected or not. */
99
- multiple?: M & boolean
100
- /** Highlight the ring color like a focus state. */
101
- highlight?: boolean
102
- underline?: boolean
103
- }
104
3
  </script>
105
4
 
106
- <script lang="ts" setup generic="T extends ArrayOrNested<SelectItem>, VK extends GetItemKeys<T> = 'value', M extends boolean = false">
107
- import { reactivePick } from '@vueuse/core'
108
- import { defu } from 'defu'
109
- import { SelectArrow, SelectContent, SelectGroup, SelectItem, SelectItemIndicator, SelectItemText, SelectLabel, SelectPortal, SelectRoot, SelectSeparator, SelectTrigger, SelectViewport, useForwardPropsEmits } from 'reka-ui'
110
- import { computed, toRef } from 'vue'
111
- import { useButtonGroup } from '../composables/useButtonGroup'
112
- import { useComponentIcons } from '../composables/useComponentIcons'
113
- import { useFormItem } from '../composables/useFormItem'
114
- import { useTheme } from '../composables/useTheme'
115
- import { compare, get, isArrayOfArray } from '../utils'
116
-
5
+ <script setup>
6
+ import { reactivePick } from "@vueuse/core";
7
+ import { defu } from "defu";
8
+ import { SelectArrow, SelectContent, SelectGroup, SelectItem, SelectItemIndicator, SelectItemText, SelectLabel, SelectPortal, SelectRoot, SelectSeparator, SelectTrigger, SelectViewport, useForwardPropsEmits } from "reka-ui";
9
+ import { computed, toRef } from "vue";
10
+ import { useButtonGroup } from "../composables/useButtonGroup";
11
+ import { useComponentIcons } from "../composables/useComponentIcons";
12
+ import { useFormItem } from "../composables/useFormItem";
13
+ import { useTheme } from "../composables/useTheme";
14
+ import { compare, get, isArrayOfArray } from "../utils";
117
15
  defineOptions({
118
- inheritAttrs: false,
119
- })
120
-
121
- const props = withDefaults(defineProps<SelectProps<T, VK, M>>(), {
122
- valueKey: 'value' as never,
123
- labelKey: 'label' as never,
124
- portal: true,
125
- })
126
-
127
- const emit = defineEmits<SelectEmits<T, VK, M>>()
128
- const slots = defineSlots<SelectSlots<T, VK, M>>()
129
-
130
- const rootProps = useForwardPropsEmits(reactivePick(props, 'open', 'defaultOpen', 'disabled', 'autocomplete', 'required', 'multiple'), emit)
131
- const contentProps = toRef(() => defu(props.content, { side: 'bottom', sideOffset: 8, collisionPadding: 8, position: 'popper' }) as SelectContentProps)
132
- const arrowProps = toRef(() => props.arrow as SelectArrowProps)
133
-
134
- const { id, name, size: formItemSize, highlight, disabled, ariaAttrs, emitFormChange, emitFormInput, emitFormBlur, emitFormFocus } = useFormItem<SelectProps<T, VK, M>>(props)
135
- const { size: buttonGroupSize, orientation } = useButtonGroup(props)
136
-
137
- const { theme, generateStyle } = useTheme()
16
+ inheritAttrs: false
17
+ });
18
+ const props = defineProps({
19
+ id: { type: String, required: false },
20
+ placeholder: { type: String, required: false },
21
+ variant: { type: null, required: false },
22
+ size: { type: null, required: false },
23
+ trailingIcon: { type: String, required: false },
24
+ selectedIcon: { type: String, required: false },
25
+ content: { type: Object, required: false },
26
+ arrow: { type: [Boolean, Object], required: false },
27
+ portal: { type: Boolean, required: false, default: true },
28
+ valueKey: { type: null, required: false, default: "value" },
29
+ labelKey: { type: null, required: false, default: "label" },
30
+ options: { type: null, required: false },
31
+ defaultValue: { type: null, required: false },
32
+ modelValue: { type: null, required: false },
33
+ multiple: { type: Boolean, required: false },
34
+ highlight: { type: Boolean, required: false },
35
+ underline: { type: Boolean, required: false },
36
+ class: { type: null, required: false },
37
+ ui: { type: null, required: false },
38
+ icon: { type: String, required: false },
39
+ leading: { type: Boolean, required: false },
40
+ leadingIcon: { type: String, required: false },
41
+ trailing: { type: Boolean, required: false },
42
+ loading: { type: Boolean, required: false },
43
+ loadingIcon: { type: String, required: false },
44
+ open: { type: Boolean, required: false },
45
+ defaultOpen: { type: Boolean, required: false },
46
+ autocomplete: { type: String, required: false },
47
+ disabled: { type: Boolean, required: false },
48
+ name: { type: String, required: false },
49
+ required: { type: Boolean, required: false }
50
+ });
51
+ const emit = defineEmits(["update:open", "change", "blur", "focus", "update:modelValue"]);
52
+ const slots = defineSlots();
53
+ const rootProps = useForwardPropsEmits(reactivePick(props, "open", "defaultOpen", "disabled", "autocomplete", "required", "multiple"), emit);
54
+ const contentProps = toRef(() => defu(props.content, { side: "bottom", sideOffset: 8, collisionPadding: 8, position: "popper" }));
55
+ const arrowProps = toRef(() => props.arrow);
56
+ const { id, name, size: formItemSize, highlight, disabled, ariaAttrs, emitFormChange, emitFormInput, emitFormBlur, emitFormFocus } = useFormItem(props);
57
+ const { size: buttonGroupSize, orientation } = useButtonGroup(props);
58
+ const { theme, generateStyle } = useTheme();
138
59
  const { isLeading, isTrailing, leadingIconName, trailingIconName } = useComponentIcons(toRef(() => defu(props, {
139
- trailingIcon: theme.value.app.icons.chevronDown,
140
- })))
141
-
142
- const style = computed(() => generateStyle('select', {
60
+ trailingIcon: theme.value.app.icons.chevronDown
61
+ })));
62
+ const style = computed(() => generateStyle("select", {
143
63
  ...props,
144
64
  groupOrientation: orientation.value,
145
65
  size: buttonGroupSize.value || formItemSize.value,
146
66
  highlight: highlight.value,
147
67
  leading: isLeading.value,
148
- trailing: isTrailing.value,
149
- }))
150
-
151
- const groups = computed<SelectItem[][]>(
152
- () => props.options?.length
153
- ? isArrayOfArray(props.options) ? props.options : [props.options]
154
- : [],
155
- )
156
-
157
- const items = computed(() => groups.value.flat() as T[])
158
-
159
- function displayValue(value?: MaybeArray<GetItemValue<T, VK>>): string {
68
+ trailing: isTrailing.value
69
+ }));
70
+ const groups = computed(
71
+ () => props.options?.length ? isArrayOfArray(props.options) ? props.options : [props.options] : []
72
+ );
73
+ const items = computed(() => groups.value.flat());
74
+ function displayValue(value) {
160
75
  if (props.multiple && Array.isArray(value))
161
- return value.map((v) => displayValue(v)).filter(Boolean).join(', ')
162
-
163
- const item = items.value.find((item) => compare(typeof item === 'object' ? get(item as Record<string, any>, props.valueKey as string) : item, value))
164
- return (item != null) && (typeof item === 'object' ? get(item, props.labelKey as string) : String(item))
76
+ return value.map((v) => displayValue(v)).filter(Boolean).join(", ");
77
+ const item = items.value.find((item2) => compare(typeof item2 === "object" ? get(item2, props.valueKey) : item2, value));
78
+ return item != null && (typeof item === "object" ? get(item, props.labelKey) : String(item));
165
79
  }
166
-
167
- function isSelectItem(item: SelectItem): item is SelectItemBase {
168
- return typeof item === 'object' && item !== null
80
+ function isSelectItem(item) {
81
+ return typeof item === "object" && item !== null;
169
82
  }
170
-
171
- function onUpdate(value: any) {
172
- // @ts-expect-error - 'target' does not exist in type 'EventInit'
173
- const event = new Event('change', { target: { value } })
174
- emit('change', event)
175
- emitFormChange()
176
- emitFormInput()
83
+ function onUpdate(value) {
84
+ const event = new Event("change", { target: { value } });
85
+ emit("change", event);
86
+ emitFormChange();
87
+ emitFormInput();
177
88
  }
178
-
179
- function onUpdateOpen(value: boolean) {
89
+ function onUpdateOpen(value) {
180
90
  if (value) {
181
- const event = new FocusEvent('focus')
182
- emit('focus', event)
183
- emitFormFocus()
184
- }
185
- else {
186
- const event = new FocusEvent('blur')
187
- emit('blur', event)
188
- emitFormBlur()
91
+ const event = new FocusEvent("focus");
92
+ emit("focus", event);
93
+ emitFormFocus();
94
+ } else {
95
+ const event = new FocusEvent("blur");
96
+ emit("blur", event);
97
+ emitFormBlur();
189
98
  }
190
99
  }
191
100
  </script>
@@ -197,68 +106,69 @@ function onUpdateOpen(value: boolean) {
197
106
  :name="name"
198
107
  :autocomplete="props.autocomplete"
199
108
  :disabled="disabled"
200
- :default-value="(props.defaultValue as MaybeArray<AcceptableValue>)"
201
- :model-value="(props.modelValue as MaybeArray<AcceptableValue>)"
109
+ :default-value="props.defaultValue"
110
+ :model-value="props.modelValue"
202
111
  @update:model-value="onUpdate"
203
112
  @update:open="onUpdateOpen"
204
113
  >
205
- <SelectTrigger v-bind="{ ...$attrs, ...ariaAttrs, id }" :class="style.base({ class: [props.class, props.ui?.base] })">
206
- <span v-if="isLeading || slots.leading" :class="style.leading({ class: props.ui?.leading })">
207
- <slot name="leading" :model-value="(innerValue as GetModelValue<T, VK, M>)" :open="open" :ui="props.ui">
208
- <span v-if="isLeading && leadingIconName" :class="style.leadingIcon({ class: [leadingIconName, props.ui?.leadingIcon] })"></span>
114
+ <SelectTrigger v-bind="{ ...$attrs, ...ariaAttrs, id }" :class="style.base({ class: [props.class, props.ui?.base] })" data-part="base">
115
+ <span v-if="isLeading || slots.leading" :class="style.leading({ class: props.ui?.leading })" data-part="leading">
116
+ <slot name="leading" :model-value="innerValue" :open="open" :ui="props.ui">
117
+ <span v-if="isLeading && leadingIconName" :class="style.leadingIcon({ class: [leadingIconName, props.ui?.leadingIcon] })" data-part="leading-icon"></span>
209
118
  </slot>
210
119
  </span>
211
120
 
212
- <slot :model-value="(innerValue as GetModelValue<T, VK, M>)" :open="open">
213
- <template v-for="displayedModelValue in [displayValue((innerValue as GetModelValue<T, VK, M>))]" :key="displayedModelValue">
214
- <span v-if="displayedModelValue" :class="style.value({ class: props.ui?.value })">
121
+ <slot :model-value="innerValue" :open="open">
122
+ <template v-for="displayedModelValue in [displayValue(innerValue)]" :key="displayedModelValue">
123
+ <span v-if="displayedModelValue" :class="style.value({ class: props.ui?.value })" data-part="value">
215
124
  {{ displayedModelValue }}
216
125
  </span>
217
- <span v-else :class="style.placeholder({ class: props.ui?.placeholder })">
126
+ <span v-else :class="style.placeholder({ class: props.ui?.placeholder })" data-part="placeholder">
218
127
  {{ placeholder }}&nbsp;
219
128
  </span>
220
129
  </template>
221
130
  </slot>
222
131
 
223
- <span v-if="isTrailing || !!slots.trailing" :class="style.trailing({ class: props.ui?.trailing })">
224
- <slot name="trailing" :model-value="(innerValue as GetModelValue<T, VK, M>)" :open="open" :ui="props.ui">
225
- <span v-if="trailingIconName" :class="style.trailingIcon({ class: [trailingIconName, props.ui?.trailingIcon] })"></span>
132
+ <span v-if="isTrailing || !!slots.trailing" :class="style.trailing({ class: props.ui?.trailing })" data-part="trailing">
133
+ <slot name="trailing" :model-value="innerValue" :open="open" :ui="props.ui">
134
+ <span v-if="trailingIconName" :class="style.trailingIcon({ class: [trailingIconName, props.ui?.trailingIcon] })" data-part="trailing-icon"></span>
226
135
  </slot>
227
136
  </span>
228
137
  </SelectTrigger>
229
138
 
230
139
  <SelectPortal :disabled="!props.portal">
231
- <SelectContent v-bind="contentProps" :class="style.content({ class: props.ui?.content })">
232
- <SelectViewport :class="style.viewport({ class: props.ui?.viewport })">
233
- <SelectGroup v-for="(group, groupIndex) in groups" :key="`group-${groupIndex}`" :class="style.group({ class: props.ui?.group })">
140
+ <SelectContent v-bind="contentProps" :class="style.content({ class: props.ui?.content })" data-part="content">
141
+ <SelectViewport :class="style.viewport({ class: props.ui?.viewport })" data-part="viewport">
142
+ <SelectGroup v-for="(group, groupIndex) in groups" :key="`group-${groupIndex}`" :class="style.group({ class: props.ui?.group })" data-part="group">
234
143
  <template v-for="(item, index) in group" :key="`group-${groupIndex}-${index}`">
235
- <SelectLabel v-if="isSelectItem(item) && item.type === 'label'" :class="style.label({ class: props.ui?.label })">
236
- {{ get(item, props.labelKey as string) }}
144
+ <SelectLabel v-if="isSelectItem(item) && item.type === 'label'" :class="style.label({ class: props.ui?.label })" data-part="label">
145
+ {{ get(item, props.labelKey) }}
237
146
  </SelectLabel>
238
- <SelectSeparator v-else-if="isSelectItem(item) && item.type === 'separator'" :class="style.separator({ class: props.ui?.separator })" />
147
+ <SelectSeparator v-else-if="isSelectItem(item) && item.type === 'separator'" :class="style.separator({ class: props.ui?.separator })" data-part="separator" />
239
148
 
240
149
  <SelectItem
241
150
  v-else
242
- :class="style.item({ class: props.ui?.item })"
151
+ :value="isSelectItem(item) ? get(item, props.valueKey) : item"
243
152
  :disabled="isSelectItem(item) && item.disabled"
244
- :value="isSelectItem(item) ? get(item, props.valueKey as string) : item"
153
+ :class="style.item({ class: props.ui?.item })"
154
+ data-part="item"
245
155
  >
246
- <slot name="item" :item="(item as NestedItem<T>)" :index="index">
247
- <slot name="item-leading" :item="(item as NestedItem<T>)" :index="index">
248
- <span v-if="isSelectItem(item) && item.icon" :class="style.itemLeadingIcon({ class: [item.icon, props.ui?.itemLeadingIcon] })"></span>
156
+ <slot name="item" :item="item" :index="index">
157
+ <slot name="item-leading" :item="item" :index="index">
158
+ <span v-if="isSelectItem(item) && item.icon" :class="style.itemLeadingIcon({ class: [item.icon, props.ui?.itemLeadingIcon] })" data-part="item-leading-icon"></span>
249
159
  </slot>
250
160
 
251
- <SelectItemText :class="style.itemLabel({ class: props.ui?.itemLabel })">
252
- <slot name="item-label" :item="(item as NestedItem<T>)" :index="index">
253
- {{ isSelectItem(item) ? get(item, props.labelKey as string) : item }}
161
+ <SelectItemText :class="style.itemLabel({ class: props.ui?.itemLabel })" data-part="item-label">
162
+ <slot name="item-label" :item="item" :index="index">
163
+ {{ isSelectItem(item) ? get(item, props.labelKey) : item }}
254
164
  </slot>
255
165
  </SelectItemText>
256
166
 
257
- <span :class="style.itemTrailing({ class: props.ui?.itemTrailing })">
258
- <slot name="item-trailing" :item="(item as NestedItem<T>)" :index="index"></slot>
167
+ <span :class="style.itemTrailing({ class: props.ui?.itemTrailing })" data-part="item-trailing">
168
+ <slot name="item-trailing" :item="item" :index="index"></slot>
259
169
 
260
170
  <SelectItemIndicator as-child>
261
- <span :class="style.itemTrailingIcon({ class: [props.selectedIcon || theme.app.icons.check, props.ui?.itemTrailingIcon] })"></span>
171
+ <span :class="style.itemTrailingIcon({ class: [props.selectedIcon || theme.app.icons.check, props.ui?.itemTrailingIcon] })" data-part="item-trailing-icon"></span>
262
172
  </SelectItemIndicator>
263
173
  </span>
264
174
  </slot>
@@ -267,7 +177,7 @@ function onUpdateOpen(value: boolean) {
267
177
  </SelectGroup>
268
178
  </SelectViewport>
269
179
 
270
- <SelectArrow v-if="!!props.arrow" v-bind="arrowProps" :class="style.arrow({ class: props.ui?.arrow })" />
180
+ <SelectArrow v-if="!!props.arrow" v-bind="arrowProps" :class="style.arrow({ class: props.ui?.arrow })" data-part="arrow" />
271
181
  </SelectContent>
272
182
  </SelectPortal>
273
183
  </SelectRoot>
@@ -0,0 +1,119 @@
1
+ import type { VariantProps } from '@byyuurin/ui-kit';
2
+ import type { SelectArrowProps, SelectContentEmits, SelectContentProps, SelectRootEmits, SelectRootProps } from 'reka-ui';
3
+ import type { UseComponentIconsProps } from '../composables/useComponentIcons.js';
4
+ import type { select } from '../theme/index.js';
5
+ import type { AcceptableValue, ArrayOrNested, ComponentAttrs, EmitsToProps, GetItemKeys, GetModelValue, GetModelValueEmits, NestedItem } from '../types/index.js';
6
+ interface SelectItemBase {
7
+ label?: string;
8
+ icon?: string;
9
+ /**
10
+ * The option type.
11
+ * @default "option"
12
+ */
13
+ type?: 'label' | 'separator' | 'option';
14
+ value?: AcceptableValue;
15
+ disabled?: boolean;
16
+ [key: string]: any;
17
+ }
18
+ export type SelectItem = SelectItemBase | string | number | boolean;
19
+ export type SelectEmits<T extends ArrayOrNested<SelectItem>, VK extends GetItemKeys<T> | undefined, M extends boolean> = Omit<SelectRootEmits, 'update:modelValue'> & {
20
+ change: [payload: Event];
21
+ blur: [payload: FocusEvent];
22
+ focus: [payload: FocusEvent];
23
+ } & GetModelValueEmits<T, VK, M>;
24
+ type SlotProps<T extends SelectItem> = (props: {
25
+ item: T;
26
+ index: number;
27
+ }) => any;
28
+ export interface SelectSlots<T extends ArrayOrNested<SelectItem> = ArrayOrNested<SelectItem>, VK extends GetItemKeys<T> | undefined = undefined, M extends boolean = false, I extends NestedItem<T> = NestedItem<T>> {
29
+ 'leading'?: (props: {
30
+ modelValue?: GetModelValue<T, VK, M>;
31
+ open: boolean;
32
+ ui: ComponentAttrs<typeof select>['ui'];
33
+ }) => any;
34
+ 'default'?: (props: {
35
+ modelValue?: GetModelValue<T, VK, M>;
36
+ open: boolean;
37
+ }) => any;
38
+ 'trailing'?: (props: {
39
+ modelValue?: GetModelValue<T, VK, M>;
40
+ open: boolean;
41
+ ui: ComponentAttrs<typeof select>['ui'];
42
+ }) => any;
43
+ 'item'?: SlotProps<I>;
44
+ 'item-leading'?: SlotProps<I>;
45
+ 'item-label'?: SlotProps<I>;
46
+ 'item-trailing'?: SlotProps<I>;
47
+ }
48
+ type SelectVariants = VariantProps<typeof select>;
49
+ export interface SelectProps<T extends ArrayOrNested<SelectItem> = ArrayOrNested<SelectItem>, VK extends GetItemKeys<T> = 'value', M extends boolean = false> extends ComponentAttrs<typeof select>, UseComponentIconsProps, Omit<SelectRootProps<T>, 'dir' | 'multiple' | 'modelValue' | 'defaultValue' | 'by'> {
50
+ id?: string;
51
+ /** The placeholder text when the select is empty. */
52
+ placeholder?: string;
53
+ variant?: SelectVariants['variant'];
54
+ size?: SelectVariants['size'];
55
+ /**
56
+ * The icon displayed to open the menu.
57
+ * @default app.icons.chevronDown
58
+ */
59
+ trailingIcon?: string;
60
+ /**
61
+ * The icon displayed when an item is selected.
62
+ * @default app.icons.check
63
+ */
64
+ selectedIcon?: string;
65
+ /**
66
+ * The content of the menu.
67
+ * @default { side: 'bottom', sideOffset: 8, collisionPadding: 8, position: 'popper' }
68
+ */
69
+ content?: Omit<SelectContentProps, 'as' | 'asChild' | 'forceMount'> & Partial<EmitsToProps<SelectContentEmits>>;
70
+ /**
71
+ * Display an arrow alongside the menu.
72
+ * @default false
73
+ */
74
+ arrow?: boolean | Omit<SelectArrowProps, 'as' | 'asChild'>;
75
+ /**
76
+ * Render the menu in a portal.
77
+ * @default true
78
+ */
79
+ portal?: boolean;
80
+ /**
81
+ * When `options` is an array of objects, select the field to use as the value.
82
+ * @default "value"
83
+ */
84
+ valueKey?: VK;
85
+ /**
86
+ * When `options` is an array of objects, select the field to use as the label.
87
+ * @default "label"
88
+ */
89
+ labelKey?: VK;
90
+ options?: T;
91
+ /** The value of the Select when initially rendered. Use when you do not need to control the state of the Select. */
92
+ defaultValue?: GetModelValue<T, VK, M> | null;
93
+ /** The controlled value of the Select. Can be bind as `v-model`. */
94
+ modelValue?: GetModelValue<T, VK, M> | null;
95
+ /** Whether multiple options can be selected or not. */
96
+ multiple?: M & boolean;
97
+ /** Highlight the ring color like a focus state. */
98
+ highlight?: boolean;
99
+ underline?: boolean;
100
+ }
101
+ declare const _default: <T extends ArrayOrNested<SelectItem>, VK extends GetItemKeys<T> = "value", M extends boolean = false>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
102
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
103
+ readonly onBlur?: ((payload: FocusEvent) => any) | undefined;
104
+ readonly onChange?: ((payload: Event) => any) | undefined;
105
+ readonly onFocus?: ((payload: FocusEvent) => any) | undefined;
106
+ readonly "onUpdate:open"?: ((value: boolean) => any) | undefined;
107
+ readonly "onUpdate:modelValue"?: ((payload: GetModelValue<T, VK, M>) => any) | undefined;
108
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onFocus" | "onBlur" | "onChange" | "onUpdate:open" | "onUpdate:modelValue"> & SelectProps<T, VK, M> & Partial<{}>> & import("vue").PublicProps;
109
+ expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
110
+ attrs: any;
111
+ slots: SelectSlots<T, VK, M, NestedItem<T>>;
112
+ emit: ((evt: "blur", payload: FocusEvent) => void) & ((evt: "change", payload: Event) => void) & ((evt: "focus", payload: FocusEvent) => void) & ((evt: "update:open", value: boolean) => void) & ((evt: "update:modelValue", payload: GetModelValue<T, VK, M>) => void);
113
+ }>) => import("vue").VNode & {
114
+ __ctx?: Awaited<typeof __VLS_setup>;
115
+ };
116
+ export default _default;
117
+ type __VLS_PrettifyLocal<T> = {
118
+ [K in keyof T]: T[K];
119
+ } & {};