@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,98 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/vue3"
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
5
|
+
import * as components from "../index.js"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const meta = {
|
|
9
|
+
component: components.LibSimpleInput,
|
|
10
|
+
title: "Components/SimpleInput",
|
|
11
|
+
args: {
|
|
12
|
+
modelValue: "Value",
|
|
13
|
+
placeholder: "Placeholder",
|
|
14
|
+
},
|
|
15
|
+
} satisfies Meta<typeof components.LibSimpleInput> & Meta<{ custom: string }>
|
|
16
|
+
|
|
17
|
+
export default meta
|
|
18
|
+
type Story = StoryObj<typeof components.LibSimpleInput> // & StoryObj<typeof extraArgs>
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/** Input */
|
|
22
|
+
export const Primary: Story = {
|
|
23
|
+
args: {
|
|
24
|
+
modelValue: "some value",
|
|
25
|
+
},
|
|
26
|
+
render: args => ({
|
|
27
|
+
components,
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
setup: () => ({ args, test: () => console.log("Enter") }),
|
|
30
|
+
template: `
|
|
31
|
+
<lib-simple-input
|
|
32
|
+
@keydown="test"
|
|
33
|
+
class="m-2" v-bind="args" v-model="args.modelValue" ></lib-simple-input>
|
|
34
|
+
<lib-simple-input class="m-2" v-bind="{...args, modelValue:''}" ></lib-simple-input>
|
|
35
|
+
`,
|
|
36
|
+
}),
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Has more reasonable min-width inside a flexbox. */
|
|
40
|
+
export const InsideAFlexbox: Story = {
|
|
41
|
+
render: args => ({
|
|
42
|
+
components,
|
|
43
|
+
setup: () => ({ args }),
|
|
44
|
+
template: `
|
|
45
|
+
Inside a flexbox:
|
|
46
|
+
<div class="flex flex-wrap">
|
|
47
|
+
<lib-simple-input v-bind="args" v-model="args.modelValue"></lib-simple-input>
|
|
48
|
+
<div class="border-1 border-danger-500 flex-1 whitespace-nowrap">Flex Grow: 1</div>
|
|
49
|
+
</div>
|
|
50
|
+
`,
|
|
51
|
+
}),
|
|
52
|
+
args: {
|
|
53
|
+
stretch: true,
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
export const Disabled = {
|
|
59
|
+
...Primary,
|
|
60
|
+
args: {
|
|
61
|
+
disabled: true,
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
export const Readonly = {
|
|
65
|
+
...Primary,
|
|
66
|
+
args: {
|
|
67
|
+
readonly: true,
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
export const Invalid = {
|
|
71
|
+
...Primary,
|
|
72
|
+
args: {
|
|
73
|
+
valid: false,
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Intended for being wrapped.
|
|
78
|
+
* Should not have any border or focus outline styles.
|
|
79
|
+
*/
|
|
80
|
+
export const Borderless = {
|
|
81
|
+
...Primary,
|
|
82
|
+
args: {
|
|
83
|
+
border: false,
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const Numerical = {
|
|
88
|
+
...Primary,
|
|
89
|
+
args: {
|
|
90
|
+
type: "number",
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
export const NumericalInsideAFlexbox = {
|
|
94
|
+
...InsideAFlexbox,
|
|
95
|
+
args: {
|
|
96
|
+
type: "number",
|
|
97
|
+
},
|
|
98
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<input
|
|
3
|
+
:id="id ?? fallbackId"
|
|
4
|
+
:class="twMerge(`
|
|
5
|
+
input
|
|
6
|
+
flex-1
|
|
7
|
+
grow-[999999]
|
|
8
|
+
rounded-sm
|
|
9
|
+
px-1
|
|
10
|
+
focus-outline
|
|
11
|
+
min-w-[2rem]
|
|
12
|
+
bg-inherit
|
|
13
|
+
placeholder:text-neutral-400
|
|
14
|
+
placeholder:focus:text-accent-300
|
|
15
|
+
read-only:bg-neutral-50
|
|
16
|
+
read-only:text-neutral-800
|
|
17
|
+
read-only:placeholder:select-none
|
|
18
|
+
read-only:placeholder:text-opacity-0
|
|
19
|
+
read-only:focus:placeholder:text-opacity-0
|
|
20
|
+
disabled:placeholder:text-nuetral-400
|
|
21
|
+
disabled:cursor-unset
|
|
22
|
+
disabled:bg-neutral-50
|
|
23
|
+
disabled:text-neutral-400
|
|
24
|
+
dark:read-only:bg-neutral-950
|
|
25
|
+
dark:read-only:text-neutral-200
|
|
26
|
+
dark:disabled:placeholder:text-nuetral-600
|
|
27
|
+
dark:disabled:bg-neutral-950
|
|
28
|
+
dark:disabled:text-neutral-500
|
|
29
|
+
`,
|
|
30
|
+
type === `text` && `
|
|
31
|
+
min-w-[10ch]
|
|
32
|
+
w-full
|
|
33
|
+
`,
|
|
34
|
+
type === `number` && `
|
|
35
|
+
w-12
|
|
36
|
+
placeholder:text-transparent
|
|
37
|
+
appearance-none
|
|
38
|
+
pr-0
|
|
39
|
+
`,
|
|
40
|
+
border && `
|
|
41
|
+
border
|
|
42
|
+
border-neutral-500
|
|
43
|
+
focus:border-accent-500
|
|
44
|
+
disabled:border-neutral-400
|
|
45
|
+
dark:disabled:border-neutral-600
|
|
46
|
+
`,
|
|
47
|
+
!valid && `
|
|
48
|
+
placeholder:text-danger-700
|
|
49
|
+
border-danger-700
|
|
50
|
+
focus:border-danger-700
|
|
51
|
+
outlined:!ring-danger-700
|
|
52
|
+
text-danger-800
|
|
53
|
+
dark:text-danger-400
|
|
54
|
+
dark:placeholder:text-danger-700
|
|
55
|
+
dark:border-danger-600
|
|
56
|
+
`,
|
|
57
|
+
($attrs as any)?.class
|
|
58
|
+
)"
|
|
59
|
+
:data-border="border"
|
|
60
|
+
:data-invalid="!valid"
|
|
61
|
+
:type="type"
|
|
62
|
+
:placeholder="placeholder"
|
|
63
|
+
:disabled="disabled"
|
|
64
|
+
:readonly="readonly"
|
|
65
|
+
v-model="modelValue"
|
|
66
|
+
v-bind="{...$attrs, class:undefined, ...ariaLabel}"
|
|
67
|
+
@keydown="handleKeydown"
|
|
68
|
+
@input="emit('input', $event as InputEvent)"
|
|
69
|
+
>
|
|
70
|
+
</template>
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
<script lang="ts" setup generic="T">
|
|
74
|
+
import { keys } from "@alanscodelog/utils/keys.js"
|
|
75
|
+
import { pick } from "@alanscodelog/utils/pick.js"
|
|
76
|
+
import type { MakeRequired } from "@alanscodelog/utils/types"
|
|
77
|
+
import { castType } from "@alanscodelog/utils/utils"
|
|
78
|
+
import { getCurrentInstance, type InputHTMLAttributes, type InputTypeHTMLAttribute,toRef,useAttrs } from "vue"
|
|
79
|
+
|
|
80
|
+
import { useAriaLabel } from "../../composables/useAriaLabel.js"
|
|
81
|
+
import { hasModifiers } from "../../helpers/hasModifiers.js"
|
|
82
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
83
|
+
import { type BaseInteractiveProps, baseInteractivePropsDefaults, getFallbackId,type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
defineOptions({
|
|
87
|
+
name: "lib-simple-input",
|
|
88
|
+
inheritAttrs: false,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const fallbackId = getFallbackId()
|
|
92
|
+
|
|
93
|
+
// eslint-disable-next-line no-use-before-define
|
|
94
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
95
|
+
id: "",
|
|
96
|
+
placeholder: "",
|
|
97
|
+
valid: true,
|
|
98
|
+
label: "",
|
|
99
|
+
type: undefined,
|
|
100
|
+
...baseInteractivePropsDefaults
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const modelValue = defineModel<T>({ required: true })
|
|
104
|
+
|
|
105
|
+
const emit = defineEmits<{
|
|
106
|
+
/* User presses enter.*/
|
|
107
|
+
(e: "submit", val: T): void
|
|
108
|
+
(e: "input", val: InputEvent): void
|
|
109
|
+
}>()
|
|
110
|
+
const $attrs = useAttrs()
|
|
111
|
+
const ariaLabel = useAriaLabel(props, fallbackId)
|
|
112
|
+
|
|
113
|
+
function handleKeydown(e: KeyboardEvent) {
|
|
114
|
+
if (e.key === "Enter" && !hasModifiers(e)) {
|
|
115
|
+
emit("submit", modelValue.value)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
</script>
|
|
120
|
+
|
|
121
|
+
<script lang="ts">
|
|
122
|
+
|
|
123
|
+
type RealProps =
|
|
124
|
+
& LinkableByIdProps
|
|
125
|
+
& LabelProps
|
|
126
|
+
& BaseInteractiveProps
|
|
127
|
+
& {
|
|
128
|
+
placeholder?: InputHTMLAttributes["placeholder"]
|
|
129
|
+
disabled?: InputHTMLAttributes["disabled"]
|
|
130
|
+
id?: InputHTMLAttributes["id"]
|
|
131
|
+
type?: InputHTMLAttributes["type"]
|
|
132
|
+
valid?: boolean
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface Props
|
|
136
|
+
extends
|
|
137
|
+
/** @vue-ignore */
|
|
138
|
+
Partial<Omit<
|
|
139
|
+
InputHTMLAttributes,
|
|
140
|
+
| "class"
|
|
141
|
+
| "readonly"
|
|
142
|
+
| "disabled"
|
|
143
|
+
| "onSubmit"
|
|
144
|
+
| "onInput"
|
|
145
|
+
> & TailwindClassProp>,
|
|
146
|
+
RealProps
|
|
147
|
+
{}
|
|
148
|
+
</script>
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
import type { StoryObj } from "@storybook/vue3"
|
|
3
|
+
import { computed, onMounted, ref } from "vue"
|
|
4
|
+
import type { ComponentExposed } from "vue-component-type-helpers"
|
|
5
|
+
|
|
6
|
+
import LibSuggestions from "./LibSuggestions.vue"
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
9
|
+
import * as components from "../index.js"
|
|
10
|
+
|
|
11
|
+
const meta = {
|
|
12
|
+
component: LibSuggestions,
|
|
13
|
+
title: "Components/Suggestions",
|
|
14
|
+
args: {
|
|
15
|
+
id: "some-id",
|
|
16
|
+
modelValue: "",
|
|
17
|
+
label: "Some Label",
|
|
18
|
+
border: true,
|
|
19
|
+
suggestions: ["A", "AB", "ABC", "B", "BC", "C", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"],
|
|
20
|
+
},
|
|
21
|
+
} // satisfies Meta<typeof LibSuggestions> & Meta<{ custom: string }>
|
|
22
|
+
|
|
23
|
+
export default meta
|
|
24
|
+
type Story = StoryObj<typeof LibSuggestions> // & StoryObj<typeof extraArgs>
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The suggestions component is just the dropdown part.
|
|
28
|
+
*
|
|
29
|
+
* Here it is decoupled from the input.
|
|
30
|
+
*
|
|
31
|
+
* More examples can be found in the input component.
|
|
32
|
+
*/
|
|
33
|
+
export const Primary: Story = {
|
|
34
|
+
render: args => ({
|
|
35
|
+
components: { ...components, LibSuggestions },
|
|
36
|
+
|
|
37
|
+
setup: () => {
|
|
38
|
+
const inputValue = ref(args.modelValue)
|
|
39
|
+
const modelValue = ref(args.modelValue)
|
|
40
|
+
const drawer = ref<ComponentExposed<typeof LibSuggestions> | null>(null)
|
|
41
|
+
const keydownHandler = (e: KeyboardEvent): void => {
|
|
42
|
+
drawer.value?.inputKeydownHandler(e)
|
|
43
|
+
}
|
|
44
|
+
const suggestions = computed(() => drawer.value?.suggestions)
|
|
45
|
+
const blurHandler = (e: MouseEvent) => {
|
|
46
|
+
drawer.value?.inputBlurHandler(e)
|
|
47
|
+
}
|
|
48
|
+
onMounted(() => {
|
|
49
|
+
drawer.value?.suggestions.open()
|
|
50
|
+
})
|
|
51
|
+
return {
|
|
52
|
+
args,
|
|
53
|
+
inputValue,
|
|
54
|
+
modelValue,
|
|
55
|
+
isOpen: ref(false),
|
|
56
|
+
suggestions,
|
|
57
|
+
drawer,
|
|
58
|
+
keydownHandler,
|
|
59
|
+
blurHandler,
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
template: `
|
|
64
|
+
<div class="flex flex-col gap-3">
|
|
65
|
+
Temporary Value: {{inputValue}}
|
|
66
|
+
<br/>
|
|
67
|
+
Model Value (Final Value): <span class="inline-block" data-testid="model-value">{{modelValue}}</span>\n
|
|
68
|
+
|
|
69
|
+
<br/>
|
|
70
|
+
Selected: {{suggestions?.filtered[suggestions.active]}}
|
|
71
|
+
<label>Some Label</label>
|
|
72
|
+
<lib-simple-input
|
|
73
|
+
:class="isOpen ? 'open' : ''"
|
|
74
|
+
v-model="inputValue"
|
|
75
|
+
@focus="suggestions.open()"
|
|
76
|
+
@blur="blurHandler"
|
|
77
|
+
@keydown="keydownHandler"
|
|
78
|
+
></lib-simple-input>
|
|
79
|
+
<lib-suggestions
|
|
80
|
+
ref="drawer"
|
|
81
|
+
v-bind="{...args}"
|
|
82
|
+
@update:isOpen="isOpen = $event"
|
|
83
|
+
v-model="modelValue"
|
|
84
|
+
v-model:inputValue="inputValue"
|
|
85
|
+
>
|
|
86
|
+
<template #item={item}>
|
|
87
|
+
{{item}}
|
|
88
|
+
</template>
|
|
89
|
+
</lib-suggestions>
|
|
90
|
+
</div>
|
|
91
|
+
`,
|
|
92
|
+
}),
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const RestrictToSuggestions: Story = {
|
|
96
|
+
...Primary,
|
|
97
|
+
args: {
|
|
98
|
+
...Primary.args,
|
|
99
|
+
restrictToSuggestions: true,
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
export const AlwaysShowAllSuggestions = {
|
|
105
|
+
...Primary,
|
|
106
|
+
args: {
|
|
107
|
+
...Primary.args,
|
|
108
|
+
restrictToSuggestions: true,
|
|
109
|
+
suggestionsFilter: (_input: string, items: string[]) => items,
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
export const AlwaysShowAllSuggestionsAndNoRestrictToSuggestions = {
|
|
114
|
+
...Primary,
|
|
115
|
+
args: {
|
|
116
|
+
...Primary.args,
|
|
117
|
+
restrictToSuggestions: false,
|
|
118
|
+
suggestionsFilter: (_input: string, items: string[]) => items,
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
export const CustomSuggestionsObject = {
|
|
123
|
+
...Primary,
|
|
124
|
+
args: {
|
|
125
|
+
...Primary.args,
|
|
126
|
+
restrictToSuggestions: true,
|
|
127
|
+
suggestions: [
|
|
128
|
+
{ label: "A", other: "some data A" },
|
|
129
|
+
{ label: "AB", other: "some data AB" },
|
|
130
|
+
{ label: "ABC", other: "some data ABC" },
|
|
131
|
+
{ label: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", other: "some data ABCDEFGHIJKLMNOPQRSTUVWXYZ" },
|
|
132
|
+
],
|
|
133
|
+
suggestionLabel: (item: any) => item.label,
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
v-if="suggestions.isOpen"
|
|
4
|
+
:id="`suggestions-${id ?? fallbackId}`"
|
|
5
|
+
:class="twMerge(`
|
|
6
|
+
suggestions
|
|
7
|
+
bg-bg
|
|
8
|
+
dark:bg-fg
|
|
9
|
+
`,
|
|
10
|
+
($.attrs as any)?.class
|
|
11
|
+
)"
|
|
12
|
+
:data-open="suggestions.isOpen"
|
|
13
|
+
role="listbox"
|
|
14
|
+
ref="el"
|
|
15
|
+
v-bind="{...$.attrs, class:undefined}"
|
|
16
|
+
>
|
|
17
|
+
<!-- Click event is just in case, it should not really be triggered. We can do click selections via the blur handler. -->
|
|
18
|
+
<div :id="`suggestion-${id ?? fallbackId}-${index}`"
|
|
19
|
+
role="option"
|
|
20
|
+
:class="twMerge(`
|
|
21
|
+
px-1
|
|
22
|
+
user-select-none
|
|
23
|
+
cursor-pointer
|
|
24
|
+
px-2
|
|
25
|
+
`,
|
|
26
|
+
index=== suggestions.active && `bg-accent-200 dark:bg-accent-800`,
|
|
27
|
+
($.itemAttrs as any)?.class
|
|
28
|
+
)"
|
|
29
|
+
v-bind="{...$.itemAttrs, class:undefined}"
|
|
30
|
+
:aria-selected="index === suggestions.active ? true : false"
|
|
31
|
+
:aria-label="suggestions.getLabel(item)"
|
|
32
|
+
v-for="(item, index) in suggestions.filtered"
|
|
33
|
+
:key="item"
|
|
34
|
+
@mouseover="suggestions.active = index"
|
|
35
|
+
@mousedown.prevent
|
|
36
|
+
@mouseup="suggestions.enterSuggestion(index)"
|
|
37
|
+
>
|
|
38
|
+
<slot name="item" :item="item" :index="index">
|
|
39
|
+
{{ item }}
|
|
40
|
+
</slot>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<script setup lang="ts" generic="TSuggestion extends string | object">
|
|
47
|
+
|
|
48
|
+
import { type HTMLAttributes,reactive, ref } from "vue"
|
|
49
|
+
|
|
50
|
+
import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
|
|
51
|
+
import { useSuggestions } from "../../composables/useSuggestions.js"
|
|
52
|
+
import { hasModifiers } from "../../helpers/hasModifiers.js"
|
|
53
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
54
|
+
import { type BaseInteractiveProps, baseInteractivePropsDefaults, getFallbackId,type LabelProps, type LinkableByIdProps, type MultiValueProps, type SuggestionsEmits, type SuggestionsProps, type WrapperProps } from "../shared/props.js"
|
|
55
|
+
|
|
56
|
+
defineOptions({
|
|
57
|
+
name: "lib-suggestions",
|
|
58
|
+
inheritAttrs: false,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const $ = useDivideAttrs(["item"] as const)
|
|
62
|
+
|
|
63
|
+
const emits = defineEmits<SuggestionsEmits>()
|
|
64
|
+
|
|
65
|
+
const fallbackId = getFallbackId()
|
|
66
|
+
// eslint-disable-next-line no-use-before-define
|
|
67
|
+
const props = withDefaults(defineProps<Props & SuggestionsProps<TSuggestion>>(), {
|
|
68
|
+
isValid: true,
|
|
69
|
+
canOpen: true,
|
|
70
|
+
values: undefined,
|
|
71
|
+
filterKeydown: undefined,
|
|
72
|
+
...baseInteractivePropsDefaults
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The final valid value. This is *not* the value you want to share with the input. If `restrictToSuggestions` is true this will not update on any invalid values that `inputValue` might be set to.
|
|
77
|
+
*
|
|
78
|
+
* If suggestions are objects, this will be the string returned by the `suggestionLabel` prop.
|
|
79
|
+
*/
|
|
80
|
+
const $modelValue = defineModel<string>("modelValue", { required: true })
|
|
81
|
+
/**
|
|
82
|
+
* If the element is bound to an input, this is the value that the input should be sharing.
|
|
83
|
+
*
|
|
84
|
+
* It allows the component to read even invalid output, and also to reset that invalid output when either modelValue is set to a new value, or when the component is closed via cancel.
|
|
85
|
+
*/
|
|
86
|
+
const $inputValue = defineModel<string >("inputValue", { default: "" })
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if (typeof props.suggestions?.[0] === "object" && !props.suggestionLabel && !props.suggestionsFilter) {
|
|
90
|
+
throw new Error("`suggestionLabel` or `suggestionsFilter` must be passed if suggestions are objects.")
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const el = ref<HTMLElement | null>(null)
|
|
94
|
+
const mousedown = ref(false)
|
|
95
|
+
|
|
96
|
+
const suggestions = reactive(useSuggestions(
|
|
97
|
+
$inputValue,
|
|
98
|
+
$modelValue,
|
|
99
|
+
emits,
|
|
100
|
+
props
|
|
101
|
+
))
|
|
102
|
+
|
|
103
|
+
const inputKeydownHandler = (e: KeyboardEvent): void => {
|
|
104
|
+
if (props.filterKeydown?.(e)) return
|
|
105
|
+
if (hasModifiers(e)) return
|
|
106
|
+
if (e.key === "Enter") {
|
|
107
|
+
suggestions.enterSelected()
|
|
108
|
+
e.preventDefault()
|
|
109
|
+
} else if (e.key === "Escape") {
|
|
110
|
+
suggestions.cancel()
|
|
111
|
+
e.preventDefault()
|
|
112
|
+
} else if (!suggestions.isOpen && ["ArrowDown", "ArrowUp", "PageUp", "PageDown"].includes(e.key) && suggestions.available) {
|
|
113
|
+
suggestions.open()
|
|
114
|
+
e.preventDefault()
|
|
115
|
+
if (e.key === "PageUp") {
|
|
116
|
+
suggestions.first()
|
|
117
|
+
} else if (e.key === "PageDown") {
|
|
118
|
+
suggestions.last()
|
|
119
|
+
}
|
|
120
|
+
} else if (e.key === "ArrowUp") {
|
|
121
|
+
suggestions.prev()
|
|
122
|
+
e.preventDefault()
|
|
123
|
+
} else if (e.key === "ArrowDown") {
|
|
124
|
+
suggestions.next()
|
|
125
|
+
e.preventDefault()
|
|
126
|
+
} else if (e.key === "PageUp") {
|
|
127
|
+
suggestions.first()
|
|
128
|
+
e.preventDefault()
|
|
129
|
+
} else if (e.key === "PageDown") {
|
|
130
|
+
suggestions.last()
|
|
131
|
+
e.preventDefault()
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const inputBlurHandler = (e: MouseEvent): void => {
|
|
135
|
+
if (props.filterBlur?.(e)) return
|
|
136
|
+
|
|
137
|
+
if (!suggestions.isOpen) return
|
|
138
|
+
|
|
139
|
+
if (props.restrictToSuggestions) {
|
|
140
|
+
suggestions.cancel()
|
|
141
|
+
} else {
|
|
142
|
+
$modelValue.value = $inputValue.value
|
|
143
|
+
}
|
|
144
|
+
if (suggestions.isOpen) {
|
|
145
|
+
suggestions.close()
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const inputFocusHandler = (e: FocusEvent): void => {
|
|
149
|
+
if (props.filterFocus?.(e)) return
|
|
150
|
+
suggestions.open()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
defineExpose({
|
|
154
|
+
suggestions,
|
|
155
|
+
el,
|
|
156
|
+
/** A simple keydown handler that can be passed to an input to control the component while still focused inside it. */
|
|
157
|
+
inputKeydownHandler,
|
|
158
|
+
/** A blur handler for the input that controls the component. This also takes care of making clicking on a suggestion work, since otherwise if canOpen is set to false in the blur handler, no click event will fire. */
|
|
159
|
+
inputBlurHandler,
|
|
160
|
+
/** A focus handler for the input that controls the component. */
|
|
161
|
+
inputFocusHandler,
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
</script>
|
|
165
|
+
|
|
166
|
+
<script lang="ts">
|
|
167
|
+
type WrapperTypes = Partial<WrapperProps<"item",HTMLAttributes, {
|
|
168
|
+
/** Tailwind classes. */
|
|
169
|
+
class?: string
|
|
170
|
+
}>>
|
|
171
|
+
|
|
172
|
+
type RealProps =
|
|
173
|
+
& LinkableByIdProps
|
|
174
|
+
& LabelProps
|
|
175
|
+
& BaseInteractiveProps
|
|
176
|
+
& MultiValueProps
|
|
177
|
+
& {
|
|
178
|
+
/** Return true to prevent the keydown event from being handled. */
|
|
179
|
+
filterKeydown?: (e: KeyboardEvent) => boolean
|
|
180
|
+
/** Return true to prevent the blur event from being handled. */
|
|
181
|
+
filterBlur?: (e: MouseEvent) => boolean
|
|
182
|
+
/** Return true to prevent the focus event from being handled. */
|
|
183
|
+
filterFocus?: (e: FocusEvent) => boolean
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interface Props
|
|
187
|
+
extends
|
|
188
|
+
/** @vue-ignore */
|
|
189
|
+
Partial<Omit<HTMLAttributes,"class" | "onSubmit"> & {
|
|
190
|
+
/** Tailwind classes. */
|
|
191
|
+
class?: string
|
|
192
|
+
}>,
|
|
193
|
+
/** @vue-ignore */
|
|
194
|
+
WrapperTypes,
|
|
195
|
+
RealProps
|
|
196
|
+
{}
|
|
197
|
+
|
|
198
|
+
</script>
|