@witchcraft/ui 0.2.1-beta.2 → 0.2.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/dist/module.json +1 -1
- package/dist/module.mjs +4 -5
- package/dist/runtime/build/WitchcraftUiResolver.d.ts +2 -2
- package/dist/runtime/build/generateTheme.js +2 -2
- package/dist/runtime/components/Aria/Aria.vue +4 -2
- package/dist/runtime/components/Aria/Aria.vue.d.ts +1 -1
- package/dist/runtime/components/Icon/Icon.vue +3 -3
- package/dist/runtime/components/Icon/Icon.vue.d.ts +1 -1
- package/dist/runtime/components/LibButton/LibButton.vue +9 -4
- package/dist/runtime/components/LibButton/LibButton.vue.d.ts +1 -1
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +3 -4
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +1 -1
- package/dist/runtime/components/LibColorInput/LibColorInput.vue +15 -8
- package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +1 -1
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +10 -6
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +1 -1
- package/dist/runtime/components/LibColorPicker/utils/truncate.js +1 -1
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +5 -2
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +1 -1
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +1 -1
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +8 -6
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +1 -1
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +7 -5
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +1 -1
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +1 -1
- package/dist/runtime/components/LibDebug/LibDebug.vue +9 -4
- package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +1 -1
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +2 -1
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +4 -1
- package/dist/runtime/components/LibFileInput/LibFileInput.vue +29 -13
- package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +2 -2
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +42 -12
- package/dist/runtime/components/LibLabel/LibLabel.vue +2 -2
- package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +3 -3
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +1 -2
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +2 -2
- package/dist/runtime/components/LibNotifications/LibNotification.vue +19 -8
- package/dist/runtime/components/LibNotifications/LibNotifications.vue +10 -6
- package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +2 -2
- package/dist/runtime/components/LibPagination/LibPagination.vue +25 -12
- package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +2 -2
- package/dist/runtime/components/LibPalette/LibPalette.vue +6 -5
- package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +5 -5
- package/dist/runtime/components/LibPopup/LibPopup.vue +6 -4
- package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +3 -3
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +5 -3
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +9 -9
- package/dist/runtime/components/LibRecorder/LibRecorder.vue +1 -1
- package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +2 -2
- package/dist/runtime/components/LibRoot/LibRoot.vue +11 -6
- package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +1 -1
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +1 -1
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +1 -1
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +5 -3
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +1 -1
- package/dist/runtime/components/LibTable/LibTable.vue +23 -8
- package/dist/runtime/components/LibTable/LibTable.vue.d.ts +1 -1
- package/dist/runtime/components/Template/NAME.vue +2 -3
- package/dist/runtime/components/Template/NAME.vue.d.ts +1 -1
- package/dist/runtime/components/TestControls/TestControls.vue +4 -2
- package/dist/runtime/components/TestControls/TestControls.vue.d.ts +1 -1
- package/dist/runtime/composables/useDragWithThreshold.d.ts +1 -1
- package/dist/runtime/composables/useInjectedI18n.d.ts +1 -1
- package/dist/runtime/composables/useScrollNearContainerEdges.d.ts +1 -1
- package/dist/runtime/composables/useSetupI18n.d.ts +1 -1
- package/dist/runtime/composables/useSuggestions.d.ts +2 -2
- package/dist/runtime/helpers/NotificationHandler.d.ts +1 -1
- package/dist/runtime/helpers/base64ToImg.js +2 -2
- package/dist/runtime/tailwind/themeConvertionOpts.d.ts +1 -1
- package/dist/runtime/types/index.d.ts +1 -1
- package/dist/runtime/utils/notifyIfError.d.ts +1 -1
- package/package.json +4 -6
- package/src/module.ts +28 -32
- package/src/runtime/build/WitchcraftUiResolver.ts +3 -3
- package/src/runtime/build/generateTheme.ts +3 -2
- package/src/runtime/build/unpluginIconViteOptions.ts +1 -1
- package/src/runtime/components/Aria/Aria.vue +5 -6
- package/src/runtime/components/Focus.stories.ts +11 -12
- package/src/runtime/components/Icon/Icon.vue +5 -9
- package/src/runtime/components/LibButton/LibButton.stories.ts +21 -22
- package/src/runtime/components/LibButton/LibButton.vue +23 -21
- package/src/runtime/components/LibCheckbox/LibCheckbox.stories.ts +6 -10
- package/src/runtime/components/LibCheckbox/LibCheckbox.vue +17 -19
- package/src/runtime/components/LibColorInput/LibColorInput.stories.ts +8 -13
- package/src/runtime/components/LibColorInput/LibColorInput.vue +49 -45
- package/src/runtime/components/LibColorPicker/LibColorPicker.stories.ts +14 -18
- package/src/runtime/components/LibColorPicker/LibColorPicker.vue +50 -52
- package/src/runtime/components/LibColorPicker/utils/safeConvertToHsva.ts +1 -2
- package/src/runtime/components/LibColorPicker/utils/safeConvertToRgba.ts +1 -2
- package/src/runtime/components/LibColorPicker/utils/truncate.ts +1 -2
- package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.ts +5 -8
- package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +11 -9
- package/src/runtime/components/LibDatePicker/LibDatePicker.stories.ts +14 -15
- package/src/runtime/components/LibDatePicker/LibDatePicker.vue +1 -2
- package/src/runtime/components/LibDatePicker/LibRangeDatePicker.vue +13 -13
- package/src/runtime/components/LibDatePicker/LibSingleDatePicker.vue +9 -8
- package/src/runtime/components/LibDatePicker/LibTimeZonePicker.vue +2 -1
- package/src/runtime/components/LibDatePicker/helpers.ts +0 -2
- package/src/runtime/components/LibDebug/LibDebug.stories.ts +11 -15
- package/src/runtime/components/LibDebug/LibDebug.vue +14 -11
- package/src/runtime/components/LibDevOnly/LibDevOnly.vue +8 -4
- package/src/runtime/components/LibFileInput/LibFileInput.stories.ts +12 -15
- package/src/runtime/components/LibFileInput/LibFileInput.vue +65 -47
- package/src/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.ts +59 -67
- package/src/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +73 -48
- package/src/runtime/components/LibLabel/LibLabel.stories.ts +4 -8
- package/src/runtime/components/LibLabel/LibLabel.vue +8 -8
- package/src/runtime/components/LibMultiValues/LibMultiValues.stories.ts +10 -15
- package/src/runtime/components/LibMultiValues/LibMultiValues.vue +14 -18
- package/src/runtime/components/LibNotifications/LibNotification.stories.ts +30 -34
- package/src/runtime/components/LibNotifications/LibNotification.vue +27 -17
- package/src/runtime/components/LibNotifications/LibNotifications.stories.ts +11 -15
- package/src/runtime/components/LibNotifications/LibNotifications.vue +21 -16
- package/src/runtime/components/LibPagination/LibPagination.stories.ts +5 -9
- package/src/runtime/components/LibPagination/LibPagination.vue +46 -32
- package/src/runtime/components/LibPalette/LibPalette.stories.ts +3 -7
- package/src/runtime/components/LibPalette/LibPalette.vue +13 -12
- package/src/runtime/components/LibPopup/LibPopup.stories.ts +19 -23
- package/src/runtime/components/LibPopup/LibPopup.vue +31 -35
- package/src/runtime/components/LibProgressBar/LibProgressBar.stories.ts +13 -17
- package/src/runtime/components/LibProgressBar/LibProgressBar.vue +36 -33
- package/src/runtime/components/LibRecorder/LibRecorder.stories.ts +11 -12
- package/src/runtime/components/LibRecorder/LibRecorder.vue +34 -34
- package/src/runtime/components/LibRoot/LibRoot.vue +16 -12
- package/src/runtime/components/LibSimpleInput/LibSimpleInput.stories.ts +20 -24
- package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +17 -21
- package/src/runtime/components/LibSuggestions/LibSuggestions.stories.ts +16 -19
- package/src/runtime/components/LibSuggestions/LibSuggestions.vue +27 -30
- package/src/runtime/components/LibTable/LibTable.stories.ts +30 -33
- package/src/runtime/components/LibTable/LibTable.vue +38 -24
- package/src/runtime/components/Reset.stories.ts +3 -6
- package/src/runtime/components/Scrolling.stories.ts +5 -8
- package/src/runtime/components/Template/NAME.vue +11 -11
- package/src/runtime/components/Template/TemplateStory.ts +9 -10
- package/src/runtime/components/TestControls/TestControls.vue +5 -5
- package/src/runtime/components/shared/props.ts +4 -6
- package/src/runtime/components/shared/storyHelpers/playInput.ts +2 -3
- package/src/runtime/components/shared/storyHelpers/playSuggestions.ts +5 -9
- package/src/runtime/composables/useAccesibilityOutline.ts +1 -1
- package/src/runtime/composables/useAriaLabel.ts +1 -1
- package/src/runtime/composables/useDarkMode.ts +15 -19
- package/src/runtime/composables/useDragWithThreshold.ts +6 -8
- package/src/runtime/composables/useGlobalResizeObserver.ts +0 -1
- package/src/runtime/composables/useInjectedDarkMode.ts +2 -2
- package/src/runtime/composables/useInjectedI18n.ts +1 -1
- package/src/runtime/composables/useInjectedLocale.ts +3 -4
- package/src/runtime/composables/useScrollNearContainerEdges.stories.ts +4 -4
- package/src/runtime/composables/useScrollNearContainerEdges.ts +12 -13
- package/src/runtime/composables/useSetupI18n.ts +4 -7
- package/src/runtime/composables/useSetupLocale.ts +3 -5
- package/src/runtime/composables/useSuggestions.ts +25 -30
- package/src/runtime/directives/vDetectFlex.ts +5 -8
- package/src/runtime/directives/vExtractRootEl.ts +1 -1
- package/src/runtime/directives/vResizableCols.ts +3 -7
- package/src/runtime/directives/vResizeObserver.ts +1 -2
- package/src/runtime/globalResizeObserver.ts +0 -1
- package/src/runtime/helpers/NotificationHandler.ts +8 -12
- package/src/runtime/helpers/base64ToImg.ts +2 -3
- package/src/runtime/helpers/createNoonUtcDate.ts +0 -1
- package/src/runtime/helpers/defaultTranslationFunction.ts +0 -1
- package/src/runtime/helpers/getTimeZoneList.ts +0 -1
- package/src/runtime/helpers/readFile.ts +2 -2
- package/src/runtime/helpers/resizeObserverWrapper.ts +0 -1
- package/src/runtime/helpers/storybook.ts +2 -3
- package/src/runtime/main.lib.ts +0 -2
- package/src/runtime/nuxt/plugins/vue-plugin.ts +4 -5
- package/src/runtime/tailwind/themeConvertionOpts.ts +3 -4
- package/src/runtime/theme.ts +0 -1
- package/src/runtime/types/index.ts +3 -4
- package/src/runtime/utils/notifyIfError.ts +2 -2
- package/src/runtime/utils/twMerge.ts +2 -2
- package/src/runtime/vue/VueComponentsPlugin.ts +1 -2
- package/src/runtime/vue/registerComponents.ts +0 -1
|
@@ -4,22 +4,19 @@ import { ref } from "vue"
|
|
|
4
4
|
|
|
5
5
|
import LibColorInput from "./LibColorInput.vue"
|
|
6
6
|
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
8
7
|
import * as components from "../index.js"
|
|
9
8
|
|
|
10
|
-
|
|
11
9
|
const meta: Meta<typeof LibColorInput> = {
|
|
12
10
|
component: LibColorInput,
|
|
13
11
|
title: "Components/ColorInput",
|
|
14
12
|
args: {
|
|
15
|
-
|
|
16
|
-
}
|
|
13
|
+
|
|
14
|
+
}
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
export default meta
|
|
20
18
|
type Story = StoryObj<typeof LibColorInput>
|
|
21
19
|
|
|
22
|
-
|
|
23
20
|
export const Primary: Story = {
|
|
24
21
|
render: args => ({
|
|
25
22
|
components,
|
|
@@ -33,9 +30,9 @@ export const Primary: Story = {
|
|
|
33
30
|
outline: false,
|
|
34
31
|
color,
|
|
35
32
|
allowAlpha: true,
|
|
36
|
-
...args
|
|
33
|
+
...args
|
|
37
34
|
},
|
|
38
|
-
handleChange
|
|
35
|
+
handleChange
|
|
39
36
|
}
|
|
40
37
|
},
|
|
41
38
|
template: `
|
|
@@ -55,15 +52,13 @@ export const Primary: Story = {
|
|
|
55
52
|
>
|
|
56
53
|
</lib-color-Input>
|
|
57
54
|
</div>
|
|
58
|
-
|
|
59
|
-
})
|
|
55
|
+
`
|
|
56
|
+
})
|
|
60
57
|
}
|
|
61
58
|
|
|
62
|
-
|
|
63
59
|
export const DoesNotAllowAlpha: Story = {
|
|
64
60
|
...Primary,
|
|
65
61
|
args: {
|
|
66
|
-
allowAlpha: false
|
|
67
|
-
}
|
|
62
|
+
allowAlpha: false
|
|
63
|
+
}
|
|
68
64
|
}
|
|
69
|
-
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
v-model="showPopup"
|
|
5
5
|
@close="$tempValue = undefined;emit('cancel')"
|
|
6
6
|
>
|
|
7
|
-
<template #button="{extractEl}">
|
|
7
|
+
<template #button="{ extractEl }">
|
|
8
8
|
<!-- <div -->
|
|
9
9
|
<!-- class=" -->
|
|
10
10
|
<!-- flex -->
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<!-- " -->
|
|
14
14
|
<!-- v-extract-root-el="extractEl" -->
|
|
15
15
|
<!-- > -->
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
<!-- -->
|
|
18
18
|
<lib-button
|
|
19
19
|
:id="id ?? fallbackId"
|
|
@@ -31,28 +31,31 @@
|
|
|
31
31
|
)"
|
|
32
32
|
:aria-label="t('color-input.aria-and-title-prefix') + stringColor"
|
|
33
33
|
:title="t('color-input.aria-and-title-prefix') + stringColor"
|
|
34
|
-
v-bind="{...$attrs, class: undefined}"
|
|
34
|
+
v-bind="{ ...$attrs, class: undefined }"
|
|
35
35
|
v-extract-root-el="extractEl"
|
|
36
36
|
@click="togglePopup"
|
|
37
37
|
>
|
|
38
38
|
<template #label>
|
|
39
|
-
<div
|
|
39
|
+
<div
|
|
40
|
+
class="
|
|
40
41
|
color-input--swatch-wrapper
|
|
41
42
|
flex
|
|
42
43
|
w-full
|
|
43
44
|
"
|
|
44
45
|
>
|
|
45
|
-
<slot v-bind="{stringColor, classes:swatchClasses}">
|
|
46
|
-
<div
|
|
46
|
+
<slot v-bind="{ stringColor, classes: swatchClasses }">
|
|
47
|
+
<div
|
|
48
|
+
:class="swatchClasses"
|
|
47
49
|
:style="`background:${stringColor}`"
|
|
48
50
|
/>
|
|
49
51
|
</slot>
|
|
50
52
|
<slot
|
|
51
53
|
v-if="$tempValue"
|
|
52
|
-
v-bind="{tempStringColor, classes:swatchClasses}"
|
|
54
|
+
v-bind="{ tempStringColor, classes: swatchClasses }"
|
|
53
55
|
name="temp"
|
|
54
56
|
>
|
|
55
|
-
<div
|
|
57
|
+
<div
|
|
58
|
+
:class="swatchClasses"
|
|
56
59
|
:style="`background:${tempStringColor}`"
|
|
57
60
|
/>
|
|
58
61
|
</slot>
|
|
@@ -60,9 +63,13 @@
|
|
|
60
63
|
</template>
|
|
61
64
|
</lib-button>
|
|
62
65
|
</template>
|
|
63
|
-
<template #popup="{extractEl}">
|
|
64
|
-
<div
|
|
65
|
-
|
|
66
|
+
<template #popup="{ extractEl }">
|
|
67
|
+
<div
|
|
68
|
+
class="color-input--popup-wrapper p-5"
|
|
69
|
+
v-extract-root-el="extractEl"
|
|
70
|
+
>
|
|
71
|
+
<lib-color-picker
|
|
72
|
+
v-if="showPopup"
|
|
66
73
|
:id="id ?? fallbackId"
|
|
67
74
|
:allow-alpha="allowAlpha"
|
|
68
75
|
:custom-representation="customRepresentation"
|
|
@@ -79,7 +86,7 @@
|
|
|
79
86
|
|
|
80
87
|
<script setup lang="ts">
|
|
81
88
|
import Color from "colorjs.io"
|
|
82
|
-
import { type ButtonHTMLAttributes,computed,
|
|
89
|
+
import { type ButtonHTMLAttributes, computed, ref, useAttrs } from "vue"
|
|
83
90
|
|
|
84
91
|
import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
|
|
85
92
|
import { vExtractRootEl } from "../../directives/vExtractRootEl.js"
|
|
@@ -90,9 +97,8 @@ import LibColorPicker from "../LibColorPicker/LibColorPicker.vue"
|
|
|
90
97
|
import LibPopup from "../LibPopup/LibPopup.vue"
|
|
91
98
|
import { getFallbackId, type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js"
|
|
92
99
|
|
|
93
|
-
|
|
94
100
|
defineOptions({
|
|
95
|
-
name: "
|
|
101
|
+
name: "LibColorInput"
|
|
96
102
|
})
|
|
97
103
|
|
|
98
104
|
const swatchClasses = `
|
|
@@ -111,19 +117,18 @@ const swatchClasses = `
|
|
|
111
117
|
const fallbackId = getFallbackId()
|
|
112
118
|
|
|
113
119
|
const t = useInjectedI18n()
|
|
114
|
-
const props =
|
|
120
|
+
/* const props = */withDefaults(defineProps<Props>(), {
|
|
115
121
|
allowAlpha: true,
|
|
116
122
|
border: true,
|
|
117
123
|
copyTransform: (_val: HsvaColor, stringVal: string) => stringVal,
|
|
118
124
|
stringPrecision: 3,
|
|
119
|
-
customRepresentation: undefined
|
|
125
|
+
customRepresentation: undefined
|
|
120
126
|
})
|
|
121
127
|
const emit = defineEmits<{
|
|
122
128
|
(e: "save"): void
|
|
123
129
|
(e: "cancel"): void
|
|
124
130
|
}>()
|
|
125
131
|
|
|
126
|
-
|
|
127
132
|
function save() {
|
|
128
133
|
$value.value = internalTempValue.value
|
|
129
134
|
showPopup.value = false
|
|
@@ -137,63 +142,62 @@ function cancel() {
|
|
|
137
142
|
}
|
|
138
143
|
|
|
139
144
|
const $attrs = useAttrs()
|
|
140
|
-
|
|
145
|
+
|
|
141
146
|
const $value = defineModel<RgbaColor>({ required: false, default: () => ({ r: 0, g: 0, b: 0 }) })
|
|
142
147
|
const $tempValue = defineModel<RgbaColor | undefined>("tempValue", { required: false, default: () => (undefined) })
|
|
143
148
|
|
|
144
149
|
const stringColor = computed(() => new Color("srgb", [
|
|
145
150
|
$value.value.r / 255,
|
|
146
151
|
$value.value.g / 255,
|
|
147
|
-
$value.value.b / 255
|
|
148
|
-
], $value.value.a ?? 1
|
|
152
|
+
$value.value.b / 255
|
|
153
|
+
], $value.value.a ?? 1).toString())
|
|
149
154
|
|
|
150
|
-
const tempStringColor = computed(() => $tempValue.value
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
+
const tempStringColor = computed(() => $tempValue.value
|
|
156
|
+
? new Color("srgb", [
|
|
157
|
+
$tempValue.value.r / 255,
|
|
158
|
+
$tempValue.value.g / 255,
|
|
159
|
+
$tempValue.value.b / 255
|
|
160
|
+
], $tempValue.value.a ?? 1).toString()
|
|
161
|
+
: "")
|
|
155
162
|
|
|
156
163
|
const internalTempValue = ref({ ...$value.value })
|
|
157
164
|
|
|
158
165
|
const showPopup = ref(false)
|
|
159
166
|
|
|
160
|
-
|
|
161
167
|
const togglePopup = (): void => {
|
|
162
168
|
if (showPopup.value) {
|
|
163
169
|
$value.value = internalTempValue.value
|
|
164
170
|
}
|
|
165
171
|
showPopup.value = !showPopup.value
|
|
166
172
|
}
|
|
167
|
-
|
|
168
173
|
</script>
|
|
169
174
|
|
|
170
175
|
<script lang="ts">
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
&
|
|
174
|
-
&
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
176
|
+
type RealProps
|
|
177
|
+
= & LabelProps
|
|
178
|
+
& LinkableByIdProps
|
|
179
|
+
& {
|
|
180
|
+
allowAlpha?: boolean
|
|
181
|
+
border?: boolean
|
|
182
|
+
/** See ColorPicker.copyTransform */
|
|
183
|
+
copyTransform?: (val: HsvaColor, stringVal: string) => any
|
|
184
|
+
/** See ColorPicker.allowAlpha */
|
|
185
|
+
stringPrecision?: number
|
|
186
|
+
/** See ColorPicker.customRepresentation */
|
|
187
|
+
customRepresentation?: {
|
|
188
|
+
fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string
|
|
189
|
+
}
|
|
190
|
+
}
|
|
187
191
|
interface Props
|
|
188
192
|
extends
|
|
189
193
|
/** @vue-ignore */
|
|
190
|
-
Partial<Omit<ButtonHTMLAttributes,"class">
|
|
194
|
+
Partial<Omit<ButtonHTMLAttributes, "class">
|
|
191
195
|
& TailwindClassProp
|
|
192
196
|
& {
|
|
193
197
|
// why is this not already a part of button?
|
|
198
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
194
199
|
"aria-label": string
|
|
195
200
|
}>,
|
|
196
201
|
RealProps
|
|
197
202
|
{}
|
|
198
203
|
</script>
|
|
199
|
-
|
|
@@ -5,22 +5,19 @@ import { ref } from "vue"
|
|
|
5
5
|
|
|
6
6
|
import LibColorPicker from "./LibColorPicker.vue"
|
|
7
7
|
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
9
8
|
import * as components from "../index.js"
|
|
10
9
|
|
|
11
|
-
|
|
12
10
|
const meta: Meta<typeof LibColorPicker> = {
|
|
13
11
|
component: LibColorPicker,
|
|
14
12
|
title: "Components/ColorPicker",
|
|
15
13
|
args: {
|
|
16
|
-
|
|
17
|
-
}
|
|
14
|
+
|
|
15
|
+
}
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
export default meta
|
|
21
19
|
type Story = StoryObj<typeof LibColorPicker>
|
|
22
20
|
|
|
23
|
-
|
|
24
21
|
export const Primary: Story = {
|
|
25
22
|
render: args => ({
|
|
26
23
|
components,
|
|
@@ -35,9 +32,9 @@ export const Primary: Story = {
|
|
|
35
32
|
outline: false,
|
|
36
33
|
color,
|
|
37
34
|
allowAlpha: true,
|
|
38
|
-
...args
|
|
35
|
+
...args
|
|
39
36
|
},
|
|
40
|
-
handleChange
|
|
37
|
+
handleChange
|
|
41
38
|
}
|
|
42
39
|
},
|
|
43
40
|
template: `
|
|
@@ -50,20 +47,20 @@ export const Primary: Story = {
|
|
|
50
47
|
>
|
|
51
48
|
</lib-color-picker>
|
|
52
49
|
</lib-root>
|
|
53
|
-
|
|
54
|
-
})
|
|
50
|
+
`
|
|
51
|
+
})
|
|
55
52
|
}
|
|
56
53
|
export const DoesNotAllowAlpha: Story = {
|
|
57
54
|
...Primary,
|
|
58
55
|
args: {
|
|
59
|
-
allowAlpha: false
|
|
60
|
-
}
|
|
56
|
+
allowAlpha: false
|
|
57
|
+
}
|
|
61
58
|
}
|
|
62
59
|
export const WithExistingValue: Story = {
|
|
63
60
|
...Primary,
|
|
64
61
|
args: {
|
|
65
|
-
modelValue: { r: 255, g: 0, b: 0 }
|
|
66
|
-
}
|
|
62
|
+
modelValue: { r: 255, g: 0, b: 0 }
|
|
63
|
+
}
|
|
67
64
|
}
|
|
68
65
|
export const CustomStringRepresentation: Story = {
|
|
69
66
|
...Primary,
|
|
@@ -73,9 +70,8 @@ export const CustomStringRepresentation: Story = {
|
|
|
73
70
|
fromHsvaToString: (hsva: any, includeAlpha: boolean) => new Color(
|
|
74
71
|
"hsv",
|
|
75
72
|
[hsva.h, hsva.s, hsva.v],
|
|
76
|
-
|
|
77
|
-
).toString({ format: "hex" })
|
|
78
|
-
}
|
|
79
|
-
}
|
|
73
|
+
includeAlpha ? hsva.a : 1 // this takes care of the correct hex format
|
|
74
|
+
).toString({ format: "hex" })
|
|
75
|
+
}
|
|
76
|
+
}
|
|
80
77
|
}
|
|
81
|
-
|
|
@@ -113,7 +113,8 @@
|
|
|
113
113
|
/>
|
|
114
114
|
</div>
|
|
115
115
|
<div class="color-picker--footer flex w-full flex-1 gap-2">
|
|
116
|
-
<div
|
|
116
|
+
<div
|
|
117
|
+
class=" color-picker--preview-wrapper
|
|
117
118
|
bg-transparency-squares
|
|
118
119
|
relative
|
|
119
120
|
aspect-square
|
|
@@ -122,7 +123,8 @@
|
|
|
122
123
|
shadow-xs
|
|
123
124
|
"
|
|
124
125
|
>
|
|
125
|
-
<div
|
|
126
|
+
<div
|
|
127
|
+
class="
|
|
126
128
|
color-picker--footer--preview
|
|
127
129
|
size-full
|
|
128
130
|
rounded-full
|
|
@@ -143,7 +145,11 @@
|
|
|
143
145
|
@input="parseInput"
|
|
144
146
|
@blur="onBlurFixInvalidValue"
|
|
145
147
|
/>
|
|
146
|
-
<lib-button
|
|
148
|
+
<lib-button
|
|
149
|
+
class="color-picker--copy-button"
|
|
150
|
+
:aria-label="t('copy')"
|
|
151
|
+
@click="copy(copyTransform?.(localColor.val, localColorString) ?? localColorString)"
|
|
152
|
+
>
|
|
147
153
|
<icon><i-fa6-regular-copy/></icon>
|
|
148
154
|
</lib-button>
|
|
149
155
|
</slot>
|
|
@@ -171,11 +177,10 @@
|
|
|
171
177
|
<script setup lang="ts">
|
|
172
178
|
/* todo change to colorjsio for less dependencies */
|
|
173
179
|
import { castType } from "@alanscodelog/utils/castType"
|
|
174
|
-
import { clampNumber } from "@alanscodelog/utils/clampNumber"
|
|
175
180
|
import { isArray } from "@alanscodelog/utils/isArray"
|
|
176
181
|
import { unreachable } from "@alanscodelog/utils/unreachable"
|
|
177
182
|
import Color from "colorjs.io"
|
|
178
|
-
import { computed, onMounted, reactive, type Ref, ref, type UnwrapRef,useAttrs, watch } from "vue"
|
|
183
|
+
import { computed, onMounted, reactive, type Ref, ref, type UnwrapRef, useAttrs, watch } from "vue"
|
|
179
184
|
|
|
180
185
|
import { safeConvertToHsva } from "./utils/safeConvertToHsva.js"
|
|
181
186
|
import { safeConvertToRgba } from "./utils/safeConvertToRgba.js"
|
|
@@ -187,14 +192,13 @@ import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
|
|
|
187
192
|
import { copy } from "../../helpers/copy.js"
|
|
188
193
|
import type { HsvaColor, RgbaColor } from "../../types/index.js"
|
|
189
194
|
import { twMerge } from "../../utils/twMerge.js"
|
|
190
|
-
import aria from "../Aria/Aria.vue"
|
|
191
195
|
import Icon from "../Icon/Icon.vue"
|
|
192
196
|
import LibButton from "../LibButton/LibButton.vue"
|
|
193
197
|
import LibSimpleInput from "../LibSimpleInput/LibSimpleInput.vue"
|
|
194
|
-
import { getFallbackId, type LabelProps
|
|
198
|
+
import { getFallbackId, type LabelProps, type LinkableByIdProps } from "../shared/props.js"
|
|
195
199
|
|
|
196
200
|
defineOptions({
|
|
197
|
-
name: "
|
|
201
|
+
name: "LibColorPicker"
|
|
198
202
|
})
|
|
199
203
|
|
|
200
204
|
const $attrs = useAttrs()
|
|
@@ -231,37 +235,36 @@ const emits = defineEmits<{
|
|
|
231
235
|
}>()
|
|
232
236
|
|
|
233
237
|
const props = withDefaults(defineProps<
|
|
234
|
-
LabelProps
|
|
235
|
-
& LinkableByIdProps
|
|
236
|
-
& {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}>(), {
|
|
238
|
+
LabelProps
|
|
239
|
+
& LinkableByIdProps
|
|
240
|
+
& {
|
|
241
|
+
allowAlpha?: boolean
|
|
242
|
+
/**
|
|
243
|
+
* The precision of the rgba string representation of the color. Defaults to 3. Extra trailing zeros are removed for a prettier number.
|
|
244
|
+
*
|
|
245
|
+
* Does not affect the number saved unless the user manually edits the color.
|
|
246
|
+
*
|
|
247
|
+
* Ignored if `customRepresentation` is set.
|
|
248
|
+
*/
|
|
249
|
+
stringPrecision?: number
|
|
250
|
+
/** Allows overriding the string representation of the color. Useful for using a different representation than rgba (e.g. hex). The fromStringToHsva part is rarely needed as the colorjs.io library can normally parse the color. Returning undefined signals an error. */
|
|
251
|
+
customRepresentation?: {
|
|
252
|
+
fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string
|
|
253
|
+
fromStringToHsva?: (string: string) => HsvaColor | undefined
|
|
254
|
+
}
|
|
255
|
+
border?: boolean
|
|
256
|
+
/** Modify what the user copies to the clipboard. */
|
|
257
|
+
copyTransform?: (val: HsvaColor, stringVal: string) => any
|
|
258
|
+
valid?: boolean
|
|
259
|
+
}>(), {
|
|
256
260
|
allowAlpha: true,
|
|
257
261
|
border: true,
|
|
258
262
|
stringPrecision: 3,
|
|
259
263
|
copyTransform: (_val: HsvaColor, stringVal: string) => stringVal,
|
|
260
264
|
customRepresentation: undefined,
|
|
261
|
-
valid: true
|
|
265
|
+
valid: true
|
|
262
266
|
})
|
|
263
267
|
|
|
264
|
-
|
|
265
268
|
const ariaDescription = t("color-picker.aria.description")
|
|
266
269
|
const fallbackId = getFallbackId()
|
|
267
270
|
|
|
@@ -284,32 +287,31 @@ const config: Config = {
|
|
|
284
287
|
hue: {
|
|
285
288
|
el: hueSliderEl as Ref<HTMLCanvasElement>,
|
|
286
289
|
xKey: "h",
|
|
287
|
-
xSteps: 360
|
|
290
|
+
xSteps: 360
|
|
288
291
|
},
|
|
289
292
|
alpha: {
|
|
290
293
|
el: alphaSliderEl as Ref<HTMLCanvasElement>,
|
|
291
294
|
xSteps: 1,
|
|
292
|
-
xKey: "a"
|
|
295
|
+
xKey: "a"
|
|
293
296
|
},
|
|
294
297
|
all: {
|
|
295
298
|
el: pickerEl as Ref<HTMLCanvasElement>,
|
|
296
299
|
xSteps: 100,
|
|
297
300
|
ySteps: 100,
|
|
298
301
|
xKey: "s",
|
|
299
|
-
yKey: "v"
|
|
300
|
-
}
|
|
302
|
+
yKey: "v"
|
|
303
|
+
}
|
|
301
304
|
}
|
|
302
305
|
|
|
303
306
|
const localColor = reactive<Record<"percent" | "val", HsvaColor>>({
|
|
304
307
|
percent: {
|
|
305
|
-
h: 0, s: 0, v: 0, a: 0
|
|
308
|
+
h: 0, s: 0, v: 0, a: 0
|
|
306
309
|
},
|
|
307
310
|
val: {
|
|
308
|
-
h: 0, s: 0, v: 0, a: 0
|
|
309
|
-
}
|
|
311
|
+
h: 0, s: 0, v: 0, a: 0
|
|
312
|
+
}
|
|
310
313
|
})
|
|
311
314
|
|
|
312
|
-
|
|
313
315
|
const asRgba = computed(() => {
|
|
314
316
|
const rgba = safeConvertToRgba(localColor.val, props.allowAlpha)
|
|
315
317
|
if (!rgba) unreachable()
|
|
@@ -347,7 +349,6 @@ function updatePicker(el: HTMLCanvasElement, hue: number): void {
|
|
|
347
349
|
gradientColor.addColorStop(0, `hsla(${hue} 100% 50% / 0)`)
|
|
348
350
|
gradientColor.addColorStop(1, `hsla(${hue} 100% 50% /1)`)
|
|
349
351
|
|
|
350
|
-
|
|
351
352
|
ctx.fillStyle = gradient
|
|
352
353
|
ctx.fillRect(0, 0, width, height)
|
|
353
354
|
ctx.fillStyle = gradientColor
|
|
@@ -375,7 +376,6 @@ function updateSlider(el: HTMLCanvasElement, stops: ((i: number) => string) | st
|
|
|
375
376
|
ctx.fillRect(0, 0, width, height)
|
|
376
377
|
}
|
|
377
378
|
|
|
378
|
-
|
|
379
379
|
function getVal(x: number, width: number, steps: number = 100, accuracy: number = 100, reverse = false): { val: number, percent: number } {
|
|
380
380
|
const percent = (x / width)
|
|
381
381
|
const unrounded = percent * steps
|
|
@@ -427,8 +427,8 @@ const slider = {
|
|
|
427
427
|
const { x, y, width, height } = e.target.getBoundingClientRect()
|
|
428
428
|
let xDiff = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0
|
|
429
429
|
let yDiff = e.key === "ArrowUp" ? -1 : e.key === "ArrowDown" ? 1 : 0
|
|
430
|
-
if (e.shiftKey) {xDiff *= 10}
|
|
431
|
-
if (e.shiftKey) {yDiff *= 10}
|
|
430
|
+
if (e.shiftKey) { xDiff *= 10 }
|
|
431
|
+
if (e.shiftKey) { yDiff *= 10 }
|
|
432
432
|
moveHandle({ clientX: x + (width / 2) + xDiff, clientY: y + (height / 2) + yDiff }, type)
|
|
433
433
|
}
|
|
434
434
|
if (e.key === "Enter") {
|
|
@@ -466,7 +466,7 @@ const slider = {
|
|
|
466
466
|
elDragging.value = ""
|
|
467
467
|
document.removeEventListener("pointermove", slider.pointermove)
|
|
468
468
|
document.removeEventListener("pointerup", slider.pointerup)
|
|
469
|
-
}
|
|
469
|
+
}
|
|
470
470
|
}
|
|
471
471
|
function updateSliders(_: HsvaColor): void {
|
|
472
472
|
if (alphaSliderEl.value) {
|
|
@@ -486,12 +486,12 @@ function updateValueAndPosition(_: HsvaColor): void {
|
|
|
486
486
|
localColor.percent.h = Math.round((_.h / 360) * 10000) / 100
|
|
487
487
|
localColor.percent.s = _.s
|
|
488
488
|
localColor.percent.v = 100 - _.v
|
|
489
|
-
localColor.percent.a
|
|
490
|
-
props.allowAlpha
|
|
491
|
-
|
|
492
|
-
|
|
489
|
+
localColor.percent.a
|
|
490
|
+
= props.allowAlpha
|
|
491
|
+
? _.a !== undefined
|
|
492
|
+
? _.a * 100
|
|
493
|
+
: 1
|
|
493
494
|
: 1
|
|
494
|
-
: 1
|
|
495
495
|
localColor.val = { ..._, a: props.allowAlpha ? _.a : 1 }
|
|
496
496
|
}
|
|
497
497
|
|
|
@@ -511,7 +511,6 @@ function save(): void {
|
|
|
511
511
|
emits("save", rgba)
|
|
512
512
|
}
|
|
513
513
|
|
|
514
|
-
|
|
515
514
|
function parseInput(e: Event): void {
|
|
516
515
|
const val = (e.target as HTMLInputElement)?.value
|
|
517
516
|
const converted = props.customRepresentation?.fromStringToHsva
|
|
@@ -523,7 +522,6 @@ function parseInput(e: Event): void {
|
|
|
523
522
|
}
|
|
524
523
|
}
|
|
525
524
|
|
|
526
|
-
|
|
527
525
|
let disableUpdateTempValue = false
|
|
528
526
|
|
|
529
527
|
onMounted(() => {
|
|
@@ -14,11 +14,10 @@ export function safeConvertToHsva(val: string | RgbaColor, allowAlpha: boolean):
|
|
|
14
14
|
h: clampNumber(hsv[0] ?? 0, 0, Number.MAX_SAFE_INTEGER),
|
|
15
15
|
s: clampNumber(hsv[1], 0, 100),
|
|
16
16
|
v: clampNumber(hsv[2], 0, 100),
|
|
17
|
-
a: clampNumber(allowAlpha ? color.alpha : 1, 0, 1)
|
|
17
|
+
a: clampNumber(allowAlpha ? color.alpha : 1, 0, 1)
|
|
18
18
|
}
|
|
19
19
|
return final
|
|
20
20
|
} catch {
|
|
21
21
|
return undefined
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
|
|
@@ -14,10 +14,9 @@ export function safeConvertToRgba(val: string | HsvaColor, allowAlpha: boolean):
|
|
|
14
14
|
r: clampNumber(rgb[0] / 1 * 255, 0, 255),
|
|
15
15
|
g: clampNumber(rgb[1] / 1 * 255, 0, 255),
|
|
16
16
|
b: clampNumber(rgb[2] / 1 * 255, 0, 255),
|
|
17
|
-
a: clampNumber(allowAlpha ? color.alpha : 1, 0, 1)
|
|
17
|
+
a: clampNumber(allowAlpha ? color.alpha : 1, 0, 1)
|
|
18
18
|
}
|
|
19
19
|
} catch {
|
|
20
20
|
return undefined
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
@@ -6,7 +6,6 @@ import { ref } from "vue"
|
|
|
6
6
|
import LibDarkModeSwitcher from "./LibDarkModeSwitcher.vue"
|
|
7
7
|
|
|
8
8
|
// todo, maybe don't do this for perf reasons
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
10
9
|
import * as components from "../index.js"
|
|
11
10
|
|
|
12
11
|
const meta: Meta<typeof LibDarkModeSwitcher> = {
|
|
@@ -14,13 +13,12 @@ const meta: Meta<typeof LibDarkModeSwitcher> = {
|
|
|
14
13
|
title: "Components/DarkModeSwitcher",
|
|
15
14
|
args: {
|
|
16
15
|
|
|
17
|
-
}
|
|
16
|
+
}
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
export default meta
|
|
21
20
|
type Story = StoryObj<typeof LibDarkModeSwitcher>
|
|
22
21
|
|
|
23
|
-
|
|
24
22
|
export const Primary: Story = {
|
|
25
23
|
render: args => ({
|
|
26
24
|
components,
|
|
@@ -38,14 +36,13 @@ export const Primary: Story = {
|
|
|
38
36
|
v-bind="{...args}"
|
|
39
37
|
></LibDarkModeSwitcher>
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
})
|
|
39
|
+
`
|
|
40
|
+
})
|
|
43
41
|
}
|
|
44
42
|
export const WithoutLabel: Story = {
|
|
45
43
|
...Primary,
|
|
46
44
|
args: {
|
|
47
45
|
...Primary.args,
|
|
48
|
-
showLabel: false
|
|
49
|
-
}
|
|
46
|
+
showLabel: false
|
|
47
|
+
}
|
|
50
48
|
}
|
|
51
|
-
|