@byyuurin/ui 0.0.9 → 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 (215) hide show
  1. package/README.md +2 -5
  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 +9323 -3
  6. package/dist/runtime/app/injections.js +35 -0
  7. package/dist/runtime/components/Accordion.vue +36 -69
  8. package/dist/runtime/components/Accordion.vue.d.ts +52 -0
  9. package/dist/runtime/components/Alert.vue +37 -75
  10. package/dist/runtime/components/Alert.vue.d.ts +59 -0
  11. package/dist/runtime/components/App.vue +25 -40
  12. package/dist/runtime/components/App.vue.d.ts +24 -0
  13. package/dist/runtime/components/Avatar.vue +31 -51
  14. package/dist/runtime/components/Avatar.vue.d.ts +25 -0
  15. package/dist/runtime/components/AvatarGroup.vue +38 -69
  16. package/dist/runtime/components/AvatarGroup.vue.d.ts +27 -0
  17. package/dist/runtime/components/Badge.vue +25 -51
  18. package/dist/runtime/components/Badge.vue.d.ts +44 -0
  19. package/dist/runtime/components/Breadcrumb.vue +35 -77
  20. package/dist/runtime/components/Breadcrumb.vue.d.ts +52 -0
  21. package/dist/runtime/components/Button.vue +62 -51
  22. package/dist/runtime/components/Button.vue.d.ts +29 -0
  23. package/dist/runtime/components/ButtonGroup.vue +17 -37
  24. package/dist/runtime/components/ButtonGroup.vue.d.ts +26 -0
  25. package/dist/runtime/components/Calendar.vue +75 -101
  26. package/dist/runtime/components/Calendar.vue.d.ts +75 -0
  27. package/dist/runtime/components/Card.vue +25 -42
  28. package/dist/runtime/components/Card.vue.d.ts +30 -0
  29. package/dist/runtime/components/Carousel.vue +118 -223
  30. package/dist/runtime/components/Carousel.vue.d.ts +104 -0
  31. package/dist/runtime/components/Checkbox.vue +49 -71
  32. package/dist/runtime/components/Checkbox.vue.d.ts +56 -0
  33. package/dist/runtime/components/Chip.vue +31 -48
  34. package/dist/runtime/components/Chip.vue.d.ts +30 -0
  35. package/dist/runtime/components/Collapsible.vue +22 -30
  36. package/dist/runtime/components/Collapsible.vue.d.ts +26 -0
  37. package/dist/runtime/components/Drawer.vue +52 -102
  38. package/dist/runtime/components/Drawer.vue.d.ts +80 -0
  39. package/dist/runtime/components/DropdownMenu.vue +65 -0
  40. package/dist/runtime/components/DropdownMenu.vue.d.ts +99 -0
  41. package/dist/runtime/components/DropdownMenuContent.vue +192 -0
  42. package/dist/runtime/components/DropdownMenuContent.vue.d.ts +39 -0
  43. package/dist/runtime/components/Form.vue +197 -0
  44. package/dist/runtime/components/Form.vue.d.ts +78 -0
  45. package/dist/runtime/components/FormItem.vue +90 -0
  46. package/dist/runtime/components/FormItem.vue.d.ts +60 -0
  47. package/dist/runtime/components/Input.vue +93 -115
  48. package/dist/runtime/components/Input.vue.d.ts +64 -0
  49. package/dist/runtime/components/InputNumber.vue +81 -116
  50. package/dist/runtime/components/InputNumber.vue.d.ts +245 -0
  51. package/dist/runtime/components/Kbd.vue +18 -39
  52. package/dist/runtime/components/Kbd.vue.d.ts +28 -0
  53. package/dist/runtime/components/Link.vue +170 -244
  54. package/dist/runtime/components/Link.vue.d.ts +95 -0
  55. package/dist/runtime/components/LinkBase.vue +36 -54
  56. package/dist/runtime/components/LinkBase.vue.d.ts +28 -0
  57. package/dist/runtime/components/Modal.vue +50 -85
  58. package/dist/runtime/components/Modal.vue.d.ts +66 -0
  59. package/dist/runtime/components/OverlayProvider.vue +10 -14
  60. package/dist/runtime/components/OverlayProvider.vue.d.ts +2 -0
  61. package/dist/runtime/components/Pagination.vue +55 -121
  62. package/dist/runtime/components/Pagination.vue.d.ts +93 -0
  63. package/dist/runtime/components/PinInput.vue +57 -57
  64. package/dist/runtime/components/PinInput.vue.d.ts +35 -0
  65. package/dist/runtime/components/Popover.vue +39 -68
  66. package/dist/runtime/components/Popover.vue.d.ts +45 -0
  67. package/dist/runtime/components/Progress.vue +68 -120
  68. package/dist/runtime/components/Progress.vue.d.ts +54 -0
  69. package/dist/runtime/components/RadioGroup.vue +75 -129
  70. package/dist/runtime/components/RadioGroup.vue.d.ts +74 -0
  71. package/dist/runtime/components/ScrollArea.vue +31 -31
  72. package/dist/runtime/components/ScrollArea.vue.d.ts +17 -0
  73. package/dist/runtime/components/Select.vue +119 -199
  74. package/dist/runtime/components/Select.vue.d.ts +119 -0
  75. package/dist/runtime/components/Separator.vue +26 -44
  76. package/dist/runtime/components/Separator.vue.d.ts +27 -0
  77. package/dist/runtime/components/Skeleton.vue +12 -21
  78. package/dist/runtime/components/Skeleton.vue.d.ts +19 -0
  79. package/dist/runtime/components/Slider.vue +54 -71
  80. package/dist/runtime/components/Slider.vue.d.ts +36 -0
  81. package/dist/runtime/components/Switch.vue +54 -68
  82. package/dist/runtime/components/Switch.vue.d.ts +49 -0
  83. package/dist/runtime/components/Table.vue +113 -186
  84. package/dist/runtime/components/Table.vue.d.ts +148 -0
  85. package/dist/runtime/components/Tabs.vue +35 -79
  86. package/dist/runtime/components/Tabs.vue.d.ts +65 -0
  87. package/dist/runtime/components/Textarea.vue +82 -123
  88. package/dist/runtime/components/Textarea.vue.d.ts +60 -0
  89. package/dist/runtime/components/Toast.vue +51 -76
  90. package/dist/runtime/components/Toast.vue.d.ts +131 -0
  91. package/dist/runtime/components/ToastProvider.vue +65 -101
  92. package/dist/runtime/components/ToastProvider.vue.d.ts +38 -0
  93. package/dist/runtime/components/Tooltip.vue +36 -47
  94. package/dist/runtime/components/Tooltip.vue.d.ts +31 -0
  95. package/dist/runtime/composables/useAvatarGroup.d.ts +1 -1
  96. package/dist/runtime/composables/useButtonGroup.d.ts +2 -2
  97. package/dist/runtime/composables/useFormItem.d.ts +27 -0
  98. package/dist/runtime/composables/useFormItem.js +64 -0
  99. package/dist/runtime/composables/useKbd.d.ts +1 -1
  100. package/dist/runtime/composables/useLocale.d.ts +3 -3
  101. package/dist/runtime/composables/useTheme.d.ts +1 -1
  102. package/dist/runtime/composables/useTheme.js +2 -1
  103. package/dist/runtime/composables/useToast.d.ts +1 -1
  104. package/dist/runtime/index.d.ts +3 -0
  105. package/dist/runtime/index.js +3 -0
  106. package/dist/runtime/locale/en.d.ts +1 -1
  107. package/dist/runtime/locale/zh-tw.d.ts +1 -1
  108. package/dist/runtime/theme/accordion.d.ts +45 -51
  109. package/dist/runtime/theme/accordion.js +1 -1
  110. package/dist/runtime/theme/alert.d.ts +115 -121
  111. package/dist/runtime/theme/alert.js +1 -1
  112. package/dist/runtime/theme/app.d.ts +1 -0
  113. package/dist/runtime/theme/app.js +2 -1
  114. package/dist/runtime/theme/avatar-group.d.ts +42 -48
  115. package/dist/runtime/theme/avatar-group.js +1 -1
  116. package/dist/runtime/theme/avatar.d.ts +46 -52
  117. package/dist/runtime/theme/avatar.js +1 -1
  118. package/dist/runtime/theme/badge.d.ts +63 -93
  119. package/dist/runtime/theme/badge.js +1 -1
  120. package/dist/runtime/theme/breadcrumb.d.ts +52 -58
  121. package/dist/runtime/theme/breadcrumb.js +1 -1
  122. package/dist/runtime/theme/button-group.d.ts +36 -42
  123. package/dist/runtime/theme/button.d.ts +165 -117
  124. package/dist/runtime/theme/button.js +1 -1
  125. package/dist/runtime/theme/calendar.d.ts +52 -50
  126. package/dist/runtime/theme/calendar.js +20 -3
  127. package/dist/runtime/theme/card.d.ts +52 -58
  128. package/dist/runtime/theme/card.js +1 -1
  129. package/dist/runtime/theme/carousel.d.ts +98 -104
  130. package/dist/runtime/theme/carousel.js +1 -1
  131. package/dist/runtime/theme/checkbox.d.ts +77 -83
  132. package/dist/runtime/theme/checkbox.js +1 -1
  133. package/dist/runtime/theme/chip.d.ts +50 -89
  134. package/dist/runtime/theme/chip.js +1 -1
  135. package/dist/runtime/theme/collapsible.d.ts +29 -35
  136. package/dist/runtime/theme/collapsible.js +1 -1
  137. package/dist/runtime/theme/drawer.d.ts +131 -102
  138. package/dist/runtime/theme/drawer.js +1 -1
  139. package/dist/runtime/theme/dropdown-menu.d.ts +65 -0
  140. package/dist/runtime/theme/dropdown-menu.js +83 -0
  141. package/dist/runtime/theme/form-item.d.ts +70 -0
  142. package/dist/runtime/theme/form-item.js +34 -0
  143. package/dist/runtime/theme/form.d.ts +2 -0
  144. package/dist/runtime/theme/form.js +7 -0
  145. package/dist/runtime/theme/index.d.ts +3 -0
  146. package/dist/runtime/theme/index.js +3 -0
  147. package/dist/runtime/theme/input-number.d.ts +100 -126
  148. package/dist/runtime/theme/input-number.js +1 -1
  149. package/dist/runtime/theme/input.d.ts +153 -131
  150. package/dist/runtime/theme/input.js +3 -3
  151. package/dist/runtime/theme/kbd.d.ts +30 -36
  152. package/dist/runtime/theme/link.d.ts +37 -43
  153. package/dist/runtime/theme/modal.d.ts +35 -69
  154. package/dist/runtime/theme/modal.js +1 -1
  155. package/dist/runtime/theme/pagination.d.ts +71 -77
  156. package/dist/runtime/theme/pagination.js +1 -1
  157. package/dist/runtime/theme/pinInput.d.ts +82 -88
  158. package/dist/runtime/theme/pinInput.js +2 -2
  159. package/dist/runtime/theme/popover.d.ts +29 -35
  160. package/dist/runtime/theme/popover.js +1 -1
  161. package/dist/runtime/theme/progress.d.ts +167 -109
  162. package/dist/runtime/theme/progress.js +1 -1
  163. package/dist/runtime/theme/radio-group.d.ts +99 -105
  164. package/dist/runtime/theme/radio-group.js +1 -1
  165. package/dist/runtime/theme/scroll-area.d.ts +62 -68
  166. package/dist/runtime/theme/scroll-area.js +1 -1
  167. package/dist/runtime/theme/select.d.ts +168 -158
  168. package/dist/runtime/theme/select.js +3 -2
  169. package/dist/runtime/theme/separator.d.ts +64 -85
  170. package/dist/runtime/theme/separator.js +1 -1
  171. package/dist/runtime/theme/skeleton.d.ts +1 -7
  172. package/dist/runtime/theme/slider.d.ts +62 -68
  173. package/dist/runtime/theme/slider.js +1 -1
  174. package/dist/runtime/theme/switch.d.ts +111 -117
  175. package/dist/runtime/theme/switch.js +1 -1
  176. package/dist/runtime/theme/table.d.ts +75 -78
  177. package/dist/runtime/theme/table.js +3 -2
  178. package/dist/runtime/theme/tabs.d.ts +116 -139
  179. package/dist/runtime/theme/tabs.js +1 -1
  180. package/dist/runtime/theme/textarea.d.ts +78 -90
  181. package/dist/runtime/theme/textarea.js +2 -2
  182. package/dist/runtime/theme/toast-provider.d.ts +110 -131
  183. package/dist/runtime/theme/toast-provider.js +1 -1
  184. package/dist/runtime/theme/toast.d.ts +74 -80
  185. package/dist/runtime/theme/toast.js +1 -1
  186. package/dist/runtime/theme/tooltip.d.ts +35 -41
  187. package/dist/runtime/theme/tooltip.js +1 -1
  188. package/dist/runtime/types/components.d.ts +3 -0
  189. package/dist/runtime/types/form.d.ts +45 -0
  190. package/dist/runtime/types/form.js +0 -0
  191. package/dist/runtime/types/index.d.ts +5 -2
  192. package/dist/runtime/types/index.js +1 -0
  193. package/dist/runtime/types/utils.d.ts +37 -16
  194. package/dist/runtime/utils/extend-theme.js +15 -4
  195. package/dist/runtime/utils/form.d.ts +5 -0
  196. package/dist/runtime/utils/form.js +24 -0
  197. package/dist/runtime/utils/index.d.ts +2 -0
  198. package/dist/runtime/utils/index.js +4 -0
  199. package/dist/runtime/utils/link.d.ts +4 -28
  200. package/dist/runtime/utils/link.js +10 -3
  201. package/dist/runtime/utils/styler.d.ts +2 -2
  202. package/dist/runtime/utils/styler.js +2 -2
  203. package/dist/shared/ui.D1BTWZFB.mjs +5 -0
  204. package/dist/shared/ui.D1BTWZFB.mjs.map +1 -0
  205. package/dist/types.d.mts +1 -1
  206. package/dist/unocss.mjs +7 -6
  207. package/dist/unocss.mjs.map +1 -1
  208. package/dist/unplugin.mjs +1 -1
  209. package/dist/unplugin.mjs.map +1 -1
  210. package/dist/vite.mjs +1 -1
  211. package/package.json +78 -74
  212. package/dist/module.cjs +0 -5
  213. package/dist/shared/ui.1a1f119c.mjs +0 -5
  214. package/dist/shared/ui.1a1f119c.mjs.map +0 -1
  215. package/dist/types.d.ts +0 -1
@@ -0,0 +1,78 @@
1
+ import type { ComputedRef, DeepReadonly, Ref } from 'vue';
2
+ import type { form } from '../theme/index.js';
3
+ import type { ComponentAttrs, FormError, FormErrorEvent, FormErrorWithId, FormInputEvents, FormSchema, FormSubmitEvent, FormValidateOptions } from '../types/index.js';
4
+ export interface FormEmits<T extends object> {
5
+ submit: [payload: FormSubmitEvent<T>];
6
+ error: [payload: FormErrorEvent];
7
+ }
8
+ export interface FormSlots {
9
+ default?: (props?: {
10
+ errors: FormError[];
11
+ }) => any;
12
+ }
13
+ export interface FormExpose<T extends object> {
14
+ validate: (options?: FormValidateOptions<T>) => Promise<T | false>;
15
+ clear: (path?: string) => void;
16
+ errors: Ref<FormError[]>;
17
+ setErrors: (errors: FormError[], name?: keyof T) => void;
18
+ getErrors: (name?: keyof T) => FormError[];
19
+ submit: () => Promise<void>;
20
+ disabled: ComputedRef<boolean>;
21
+ dirty: ComputedRef<boolean>;
22
+ dirtyFields: DeepReadonly<Set<keyof T>>;
23
+ touchedFields: DeepReadonly<Set<keyof T>>;
24
+ blurredFields: DeepReadonly<Set<keyof T>>;
25
+ }
26
+ export interface FormProps<T extends object> extends Omit<ComponentAttrs<typeof form>, 'ui'> {
27
+ id?: string | number;
28
+ /** Schema to validate the form state. */
29
+ schema?: FormSchema<T>;
30
+ /** An object representing the current state of the form. */
31
+ state: Partial<T>;
32
+ /**
33
+ * Custom validation function to validate the form state.
34
+ * @param state - The current state of the form.
35
+ * @returns A promise that resolves to an array of FormError objects, or an array of FormError objects directly.
36
+ */
37
+ validate?: (state: Partial<T>) => Promise<FormError[]> | FormError[];
38
+ /**
39
+ * The list of input events that trigger the form validation.
40
+ * @default ["blur", "change", "input"]
41
+ */
42
+ validateOn?: FormInputEvents[];
43
+ /** Disable all inputs inside the form. */
44
+ disabled?: boolean;
45
+ /**
46
+ * Delay in milliseconds before validating the form on input events.
47
+ * @default 300
48
+ */
49
+ validateOnInputDelay?: number;
50
+ /**
51
+ * If true, schema transformations will be applied to the state on submit.
52
+ * @default true
53
+ */
54
+ transform?: boolean;
55
+ onSubmit?: ((event: FormSubmitEvent<T>) => void | Promise<void>) | (() => void | Promise<void>);
56
+ }
57
+ export declare class FormValidationExceptionError extends Error {
58
+ formId: string | number;
59
+ errors: FormErrorWithId[];
60
+ children?: FormValidationExceptionError[];
61
+ constructor(formId: string | number, errors: FormErrorWithId[], childErrors?: FormValidationExceptionError[]);
62
+ }
63
+ declare const _default: <T extends object>(__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<{
64
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
65
+ readonly onError?: ((payload: FormErrorEvent) => any) | undefined;
66
+ readonly onSubmit?: ((payload: FormSubmitEvent<T>) => any) | undefined;
67
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onSubmit" | "onError"> & FormProps<T> & Partial<{}>> & import("vue").PublicProps;
68
+ expose(exposed: import("vue").ShallowUnwrapRef<FormExpose<T>>): void;
69
+ attrs: any;
70
+ slots: FormSlots;
71
+ emit: ((evt: "error", payload: FormErrorEvent) => void) & ((evt: "submit", payload: FormSubmitEvent<T>) => void);
72
+ }>) => import("vue").VNode & {
73
+ __ctx?: Awaited<typeof __VLS_setup>;
74
+ };
75
+ export default _default;
76
+ type __VLS_PrettifyLocal<T> = {
77
+ [K in keyof T]: T[K];
78
+ } & {};
@@ -0,0 +1,90 @@
1
+ <script>
2
+
3
+ </script>
4
+
5
+ <script setup>
6
+ import { Label, Primitive } from "reka-ui";
7
+ import { computed, ref, useId } from "vue";
8
+ import { injectFormErrors, provideFormInputId, provideFormItem } from "../app/injections";
9
+ import { useTheme } from "../composables/useTheme";
10
+ const props = defineProps({
11
+ as: { type: null, required: false },
12
+ name: { type: String, required: false },
13
+ errorPattern: { type: null, required: false },
14
+ label: { type: String, required: false },
15
+ description: { type: String, required: false },
16
+ help: { type: String, required: false },
17
+ error: { type: [String, Boolean], required: false },
18
+ hint: { type: String, required: false },
19
+ size: { type: null, required: false },
20
+ required: { type: Boolean, required: false },
21
+ eagerValidation: { type: Boolean, required: false },
22
+ validateOnInputDelay: { type: Number, required: false },
23
+ class: { type: null, required: false },
24
+ ui: { type: null, required: false }
25
+ });
26
+ const slots = defineSlots();
27
+ const id = ref(useId());
28
+ const ariaId = id.value;
29
+ provideFormInputId(id);
30
+ const formErrors = injectFormErrors();
31
+ const error = computed(() => {
32
+ if (props.error)
33
+ return props.error;
34
+ const formError = formErrors?.value.find((error2) => {
35
+ if (error2.name && error2.name === props.name)
36
+ return true;
37
+ if (error2.name && props.errorPattern)
38
+ return error2.name.match(props.errorPattern);
39
+ return false;
40
+ });
41
+ return formError?.message;
42
+ });
43
+ provideFormItem(computed(() => ({
44
+ ...props,
45
+ error: error.value,
46
+ ariaId
47
+ })));
48
+ const { generateStyle } = useTheme();
49
+ const style = computed(() => generateStyle("formItem", props));
50
+ </script>
51
+
52
+ <template>
53
+ <Primitive :as="props.as" :class="style.root({ class: [props.class, props.ui?.root] })" data-part="root">
54
+ <div :class="style.wrapper({ class: props.ui?.wrapper })" data-part="wrapper">
55
+ <div v-if="props.label || slots.label" :class="style.labelWrapper({ class: props.ui?.labelWrapper })" data-part="label-wrapper">
56
+ <Label :for="id" :class="style.label({ class: props.ui?.label })" data-part="label">
57
+ <slot name="label" :label="props.label">
58
+ {{ props.label }}
59
+ </slot>
60
+ </Label>
61
+ <span v-if="props.hint || slots.hint" :id="`${ariaId}-hint`" :class="style.hint({ class: props.ui?.hint })" data-part="hint">
62
+ <slot name="hint" :hint="props.hint">
63
+ {{ props.hint }}
64
+ </slot>
65
+ </span>
66
+ </div>
67
+
68
+ <p v-if="props.description || slots.description" :id="`${ariaId}-description`" :class="style.description({ class: props.ui?.description })" data-part="description">
69
+ <slot name="description" :description="props.description">
70
+ {{ props.description }}
71
+ </slot>
72
+ </p>
73
+ </div>
74
+
75
+ <div :class="(props.label || slots.label || props.description || slots.description) && style.container({ class: props.ui?.container })" data-part="container">
76
+ <slot :error="error"></slot>
77
+
78
+ <p v-if="typeof error === 'string' && error || slots.error" :id="`${ariaId}-error`" :class="style.error({ class: props.ui?.error })" data-part="error">
79
+ <slot name="error" :error="error">
80
+ {{ error }}
81
+ </slot>
82
+ </p>
83
+ <p v-else :class="style.help({ class: props.ui?.help })" data-part="help">
84
+ <slot name="help" :help="props.help">
85
+ {{ help }}
86
+ </slot>
87
+ </p>
88
+ </div>
89
+ </Primitive>
90
+ </template>
@@ -0,0 +1,60 @@
1
+ import type { VariantProps } from '@byyuurin/ui-kit';
2
+ import type { PrimitiveProps } from 'reka-ui';
3
+ import type { formItem } from '../theme/index.js';
4
+ import type { ComponentAttrs } from '../types/index.js';
5
+ export interface FormFieldSlots {
6
+ label?: (props: {
7
+ label?: string;
8
+ }) => any;
9
+ hint?: (props: {
10
+ hint?: string;
11
+ }) => any;
12
+ description?: (props: {
13
+ description?: string;
14
+ }) => any;
15
+ help?: (props: {
16
+ help?: string;
17
+ }) => any;
18
+ error?: (props: {
19
+ error?: string | boolean;
20
+ }) => any;
21
+ default?: (props: {
22
+ error?: string | boolean;
23
+ }) => any;
24
+ }
25
+ type FormItemVariants = VariantProps<typeof formItem>;
26
+ export interface FormItemProps extends ComponentAttrs<typeof formItem> {
27
+ /**
28
+ * The element or component this component should render as.
29
+ * @default "div"
30
+ */
31
+ as?: PrimitiveProps['as'];
32
+ /** The name of the FormItem. Also used to match form errors. */
33
+ name?: string;
34
+ /** A regular expression to match form error names. */
35
+ errorPattern?: RegExp;
36
+ label?: string;
37
+ description?: string;
38
+ help?: string;
39
+ error?: string | boolean;
40
+ hint?: string;
41
+ /**
42
+ * @default 'md'
43
+ */
44
+ size?: FormItemVariants['size'];
45
+ required?: boolean;
46
+ /** If true, validation on input will be active immediately instead of waiting for a blur event. */
47
+ eagerValidation?: boolean;
48
+ /**
49
+ * Delay in milliseconds before validating the form on input events.
50
+ * @default 300
51
+ */
52
+ validateOnInputDelay?: number;
53
+ }
54
+ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<FormItemProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<FormItemProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, FormFieldSlots>;
55
+ export default _default;
56
+ type __VLS_WithSlots<T, S> = T & {
57
+ new (): {
58
+ $slots: S;
59
+ };
60
+ };
@@ -1,173 +1,151 @@
1
- <script lang="ts">
2
- import type { VariantProps } from '@byyuurin/ui-kit'
3
- import type { PrimitiveProps } from 'reka-ui'
4
- import type { InputHTMLAttributes } from 'vue'
5
- import type { UseComponentIconsProps } from '../composables/useComponentIcons'
6
- import type { input } from '../theme'
7
- import type { ComponentAttrs } from '../types'
1
+ <script>
8
2
 
9
- export interface InputEmits {
10
- (e: 'update:modelValue', payload: string | number): void
11
- (e: 'blur', event: FocusEvent): void
12
- (e: 'change', event: Event): void
13
- }
14
-
15
- export interface InputSlots {
16
- leading?: (props?: {}) => any
17
- default?: (props?: {}) => any
18
- trailing?: (props?: {}) => any
19
- }
20
-
21
- type InputVariants = VariantProps<typeof input>
22
-
23
- export interface InputProps extends ComponentAttrs<typeof input>, UseComponentIconsProps {
24
- /**
25
- * The element or component this component should render as.
26
- * @default "div"
27
- */
28
- as?: PrimitiveProps['as']
29
- id?: string
30
- name?: string
31
- type?: InputHTMLAttributes['type']
32
- placeholder?: string
33
- size?: InputVariants['size']
34
- variant?: InputVariants['variant']
35
- loading?: boolean
36
- highlight?: boolean
37
- underline?: boolean
38
- required?: boolean
39
- autocomplete?: InputHTMLAttributes['autocomplete']
40
- autofocus?: boolean
41
- autofocusDelay?: number
42
- disabled?: boolean
43
- }
44
3
  </script>
45
4
 
46
- <script setup lang="ts">
47
- import { Primitive } from 'reka-ui'
48
- import { computed, onMounted, ref } from 'vue'
49
- import { useButtonGroup } from '../composables/useButtonGroup'
50
- import { useComponentIcons } from '../composables/useComponentIcons'
51
- import { useTheme } from '../composables/useTheme'
52
- import { looseToNumber } from '../utils'
53
-
5
+ <script setup>
6
+ import { Primitive } from "reka-ui";
7
+ import { computed, onMounted, ref } from "vue";
8
+ import { useButtonGroup } from "../composables/useButtonGroup";
9
+ import { useComponentIcons } from "../composables/useComponentIcons";
10
+ import { useFormItem } from "../composables/useFormItem";
11
+ import { useTheme } from "../composables/useTheme";
12
+ import { looseToNumber } from "../utils";
54
13
  defineOptions({
55
- inheritAttrs: false,
56
- })
57
-
58
- const props = withDefaults(defineProps<InputProps>(), {
59
- type: 'text',
60
- variant: 'outline',
61
- autocomplete: 'off',
62
- autofocusDelay: 0,
63
- })
64
-
65
- const emit = defineEmits<InputEmits>()
66
- const slots = defineSlots<InputSlots>()
67
- const [modelValue, modelModifiers] = defineModel<string | number>()
68
-
69
- const inputRef = ref<HTMLInputElement | null>(null)
70
-
71
- const { size, orientation } = useButtonGroup(props)
72
- const { isLeading, leadingIconName, isTrailing, trailingIconName } = useComponentIcons(props)
73
-
74
- const { generateStyle } = useTheme()
75
- const style = computed(() => generateStyle('input', {
14
+ inheritAttrs: false
15
+ });
16
+ const props = defineProps({
17
+ as: { type: null, required: false },
18
+ id: { type: String, required: false },
19
+ name: { type: String, required: false },
20
+ type: { type: null, required: false, default: "text" },
21
+ placeholder: { type: String, required: false },
22
+ size: { type: null, required: false },
23
+ variant: { type: null, required: false, default: "outline" },
24
+ loading: { type: Boolean, required: false },
25
+ highlight: { type: Boolean, required: false },
26
+ underline: { type: Boolean, required: false },
27
+ required: { type: Boolean, required: false },
28
+ autocomplete: { type: null, required: false, default: "off" },
29
+ autofocus: { type: Boolean, required: false },
30
+ autofocusDelay: { type: Number, required: false, default: 0 },
31
+ disabled: { type: Boolean, required: false },
32
+ class: { type: null, required: false },
33
+ ui: { type: null, required: false },
34
+ icon: { type: String, required: false },
35
+ leading: { type: Boolean, required: false },
36
+ leadingIcon: { type: String, required: false },
37
+ trailing: { type: Boolean, required: false },
38
+ trailingIcon: { type: String, required: false },
39
+ loadingIcon: { type: String, required: false }
40
+ });
41
+ const emit = defineEmits(["update:modelValue", "blur", "change"]);
42
+ const slots = defineSlots();
43
+ const [modelValue, modelModifiers] = defineModel({ type: [String, Number] });
44
+ const inputRef = ref(null);
45
+ const {
46
+ size: formItemSize,
47
+ id,
48
+ name,
49
+ highlight,
50
+ disabled,
51
+ ariaAttrs,
52
+ emitFormBlur,
53
+ emitFormInput,
54
+ emitFormChange,
55
+ emitFormFocus
56
+ } = useFormItem(props, { deferInputValidation: true });
57
+ const { size: buttonGroupSize, orientation } = useButtonGroup(props);
58
+ const { isLeading, leadingIconName, isTrailing, trailingIconName } = useComponentIcons(props);
59
+ const { generateStyle } = useTheme();
60
+ const style = computed(() => generateStyle("input", {
76
61
  ...props,
77
- // @ts-expect-error ignore type
78
62
  type: props.type,
79
- size: size.value,
63
+ size: buttonGroupSize.value || formItemSize.value,
64
+ highlight: highlight.value,
80
65
  groupOrientation: orientation.value,
81
66
  leading: isLeading.value || !!slots.leading,
82
- trailing: isTrailing.value || !!slots.trailing,
83
- }))
84
-
67
+ trailing: isTrailing.value || !!slots.trailing
68
+ }));
85
69
  function autoFocus() {
86
70
  if (props.autofocus)
87
- inputRef.value?.focus()
71
+ inputRef.value?.focus();
88
72
  }
89
-
90
- function updateInput(value: string) {
73
+ function updateInput(value) {
91
74
  if (modelModifiers.trim)
92
- value = value.trim()
93
-
94
- if (modelModifiers.number || props.type === 'number')
95
- value = looseToNumber(value)
96
-
97
- modelValue.value = value
75
+ value = value.trim();
76
+ if (modelModifiers.number || props.type === "number")
77
+ value = looseToNumber(value);
78
+ modelValue.value = value;
79
+ emitFormInput();
98
80
  }
99
-
100
- function onInput(event: Event) {
81
+ function onInput(event) {
101
82
  if (!modelModifiers.lazy)
102
- updateInput((event.target as HTMLInputElement).value)
83
+ updateInput(event.target.value);
103
84
  }
104
-
105
- function onChange(event: Event) {
106
- const value = (event.target as HTMLInputElement).value
107
-
85
+ function onChange(event) {
86
+ const value = event.target.value;
108
87
  if (modelModifiers.lazy)
109
- updateInput(value)
110
-
88
+ updateInput(value);
111
89
  if (modelModifiers.trim)
112
- (event.target as HTMLInputElement).value = value.trim()
113
-
114
- emit('change', event)
90
+ event.target.value = value.trim();
91
+ emit("change", event);
92
+ emitFormChange();
115
93
  }
116
-
117
- function onBlur(event: FocusEvent) {
118
- emit('blur', event)
94
+ function onBlur(event) {
95
+ emit("blur", event);
96
+ emitFormBlur();
119
97
  }
120
-
121
98
  defineExpose({
122
- inputRef,
123
- })
124
-
99
+ inputRef
100
+ });
125
101
  onMounted(() => {
126
102
  setTimeout(() => {
127
- autoFocus()
128
- }, props.autofocusDelay)
129
- })
103
+ autoFocus();
104
+ }, props.autofocusDelay);
105
+ });
130
106
  </script>
131
107
 
132
108
  <template>
133
109
  <Primitive
134
110
  :as="as"
111
+ :aria-disabled="disabled ? true : void 0"
135
112
  :class="style.base({ class: [props.class, props.ui?.base] })"
136
- :aria-disabled="props.disabled ? true : undefined"
113
+ :data-part="$attrs['data-part'] ?? 'base'"
137
114
  >
138
- <span v-if="isLeading || slots.leading" :class="style.leading({ class: props.ui?.leading })">
115
+ <span v-if="isLeading || slots.leading" :class="style.leading({ class: props.ui?.leading })" data-part="leading">
139
116
  <slot name="leading">
140
117
  <span
141
118
  v-if="isLeading && leadingIconName"
142
119
  :class="style.leadingIcon({ class: [leadingIconName, props.ui?.leadingIcon] })"
120
+ data-part="leading-icon"
143
121
  ></span>
144
122
  </slot>
145
123
  </span>
146
124
 
147
125
  <input
148
- :id="id"
149
126
  ref="inputRef"
127
+ :class="style.input({ class: props.ui?.input })"
128
+ data-part="input"
150
129
  :type="props.type"
151
130
  :value="modelValue"
152
- :name="props.name"
153
131
  :placeholder="props.placeholder"
154
- :class="style.input({ class: props.ui?.input })"
155
- :disabled="props.disabled"
156
132
  :required="props.required"
157
133
  :autocomplete="props.autocomplete"
158
- v-bind="$attrs"
134
+ v-bind="{ ...$attrs, ...ariaAttrs, id, name, disabled }"
159
135
  @input="onInput"
160
136
  @blur="onBlur"
161
137
  @change="onChange"
138
+ @focus="emitFormFocus"
162
139
  />
163
140
 
164
141
  <slot></slot>
165
142
 
166
- <span v-if="isTrailing || slots.trailing" :class="style.trailing({ class: props.ui?.trailing })">
143
+ <span v-if="isTrailing || slots.trailing" :class="style.trailing({ class: props.ui?.trailing })" data-part="trailing">
167
144
  <slot name="trailing">
168
145
  <span
169
146
  v-if="isTrailing && trailingIconName"
170
147
  :class="style.trailingIcon({ class: [trailingIconName, props.ui?.trailingIcon] })"
148
+ data-part="trailing-icon"
171
149
  ></span>
172
150
  </slot>
173
151
  </span>
@@ -0,0 +1,64 @@
1
+ import type { VariantProps } from '@byyuurin/ui-kit';
2
+ import type { PrimitiveProps } from 'reka-ui';
3
+ import type { InputHTMLAttributes } from 'vue';
4
+ import type { UseComponentIconsProps } from '../composables/useComponentIcons.js';
5
+ import type { input } from '../theme/index.js';
6
+ import type { ComponentAttrs } from '../types/index.js';
7
+ export interface InputEmits {
8
+ 'update:modelValue': [payload: string | number];
9
+ 'blur': [event: FocusEvent];
10
+ 'change': [event: Event];
11
+ }
12
+ export interface InputSlots {
13
+ leading?: (props?: {}) => any;
14
+ default?: (props?: {}) => any;
15
+ trailing?: (props?: {}) => any;
16
+ }
17
+ type InputVariants = VariantProps<typeof input>;
18
+ export interface InputProps extends ComponentAttrs<typeof input>, UseComponentIconsProps {
19
+ /**
20
+ * The element or component this component should render as.
21
+ * @default "div"
22
+ */
23
+ as?: PrimitiveProps['as'];
24
+ id?: string;
25
+ name?: string;
26
+ type?: InputHTMLAttributes['type'];
27
+ placeholder?: string;
28
+ size?: InputVariants['size'];
29
+ variant?: InputVariants['variant'];
30
+ loading?: boolean;
31
+ highlight?: boolean;
32
+ underline?: boolean;
33
+ required?: boolean;
34
+ autocomplete?: InputHTMLAttributes['autocomplete'];
35
+ autofocus?: boolean;
36
+ autofocusDelay?: number;
37
+ disabled?: boolean;
38
+ }
39
+ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<InputProps & {
40
+ modelValue?: string | number;
41
+ }, {
42
+ inputRef: import("vue").Ref<HTMLInputElement | null, HTMLInputElement | null>;
43
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
44
+ blur: (event: FocusEvent) => any;
45
+ change: (event: Event) => any;
46
+ "update:modelValue": (...args: unknown[]) => any;
47
+ }, string, import("vue").PublicProps, Readonly<InputProps & {
48
+ modelValue?: string | number;
49
+ }> & Readonly<{
50
+ onBlur?: ((event: FocusEvent) => any) | undefined;
51
+ onChange?: ((event: Event) => any) | undefined;
52
+ "onUpdate:modelValue"?: ((...args: unknown[]) => any) | undefined;
53
+ }>, {
54
+ variant: "outline" | "soft" | "soft-outline" | "ghost" | "none";
55
+ type: import("vue").InputTypeHTMLAttribute;
56
+ autocomplete: string;
57
+ autofocusDelay: number;
58
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, InputSlots>;
59
+ export default _default;
60
+ type __VLS_WithSlots<T, S> = T & {
61
+ new (): {
62
+ $slots: S;
63
+ };
64
+ };