@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,448 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :id="id ?? fallbackId"
|
|
3
|
+
:aria-label="t('color-picker.aria')"
|
|
4
|
+
:class="twMerge(`color-picker
|
|
5
|
+
[--slider-size:calc(var(--spacing)_*_4)]
|
|
6
|
+
[--contrast-dark:var(--color-neutral-100)]
|
|
7
|
+
[--contrast-light:var(--color-neutral-800)]
|
|
8
|
+
[--fg:rgb(var(--contrast-dark))]
|
|
9
|
+
[--bg:rgb(var(--contrast-light))]
|
|
10
|
+
max-w-[300px]
|
|
11
|
+
flex flex-col items-center justify-center
|
|
12
|
+
bg-neutral-50
|
|
13
|
+
dark:bg-neutral-950
|
|
14
|
+
gap-3
|
|
15
|
+
p-3
|
|
16
|
+
`,
|
|
17
|
+
invertColors && `
|
|
18
|
+
[--fg:rgb(var(--contrast-light))]
|
|
19
|
+
[--bg:rgb(var(--contrast-dark))]
|
|
20
|
+
`,
|
|
21
|
+
border && `
|
|
22
|
+
border rounded-sm border-neutral-600
|
|
23
|
+
`
|
|
24
|
+
)"
|
|
25
|
+
>
|
|
26
|
+
<div
|
|
27
|
+
:class="`picker
|
|
28
|
+
no-touch-action
|
|
29
|
+
w-full
|
|
30
|
+
aspect-square
|
|
31
|
+
relative
|
|
32
|
+
flex
|
|
33
|
+
rounded-sm
|
|
34
|
+
focus:border-accent-500
|
|
35
|
+
`"
|
|
36
|
+
@pointerdown="slider.pointerdown($event, 'picker')"
|
|
37
|
+
@pointerleave="slider.pointerleave($event)"
|
|
38
|
+
>
|
|
39
|
+
<canvas
|
|
40
|
+
class="size-full shadow-xs shadow-black/50 rounded-sm"
|
|
41
|
+
ref="pickerEl"
|
|
42
|
+
/>
|
|
43
|
+
<div
|
|
44
|
+
aria-live="assertive"
|
|
45
|
+
:aria-description="ariaDescription"
|
|
46
|
+
:class="`
|
|
47
|
+
handle ${handleClasses}
|
|
48
|
+
border-[var(--fg)]
|
|
49
|
+
hover:shadow-black
|
|
50
|
+
active:shadow-black
|
|
51
|
+
`"
|
|
52
|
+
tabindex="0"
|
|
53
|
+
:style="`
|
|
54
|
+
left: calc(${localColor.percent.s}% - var(--slider-size)/2);
|
|
55
|
+
top: calc(${localColor.percent.v}% - var(--slider-size)/2);
|
|
56
|
+
background: ${localColorStringOpaque};
|
|
57
|
+
`"
|
|
58
|
+
@keydown="slider.keydown($event, 'picker')"
|
|
59
|
+
>
|
|
60
|
+
<aria :value="`${t('color-picker.aria.saturation')}: ${localColor.percent.s}, ${t('color-picker.aria.value')}: ${localColor.percent.s}`"/>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
<div
|
|
64
|
+
:class="`hue-slider ${sliderClasses}`"
|
|
65
|
+
@pointerdown="slider.pointerdown($event, 'hue')"
|
|
66
|
+
>
|
|
67
|
+
<canvas
|
|
68
|
+
class="size-full shadow-xs shadow-black/50 rounded-sm"
|
|
69
|
+
ref="hueSliderEl"
|
|
70
|
+
/>
|
|
71
|
+
<div
|
|
72
|
+
role="slider"
|
|
73
|
+
:aria-valuenow="`${localColor.percent.h}`"
|
|
74
|
+
:aria-valuemin="0"
|
|
75
|
+
:aria-valuemax="100"
|
|
76
|
+
:aria-label="t('color-picker.aria.hue')"
|
|
77
|
+
:aria-description="ariaDescription"
|
|
78
|
+
tabindex="0"
|
|
79
|
+
:class="`handle ${handleClasses} bg-neutral-50`"
|
|
80
|
+
:style="`left: calc(${localColor.percent.h}% - var(--slider-size)/2)`"
|
|
81
|
+
@keydown="slider.keydown($event, 'hue')"
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
84
|
+
<div
|
|
85
|
+
v-if="allowAlpha"
|
|
86
|
+
|
|
87
|
+
:class="`alpha-slider ${sliderClasses}`"
|
|
88
|
+
@keydown="slider.keydown($event, 'alpha')"
|
|
89
|
+
@pointerdown="slider.pointerdown($event, 'alpha')"
|
|
90
|
+
>
|
|
91
|
+
<canvas
|
|
92
|
+
class="size-full shadow-xs shadow-black/50 rounded-sm bg-transparency-squares"
|
|
93
|
+
ref="alphaSliderEl"
|
|
94
|
+
/>
|
|
95
|
+
<div
|
|
96
|
+
role="slider"
|
|
97
|
+
:aria-label="t('color-picker.aria.alpha-slider')"
|
|
98
|
+
:aria-valuenow="`${localColor.percent.h}`"
|
|
99
|
+
:aria-valuemin="0"
|
|
100
|
+
:aria-valuemax="100"
|
|
101
|
+
:aria-description="ariaDescription"
|
|
102
|
+
tabindex="0"
|
|
103
|
+
:class="`handle ${handleClasses} bg-neutral-50`"
|
|
104
|
+
:style="`left: calc(${localColor.percent.a}% - var(--slider-size)/2)`"
|
|
105
|
+
/>
|
|
106
|
+
</div>
|
|
107
|
+
<div class="color-group flex w-full flex-1 gap-2">
|
|
108
|
+
<div class=" color-wrapper
|
|
109
|
+
bg-transparency-squares
|
|
110
|
+
relative
|
|
111
|
+
aspect-square
|
|
112
|
+
h-[calc(var(--slider-size)*3)]
|
|
113
|
+
rounded-full
|
|
114
|
+
shadow-xs
|
|
115
|
+
"
|
|
116
|
+
>
|
|
117
|
+
<!-- <input class="color-input" :value="localColorString" @input="parseInput"> -->
|
|
118
|
+
<div class="color
|
|
119
|
+
size-full
|
|
120
|
+
rounded-full
|
|
121
|
+
border-2
|
|
122
|
+
border-neutral-600
|
|
123
|
+
dark:border-neutral-300
|
|
124
|
+
"
|
|
125
|
+
:style="`background:${localColorString}`"
|
|
126
|
+
/>
|
|
127
|
+
</div>
|
|
128
|
+
<div class="color-controls flex flex-1 items-center gap-2">
|
|
129
|
+
<slot name="input">
|
|
130
|
+
<lib-simple-input
|
|
131
|
+
class="w-full"
|
|
132
|
+
:aria-label="label"
|
|
133
|
+
:model-value="localColorString"
|
|
134
|
+
@input="parseInput"
|
|
135
|
+
/>
|
|
136
|
+
<lib-button :aria-label="t('copy')" @click="copy()">
|
|
137
|
+
<icon><i-fa6-regular-copy/></icon>
|
|
138
|
+
</lib-button>
|
|
139
|
+
</slot>
|
|
140
|
+
</div>
|
|
141
|
+
<!-- <lib-button @click="emits('update:modelValue', localColor.val)">Save</lib-button> -->
|
|
142
|
+
</div>
|
|
143
|
+
<slot name="buttons">
|
|
144
|
+
<div class="save-cancel-group flex w-full items-center justify-center gap-2">
|
|
145
|
+
<lib-button @click="save()">{{ t("save") }}</lib-button>
|
|
146
|
+
<lib-button @click="emits('cancel')">{{ t("cancel") }}</lib-button>
|
|
147
|
+
</div>
|
|
148
|
+
</slot>
|
|
149
|
+
</div>
|
|
150
|
+
</template>
|
|
151
|
+
|
|
152
|
+
<script setup lang="ts">
|
|
153
|
+
/* todo change to colorjsio for less dependencies */
|
|
154
|
+
import { castType } from "@alanscodelog/utils/castType.js"
|
|
155
|
+
import { isArray } from "@alanscodelog/utils/isArray.js"
|
|
156
|
+
import { colord } from "colord"
|
|
157
|
+
import { computed, onMounted, type PropType, reactive, type Ref, ref, type UnwrapRef,watch } from "vue"
|
|
158
|
+
|
|
159
|
+
import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
|
|
160
|
+
import type { HsvaColor, RgbaColor } from "../../types/index.js"
|
|
161
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
162
|
+
import aria from "../Aria/Aria.vue"
|
|
163
|
+
import Icon from "../Icon/Icon.vue"
|
|
164
|
+
import LibButton from "../LibButton/LibButton.vue"
|
|
165
|
+
import LibSimpleInput from "../LibSimpleInput/LibSimpleInput.vue"
|
|
166
|
+
import { getFallbackId, type LabelProps , type LinkableByIdProps } from "../shared/props.js"
|
|
167
|
+
|
|
168
|
+
defineOptions({
|
|
169
|
+
name: "lib-color-picker",
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
const t = useInjectedI18n()
|
|
173
|
+
|
|
174
|
+
const sliderClasses = `
|
|
175
|
+
slider
|
|
176
|
+
no-touch-action
|
|
177
|
+
h-4
|
|
178
|
+
w-full
|
|
179
|
+
relative
|
|
180
|
+
flex
|
|
181
|
+
`
|
|
182
|
+
|
|
183
|
+
const handleClasses = `
|
|
184
|
+
h-[var(--slider-size)]
|
|
185
|
+
w-[var(--slider-size)]
|
|
186
|
+
shadow-xs
|
|
187
|
+
shadow-black/50
|
|
188
|
+
border-2 border-neutral-700
|
|
189
|
+
rounded-full
|
|
190
|
+
absolute
|
|
191
|
+
cursor-pointer
|
|
192
|
+
outline-hidden
|
|
193
|
+
focus:border-accent-500
|
|
194
|
+
active:border-accent-500
|
|
195
|
+
hover:border-accent-500
|
|
196
|
+
`
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
const ariaDescription = t("color-picker.aria.description")
|
|
200
|
+
|
|
201
|
+
const $value = defineModel<RgbaColor>({ required: false, default: () => ({ r: 0, g: 0, b: 0 }) })
|
|
202
|
+
|
|
203
|
+
const fallbackId = getFallbackId()
|
|
204
|
+
const props = withDefaults(defineProps<
|
|
205
|
+
& LabelProps
|
|
206
|
+
& LinkableByIdProps
|
|
207
|
+
& {
|
|
208
|
+
allowAlpha?: boolean
|
|
209
|
+
border?: boolean
|
|
210
|
+
copyTransform?: (val: HsvaColor, stringVal: string) => any
|
|
211
|
+
}>(), {
|
|
212
|
+
allowAlpha: true,
|
|
213
|
+
border: true,
|
|
214
|
+
copyTransform: (_val: HsvaColor, stringVal: string) => stringVal,
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
const emits = defineEmits<{
|
|
219
|
+
(e: "save", val: RgbaColor): void
|
|
220
|
+
(e: "cancel"): void
|
|
221
|
+
}>()
|
|
222
|
+
|
|
223
|
+
const pickerEl = ref<HTMLCanvasElement | null>(null)
|
|
224
|
+
const hueSliderEl = ref<HTMLCanvasElement | null>(null)
|
|
225
|
+
const alphaSliderEl = ref<HTMLCanvasElement | null>(null)
|
|
226
|
+
|
|
227
|
+
type Config = Record<string, { el: Ref<HTMLCanvasElement>, xKey?: keyof HsvaColor, yKey?: keyof HsvaColor, xSteps?: number, ySteps?: number }>
|
|
228
|
+
const config: Config = {
|
|
229
|
+
hue: {
|
|
230
|
+
el: hueSliderEl as Ref<HTMLCanvasElement>,
|
|
231
|
+
xKey: "h",
|
|
232
|
+
xSteps: 360,
|
|
233
|
+
},
|
|
234
|
+
alpha: {
|
|
235
|
+
el: alphaSliderEl as Ref<HTMLCanvasElement>,
|
|
236
|
+
xSteps: 1,
|
|
237
|
+
xKey: "a",
|
|
238
|
+
},
|
|
239
|
+
picker: {
|
|
240
|
+
el: pickerEl as Ref<HTMLCanvasElement>,
|
|
241
|
+
xSteps: 100,
|
|
242
|
+
ySteps: 100,
|
|
243
|
+
xKey: "s",
|
|
244
|
+
yKey: "v",
|
|
245
|
+
},
|
|
246
|
+
}
|
|
247
|
+
const localColor = reactive<Record<"percent" | "val", HsvaColor>>({
|
|
248
|
+
percent: {
|
|
249
|
+
h: 0, s: 0, v: 0, a: 0,
|
|
250
|
+
},
|
|
251
|
+
val: {
|
|
252
|
+
h: 0, s: 0, v: 0, a: 0,
|
|
253
|
+
},
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
const localColorString = computed(() =>
|
|
257
|
+
colord(localColor.val).toRgbString(),
|
|
258
|
+
)
|
|
259
|
+
const localColorStringOpaque = computed(() =>
|
|
260
|
+
colord({ ...localColor.val, a: 1 }).toRgbString(),
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
const copy = (): void => {
|
|
265
|
+
if (navigator.clipboard) {
|
|
266
|
+
const text = props.copyTransform?.(localColor.val, localColorString.value)
|
|
267
|
+
|
|
268
|
+
navigator.clipboard.writeText(text).catch(() => { })
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const updatePicker = (el: HTMLCanvasElement, hue: number): void => {
|
|
273
|
+
const ctx = el.getContext("2d")!
|
|
274
|
+
const { height, width } = el
|
|
275
|
+
ctx.clearRect(0, 0, width, height)
|
|
276
|
+
|
|
277
|
+
const gradient = ctx.createLinearGradient(0, 0, 0, height)
|
|
278
|
+
gradient.addColorStop(0, "white")
|
|
279
|
+
gradient.addColorStop(1, "black")
|
|
280
|
+
const gradientColor = ctx.createLinearGradient(0, 0, width, 0)
|
|
281
|
+
gradientColor.addColorStop(0, `hsla(${hue} 100% 50% / 0)`)
|
|
282
|
+
gradientColor.addColorStop(1, `hsla(${hue} 100% 50% /1)`)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
ctx.fillStyle = gradient
|
|
286
|
+
ctx.fillRect(0, 0, width, height)
|
|
287
|
+
ctx.fillStyle = gradientColor
|
|
288
|
+
ctx.globalCompositeOperation = "multiply"
|
|
289
|
+
ctx.fillRect(0, 0, width, height)
|
|
290
|
+
ctx.globalCompositeOperation = "source-over"
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const updateSlider = (el: HTMLCanvasElement, stops: ((i: number) => string) | string[], length: number = 360): void => {
|
|
294
|
+
const ctx = el.getContext("2d")!
|
|
295
|
+
const { height, width } = el// .getBoundingClientRect()
|
|
296
|
+
ctx.clearRect(0, 0, width, height)
|
|
297
|
+
|
|
298
|
+
const end = isArray(stops) ? stops.length - 1 : length
|
|
299
|
+
|
|
300
|
+
const gradient = ctx.createLinearGradient(0, 0, width, 0)
|
|
301
|
+
|
|
302
|
+
for (let i = 0; i < end + 1; i++) {
|
|
303
|
+
const stop = stops instanceof Function ? stops(i) : stops[i]
|
|
304
|
+
gradient.addColorStop(i / end, stop)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
ctx.fillStyle = gradient
|
|
308
|
+
ctx.fillRect(0, 0, width, height)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
const getVal = (x: number, width: number, steps: number = 100, accuracy: number = 100, reverse = false): { val: number, percent: number } => {
|
|
313
|
+
// const stepWidth = width / (steps * accuracy)
|
|
314
|
+
const percent = (x / width)
|
|
315
|
+
const unrounded = percent * steps
|
|
316
|
+
|
|
317
|
+
const val = Math.round(unrounded * accuracy) / accuracy
|
|
318
|
+
const percentVal = steps === accuracy ? val : Math.round(percent * 100 * accuracy) / accuracy
|
|
319
|
+
const res = { val, percent: percentVal }
|
|
320
|
+
if (reverse) res.val = steps - val
|
|
321
|
+
return res
|
|
322
|
+
}
|
|
323
|
+
type Types = keyof UnwrapRef<Config>
|
|
324
|
+
const elDragging = ref<Types | "">("")
|
|
325
|
+
let dragging = false
|
|
326
|
+
|
|
327
|
+
const moveHandle = (e: { clientX: number, clientY: number }, type: string) => {
|
|
328
|
+
const el = config[type].el.value
|
|
329
|
+
const { x, y, width, height } = el.getBoundingClientRect()
|
|
330
|
+
|
|
331
|
+
const info = config[type]
|
|
332
|
+
if (info.xKey !== undefined) {
|
|
333
|
+
let newPosX = e.clientX - x
|
|
334
|
+
newPosX = newPosX < 0 ? 0 : newPosX > width ? width : newPosX
|
|
335
|
+
const newX = getVal(newPosX, width, info.xSteps ?? 100)
|
|
336
|
+
|
|
337
|
+
localColor.percent[info.xKey] = newX.percent
|
|
338
|
+
localColor.val[info.xKey] = newX.val
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (info.yKey !== undefined) {
|
|
342
|
+
let newPosY = e.clientY - y
|
|
343
|
+
newPosY = newPosY < 0 ? 0 : newPosY > height ? height : newPosY
|
|
344
|
+
const newY = getVal(newPosY, height, info.ySteps ?? 100, 100, true)
|
|
345
|
+
|
|
346
|
+
localColor.percent[info.yKey] = newY.percent
|
|
347
|
+
localColor.val[info.yKey] = newY.val
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const slider = {
|
|
351
|
+
keydown: (e: KeyboardEvent, type: Types) => {
|
|
352
|
+
castType<HTMLElement | undefined>(e.target)
|
|
353
|
+
if (e.target?.getBoundingClientRect && ["ArrowRight", "ArrowLeft", "ArrowUp", "ArrowDown"].includes(e.key)) {
|
|
354
|
+
e.preventDefault()
|
|
355
|
+
const { x, y, width, height } = e.target.getBoundingClientRect()
|
|
356
|
+
let xDiff = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0
|
|
357
|
+
let yDiff = e.key === "ArrowUp" ? -1 : e.key === "ArrowDown" ? 1 : 0
|
|
358
|
+
if (e.shiftKey) {xDiff *= 10}
|
|
359
|
+
if (e.shiftKey) {yDiff *= 10}
|
|
360
|
+
moveHandle({ clientX: x + (width / 2) + xDiff, clientY: y + (height / 2) + yDiff }, type)
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
pointerdown: (e: PointerEvent, type: Types) => {
|
|
364
|
+
if (dragging) return
|
|
365
|
+
e.preventDefault()
|
|
366
|
+
elDragging.value = type
|
|
367
|
+
dragging = true
|
|
368
|
+
document.addEventListener("pointermove", slider.pointermove)
|
|
369
|
+
document.addEventListener("pointerup", slider.pointerup)
|
|
370
|
+
},
|
|
371
|
+
pointerleave: (e: PointerEvent) => {
|
|
372
|
+
if (dragging) {
|
|
373
|
+
e.preventDefault()
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
pointermove: (e: PointerEvent) => {
|
|
377
|
+
if (dragging) {
|
|
378
|
+
e.preventDefault()
|
|
379
|
+
requestAnimationFrame(() => {
|
|
380
|
+
const type = elDragging.value
|
|
381
|
+
moveHandle(e, type)
|
|
382
|
+
})
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
pointerup: (e: PointerEvent) => {
|
|
386
|
+
e.preventDefault()
|
|
387
|
+
elDragging.value = ""
|
|
388
|
+
dragging = false
|
|
389
|
+
document.removeEventListener("pointermove", slider.pointermove)
|
|
390
|
+
document.removeEventListener("pointerup", slider.pointerup)
|
|
391
|
+
},
|
|
392
|
+
}
|
|
393
|
+
const update = (_: HsvaColor, { updatePosition = true, updateValue = true }: { updatePosition?: boolean, updateValue?: boolean } = {}): void => {
|
|
394
|
+
if (alphaSliderEl.value) {
|
|
395
|
+
const hsl = colord(_)
|
|
396
|
+
const hsl0 = hsl.alpha(0).toHslString()
|
|
397
|
+
const hsl1 = hsl.alpha(1).toHslString()
|
|
398
|
+
updateSlider(alphaSliderEl.value, [hsl0, hsl1])
|
|
399
|
+
}
|
|
400
|
+
updateSlider(hueSliderEl.value!, i => `hsl(${i} 100% 50%)`)
|
|
401
|
+
updatePicker(pickerEl.value!, _.h)
|
|
402
|
+
if (updatePosition) {
|
|
403
|
+
localColor.percent.h = Math.round((_.h / 360) * 10000) / 100
|
|
404
|
+
localColor.percent.s = _.s
|
|
405
|
+
localColor.percent.v = 100 - _.v
|
|
406
|
+
localColor.percent.a =
|
|
407
|
+
props.allowAlpha
|
|
408
|
+
? _.a !== undefined
|
|
409
|
+
? _.a * 100
|
|
410
|
+
: 1
|
|
411
|
+
: 1
|
|
412
|
+
}
|
|
413
|
+
if (updateValue) {
|
|
414
|
+
localColor.val = { ..._, a: props.allowAlpha ? _.a : 1 }
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const parseInput = (e: Event): void => {
|
|
419
|
+
const val = (e.target as HTMLInputElement)?.value
|
|
420
|
+
if (val) {
|
|
421
|
+
const color = colord(val)
|
|
422
|
+
if (!color.isValid()) return
|
|
423
|
+
update(color.toHsv())
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
onMounted(() => {
|
|
428
|
+
const color = colord($value.value)
|
|
429
|
+
update(color.toHsv())
|
|
430
|
+
})
|
|
431
|
+
watch(props, () => {
|
|
432
|
+
const color = colord($value.value)
|
|
433
|
+
update(color.toHsv())
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
watch(localColor, () => {
|
|
437
|
+
update(localColor.val, { updatePosition: false, updateValue: false })
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
const save = (): void => {
|
|
441
|
+
const color = colord(localColor.val).toRgb()
|
|
442
|
+
update(localColor.val, { updatePosition: false, updateValue: false })
|
|
443
|
+
$value.value = color
|
|
444
|
+
emits("save", color)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const invertColors = computed(() => !!(localColor.percent.v < 50 || (localColor.val.a === undefined || localColor.val.a < 0.5)))
|
|
448
|
+
</script>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @ts-nocheck remove when copying
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
3
|
+
import type { Meta, StoryObj } from "@storybook/vue3"
|
|
4
|
+
import { ref } from "vue"
|
|
5
|
+
|
|
6
|
+
import LibDarkModeSwitcher from "./LibDarkModeSwitcher.vue"
|
|
7
|
+
|
|
8
|
+
// todo, maybe don't do this for perf reasons
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
10
|
+
import * as components from "../index.js"
|
|
11
|
+
|
|
12
|
+
const meta: Meta<typeof LibDarkModeSwitcher> = {
|
|
13
|
+
component: LibDarkModeSwitcher,
|
|
14
|
+
title: "Components/DarkModeSwitcher",
|
|
15
|
+
args: {
|
|
16
|
+
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default meta
|
|
21
|
+
type Story = StoryObj<typeof LibDarkModeSwitcher>
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export const Primary: Story = {
|
|
25
|
+
render: args => ({
|
|
26
|
+
components,
|
|
27
|
+
setup: () => {
|
|
28
|
+
const darkMode = ref(false)
|
|
29
|
+
return {
|
|
30
|
+
args,
|
|
31
|
+
darkMode
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
template: `
|
|
35
|
+
Value: {{darkMode}}
|
|
36
|
+
<LibDarkModeSwitcher
|
|
37
|
+
@update:darkMode="darkMode = $event"
|
|
38
|
+
v-bind="{...args}"
|
|
39
|
+
></LibDarkModeSwitcher>
|
|
40
|
+
|
|
41
|
+
`,
|
|
42
|
+
}),
|
|
43
|
+
}
|
|
44
|
+
export const WithoutLabel: Story = {
|
|
45
|
+
...Primary,
|
|
46
|
+
args: {
|
|
47
|
+
...Primary.args,
|
|
48
|
+
autoLabel: false,
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<lib-button
|
|
3
|
+
v-bind="{...$attrs, class:undefined}"
|
|
4
|
+
:class="!($attrs as any).unstyle && twMerge(`
|
|
5
|
+
rounded-full
|
|
6
|
+
after:rounded-full
|
|
7
|
+
`,
|
|
8
|
+
($attrs as any)?.class
|
|
9
|
+
)"
|
|
10
|
+
:title="`${t('dark-mode-switcher.title')}${t(`dark-mode-switcher.${darkModeState}`)}`"
|
|
11
|
+
:label="showLabel
|
|
12
|
+
? t(`dark-mode-switcher.${darkModeState}`)
|
|
13
|
+
: ''
|
|
14
|
+
"
|
|
15
|
+
@click="cycleDarkMode"
|
|
16
|
+
>
|
|
17
|
+
<template #icon>
|
|
18
|
+
<icon
|
|
19
|
+
v-if="darkModeState==='dark'"
|
|
20
|
+
class="w-[1em] flex items-center"
|
|
21
|
+
>
|
|
22
|
+
<i-fa-solid-moon/>
|
|
23
|
+
</icon>
|
|
24
|
+
<icon
|
|
25
|
+
v-else-if="darkModeState==='light'"
|
|
26
|
+
class="w-[1em]"
|
|
27
|
+
>
|
|
28
|
+
<i-ph-sun-bold/>
|
|
29
|
+
</icon>
|
|
30
|
+
<icon
|
|
31
|
+
v-else
|
|
32
|
+
class="w-[1em]"
|
|
33
|
+
>
|
|
34
|
+
<i-fa6-solid-circle-half-stroke/>
|
|
35
|
+
</icon>
|
|
36
|
+
</template>
|
|
37
|
+
</lib-button>
|
|
38
|
+
</template>
|
|
39
|
+
<script lang="ts" setup>
|
|
40
|
+
import { type ButtonHTMLAttributes,onMounted,useAttrs, watch } from "vue"
|
|
41
|
+
|
|
42
|
+
import { useInjectedDarkMode } from "../../composables/useInjectedDarkMode.js"
|
|
43
|
+
import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
|
|
44
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
45
|
+
import Icon from "../Icon/Icon.vue"
|
|
46
|
+
import LibButton from "../LibButton/LibButton.vue"
|
|
47
|
+
import type { TailwindClassProp } from "../shared/props.js"
|
|
48
|
+
|
|
49
|
+
const t = useInjectedI18n()
|
|
50
|
+
|
|
51
|
+
const emit = defineEmits<{
|
|
52
|
+
/** Emits whether dark mode should be enabled. */
|
|
53
|
+
(e: "update:darkMode", value: boolean): void
|
|
54
|
+
/** Emits the change, but as a state string (dark, light, system) */
|
|
55
|
+
(e: "update:darkModeState", value: "dark" | "light" | "system"): void
|
|
56
|
+
}>()
|
|
57
|
+
const $attrs = useAttrs()
|
|
58
|
+
|
|
59
|
+
// eslint-disable-next-line no-use-before-define
|
|
60
|
+
withDefaults(defineProps<Props>(), { })
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const {
|
|
64
|
+
darkMode,
|
|
65
|
+
cycleDarkMode,
|
|
66
|
+
darkModeState,
|
|
67
|
+
} = useInjectedDarkMode()
|
|
68
|
+
|
|
69
|
+
watch(darkMode, value => emit("update:darkMode", value))
|
|
70
|
+
watch(darkModeState, value => emit("update:darkModeState", value))
|
|
71
|
+
|
|
72
|
+
onMounted(() => {
|
|
73
|
+
emit("update:darkMode", darkMode.value)
|
|
74
|
+
})
|
|
75
|
+
</script>
|
|
76
|
+
<script lang="ts">
|
|
77
|
+
export default {
|
|
78
|
+
name: "lib-dark-mode-switcher"
|
|
79
|
+
}
|
|
80
|
+
type RealProps = {
|
|
81
|
+
showLabel?: boolean
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface Props
|
|
85
|
+
extends
|
|
86
|
+
/** @vue-ignore */
|
|
87
|
+
Partial<Omit<ButtonHTMLAttributes,"class" | "color" | "disabled">
|
|
88
|
+
& TailwindClassProp
|
|
89
|
+
& {
|
|
90
|
+
disabled?: boolean
|
|
91
|
+
unstyle?: boolean
|
|
92
|
+
}>,
|
|
93
|
+
RealProps
|
|
94
|
+
{ }
|
|
95
|
+
</script>
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
import { CalendarDate,fromDate, getLocalTimeZone, toTimeZone } from "@internationalized/date"
|
|
3
|
+
import type { Meta, StoryObj } from "@storybook/vue3"
|
|
4
|
+
import { computed,ref } from "vue"
|
|
5
|
+
|
|
6
|
+
import { createNoonUtcDate } from "../../helpers/createNoonUtcDate.js"
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
8
|
+
import * as components from "../index.js"
|
|
9
|
+
|
|
10
|
+
function html(strings: TemplateStringsArray, ...values: any[]): string {
|
|
11
|
+
return String.raw(strings, ...values)
|
|
12
|
+
}
|
|
13
|
+
const singleMeta: Meta<typeof components.LibDatePicker> = {
|
|
14
|
+
component: components.LibDatePicker,
|
|
15
|
+
title: "Components/DatePicker",
|
|
16
|
+
args: {
|
|
17
|
+
// @ts-expect-error custom prop just for story
|
|
18
|
+
slot: "",
|
|
19
|
+
timeZone: getLocalTimeZone(),
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default singleMeta
|
|
24
|
+
type Story = StoryObj<typeof components.LibDatePicker>
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
function toUTC(m: Date, timeZone: string) {
|
|
28
|
+
return toTimeZone(fromDate(m, timeZone), "UTC").toAbsoluteString()
|
|
29
|
+
}
|
|
30
|
+
export const Primary: Story = {
|
|
31
|
+
render: (args: any) => ({
|
|
32
|
+
components: {
|
|
33
|
+
...components,
|
|
34
|
+
},
|
|
35
|
+
setup: () => {
|
|
36
|
+
const modelValue = ref(args.modelValue)
|
|
37
|
+
const timeZone = ref(args.timeZone)
|
|
38
|
+
const debugUtcDate = computed(() => {
|
|
39
|
+
const m = modelValue.value
|
|
40
|
+
const z = timeZone.value
|
|
41
|
+
return m instanceof Date
|
|
42
|
+
? toUTC(m, z)
|
|
43
|
+
: typeof m === "object"
|
|
44
|
+
? `Start: ${m.start ? toUTC(m.start, z) : "undefined"}, End: ${m.end ? toUTC(m.end, z) : "undefined"}`
|
|
45
|
+
: "undefined"
|
|
46
|
+
})
|
|
47
|
+
return { args, getLocalTimeZone, modelValue, timeZone, debugUtcDate } },
|
|
48
|
+
template: `
|
|
49
|
+
<div>Date: {{modelValue ?? "undefined"}}</div>
|
|
50
|
+
<div>Date UTC: {{debugUtcDate}}</div>
|
|
51
|
+
<div>Detected timezone (via @internationalized/date): {{getLocalTimeZone()}}</div>
|
|
52
|
+
<LibTimeZonePicker
|
|
53
|
+
v-model="timeZone"
|
|
54
|
+
label="Override Time Zone"
|
|
55
|
+
wrapper-class="[&_.suggestions]:max-h-[200px] [&_.suggestions]:overflow-y-auto"
|
|
56
|
+
/>
|
|
57
|
+
<div>
|
|
58
|
+
This component has no border, added here to see it's size.
|
|
59
|
+
</div>
|
|
60
|
+
<div class="border border-neutral-500">
|
|
61
|
+
<LibDatePicker v-bind="args" v-model="modelValue" :time-zone="timeZone">
|
|
62
|
+
${args.slot}
|
|
63
|
+
</LibDatePicker>
|
|
64
|
+
</div>
|
|
65
|
+
`,
|
|
66
|
+
}),
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const DateRange: Story = {
|
|
70
|
+
...Primary,
|
|
71
|
+
args: {
|
|
72
|
+
modelValue: { start: undefined, end: undefined },
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const IconTriggerFirst: Story = {
|
|
77
|
+
...Primary,
|
|
78
|
+
args: {
|
|
79
|
+
...Primary.args,
|
|
80
|
+
class: "[&_.trigger]:order-first"
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const BottomSlot: Story = {
|
|
85
|
+
...Primary,
|
|
86
|
+
args: {
|
|
87
|
+
// @ts-expect-error see above
|
|
88
|
+
slot: html`
|
|
89
|
+
<template #default="slotProps">
|
|
90
|
+
<LibButton>Custom content can be added here.</LibButton>
|
|
91
|
+
<p class="break-all">
|
|
92
|
+
Content has access to the internal temporary/suggested date value and can change it (e.g. set it to today).
|
|
93
|
+
</p>
|
|
94
|
+
<p>Temp value:</p>
|
|
95
|
+
{{ slotProps.tempValue }}
|
|
96
|
+
</template>
|
|
97
|
+
`
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const DateWithTime: Story = {
|
|
102
|
+
...Primary,
|
|
103
|
+
args: {
|
|
104
|
+
...Primary.args,
|
|
105
|
+
showTime: true,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export const WithDifferentFallbackDate: Story = {
|
|
109
|
+
...Primary,
|
|
110
|
+
args: {
|
|
111
|
+
...Primary.args,
|
|
112
|
+
fallbackDate: createNoonUtcDate(new CalendarDate(2000, 1, 1)).toDate()
|
|
113
|
+
}
|
|
114
|
+
}
|