@witchcraft/ui 0.1.1 → 0.1.3
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.cjs +5 -0
- package/dist/module.d.ts +36 -0
- package/dist/module.json +2 -2
- package/dist/module.mjs +2 -1
- package/dist/runtime/assets/utils.css +1 -1
- package/dist/runtime/components/Aria/Aria.vue +9 -5
- 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 +30 -10
- 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 +72 -58
- 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 +74 -48
- 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 +107 -63
- package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.d.ts +9 -0
- package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +68 -0
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +352 -271
- 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 +56 -32
- 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 +38 -17
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +82 -53
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +67 -50
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +8 -7
- 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 +70 -42
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +31 -18
- 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 +156 -113
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.d.ts +33 -0
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.js +384 -0
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +241 -215
- 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 +46 -30
- package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.d.ts +23 -0
- package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.js +61 -0
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +58 -44
- 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 +48 -32
- 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 +83 -63
- 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 +111 -67
- 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 +23 -20
- 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 +351 -314
- 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 +91 -70
- 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 +177 -133
- package/dist/runtime/components/LibRoot/LibRoot.vue +100 -73
- 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 +77 -49
- 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 +156 -123
- 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 +99 -63
- package/dist/runtime/components/Reset.stories.d.ts +5 -0
- package/dist/runtime/components/Reset.stories.js +19 -0
- package/dist/runtime/components/Scrolling.stories.d.ts +6 -0
- package/dist/runtime/components/Scrolling.stories.js +44 -0
- package/dist/runtime/components/Template/NAME.vue +36 -15
- package/dist/runtime/components/TestControls/TestControls.vue +9 -6
- package/dist/runtime/composables/useScrollNearContainerEdges.stories.d.ts +7 -0
- package/dist/runtime/composables/useScrollNearContainerEdges.stories.js +85 -0
- package/dist/types.d.mts +6 -2
- package/dist/types.d.ts +7 -0
- package/package.json +11 -5
- package/src/module.ts +2 -1
- package/src/runtime/assets/utils.css +5 -5
- package/src/runtime/components/LibButton/LibButton.vue +2 -6
- package/src/runtime/nuxt/plugins/vue-plugin.ts +1 -1
- package/dist/runtime/components/Aria/Aria.vue.d.ts +0 -5
- package/dist/runtime/components/Icon/Icon.vue.d.ts +0 -21
- package/dist/runtime/components/LibButton/LibButton.vue.d.ts +0 -36
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +0 -42
- package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +0 -63
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +0 -61
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +0 -22
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +0 -40
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +0 -34
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +0 -34
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +0 -22
- package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +0 -32
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +0 -22
- package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +0 -43
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue.d.ts +0 -165
- package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +0 -27
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +0 -29
- package/dist/runtime/components/LibNotifications/LibNotification.vue.d.ts +0 -17
- package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +0 -13
- package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +0 -104
- package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +0 -14
- package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +0 -46
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +0 -41
- package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +0 -77
- package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +0 -41
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +0 -35
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +0 -94
- package/dist/runtime/components/LibTable/LibTable.vue.d.ts +0 -45
- package/dist/runtime/components/Template/NAME.vue.d.ts +0 -17
- package/dist/runtime/components/TestControls/TestControls.vue.d.ts +0 -5
|
@@ -1,35 +1,32 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div
|
|
3
|
-
:class="twMerge(
|
|
4
|
-
`
|
|
3
|
+
:class="twMerge(`
|
|
5
4
|
checkbox--wrapper
|
|
6
5
|
flex
|
|
7
6
|
items-center
|
|
8
7
|
gap-1
|
|
9
8
|
`,
|
|
10
|
-
|
|
11
|
-
)"
|
|
12
|
-
v-bind="{ ...$.wrapperAttrs, class:
|
|
9
|
+
($.wrapperAttrs as any)?.class
|
|
10
|
+
)"
|
|
11
|
+
v-bind="{ ...$.wrapperAttrs, class: undefined }"
|
|
13
12
|
ref="el"
|
|
14
13
|
>
|
|
15
14
|
<slot name="left"/>
|
|
16
15
|
<label
|
|
17
|
-
:class="twMerge(
|
|
18
|
-
`
|
|
16
|
+
:class="twMerge(`
|
|
19
17
|
checkbox--label
|
|
20
18
|
flex
|
|
21
19
|
items-center
|
|
22
20
|
gap-1
|
|
23
21
|
`,
|
|
24
|
-
|
|
25
|
-
)"
|
|
26
|
-
v-bind="{ ...$.labelAttrs, class:
|
|
22
|
+
($.labelAttrs as any)?.class
|
|
23
|
+
)"
|
|
24
|
+
v-bind="{ ...$.labelAttrs, class: undefined }"
|
|
27
25
|
:for="id ?? fallbackId"
|
|
28
26
|
>
|
|
29
27
|
<input
|
|
30
28
|
:id="id ?? fallbackId"
|
|
31
|
-
:class="
|
|
32
|
-
`
|
|
29
|
+
:class="!($attrs as any).unstyle && twMerge(`
|
|
33
30
|
checkbox
|
|
34
31
|
focus-outline-no-offset
|
|
35
32
|
m-0
|
|
@@ -56,54 +53,83 @@
|
|
|
56
53
|
checked:after:bg-accent-700
|
|
57
54
|
disabled:border-neutral-500
|
|
58
55
|
disabled:checked:after:bg-neutral-700
|
|
59
|
-
`,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)"
|
|
56
|
+
`, !disabled && `cursor-pointer`,
|
|
57
|
+
($.attrs as any).class
|
|
58
|
+
)"
|
|
63
59
|
type="checkbox"
|
|
64
60
|
:disabled="disabled"
|
|
65
61
|
ref="inputEl"
|
|
66
62
|
v-model="$value"
|
|
67
|
-
v-bind="{
|
|
63
|
+
v-bind="{...$.attrs, class: undefined}"
|
|
68
64
|
>
|
|
69
65
|
<slot/> {{ label }}
|
|
70
66
|
</label>
|
|
71
67
|
</div>
|
|
72
68
|
</template>
|
|
69
|
+
<script setup lang="ts">
|
|
70
|
+
import { keys } from "@alanscodelog/utils/keys.js"
|
|
71
|
+
import { omit } from "@alanscodelog/utils/omit.js"
|
|
72
|
+
import { pick } from "@alanscodelog/utils/pick.js"
|
|
73
|
+
import type { MakeRequired } from "@alanscodelog/utils/types"
|
|
74
|
+
import { computed, type HTMLAttributes, type InputHTMLAttributes,type PropType, ref, useAttrs, useSlots } from "vue"
|
|
75
|
+
|
|
76
|
+
import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
|
|
77
|
+
import { usePreHydrationValue } from "../../composables/usePreHydrationValue.js"
|
|
78
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
79
|
+
import { type BaseInteractiveProps, baseInteractivePropsDefaults, getFallbackId,type LabelProps, type LinkableByIdProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js"
|
|
73
80
|
|
|
74
|
-
<script setup>
|
|
75
|
-
import { keys } from "@alanscodelog/utils/keys.js";
|
|
76
|
-
import { omit } from "@alanscodelog/utils/omit.js";
|
|
77
|
-
import { pick } from "@alanscodelog/utils/pick.js";
|
|
78
|
-
import { computed, ref, useAttrs, useSlots } from "vue";
|
|
79
|
-
import { useDivideAttrs } from "../../composables/useDivideAttrs.js";
|
|
80
|
-
import { usePreHydrationValue } from "../../composables/usePreHydrationValue.js";
|
|
81
|
-
import { twMerge } from "../../utils/twMerge.js";
|
|
82
|
-
import { baseInteractivePropsDefaults, getFallbackId } from "../shared/props.js";
|
|
83
81
|
defineOptions({
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
const $
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
82
|
+
name: "lib-checkbox",
|
|
83
|
+
inheritAttrs: false,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const $ = useDivideAttrs(["label", "wrapper"])
|
|
87
|
+
const $slots = useSlots()
|
|
88
|
+
/* todo multi states */
|
|
89
|
+
|
|
90
|
+
const fallbackId = getFallbackId()
|
|
91
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
92
|
+
...baseInteractivePropsDefaults,
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
const emits = defineEmits<{
|
|
97
|
+
/* User presses enter.*/
|
|
98
|
+
(e: "submit", val: boolean): void
|
|
99
|
+
}>()
|
|
100
|
+
|
|
101
|
+
const el = ref<null | HTMLElement>(null)
|
|
102
|
+
const inputEl = ref<null | HTMLElement>(null)
|
|
103
|
+
const $value = defineModel<boolean>("modelValue", { default: false })
|
|
104
|
+
|
|
105
|
+
usePreHydrationValue(props.id ?? fallbackId, $value)
|
|
105
106
|
</script>
|
|
106
107
|
|
|
107
|
-
<script>
|
|
108
|
+
<script lang="ts">
|
|
109
|
+
|
|
110
|
+
type WrapperTypes = Partial<WrapperProps<"label",HTMLAttributes, {
|
|
111
|
+
/** Tailwind classes. */
|
|
112
|
+
class?: string
|
|
113
|
+
}>>
|
|
114
|
+
|
|
115
|
+
type RealProps =
|
|
116
|
+
|
|
117
|
+
& LinkableByIdProps
|
|
118
|
+
& LabelProps
|
|
119
|
+
& BaseInteractiveProps
|
|
120
|
+
& {
|
|
121
|
+
unstyle?: boolean
|
|
122
|
+
}
|
|
108
123
|
|
|
124
|
+
interface Props
|
|
125
|
+
extends
|
|
126
|
+
/** @vue-ignore */
|
|
127
|
+
Partial<Omit<
|
|
128
|
+
InputHTMLAttributes,
|
|
129
|
+
"class" | "readonly" | "disabled" | "onSumbit"
|
|
130
|
+
> & TailwindClassProp>,
|
|
131
|
+
/** @vue-ignore */
|
|
132
|
+
WrapperTypes,
|
|
133
|
+
RealProps
|
|
134
|
+
{}
|
|
109
135
|
</script>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3";
|
|
2
|
+
import LibColorInput from "./LibColorInput.vue.js";
|
|
3
|
+
declare const meta: Meta<typeof LibColorInput>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof LibColorInput>;
|
|
6
|
+
export declare const Primary: Story;
|
|
7
|
+
export declare const DoesNotAllowAlpha: Story;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import LibColorInput from "./LibColorInput.vue";
|
|
3
|
+
import * as components from "../index.js";
|
|
4
|
+
const meta = {
|
|
5
|
+
component: LibColorInput,
|
|
6
|
+
title: "Components/ColorInput",
|
|
7
|
+
args: {}
|
|
8
|
+
};
|
|
9
|
+
export default meta;
|
|
10
|
+
export const Primary = {
|
|
11
|
+
render: (args) => ({
|
|
12
|
+
components,
|
|
13
|
+
setup: () => {
|
|
14
|
+
const color = ref({
|
|
15
|
+
r: 0,
|
|
16
|
+
g: 0,
|
|
17
|
+
b: 0
|
|
18
|
+
/* , a: 0.5 */
|
|
19
|
+
});
|
|
20
|
+
const handleChange = (e) => {
|
|
21
|
+
color.value = { ...e };
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
args: {
|
|
25
|
+
outline: false,
|
|
26
|
+
color,
|
|
27
|
+
allowAlpha: true,
|
|
28
|
+
...args
|
|
29
|
+
},
|
|
30
|
+
handleChange
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
template: `
|
|
34
|
+
<lib-color-Input
|
|
35
|
+
:allowAlpha="args.allowAlpha"
|
|
36
|
+
:modelValue="args.color.value"
|
|
37
|
+
@update:modelValue="handleChange"
|
|
38
|
+
>
|
|
39
|
+
</lib-color-Input>
|
|
40
|
+
Stretched:
|
|
41
|
+
<div class="flex-1 flex">
|
|
42
|
+
<lib-color-Input
|
|
43
|
+
class="flex-1"
|
|
44
|
+
:allowAlpha="args.allowAlpha"
|
|
45
|
+
:modelValue="args.color.value"
|
|
46
|
+
@update:modelValue="handleChange"
|
|
47
|
+
>
|
|
48
|
+
</lib-color-Input>
|
|
49
|
+
</div>
|
|
50
|
+
`
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
export const DoesNotAllowAlpha = {
|
|
54
|
+
...Primary,
|
|
55
|
+
args: {
|
|
56
|
+
allowAlpha: false
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
<lib-popup
|
|
3
3
|
class="color-input--popup"
|
|
4
4
|
v-model="showPopup"
|
|
5
|
-
@close="$tempValue =
|
|
6
|
-
emit('cancel')"
|
|
5
|
+
@close="$tempValue = undefined;emit('cancel')"
|
|
7
6
|
>
|
|
8
|
-
<template #button="{
|
|
7
|
+
<template #button="{extractEl}">
|
|
9
8
|
<!-- <div -->
|
|
10
9
|
<!-- class=" -->
|
|
11
10
|
<!-- flex -->
|
|
@@ -18,8 +17,7 @@
|
|
|
18
17
|
<!-- -->
|
|
19
18
|
<lib-button
|
|
20
19
|
:id="id ?? fallbackId"
|
|
21
|
-
:class="twMerge(
|
|
22
|
-
`
|
|
20
|
+
:class="twMerge(`
|
|
23
21
|
p-0
|
|
24
22
|
color-input--button
|
|
25
23
|
flex flex-nowrap
|
|
@@ -29,11 +27,11 @@
|
|
|
29
27
|
[&_.button--label]:gap-0
|
|
30
28
|
after:hidden
|
|
31
29
|
`,
|
|
32
|
-
|
|
33
|
-
)"
|
|
30
|
+
($attrs as any).class
|
|
31
|
+
)"
|
|
34
32
|
:aria-label="t('color-input.aria-and-title-prefix') + stringColor"
|
|
35
33
|
:title="t('color-input.aria-and-title-prefix') + stringColor"
|
|
36
|
-
v-bind="{
|
|
34
|
+
v-bind="{...$attrs, class: undefined}"
|
|
37
35
|
v-extract-root-el="extractEl"
|
|
38
36
|
@click="togglePopup"
|
|
39
37
|
>
|
|
@@ -44,14 +42,14 @@
|
|
|
44
42
|
w-full
|
|
45
43
|
"
|
|
46
44
|
>
|
|
47
|
-
<slot v-bind="{
|
|
45
|
+
<slot v-bind="{stringColor, classes:swatchClasses}">
|
|
48
46
|
<div :class="swatchClasses"
|
|
49
47
|
:style="`background:${stringColor}`"
|
|
50
48
|
/>
|
|
51
49
|
</slot>
|
|
52
50
|
<slot
|
|
53
51
|
v-if="$tempValue"
|
|
54
|
-
v-bind="{
|
|
52
|
+
v-bind="{tempStringColor, classes:swatchClasses}"
|
|
55
53
|
name="temp"
|
|
56
54
|
>
|
|
57
55
|
<div :class="swatchClasses"
|
|
@@ -62,7 +60,7 @@
|
|
|
62
60
|
</template>
|
|
63
61
|
</lib-button>
|
|
64
62
|
</template>
|
|
65
|
-
<template #popup="{
|
|
63
|
+
<template #popup="{extractEl}">
|
|
66
64
|
<div class="color-input--popup-wrapper p-5" v-extract-root-el="extractEl">
|
|
67
65
|
<lib-color-picker v-if="showPopup"
|
|
68
66
|
:id="id ?? fallbackId"
|
|
@@ -79,19 +77,24 @@
|
|
|
79
77
|
</lib-popup>
|
|
80
78
|
</template>
|
|
81
79
|
|
|
82
|
-
<script setup>
|
|
83
|
-
import Color from "colorjs.io"
|
|
84
|
-
import { computed, ref, useAttrs } from "vue"
|
|
85
|
-
|
|
86
|
-
import {
|
|
87
|
-
import {
|
|
88
|
-
import
|
|
89
|
-
import
|
|
90
|
-
import
|
|
91
|
-
import
|
|
80
|
+
<script setup lang="ts">
|
|
81
|
+
import Color from "colorjs.io"
|
|
82
|
+
import { type ButtonHTMLAttributes,computed, type PropType, ref, useAttrs } from "vue"
|
|
83
|
+
|
|
84
|
+
import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
|
|
85
|
+
import { vExtractRootEl } from "../../directives/vExtractRootEl.js"
|
|
86
|
+
import type { HsvaColor, RgbaColor } from "../../types/index.js"
|
|
87
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
88
|
+
import LibButton from "../LibButton/LibButton.vue"
|
|
89
|
+
import LibColorPicker from "../LibColorPicker/LibColorPicker.vue"
|
|
90
|
+
import LibPopup from "../LibPopup/LibPopup.vue"
|
|
91
|
+
import { getFallbackId, type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js"
|
|
92
|
+
|
|
93
|
+
|
|
92
94
|
defineOptions({
|
|
93
|
-
|
|
94
|
-
})
|
|
95
|
+
name: "lib-color-input",
|
|
96
|
+
})
|
|
97
|
+
|
|
95
98
|
const swatchClasses = `
|
|
96
99
|
color-input--swatch
|
|
97
100
|
after:content-vertical-holder
|
|
@@ -103,53 +106,94 @@ const swatchClasses = `
|
|
|
103
106
|
before:inset-0
|
|
104
107
|
before:bg-transparency-squares
|
|
105
108
|
before:z-[-1]
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
})
|
|
118
|
-
const emit = defineEmits
|
|
109
|
+
`
|
|
110
|
+
|
|
111
|
+
const fallbackId = getFallbackId()
|
|
112
|
+
|
|
113
|
+
const t = useInjectedI18n()
|
|
114
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
115
|
+
allowAlpha: true,
|
|
116
|
+
border: true,
|
|
117
|
+
copyTransform: (_val: HsvaColor, stringVal: string) => stringVal,
|
|
118
|
+
stringPrecision: 3,
|
|
119
|
+
customRepresentation: undefined,
|
|
120
|
+
})
|
|
121
|
+
const emit = defineEmits<{
|
|
122
|
+
(e: "save"): void
|
|
123
|
+
(e: "cancel"): void
|
|
124
|
+
}>()
|
|
125
|
+
|
|
126
|
+
|
|
119
127
|
function save() {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
128
|
+
$value.value = internalTempValue.value
|
|
129
|
+
showPopup.value = false
|
|
130
|
+
$tempValue.value = undefined
|
|
131
|
+
emit("save")
|
|
124
132
|
}
|
|
125
133
|
function cancel() {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
134
|
+
showPopup.value = false
|
|
135
|
+
$tempValue.value = undefined
|
|
136
|
+
emit("cancel")
|
|
129
137
|
}
|
|
130
|
-
|
|
131
|
-
const $
|
|
132
|
-
|
|
138
|
+
|
|
139
|
+
const $attrs = useAttrs()
|
|
140
|
+
|
|
141
|
+
const $value = defineModel<RgbaColor>({ required: false, default: () => ({ r: 0, g: 0, b: 0 }) })
|
|
142
|
+
const $tempValue = defineModel<RgbaColor | undefined>("tempValue", { required: false, default: () => (undefined) })
|
|
143
|
+
|
|
133
144
|
const stringColor = computed(() => new Color("srgb", [
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
], $value.value.a ?? 1).toString())
|
|
145
|
+
$value.value.r / 255,
|
|
146
|
+
$value.value.g / 255,
|
|
147
|
+
$value.value.b / 255,
|
|
148
|
+
], $value.value.a ?? 1,).toString())
|
|
149
|
+
|
|
138
150
|
const tempStringColor = computed(() => $tempValue.value ? new Color("srgb", [
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
], $tempValue.value.a ?? 1).toString() : "")
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
$tempValue.value.r / 255,
|
|
152
|
+
$tempValue.value.g / 255,
|
|
153
|
+
$tempValue.value.b / 255,
|
|
154
|
+
], $tempValue.value.a ?? 1,).toString() : "")
|
|
155
|
+
|
|
156
|
+
const internalTempValue = ref({ ...$value.value })
|
|
157
|
+
|
|
158
|
+
const showPopup = ref(false)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
const togglePopup = (): void => {
|
|
162
|
+
if (showPopup.value) {
|
|
163
|
+
$value.value = internalTempValue.value
|
|
164
|
+
}
|
|
165
|
+
showPopup.value = !showPopup.value
|
|
166
|
+
}
|
|
167
|
+
|
|
151
168
|
</script>
|
|
152
169
|
|
|
153
|
-
<script>
|
|
170
|
+
<script lang="ts">
|
|
154
171
|
|
|
172
|
+
type RealProps =
|
|
173
|
+
& LabelProps
|
|
174
|
+
& LinkableByIdProps
|
|
175
|
+
& {
|
|
176
|
+
allowAlpha?: boolean
|
|
177
|
+
border?: boolean
|
|
178
|
+
/** See ColorPicker.copyTransform */
|
|
179
|
+
copyTransform?: (val: HsvaColor, stringVal: string) => any
|
|
180
|
+
/** See ColorPicker.allowAlpha */
|
|
181
|
+
stringPrecision?: number
|
|
182
|
+
/** See ColorPicker.customRepresentation */
|
|
183
|
+
customRepresentation?: {
|
|
184
|
+
fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
interface Props
|
|
188
|
+
extends
|
|
189
|
+
/** @vue-ignore */
|
|
190
|
+
Partial<Omit<ButtonHTMLAttributes,"class">
|
|
191
|
+
& TailwindClassProp
|
|
192
|
+
& {
|
|
193
|
+
// why is this not already a part of button?
|
|
194
|
+
"aria-label": string
|
|
195
|
+
}>,
|
|
196
|
+
RealProps
|
|
197
|
+
{}
|
|
155
198
|
</script>
|
|
199
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3";
|
|
2
|
+
import LibColorPicker from "./LibColorPicker.vue.js";
|
|
3
|
+
declare const meta: Meta<typeof LibColorPicker>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof LibColorPicker>;
|
|
6
|
+
export declare const Primary: Story;
|
|
7
|
+
export declare const DoesNotAllowAlpha: Story;
|
|
8
|
+
export declare const WithExistingValue: Story;
|
|
9
|
+
export declare const CustomStringRepresentation: Story;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import Color from "colorjs.io";
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import LibColorPicker from "./LibColorPicker.vue";
|
|
4
|
+
import * as components from "../index.js";
|
|
5
|
+
const meta = {
|
|
6
|
+
component: LibColorPicker,
|
|
7
|
+
title: "Components/ColorPicker",
|
|
8
|
+
args: {}
|
|
9
|
+
};
|
|
10
|
+
export default meta;
|
|
11
|
+
export const Primary = {
|
|
12
|
+
render: (args) => ({
|
|
13
|
+
components,
|
|
14
|
+
setup: () => {
|
|
15
|
+
const color = ref({ r: 0, g: 0, b: 0, ...args.modelValue });
|
|
16
|
+
delete args.modelValue;
|
|
17
|
+
const handleChange = (e) => {
|
|
18
|
+
color.value = { ...e };
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
args: {
|
|
22
|
+
outline: false,
|
|
23
|
+
color,
|
|
24
|
+
allowAlpha: true,
|
|
25
|
+
...args
|
|
26
|
+
},
|
|
27
|
+
handleChange
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
template: `
|
|
31
|
+
<lib-root :outline="args.outline">
|
|
32
|
+
{{args.color}}
|
|
33
|
+
<lib-color-picker
|
|
34
|
+
:modelValue="args.color.value"
|
|
35
|
+
v-bind="args"
|
|
36
|
+
@update:modelValue="handleChange"
|
|
37
|
+
>
|
|
38
|
+
</lib-color-picker>
|
|
39
|
+
</lib-root>
|
|
40
|
+
`
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
export const DoesNotAllowAlpha = {
|
|
44
|
+
...Primary,
|
|
45
|
+
args: {
|
|
46
|
+
allowAlpha: false
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export const WithExistingValue = {
|
|
50
|
+
...Primary,
|
|
51
|
+
args: {
|
|
52
|
+
modelValue: { r: 255, g: 0, b: 0 }
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
export const CustomStringRepresentation = {
|
|
56
|
+
...Primary,
|
|
57
|
+
args: {
|
|
58
|
+
allowAlpha: false,
|
|
59
|
+
customRepresentation: {
|
|
60
|
+
fromHsvaToString: (hsva, includeAlpha) => new Color(
|
|
61
|
+
"hsv",
|
|
62
|
+
[hsva.h, hsva.s, hsva.v],
|
|
63
|
+
includeAlpha ? hsva.a : 1
|
|
64
|
+
// this takes care of the correct hex format
|
|
65
|
+
).toString({ format: "hex" })
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|