@witchcraft/ui 0.0.1
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/README.md +236 -0
- package/dist/module.cjs +5 -0
- package/dist/module.d.mts +34 -0
- package/dist/module.d.ts +34 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +124 -0
- package/dist/runtime/assets/base.css +1 -0
- package/dist/runtime/assets/locales/en.json +33 -0
- package/dist/runtime/assets/style.css +1 -0
- package/dist/runtime/assets/tailwind.css +1 -0
- package/dist/runtime/assets/theme.css +1 -0
- package/dist/runtime/build/WitchcraftUiResolver.d.ts +5 -0
- package/dist/runtime/build/WitchcraftUiResolver.js +17 -0
- package/dist/runtime/build/generateTheme.d.ts +1 -0
- package/dist/runtime/build/generateTheme.js +14 -0
- package/dist/runtime/build/unpluginIconViteOptions.d.ts +2 -0
- package/dist/runtime/build/unpluginIconViteOptions.js +10 -0
- package/dist/runtime/components/Aria/Aria.vue +18 -0
- package/dist/runtime/components/Focus.stories.d.ts +11 -0
- package/dist/runtime/components/Focus.stories.js +53 -0
- package/dist/runtime/components/Icon/Icon.vue +39 -0
- package/dist/runtime/components/LibButton/LibButton.stories.d.ts +12 -0
- package/dist/runtime/components/LibButton/LibButton.stories.js +94 -0
- package/dist/runtime/components/LibButton/LibButton.vue +247 -0
- package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.d.ts +14 -0
- package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.js +29 -0
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +132 -0
- package/dist/runtime/components/LibColorInput/LibColorInput.stories.d.ts +7 -0
- package/dist/runtime/components/LibColorInput/LibColorInput.stories.js +58 -0
- package/dist/runtime/components/LibColorInput/LibColorInput.vue +125 -0
- package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.d.ts +7 -0
- package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +51 -0
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +448 -0
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.d.ts +7 -0
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.js +36 -0
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +95 -0
- package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.d.ts +11 -0
- package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.js +98 -0
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue +67 -0
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +370 -0
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +314 -0
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +27 -0
- package/dist/runtime/components/LibDatePicker/helpers.d.ts +25 -0
- package/dist/runtime/components/LibDatePicker/helpers.js +28 -0
- package/dist/runtime/components/LibDebug/LibDebug.stories.d.ts +9 -0
- package/dist/runtime/components/LibDebug/LibDebug.stories.js +46 -0
- package/dist/runtime/components/LibDebug/LibDebug.vue +91 -0
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +53 -0
- package/dist/runtime/components/LibFileInput/LibFileInput.stories.d.ts +10 -0
- package/dist/runtime/components/LibFileInput/LibFileInput.stories.js +63 -0
- package/dist/runtime/components/LibFileInput/LibFileInput.vue +273 -0
- package/dist/runtime/components/LibInput/LibInput.stories.d.ts +33 -0
- package/dist/runtime/components/LibInput/LibInput.stories.js +339 -0
- package/dist/runtime/components/LibInput/LibInput.vue +372 -0
- package/dist/runtime/components/LibLabel/LibLabel.stories.d.ts +6 -0
- package/dist/runtime/components/LibLabel/LibLabel.stories.js +25 -0
- package/dist/runtime/components/LibLabel/LibLabel.vue +66 -0
- package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.d.ts +23 -0
- package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.js +60 -0
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +127 -0
- package/dist/runtime/components/LibNotifications/LibNotification.stories.d.ts +15 -0
- package/dist/runtime/components/LibNotifications/LibNotification.stories.js +126 -0
- package/dist/runtime/components/LibNotifications/LibNotification.vue +121 -0
- package/dist/runtime/components/LibNotifications/LibNotifications.stories.d.ts +6 -0
- package/dist/runtime/components/LibNotifications/LibNotifications.stories.js +109 -0
- package/dist/runtime/components/LibNotifications/LibNotifications.vue +133 -0
- package/dist/runtime/components/LibPagination/LibPagination.stories.d.ts +6 -0
- package/dist/runtime/components/LibPagination/LibPagination.stories.js +40 -0
- package/dist/runtime/components/LibPagination/LibPagination.vue +261 -0
- package/dist/runtime/components/LibPalette/LibPalette.stories.d.ts +6 -0
- package/dist/runtime/components/LibPalette/LibPalette.stories.js +20 -0
- package/dist/runtime/components/LibPalette/LibPalette.vue +49 -0
- package/dist/runtime/components/LibPopup/LibPopup.stories.d.ts +14 -0
- package/dist/runtime/components/LibPopup/LibPopup.stories.js +147 -0
- package/dist/runtime/components/LibPopup/LibPopup.vue +441 -0
- package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.d.ts +10 -0
- package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.js +81 -0
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +192 -0
- package/dist/runtime/components/LibRecorder/LibRecorder.stories.d.ts +19 -0
- package/dist/runtime/components/LibRecorder/LibRecorder.stories.js +63 -0
- package/dist/runtime/components/LibRecorder/LibRecorder.vue +243 -0
- package/dist/runtime/components/LibRoot/LibRoot.vue +126 -0
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.d.ts +26 -0
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.js +78 -0
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +148 -0
- package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.d.ts +27 -0
- package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.js +112 -0
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +198 -0
- package/dist/runtime/components/LibTable/LibTable.stories.d.ts +16 -0
- package/dist/runtime/components/LibTable/LibTable.stories.js +156 -0
- package/dist/runtime/components/LibTable/LibTable.vue +177 -0
- package/dist/runtime/components/Template/NAME.vue +49 -0
- package/dist/runtime/components/Template/TemplateStory.d.ts +7 -0
- package/dist/runtime/components/Template/TemplateStory.js +22 -0
- package/dist/runtime/components/TestControls/TestControls.vue +19 -0
- package/dist/runtime/components/index.d.ts +19 -0
- package/dist/runtime/components/index.js +19 -0
- package/dist/runtime/components/reset.stories.d.ts +5 -0
- package/dist/runtime/components/reset.stories.js +19 -0
- package/dist/runtime/components/shared/props.d.ts +135 -0
- package/dist/runtime/components/shared/props.js +14 -0
- package/dist/runtime/components/shared/storyHelpers/playInput.d.ts +8 -0
- package/dist/runtime/components/shared/storyHelpers/playInput.js +26 -0
- package/dist/runtime/components/shared/storyHelpers/playSuggestions.d.ts +12 -0
- package/dist/runtime/components/shared/storyHelpers/playSuggestions.js +83 -0
- package/dist/runtime/composables/index.d.ts +11 -0
- package/dist/runtime/composables/index.js +11 -0
- package/dist/runtime/composables/useAccesibilityOutline.d.ts +41 -0
- package/dist/runtime/composables/useAccesibilityOutline.js +58 -0
- package/dist/runtime/composables/useAriaLabel.d.ts +6 -0
- package/dist/runtime/composables/useAriaLabel.js +15 -0
- package/dist/runtime/composables/useDarkMode.d.ts +38 -0
- package/dist/runtime/composables/useDarkMode.js +79 -0
- package/dist/runtime/composables/useDivideAttrs.d.ts +27 -0
- package/dist/runtime/composables/useDivideAttrs.js +26 -0
- package/dist/runtime/composables/useGlobalResizeObserver.d.ts +3 -0
- package/dist/runtime/composables/useGlobalResizeObserver.js +28 -0
- package/dist/runtime/composables/useInjectedDarkMode.d.ts +2 -0
- package/dist/runtime/composables/useInjectedDarkMode.js +13 -0
- package/dist/runtime/composables/useInjectedI18n.d.ts +2 -0
- package/dist/runtime/composables/useInjectedI18n.js +7 -0
- package/dist/runtime/composables/useInjectedLocale.d.ts +2 -0
- package/dist/runtime/composables/useInjectedLocale.js +21 -0
- package/dist/runtime/composables/useNotificationHandler.d.ts +4 -0
- package/dist/runtime/composables/useNotificationHandler.js +21 -0
- package/dist/runtime/composables/useScrollNearContainerEdges.d.ts +68 -0
- package/dist/runtime/composables/useScrollNearContainerEdges.js +116 -0
- package/dist/runtime/composables/useScrollNearContainerEdges.stories.d.ts +7 -0
- package/dist/runtime/composables/useScrollNearContainerEdges.stories.js +85 -0
- package/dist/runtime/composables/useSetupDarkMode.d.ts +12 -0
- package/dist/runtime/composables/useSetupDarkMode.js +4 -0
- package/dist/runtime/composables/useSetupI18n.d.ts +20 -0
- package/dist/runtime/composables/useSetupI18n.js +50 -0
- package/dist/runtime/composables/useSetupLocale.d.ts +9 -0
- package/dist/runtime/composables/useSetupLocale.js +21 -0
- package/dist/runtime/composables/useShowDevOnlyKey.d.ts +7 -0
- package/dist/runtime/composables/useShowDevOnlyKey.js +20 -0
- package/dist/runtime/composables/useSuggestions.d.ts +38 -0
- package/dist/runtime/composables/useSuggestions.js +226 -0
- package/dist/runtime/directives/index.d.ts +4 -0
- package/dist/runtime/directives/index.js +4 -0
- package/dist/runtime/directives/vDetectFlex.d.ts +2 -0
- package/dist/runtime/directives/vDetectFlex.js +109 -0
- package/dist/runtime/directives/vExtractRootEl.d.ts +22 -0
- package/dist/runtime/directives/vExtractRootEl.js +13 -0
- package/dist/runtime/directives/vResizableCols.d.ts +60 -0
- package/dist/runtime/directives/vResizableCols.js +252 -0
- package/dist/runtime/directives/vResizeObserver.d.ts +2 -0
- package/dist/runtime/directives/vResizeObserver.js +34 -0
- package/dist/runtime/globalResizeObserver.d.ts +5 -0
- package/dist/runtime/globalResizeObserver.js +5 -0
- package/dist/runtime/helpers/NotificationHandler.d.ts +48 -0
- package/dist/runtime/helpers/NotificationHandler.js +162 -0
- package/dist/runtime/helpers/addValue.d.ts +1 -0
- package/dist/runtime/helpers/addValue.js +8 -0
- package/dist/runtime/helpers/base64ToImg.d.ts +1 -0
- package/dist/runtime/helpers/base64ToImg.js +11 -0
- package/dist/runtime/helpers/copy.d.ts +1 -0
- package/dist/runtime/helpers/copy.js +10 -0
- package/dist/runtime/helpers/createNoonUtcDate.d.ts +7 -0
- package/dist/runtime/helpers/createNoonUtcDate.js +14 -0
- package/dist/runtime/helpers/defaultTranslationFunction.d.ts +16 -0
- package/dist/runtime/helpers/defaultTranslationFunction.js +14 -0
- package/dist/runtime/helpers/getTimeZoneList.d.ts +1 -0
- package/dist/runtime/helpers/getTimeZoneList.js +3 -0
- package/dist/runtime/helpers/hasModifiers.d.ts +1 -0
- package/dist/runtime/helpers/hasModifiers.js +1 -0
- package/dist/runtime/helpers/index.d.ts +8 -0
- package/dist/runtime/helpers/index.js +8 -0
- package/dist/runtime/helpers/readFile.d.ts +1 -0
- package/dist/runtime/helpers/readFile.js +13 -0
- package/dist/runtime/helpers/resizeObserverWrapper.d.ts +8 -0
- package/dist/runtime/helpers/resizeObserverWrapper.js +37 -0
- package/dist/runtime/helpers/storybook.d.ts +7 -0
- package/dist/runtime/helpers/storybook.js +42 -0
- package/dist/runtime/main.lib.d.ts +26 -0
- package/dist/runtime/main.lib.js +8 -0
- package/dist/runtime/nuxt/plugins/vue-plugin.d.ts +2 -0
- package/dist/runtime/nuxt/plugins/vue-plugin.js +12 -0
- package/dist/runtime/tailwind/index.d.ts +1 -0
- package/dist/runtime/tailwind/index.js +1 -0
- package/dist/runtime/tailwind/themeConvertionOpts.d.ts +2 -0
- package/dist/runtime/tailwind/themeConvertionOpts.js +12 -0
- package/dist/runtime/theme.d.ts +2 -0
- package/dist/runtime/theme.js +2 -0
- package/dist/runtime/types/index.d.ts +119 -0
- package/dist/runtime/types/index.js +0 -0
- package/dist/runtime/utils/twMerge.d.ts +10 -0
- package/dist/runtime/utils/twMerge.js +10 -0
- package/dist/runtime/vue/VueComponentsPlugin.d.ts +2 -0
- package/dist/runtime/vue/VueComponentsPlugin.js +10 -0
- package/dist/runtime/vue/registerComponents.d.ts +19 -0
- package/dist/runtime/vue/registerComponents.js +10 -0
- package/dist/runtime/vue/registerDirectives.d.ts +3 -0
- package/dist/runtime/vue/registerDirectives.js +9 -0
- package/dist/types.d.mts +7 -0
- package/dist/types.d.ts +7 -0
- package/package.json +207 -0
- package/src/module.ts +176 -0
- package/src/runtime/assets/base.css +67 -0
- package/src/runtime/assets/locales/en.json +33 -0
- package/src/runtime/assets/style.css +144 -0
- package/src/runtime/assets/tailwind.css +5 -0
- package/src/runtime/assets/theme.css +65 -0
- package/src/runtime/build/WitchcraftUiResolver.ts +27 -0
- package/src/runtime/build/generateTheme.ts +16 -0
- package/src/runtime/build/unpluginIconViteOptions.ts +11 -0
- package/src/runtime/components/Aria/Aria.vue +27 -0
- package/src/runtime/components/Focus.stories.ts +67 -0
- package/src/runtime/components/Icon/Icon.vue +39 -0
- package/src/runtime/components/LibButton/LibButton.stories.ts +107 -0
- package/src/runtime/components/LibButton/LibButton.vue +247 -0
- package/src/runtime/components/LibCheckbox/LibCheckbox.stories.ts +41 -0
- package/src/runtime/components/LibCheckbox/LibCheckbox.vue +132 -0
- package/src/runtime/components/LibColorInput/LibColorInput.stories.ts +69 -0
- package/src/runtime/components/LibColorInput/LibColorInput.vue +125 -0
- package/src/runtime/components/LibColorPicker/LibColorPicker.stories.ts +60 -0
- package/src/runtime/components/LibColorPicker/LibColorPicker.vue +448 -0
- package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.ts +51 -0
- package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +95 -0
- package/src/runtime/components/LibDatePicker/LibDatePicker.stories.ts +114 -0
- package/src/runtime/components/LibDatePicker/LibDatePicker.vue +67 -0
- package/src/runtime/components/LibDatePicker/LibRangeDatePicker.vue +370 -0
- package/src/runtime/components/LibDatePicker/LibSingleDatePicker.vue +314 -0
- package/src/runtime/components/LibDatePicker/LibTimeZonePicker.vue +27 -0
- package/src/runtime/components/LibDatePicker/helpers.ts +55 -0
- package/src/runtime/components/LibDebug/LibDebug.stories.ts +58 -0
- package/src/runtime/components/LibDebug/LibDebug.vue +91 -0
- package/src/runtime/components/LibDevOnly/LibDevOnly.vue +53 -0
- package/src/runtime/components/LibFileInput/LibFileInput.stories.ts +79 -0
- package/src/runtime/components/LibFileInput/LibFileInput.vue +273 -0
- package/src/runtime/components/LibInput/LibInput.stories.ts +367 -0
- package/src/runtime/components/LibInput/LibInput.vue +372 -0
- package/src/runtime/components/LibLabel/LibLabel.stories.ts +37 -0
- package/src/runtime/components/LibLabel/LibLabel.vue +66 -0
- package/src/runtime/components/LibMultiValues/LibMultiValues.stories.ts +83 -0
- package/src/runtime/components/LibMultiValues/LibMultiValues.vue +127 -0
- package/src/runtime/components/LibNotifications/LibNotification.stories.ts +142 -0
- package/src/runtime/components/LibNotifications/LibNotification.vue +121 -0
- package/src/runtime/components/LibNotifications/LibNotifications.stories.ts +124 -0
- package/src/runtime/components/LibNotifications/LibNotifications.vue +133 -0
- package/src/runtime/components/LibPagination/LibPagination.stories.ts +53 -0
- package/src/runtime/components/LibPagination/LibPagination.vue +261 -0
- package/src/runtime/components/LibPalette/LibPalette.stories.ts +32 -0
- package/src/runtime/components/LibPalette/LibPalette.vue +49 -0
- package/src/runtime/components/LibPopup/LibPopup.stories.ts +157 -0
- package/src/runtime/components/LibPopup/LibPopup.vue +441 -0
- package/src/runtime/components/LibProgressBar/LibProgressBar.stories.ts +94 -0
- package/src/runtime/components/LibProgressBar/LibProgressBar.vue +192 -0
- package/src/runtime/components/LibRecorder/LibRecorder.stories.ts +81 -0
- package/src/runtime/components/LibRecorder/LibRecorder.vue +243 -0
- package/src/runtime/components/LibRoot/LibRoot.vue +126 -0
- package/src/runtime/components/LibSimpleInput/LibSimpleInput.stories.ts +98 -0
- package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +148 -0
- package/src/runtime/components/LibSuggestions/LibSuggestions.stories.ts +137 -0
- package/src/runtime/components/LibSuggestions/LibSuggestions.vue +198 -0
- package/src/runtime/components/LibTable/LibTable.stories.ts +170 -0
- package/src/runtime/components/LibTable/LibTable.vue +177 -0
- package/src/runtime/components/Template/NAME.vue +49 -0
- package/src/runtime/components/Template/TemplateStory.ts +38 -0
- package/src/runtime/components/TestControls/TestControls.vue +19 -0
- package/src/runtime/components/index.ts +22 -0
- package/src/runtime/components/reset.stories.ts +32 -0
- package/src/runtime/components/shared/props.ts +142 -0
- package/src/runtime/components/shared/storyHelpers/playInput.ts +35 -0
- package/src/runtime/components/shared/storyHelpers/playSuggestions.ts +105 -0
- package/src/runtime/composables/index.ts +13 -0
- package/src/runtime/composables/useAccesibilityOutline.ts +104 -0
- package/src/runtime/composables/useAriaLabel.ts +23 -0
- package/src/runtime/composables/useDarkMode.ts +146 -0
- package/src/runtime/composables/useDivideAttrs.ts +52 -0
- package/src/runtime/composables/useGlobalResizeObserver.ts +33 -0
- package/src/runtime/composables/useInjectedDarkMode.ts +15 -0
- package/src/runtime/composables/useInjectedI18n.ts +10 -0
- package/src/runtime/composables/useInjectedLocale.ts +24 -0
- package/src/runtime/composables/useNotificationHandler.ts +32 -0
- package/src/runtime/composables/useScrollNearContainerEdges.stories.ts +93 -0
- package/src/runtime/composables/useScrollNearContainerEdges.ts +205 -0
- package/src/runtime/composables/useSetupDarkMode.ts +14 -0
- package/src/runtime/composables/useSetupI18n.ts +77 -0
- package/src/runtime/composables/useSetupLocale.ts +32 -0
- package/src/runtime/composables/useShowDevOnlyKey.ts +28 -0
- package/src/runtime/composables/useSuggestions.ts +297 -0
- package/src/runtime/directives/index.ts +6 -0
- package/src/runtime/directives/vDetectFlex.ts +159 -0
- package/src/runtime/directives/vExtractRootEl.ts +38 -0
- package/src/runtime/directives/vResizableCols.ts +378 -0
- package/src/runtime/directives/vResizeObserver.ts +45 -0
- package/src/runtime/globalResizeObserver.ts +12 -0
- package/src/runtime/helpers/NotificationHandler.ts +227 -0
- package/src/runtime/helpers/addValue.ts +10 -0
- package/src/runtime/helpers/base64ToImg.ts +14 -0
- package/src/runtime/helpers/copy.ts +11 -0
- package/src/runtime/helpers/createNoonUtcDate.ts +21 -0
- package/src/runtime/helpers/defaultTranslationFunction.ts +33 -0
- package/src/runtime/helpers/getTimeZoneList.ts +4 -0
- package/src/runtime/helpers/hasModifiers.ts +1 -0
- package/src/runtime/helpers/index.ts +10 -0
- package/src/runtime/helpers/readFile.ts +22 -0
- package/src/runtime/helpers/resizeObserverWrapper.ts +45 -0
- package/src/runtime/helpers/storybook.ts +52 -0
- package/src/runtime/main.lib.ts +31 -0
- package/src/runtime/nuxt/plugins/vue-plugin.ts +19 -0
- package/src/runtime/tailwind/index.ts +3 -0
- package/src/runtime/tailwind/themeConvertionOpts.ts +15 -0
- package/src/runtime/theme.ts +5 -0
- package/src/runtime/types/index.ts +116 -0
- package/src/runtime/utils/twMerge.ts +13 -0
- package/src/runtime/vue/VueComponentsPlugin.ts +16 -0
- package/src/runtime/vue/registerComponents.ts +31 -0
- package/src/runtime/vue/registerDirectives.ts +12 -0
- package/types/components.d.ts +27 -0
- package/types/global.d.ts +16 -0
- package/types/index.d.ts +5 -0
- package/types/vite.d.ts +2 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:class="twMerge(`input wrapper
|
|
4
|
+
grow
|
|
5
|
+
flex
|
|
6
|
+
flex-wrap
|
|
7
|
+
`,
|
|
8
|
+
disabled && `
|
|
9
|
+
text-neutral-400
|
|
10
|
+
`,
|
|
11
|
+
($.wrapperAttrs as any)?.class,
|
|
12
|
+
)"
|
|
13
|
+
tabindex="-1"
|
|
14
|
+
v-bind="{...$.wrapperAttrs, class:undefined}"
|
|
15
|
+
ref="inputWrapperEl"
|
|
16
|
+
>
|
|
17
|
+
<slot name="label" v-bind="{ ...slotProps, label }">
|
|
18
|
+
<lib-label v-if="label || $slots.default"
|
|
19
|
+
:id="id ?? fallbackId"
|
|
20
|
+
:disabled="disabled"
|
|
21
|
+
:readonly="readonly"
|
|
22
|
+
:valid="valid"
|
|
23
|
+
>
|
|
24
|
+
<slot v-bind="slotProps">
|
|
25
|
+
{{ label }}
|
|
26
|
+
</slot>
|
|
27
|
+
</lib-label>
|
|
28
|
+
<!-- Allow blurring when clicking the blank part of a label. -->
|
|
29
|
+
<div class="flex-1"/>
|
|
30
|
+
</slot>
|
|
31
|
+
<!-- These are mostly copies of the classes on LibSimpleInput except made to work with disabled/readonly/etc manually since a div cannot have these states. -->
|
|
32
|
+
<div
|
|
33
|
+
:data-border="border"
|
|
34
|
+
:data-invalid="!valid"
|
|
35
|
+
:data-disabled="disabled"
|
|
36
|
+
:data-read-only="readonly"
|
|
37
|
+
:data-is-open="isOpen"
|
|
38
|
+
v-bind="{...$['inner-wrapperAttrs'], class:undefined}"
|
|
39
|
+
:class="twMerge(`inner-wrapper
|
|
40
|
+
relative
|
|
41
|
+
flex
|
|
42
|
+
flex-1
|
|
43
|
+
basis-[100%]
|
|
44
|
+
flex-wrap
|
|
45
|
+
rounded-sm
|
|
46
|
+
gap-2
|
|
47
|
+
px-2
|
|
48
|
+
`,
|
|
49
|
+
border && `
|
|
50
|
+
bg-inherit
|
|
51
|
+
border
|
|
52
|
+
border-neutral-500
|
|
53
|
+
outlined-within:border-accent-500
|
|
54
|
+
`,
|
|
55
|
+
isOpen && `rounded-b-none`,
|
|
56
|
+
!valid && `
|
|
57
|
+
border-danger-700
|
|
58
|
+
outlined:!ring-danger-700
|
|
59
|
+
text-danger-800
|
|
60
|
+
dark:text-danger-400
|
|
61
|
+
dark:border-danger-600
|
|
62
|
+
`,
|
|
63
|
+
readonly && `
|
|
64
|
+
bg-neutral-50
|
|
65
|
+
text-neutral-800
|
|
66
|
+
dark:bg-neutral-950
|
|
67
|
+
dark:text-neutral-200
|
|
68
|
+
`,
|
|
69
|
+
disabled && `
|
|
70
|
+
bg-neutral-50
|
|
71
|
+
text-neutral-400
|
|
72
|
+
dark:border-neutral-600
|
|
73
|
+
border-neutral-400
|
|
74
|
+
`,
|
|
75
|
+
($['inner-wrapperAttrs'] as any)?.class,
|
|
76
|
+
)"
|
|
77
|
+
>
|
|
78
|
+
<slot name="left" v-bind="slotProps"/>
|
|
79
|
+
<slot name="input" v-bind="{ ...inputProps, ...slotProps, suggestionsIndicatorClickHandler }">
|
|
80
|
+
<lib-simple-input
|
|
81
|
+
:class="twMerge(
|
|
82
|
+
`p-0`,
|
|
83
|
+
!$slots.left && `-ml-2 pl-2`,
|
|
84
|
+
!$slots.right && (!$values || $values.length === 0) && !suggestions && `-mr-2 -pr-2`,
|
|
85
|
+
($.attrs as any)?.class,
|
|
86
|
+
)"
|
|
87
|
+
v-bind="inputProps"
|
|
88
|
+
/>
|
|
89
|
+
</slot>
|
|
90
|
+
<slot name="indicator" v-bind="{isOpen, suggestionsIndicatorClickHandler }">
|
|
91
|
+
<div
|
|
92
|
+
v-if="suggestions"
|
|
93
|
+
:data-is-open="isOpen"
|
|
94
|
+
:class="twMerge(
|
|
95
|
+
`indicator flex flex-col justify-center`,
|
|
96
|
+
)"
|
|
97
|
+
@click="suggestionsIndicatorClickHandler"
|
|
98
|
+
>
|
|
99
|
+
<icon :class="isOpen && `rotate-180`"> <i-fa6-solid-chevron-up/> </icon>
|
|
100
|
+
</div>
|
|
101
|
+
</slot>
|
|
102
|
+
<slot
|
|
103
|
+
name="values"
|
|
104
|
+
v-bind="{...multivaluesProps, ...slotProps}"
|
|
105
|
+
>
|
|
106
|
+
<template v-if="$values && $values.length > 0">
|
|
107
|
+
<lib-multi-values
|
|
108
|
+
:class="twMerge(`
|
|
109
|
+
grow-[9000]
|
|
110
|
+
justify-space-between
|
|
111
|
+
py-1
|
|
112
|
+
`,
|
|
113
|
+
!$slots.right && `
|
|
114
|
+
-mr-1
|
|
115
|
+
`,
|
|
116
|
+
($.multivaluesAttrs as any)?.class,
|
|
117
|
+
)"
|
|
118
|
+
v-bind="multivaluesProps"
|
|
119
|
+
/>
|
|
120
|
+
</template>
|
|
121
|
+
</slot>
|
|
122
|
+
<slot name="right" v-bind="slotProps"/>
|
|
123
|
+
|
|
124
|
+
<slot v-if="suggestions" name="suggestions" v-bind="{...suggestionProps, ...slotProps}">
|
|
125
|
+
<!-- todo 1px needs to be abstracted to var -->
|
|
126
|
+
<lib-suggestions
|
|
127
|
+
:class="twMerge(`
|
|
128
|
+
absolute
|
|
129
|
+
-inset-x-px
|
|
130
|
+
z-10
|
|
131
|
+
rounded-b-sm
|
|
132
|
+
border-accent-500
|
|
133
|
+
border
|
|
134
|
+
top-full
|
|
135
|
+
`,
|
|
136
|
+
!border && `
|
|
137
|
+
rounded-sm
|
|
138
|
+
`,
|
|
139
|
+
($.suggestionsAttrs as any)?.class,
|
|
140
|
+
)"
|
|
141
|
+
ref="suggestionsComponent"
|
|
142
|
+
v-bind="suggestionProps"
|
|
143
|
+
>
|
|
144
|
+
<template #item="itemSlotProps">
|
|
145
|
+
<slot name="suggestion-item" v-bind="itemSlotProps"/>
|
|
146
|
+
</template>
|
|
147
|
+
</lib-suggestions>
|
|
148
|
+
</slot>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
</template>
|
|
152
|
+
<script setup lang="ts">
|
|
153
|
+
import { isBlank } from "@alanscodelog/utils/isBlank.js"
|
|
154
|
+
import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn.js"
|
|
155
|
+
import type { MakeRequired } from "@alanscodelog/utils/types"
|
|
156
|
+
import { computed,type HTMLAttributes,type InputHTMLAttributes, nextTick, type PropType, ref, toRef, useSlots, watch } from "vue"
|
|
157
|
+
import type { ComponentExposed } from "vue-component-type-helpers"
|
|
158
|
+
|
|
159
|
+
import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
|
|
160
|
+
import { useSuggestionsInputAria } from "../../composables/useSuggestions.js"
|
|
161
|
+
import { hasModifiers } from "../../helpers/hasModifiers.js"
|
|
162
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
163
|
+
import Icon from "../Icon/Icon.vue"
|
|
164
|
+
import LibLabel from "../LibLabel/LibLabel.vue"
|
|
165
|
+
import LibMultiValues from "../LibMultiValues/LibMultiValues.vue"
|
|
166
|
+
import LibSimpleInput from "../LibSimpleInput/LibSimpleInput.vue"
|
|
167
|
+
import LibSuggestions from "../LibSuggestions/LibSuggestions.vue"
|
|
168
|
+
import { type BaseInteractiveProps, baseInteractivePropsDefaults, getFallbackId,type LabelProps, type LinkableByIdProps, type MultiValueProps, type SuggestionsProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js"
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
/* #region base */
|
|
172
|
+
defineOptions({
|
|
173
|
+
name: "lib-input",
|
|
174
|
+
inheritAttrs: false,
|
|
175
|
+
})
|
|
176
|
+
const $slots = useSlots()
|
|
177
|
+
const emit = defineEmits<{
|
|
178
|
+
(e: "submit", val: string, suggestion?: any): void
|
|
179
|
+
(e: "input", val: InputEvent): void
|
|
180
|
+
(e: "keydown", val: KeyboardEvent): void
|
|
181
|
+
(e: "blur", val: FocusEvent): void
|
|
182
|
+
(e: "focus", val: FocusEvent): void
|
|
183
|
+
(e: "indicatorClick", val: MouseEvent): void
|
|
184
|
+
}>()
|
|
185
|
+
|
|
186
|
+
const fallbackId = getFallbackId()
|
|
187
|
+
|
|
188
|
+
// eslint-disable-next-line no-use-before-define
|
|
189
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
190
|
+
valid: true,
|
|
191
|
+
suggestions: undefined,
|
|
192
|
+
updateOnlyOnSubmit: false,
|
|
193
|
+
...baseInteractivePropsDefaults,
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
const $ = useDivideAttrs(["wrapper", "inner-wrapper", "suggestions", "multivalues"] as const)
|
|
197
|
+
|
|
198
|
+
const $values = defineModel<string[] | undefined>("values", { default: undefined })
|
|
199
|
+
const $modelValue = defineModel<string>({ required: true })
|
|
200
|
+
|
|
201
|
+
const fullId = computed(() => props.id ?? fallbackId)
|
|
202
|
+
|
|
203
|
+
const $inputValue = defineModel<string>("inputValue", { default: "" })
|
|
204
|
+
$inputValue.value = $modelValue.value ?? ""
|
|
205
|
+
|
|
206
|
+
const canEdit = computed(() => !props.disabled && !props.readonly)
|
|
207
|
+
const suggestionsComponent = ref<ComponentExposed<typeof LibSuggestions> | null>(null)
|
|
208
|
+
const activeSuggestion = ref(0)
|
|
209
|
+
watch($modelValue, () => {
|
|
210
|
+
$inputValue.value = $modelValue.value
|
|
211
|
+
})
|
|
212
|
+
const inputWrapperEl = ref<HTMLElement | null>(null)
|
|
213
|
+
const isOpen = ref(false)
|
|
214
|
+
|
|
215
|
+
const suggestionsIndicatorClickHandler = (e: MouseEvent) => {
|
|
216
|
+
nextTick(() => {
|
|
217
|
+
if (props.suggestions) {
|
|
218
|
+
(suggestionsComponent.value as any)?.suggestions.toggle()
|
|
219
|
+
}
|
|
220
|
+
})
|
|
221
|
+
emit("indicatorClick", e)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
const handleKeydown = (e: KeyboardEvent) => {
|
|
226
|
+
if (props.suggestions) {
|
|
227
|
+
(suggestionsComponent.value as any)?.inputKeydownHandler?.(e)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
emit("keydown", e)
|
|
231
|
+
}
|
|
232
|
+
const handleBlur = (e: FocusEvent) => {
|
|
233
|
+
if (props.suggestions) {
|
|
234
|
+
(suggestionsComponent.value as any)?.inputBlurHandler?.(e)
|
|
235
|
+
}
|
|
236
|
+
emit("blur", e)
|
|
237
|
+
}
|
|
238
|
+
const handleFocus = (e: FocusEvent) => {
|
|
239
|
+
if (props.suggestions) {
|
|
240
|
+
(suggestionsComponent.value as any)?.inputFocusHandler?.(e)
|
|
241
|
+
}
|
|
242
|
+
emit("focus", e)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function addValue(val: string) {
|
|
246
|
+
if ($values.value === undefined) return
|
|
247
|
+
if (isBlank(val)) return
|
|
248
|
+
props.preventDuplicateValues
|
|
249
|
+
? pushIfNotIn($values.value, [val])
|
|
250
|
+
: $values.value.push(val)
|
|
251
|
+
$inputValue.value = ""
|
|
252
|
+
$modelValue.value = ""
|
|
253
|
+
}
|
|
254
|
+
const suggestions = toRef(props, "suggestions")
|
|
255
|
+
const inputAriaProps = useSuggestionsInputAria(
|
|
256
|
+
fullId,
|
|
257
|
+
isOpen,
|
|
258
|
+
activeSuggestion,
|
|
259
|
+
suggestions,
|
|
260
|
+
)
|
|
261
|
+
const inputProps = computed(() => ({
|
|
262
|
+
id: fullId.value,
|
|
263
|
+
border: false,
|
|
264
|
+
disabled: props.disabled,
|
|
265
|
+
readonly: props.readonly,
|
|
266
|
+
isValid: props.valid,
|
|
267
|
+
onKeydown: handleKeydown,
|
|
268
|
+
onBlur: handleBlur,
|
|
269
|
+
onFocus: handleFocus,
|
|
270
|
+
modelValue: $inputValue.value,
|
|
271
|
+
"onUpdate:modelValue": (e: string) => {
|
|
272
|
+
$inputValue.value = e
|
|
273
|
+
if (!props.suggestions && !props.updateOnlyOnSubmit && !props.restrictToSuggestions) {
|
|
274
|
+
$modelValue.value = e
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
onSubmit: (e: string) => {
|
|
278
|
+
if (!props.suggestions) {
|
|
279
|
+
$modelValue.value = e
|
|
280
|
+
emit("submit", e)
|
|
281
|
+
if ($values.value) {
|
|
282
|
+
addValue(e)
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
...inputAriaProps.value,
|
|
287
|
+
canEdit: canEdit.value,
|
|
288
|
+
...$.value.attrs,
|
|
289
|
+
class: undefined,
|
|
290
|
+
}))
|
|
291
|
+
|
|
292
|
+
function slotSubmit(val: any): void {
|
|
293
|
+
emit("submit", val)
|
|
294
|
+
}
|
|
295
|
+
const slotProps = computed(() => ({
|
|
296
|
+
id: fullId.value,
|
|
297
|
+
isOpen: isOpen.value,
|
|
298
|
+
valid: props.valid,
|
|
299
|
+
disabled: props.disabled,
|
|
300
|
+
readonly: props.readonly,
|
|
301
|
+
emitSubmit: slotSubmit
|
|
302
|
+
}))
|
|
303
|
+
|
|
304
|
+
const suggestionProps = computed(() => ({
|
|
305
|
+
id: fullId.value,
|
|
306
|
+
suggestions: props.suggestions,
|
|
307
|
+
allowOpenEmpty: props.allowOpenEmpty,
|
|
308
|
+
restrictToSuggestions: props.restrictToSuggestions,
|
|
309
|
+
suggestionLabel: props.suggestionLabel,
|
|
310
|
+
suggestionsFilter: props.suggestionsFilter,
|
|
311
|
+
modelValue: $modelValue.value.toString(),
|
|
312
|
+
inputValue: $inputValue.value,
|
|
313
|
+
isValid: props.isValid,
|
|
314
|
+
"onUpdate:inputValue": (e: string) => $inputValue.value = e,
|
|
315
|
+
onSubmit: (e: string, suggestion: any) => {
|
|
316
|
+
$modelValue.value = e
|
|
317
|
+
emit("submit", e, suggestion)
|
|
318
|
+
if ($values.value) {
|
|
319
|
+
addValue(e)
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
"onUpdate:isOpen": (e: boolean) => { isOpen.value = e },
|
|
323
|
+
"onUpdate:activeSuggestion": (e: number) => activeSuggestion.value = e,
|
|
324
|
+
...$.value.suggestionsAttrs,
|
|
325
|
+
class: undefined,
|
|
326
|
+
}))
|
|
327
|
+
|
|
328
|
+
const multivaluesProps = computed(() => ({
|
|
329
|
+
hasSlotRight: !$slots.right,
|
|
330
|
+
label: props.label,
|
|
331
|
+
border: props.border,
|
|
332
|
+
disabled: props.disabled,
|
|
333
|
+
readonly: props.readonly,
|
|
334
|
+
values: $values.value,
|
|
335
|
+
"onUpdate:values": (e: string[]) => $values.value = e,
|
|
336
|
+
...$.value.multivaluesAttrs,
|
|
337
|
+
class: undefined,
|
|
338
|
+
}))
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
defineExpose({
|
|
342
|
+
suggestionsComponent,
|
|
343
|
+
el: inputWrapperEl,
|
|
344
|
+
})
|
|
345
|
+
</script>
|
|
346
|
+
<script lang="ts">
|
|
347
|
+
|
|
348
|
+
type WrapperTypes =
|
|
349
|
+
& WrapperProps<"suggestions",HTMLAttributes >
|
|
350
|
+
& WrapperProps<"wrapper", HTMLAttributes >
|
|
351
|
+
& WrapperProps<"inner-wrapper",HTMLAttributes>
|
|
352
|
+
|
|
353
|
+
type RealProps =
|
|
354
|
+
SuggestionsProps
|
|
355
|
+
& LinkableByIdProps
|
|
356
|
+
& LabelProps
|
|
357
|
+
& BaseInteractiveProps
|
|
358
|
+
& MultiValueProps
|
|
359
|
+
& {
|
|
360
|
+
suggestions?: SuggestionsProps["suggestions"]
|
|
361
|
+
valid?: boolean
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
interface Props
|
|
365
|
+
extends
|
|
366
|
+
/** @vue-ignore */
|
|
367
|
+
Partial<Omit<InputHTMLAttributes,"class" | "readonly" | "disabled" | "onSubmit"> & TailwindClassProp>,
|
|
368
|
+
/** @vue-ignore */
|
|
369
|
+
Partial<WrapperTypes>,
|
|
370
|
+
RealProps { }
|
|
371
|
+
</script>
|
|
372
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/vue3"
|
|
3
|
+
|
|
4
|
+
import Label from "./LibLabel.vue"
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
7
|
+
import * as components from "../index.js"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const meta: Meta<typeof Label> = {
|
|
11
|
+
component: Label,
|
|
12
|
+
title: "Components/Label",
|
|
13
|
+
args: {
|
|
14
|
+
slot: "label",
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default meta
|
|
19
|
+
type Story = StoryObj<typeof Label>
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export const Primary: Story = {
|
|
23
|
+
render: args => ({
|
|
24
|
+
components,
|
|
25
|
+
setup: () => ({ args }),
|
|
26
|
+
template: `
|
|
27
|
+
<lib-label v-bind="args">{{args.slot}}</lib-label>
|
|
28
|
+
<br/>
|
|
29
|
+
In flex col with input:
|
|
30
|
+
<div class="flex flex-col">
|
|
31
|
+
<lib-label v-bind="args">{{args.slot}}</lib-label>
|
|
32
|
+
<lib-simple-input modelValue="some input"></lib-simple-input>
|
|
33
|
+
</div>
|
|
34
|
+
`,
|
|
35
|
+
}),
|
|
36
|
+
}
|
|
37
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- we use data-disabled because labels have no disabled property technically -->
|
|
3
|
+
<label
|
|
4
|
+
:id="`label-${id ?? fallbackId}`"
|
|
5
|
+
:class="!($attrs as any).unstyle && twMerge(`
|
|
6
|
+
pr-0
|
|
7
|
+
text-sm
|
|
8
|
+
`,
|
|
9
|
+
!valid && `text-danger-700`,
|
|
10
|
+
($attrs as any)?.class
|
|
11
|
+
)"
|
|
12
|
+
:data-disabled="disabled"
|
|
13
|
+
:data-invalid="!valid"
|
|
14
|
+
:for="id"
|
|
15
|
+
v-bind="{...$attrs, class:undefined}"
|
|
16
|
+
>
|
|
17
|
+
<slot/>
|
|
18
|
+
</label>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script setup lang="ts">
|
|
22
|
+
import type { MakeRequired } from "@alanscodelog/utils/types"
|
|
23
|
+
import { type LabelHTMLAttributes,toRef,useAttrs } from "vue"
|
|
24
|
+
|
|
25
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
26
|
+
import { type BaseInteractiveProps, baseInteractivePropsDefaults, getFallbackId, type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
defineOptions({
|
|
30
|
+
name: "lib-label",
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const fallbackId = getFallbackId()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
withDefaults(defineProps<Props>(), {
|
|
37
|
+
id: "",
|
|
38
|
+
unstyled: undefined,
|
|
39
|
+
valid: true,
|
|
40
|
+
...baseInteractivePropsDefaults,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const $attrs = useAttrs()
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<script lang="ts">
|
|
47
|
+
type RealProps =
|
|
48
|
+
& LinkableByIdProps
|
|
49
|
+
& LabelProps
|
|
50
|
+
& BaseInteractiveProps
|
|
51
|
+
& {
|
|
52
|
+
unstyled?: boolean
|
|
53
|
+
valid?: boolean
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface Props
|
|
57
|
+
extends
|
|
58
|
+
/** @vue-ignore */
|
|
59
|
+
Partial<Omit<LabelHTMLAttributes,"class"> & TailwindClassProp>,
|
|
60
|
+
RealProps
|
|
61
|
+
{}
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<script lang="ts">
|
|
65
|
+
|
|
66
|
+
</script>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/vue3"
|
|
3
|
+
import { ref } from "vue"
|
|
4
|
+
|
|
5
|
+
import LibMultiValues from "./LibMultiValues.vue"
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
8
|
+
import * as components from "../index.js"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const meta = {
|
|
12
|
+
component: LibMultiValues as any,
|
|
13
|
+
title: "Components/MultiValues",
|
|
14
|
+
args: {
|
|
15
|
+
values: ["A", "B", "C"],
|
|
16
|
+
border: true,
|
|
17
|
+
},
|
|
18
|
+
tags: ["!test"],
|
|
19
|
+
} satisfies Meta<typeof LibMultiValues> & Meta<{ custom: string }>
|
|
20
|
+
|
|
21
|
+
export default meta
|
|
22
|
+
type Story = StoryObj<typeof LibMultiValues> // & StoryObj<typeof extraArgs>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The multi-value component is just the values part beneath the input.
|
|
27
|
+
*
|
|
28
|
+
* This is a simple example of how it can be combined with the simple-input component to create an input with multiple values.
|
|
29
|
+
*
|
|
30
|
+
* Note that setting the `disabled` or `readonly` props won't prevent the component from accepting an updated `values` prop. Disabling adding must be done separately from whatever is controlling the component (e.g. the input in this case).
|
|
31
|
+
*/
|
|
32
|
+
export const Primary: Story = {
|
|
33
|
+
render: args => ({
|
|
34
|
+
components: { ...components, LibMultiValues },
|
|
35
|
+
setup: () => {
|
|
36
|
+
const inputValue = ref("B")
|
|
37
|
+
const multiValueEl = ref<typeof LibMultiValues | null>(null)
|
|
38
|
+
const onKeydownEnter = (e: KeyboardEvent): void => {
|
|
39
|
+
if (e.key === "Enter") (args.values!).push(inputValue.value)
|
|
40
|
+
}
|
|
41
|
+
return ({
|
|
42
|
+
args,
|
|
43
|
+
inputValue,
|
|
44
|
+
multiValueEl,
|
|
45
|
+
onKeydownEnter,
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
,
|
|
49
|
+
|
|
50
|
+
template: `
|
|
51
|
+
<p>Simple Input connected to multi-value.</p>
|
|
52
|
+
<p> Press enter to add value:</p>
|
|
53
|
+
<lib-simple-input
|
|
54
|
+
v-model="inputValue"
|
|
55
|
+
@keydown="onKeydownEnter"
|
|
56
|
+
>
|
|
57
|
+
</lib-simple-input>
|
|
58
|
+
<p>Multi-value component: </p>
|
|
59
|
+
<div class="flex justify-start">
|
|
60
|
+
<lib-multi-values
|
|
61
|
+
ref="multiValueEl"
|
|
62
|
+
v-bind="args"
|
|
63
|
+
v-model:values="args.values"
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
`,
|
|
67
|
+
}),
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
export const Disabled = {
|
|
72
|
+
...Primary,
|
|
73
|
+
args: {
|
|
74
|
+
disabled: true,
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const Readonly = {
|
|
79
|
+
...Primary,
|
|
80
|
+
args: {
|
|
81
|
+
readonly: true,
|
|
82
|
+
},
|
|
83
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
v-if="$values && $values?.length > 0"
|
|
4
|
+
:class="twMerge(`
|
|
5
|
+
values
|
|
6
|
+
group
|
|
7
|
+
flex
|
|
8
|
+
flex-initial
|
|
9
|
+
items-center
|
|
10
|
+
justify-center
|
|
11
|
+
gap-1
|
|
12
|
+
overflow-x-scroll
|
|
13
|
+
scrollbar-hidden
|
|
14
|
+
`,
|
|
15
|
+
($ as any)?.class)
|
|
16
|
+
"
|
|
17
|
+
:data-disabled="disabled"
|
|
18
|
+
:data-read-only="readonly"
|
|
19
|
+
:aria-label="`Values for ${label}`"
|
|
20
|
+
:tabindex="disabled ? -1 : 0"
|
|
21
|
+
v-bind="{...$, class:undefined}"
|
|
22
|
+
>
|
|
23
|
+
<div
|
|
24
|
+
:data-border="border"
|
|
25
|
+
:class="twMerge(`
|
|
26
|
+
value_wrapper
|
|
27
|
+
flex-basis-0
|
|
28
|
+
min-w-2
|
|
29
|
+
flex
|
|
30
|
+
max-w-fit
|
|
31
|
+
flex-1
|
|
32
|
+
items-center
|
|
33
|
+
gap-0.5
|
|
34
|
+
overflow-hidden
|
|
35
|
+
px-1
|
|
36
|
+
text-xs
|
|
37
|
+
leading-none`,
|
|
38
|
+
!(disabled || readonly) && `
|
|
39
|
+
group-focus:text-accent-500
|
|
40
|
+
focus:text-accent-500`,
|
|
41
|
+
border && `
|
|
42
|
+
rounded-sm
|
|
43
|
+
border-neutral-400
|
|
44
|
+
border
|
|
45
|
+
focus:border-accent-400
|
|
46
|
+
`,
|
|
47
|
+
border && (disabled || readonly) && `
|
|
48
|
+
border-neutral-200
|
|
49
|
+
focus:border-neutral-200
|
|
50
|
+
dark:border-neutral-800
|
|
51
|
+
dark:focus:border-neutral-800
|
|
52
|
+
`,
|
|
53
|
+
($.itemAttrs as any)?.class
|
|
54
|
+
)"
|
|
55
|
+
:tabindex="canEdit ? 0 : undefined"
|
|
56
|
+
v-for="(value) of $values"
|
|
57
|
+
:key="value"
|
|
58
|
+
@keydown.ctrl.c.prevent="copy(value.toString())"
|
|
59
|
+
>
|
|
60
|
+
<span class="value_label truncate">{{ value }}</span>
|
|
61
|
+
<lib-button
|
|
62
|
+
class="!p-0 text-sm !leading-none"
|
|
63
|
+
:aria-label="`Remove ${value}`"
|
|
64
|
+
:border="false"
|
|
65
|
+
:disabled="disabled || readonly"
|
|
66
|
+
@click="removeVal(value)"
|
|
67
|
+
>
|
|
68
|
+
<icon><i-fa6-solid-xmark/></icon>
|
|
69
|
+
</lib-button>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
</template>
|
|
73
|
+
|
|
74
|
+
<script setup lang="ts" generic="T extends string | number">
|
|
75
|
+
import { removeIfIn } from "@alanscodelog/utils/removeIfIn.js"
|
|
76
|
+
import { computed, type HTMLAttributes } from "vue"
|
|
77
|
+
|
|
78
|
+
import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
|
|
79
|
+
import { copy } from "../../helpers/copy.js"
|
|
80
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
81
|
+
import Icon from "../Icon/Icon.vue"
|
|
82
|
+
import LibButton from "../LibButton/LibButton.vue"
|
|
83
|
+
import { type BaseInteractiveProps, baseInteractivePropsDefaults,type LabelProps, type MultiValueProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
defineOptions({
|
|
87
|
+
name: "lib-multi-values",
|
|
88
|
+
inheritAttrs: false,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const $ = useDivideAttrs(["item"] as const)
|
|
92
|
+
// eslint-disable-next-line no-use-before-define
|
|
93
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
94
|
+
...baseInteractivePropsDefaults
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
const canEdit = computed(() => !props.disabled && !props.readonly)
|
|
99
|
+
const $values = defineModel<T[]>("values", { default: () => []})
|
|
100
|
+
|
|
101
|
+
const removeVal = (value: T) => {
|
|
102
|
+
if (!canEdit.value) return
|
|
103
|
+
removeIfIn($values.value, value)
|
|
104
|
+
}
|
|
105
|
+
</script>
|
|
106
|
+
|
|
107
|
+
<script lang="ts">
|
|
108
|
+
type WrapperTypes = Partial<WrapperProps<"item",HTMLAttributes>>
|
|
109
|
+
|
|
110
|
+
type RealProps =
|
|
111
|
+
& LabelProps
|
|
112
|
+
& BaseInteractiveProps
|
|
113
|
+
& MultiValueProps
|
|
114
|
+
& {
|
|
115
|
+
border?: boolean
|
|
116
|
+
}
|
|
117
|
+
interface Props
|
|
118
|
+
extends
|
|
119
|
+
/** @vue-ignore */
|
|
120
|
+
Partial<Omit<HTMLAttributes,"class"> & TailwindClassProp>,
|
|
121
|
+
/** @vue-ignore */
|
|
122
|
+
WrapperTypes,
|
|
123
|
+
RealProps
|
|
124
|
+
{}
|
|
125
|
+
|
|
126
|
+
</script>
|
|
127
|
+
|