@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
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
dark:bg-neutral-950
|
|
29
29
|
border-neutral-400
|
|
30
30
|
dark:border-neutral-600
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
`,
|
|
32
|
+
($attrs as any).class)"
|
|
33
33
|
:aria-disabled="disabled"
|
|
34
34
|
:aria-readonly="readonly"
|
|
35
35
|
:tabindex="disabled ? -1 : 0"
|
|
36
36
|
:title="recording ? recordingTitle : tempValue"
|
|
37
37
|
contenteditable="false"
|
|
38
38
|
ref="recorderEl"
|
|
39
|
-
v-bind="{...ariaLabel, ...$attrs, class:undefined}"
|
|
39
|
+
v-bind="{ ...ariaLabel, ...$attrs, class: undefined }"
|
|
40
40
|
@blur="handleBlurRecorder($event)"
|
|
41
41
|
@click="handleClickRecorder($event)"
|
|
42
42
|
@keydown.space.prevent="handleClickRecorder($event, true)"
|
|
@@ -69,18 +69,19 @@
|
|
|
69
69
|
</div>
|
|
70
70
|
</div>
|
|
71
71
|
</template>
|
|
72
|
+
|
|
72
73
|
<script setup lang="ts">
|
|
73
74
|
import { keys } from "@alanscodelog/utils/keys"
|
|
74
|
-
import { computed, type HTMLAttributes
|
|
75
|
+
import { computed, type HTMLAttributes, onBeforeUnmount, onMounted, ref, watch, watchPostEffect } from "vue"
|
|
75
76
|
|
|
76
77
|
import { useAriaLabel } from "../../composables/useAriaLabel.js"
|
|
77
78
|
import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
|
|
78
79
|
import { twMerge } from "../../utils/twMerge.js"
|
|
79
|
-
import { type BaseInteractiveProps, getFallbackId, type LabelProps, type LinkableByIdProps,type TailwindClassProp } from "../shared/props.js"
|
|
80
|
+
import { type BaseInteractiveProps, getFallbackId, type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js"
|
|
80
81
|
|
|
81
82
|
defineOptions({
|
|
82
|
-
name: "
|
|
83
|
-
inheritAttrs: false
|
|
83
|
+
name: "LibRecorder",
|
|
84
|
+
inheritAttrs: false
|
|
84
85
|
})
|
|
85
86
|
const t = useInjectedI18n()
|
|
86
87
|
|
|
@@ -98,7 +99,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
98
99
|
id: undefined,
|
|
99
100
|
binders: undefined,
|
|
100
101
|
recorder: undefined,
|
|
101
|
-
unstyle: false, disabled: false, readonly: false, border: true
|
|
102
|
+
unstyle: false, disabled: false, readonly: false, border: true
|
|
102
103
|
})
|
|
103
104
|
/**
|
|
104
105
|
* Puts the element into recording mode if true. See {@link props.recorder}.
|
|
@@ -108,7 +109,6 @@ const recording = defineModel<boolean>("recording", { required: false, default:
|
|
|
108
109
|
/** The final value of the recorder. For intermediate values while recording, pass a recorder and set an appropriate recording value. */
|
|
109
110
|
const modelValue = defineModel<string>({ required: true })
|
|
110
111
|
|
|
111
|
-
|
|
112
112
|
const recorderEl = ref<HTMLInputElement | null>(null)
|
|
113
113
|
const recorderIndicatorEl = ref<HTMLElement | null>(null)
|
|
114
114
|
const canEdit = computed(() => !props.disabled && !props.readonly)
|
|
@@ -206,37 +206,37 @@ const handleClickRecorder = (e: MouseEvent | KeyboardEvent, isSpaceKey: boolean
|
|
|
206
206
|
emits("recorder:click", { event: e as MouseEvent, indicator: recorderIndicatorEl.value! as HTMLElement, input: recorderEl.value! as HTMLInputElement })
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
|
|
210
209
|
</script>
|
|
210
|
+
|
|
211
211
|
<script lang="ts">
|
|
212
|
-
type RealProps
|
|
213
|
-
& LinkableByIdProps
|
|
214
|
-
& BaseInteractiveProps
|
|
215
|
-
& LabelProps
|
|
216
|
-
& {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
212
|
+
type RealProps
|
|
213
|
+
= & LinkableByIdProps
|
|
214
|
+
& BaseInteractiveProps
|
|
215
|
+
& LabelProps
|
|
216
|
+
& {
|
|
217
|
+
border?: boolean
|
|
218
|
+
/** A value to display while recording, if none given the i18n `recorder.recording` key is used. */
|
|
219
|
+
recordingValue?: string
|
|
220
|
+
/** A title to display on the input div while recording. Is also used as the aria-description. */
|
|
221
|
+
recordingTitle?: string
|
|
222
|
+
/**
|
|
223
|
+
* The recorder object is a series of event listeners to attach to the input div while recording is started. If you need to bind directly to the element, see the `binders` prop.
|
|
224
|
+
*
|
|
225
|
+
* The listeners are then unbound when recording is set to false again.
|
|
226
|
+
*
|
|
227
|
+
* Note that the component does not handle the setting of `recording` (unless the component is disabled), `modelValue`, or `recordingValue` at all and has no mechanism for cancelling a recording. It is left to the recorder listeners and any `recorder:*` handlers to determine what to do.
|
|
228
|
+
*/
|
|
229
|
+
recorder?: undefined | Record<string, any>
|
|
230
|
+
/** This provides a way to manually attach/remove event listeners to/from the element. It is an alternative to the `recorder` prop, see it for more details. Both cannot be specified at the same time. */
|
|
231
|
+
binders?: undefined | { bind: (el: HTMLElement) => void, unbind: (el: HTMLElement) => void }
|
|
232
|
+
/** The id of the element. If not provided, the id will be generated automatically. */
|
|
233
|
+
id?: string
|
|
234
|
+
}
|
|
235
235
|
|
|
236
236
|
interface Props
|
|
237
237
|
extends
|
|
238
238
|
/** @vue-ignore */
|
|
239
|
-
Partial<Omit<HTMLAttributes,"class"> & TailwindClassProp>,
|
|
239
|
+
Partial<Omit<HTMLAttributes, "class"> & TailwindClassProp>,
|
|
240
240
|
RealProps
|
|
241
241
|
{ }
|
|
242
242
|
</script>
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div
|
|
3
|
+
:id="id"
|
|
3
4
|
tabindex="-1"
|
|
4
5
|
:class="twMerge(
|
|
5
6
|
(showOutline ? 'group outlined outlined-visible' : '[&_*]:outline-hidden'),
|
|
6
7
|
darkMode && ' dark',
|
|
7
8
|
($attrs['wrapperAttrs'] as any)?.class
|
|
8
9
|
)"
|
|
9
|
-
v-bind="{ ...($attrs['wrapperAttrs']), attrs:undefined, class: undefined }"
|
|
10
|
+
v-bind="{ ...($attrs['wrapperAttrs']), attrs: undefined, class: undefined }"
|
|
10
11
|
:ref="handleRef"
|
|
11
12
|
>
|
|
12
13
|
<!-- id root is useful for teleports, so they are at the topmost level where they can still be styled -->
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
<div
|
|
15
16
|
id="root"
|
|
16
17
|
v-bind="{ ...$attrs.attrs, class: undefined, wrapperAttrs: undefined }"
|
|
17
|
-
:class="twMerge(
|
|
18
|
+
:class="twMerge(`
|
|
18
19
|
dark:bg-fg
|
|
19
20
|
dark:text-bg
|
|
20
21
|
bg-bg
|
|
@@ -31,9 +32,14 @@
|
|
|
31
32
|
`,
|
|
32
33
|
($attrs as any).attrs?.class)"
|
|
33
34
|
>
|
|
34
|
-
<TestControls
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
<TestControls
|
|
36
|
+
v-if="testWrapperMode"
|
|
37
|
+
:show-outline="showOutline"
|
|
38
|
+
/>
|
|
39
|
+
<Notifications
|
|
40
|
+
v-if="useNotifications && isClientSide"
|
|
41
|
+
data-allow-mismatch
|
|
42
|
+
/>
|
|
37
43
|
<slot/>
|
|
38
44
|
</div>
|
|
39
45
|
</div>
|
|
@@ -41,7 +47,7 @@
|
|
|
41
47
|
|
|
42
48
|
<script setup lang="ts">
|
|
43
49
|
import { unreachable } from "@alanscodelog/utils/unreachable"
|
|
44
|
-
import {
|
|
50
|
+
import type { Theme } from "metamorphosis"
|
|
45
51
|
import { type ComponentPublicInstance, computed, onBeforeUnmount, onMounted, ref, toRaw } from "vue"
|
|
46
52
|
|
|
47
53
|
import { useAccesibilityOutline } from "../../composables/useAccesibilityOutline.js"
|
|
@@ -59,7 +65,7 @@ import TestControls from "../TestControls/TestControls.vue"
|
|
|
59
65
|
|
|
60
66
|
const $attrs = useDivideAttrs(["wrapper"])
|
|
61
67
|
|
|
62
|
-
defineOptions({ name: "
|
|
68
|
+
defineOptions({ name: "Root", inheritAttrs: false, suspensible: false })
|
|
63
69
|
const props = withDefaults(defineProps<{
|
|
64
70
|
theme?: Theme
|
|
65
71
|
outline?: boolean
|
|
@@ -124,7 +130,7 @@ const darkMode = darkModeSetup.darkMode
|
|
|
124
130
|
useShowDevOnlyKey()
|
|
125
131
|
|
|
126
132
|
defineExpose({
|
|
127
|
-
darkMode: darkModeSetup
|
|
133
|
+
darkMode: darkModeSetup
|
|
128
134
|
})
|
|
129
135
|
|
|
130
136
|
if (props.useBuiltinTranslations) {
|
|
@@ -132,9 +138,7 @@ if (props.useBuiltinTranslations) {
|
|
|
132
138
|
void useSetupI18n({
|
|
133
139
|
locale: languageLocale,
|
|
134
140
|
useBuiltinTranslations: true,
|
|
135
|
-
useDummyMessageSetWhileLoading: true
|
|
141
|
+
useDummyMessageSetWhileLoading: true
|
|
136
142
|
})
|
|
137
143
|
}
|
|
138
|
-
|
|
139
144
|
</script>
|
|
140
|
-
|
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
2
|
import type { Meta, StoryObj } from "@storybook/vue3"
|
|
3
3
|
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
5
4
|
import * as components from "../index.js"
|
|
6
5
|
|
|
7
|
-
|
|
8
6
|
const meta = {
|
|
9
7
|
component: components.LibSimpleInput,
|
|
10
8
|
title: "Components/Input",
|
|
11
9
|
args: {
|
|
12
10
|
modelValue: "Value",
|
|
13
|
-
placeholder: "Placeholder"
|
|
14
|
-
}
|
|
11
|
+
placeholder: "Placeholder"
|
|
12
|
+
}
|
|
15
13
|
} satisfies Meta<typeof components.LibSimpleInput> & Meta<{ custom: string }>
|
|
16
14
|
|
|
17
15
|
export default meta
|
|
18
16
|
type Story = StoryObj<typeof components.LibSimpleInput> // & StoryObj<typeof extraArgs>
|
|
19
17
|
|
|
20
|
-
|
|
21
18
|
/** Input */
|
|
22
19
|
export const Primary: Story = {
|
|
23
20
|
args: {
|
|
24
|
-
modelValue: "some value"
|
|
21
|
+
modelValue: "some value"
|
|
25
22
|
},
|
|
26
23
|
render: args => ({
|
|
27
24
|
components,
|
|
@@ -32,8 +29,8 @@ export const Primary: Story = {
|
|
|
32
29
|
@keydown="test"
|
|
33
30
|
class="m-2" v-bind="args" v-model="args.modelValue" ></lib-simple-input>
|
|
34
31
|
<lib-simple-input class="m-2" v-bind="{...args, modelValue:''}" ></lib-simple-input>
|
|
35
|
-
|
|
36
|
-
})
|
|
32
|
+
`
|
|
33
|
+
})
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
/** Has more reasonable min-width inside a flexbox. */
|
|
@@ -47,31 +44,30 @@ export const InsideAFlexbox: Story = {
|
|
|
47
44
|
<lib-simple-input v-bind="args" v-model="args.modelValue"></lib-simple-input>
|
|
48
45
|
<div class="border-1 border-danger-500 flex-1 whitespace-nowrap">Flex Grow: 1</div>
|
|
49
46
|
</div>
|
|
50
|
-
|
|
47
|
+
`
|
|
51
48
|
}),
|
|
52
49
|
args: {
|
|
53
|
-
stretch: true
|
|
54
|
-
}
|
|
50
|
+
stretch: true
|
|
51
|
+
}
|
|
55
52
|
}
|
|
56
53
|
|
|
57
|
-
|
|
58
54
|
export const Disabled = {
|
|
59
55
|
...Primary,
|
|
60
56
|
args: {
|
|
61
|
-
disabled: true
|
|
62
|
-
}
|
|
57
|
+
disabled: true
|
|
58
|
+
}
|
|
63
59
|
}
|
|
64
60
|
export const Readonly = {
|
|
65
61
|
...Primary,
|
|
66
62
|
args: {
|
|
67
|
-
readonly: true
|
|
68
|
-
}
|
|
63
|
+
readonly: true
|
|
64
|
+
}
|
|
69
65
|
}
|
|
70
66
|
export const Invalid = {
|
|
71
67
|
...Primary,
|
|
72
68
|
args: {
|
|
73
|
-
valid: false
|
|
74
|
-
}
|
|
69
|
+
valid: false
|
|
70
|
+
}
|
|
75
71
|
}
|
|
76
72
|
/**
|
|
77
73
|
* Intended for being wrapped.
|
|
@@ -80,19 +76,19 @@ export const Invalid = {
|
|
|
80
76
|
export const Borderless = {
|
|
81
77
|
...Primary,
|
|
82
78
|
args: {
|
|
83
|
-
border: false
|
|
84
|
-
}
|
|
79
|
+
border: false
|
|
80
|
+
}
|
|
85
81
|
}
|
|
86
82
|
|
|
87
83
|
export const Numerical = {
|
|
88
84
|
...Primary,
|
|
89
85
|
args: {
|
|
90
|
-
type: "number"
|
|
91
|
-
}
|
|
86
|
+
type: "number"
|
|
87
|
+
}
|
|
92
88
|
}
|
|
93
89
|
export const NumericalInsideAFlexbox = {
|
|
94
90
|
...InsideAFlexbox,
|
|
95
91
|
args: {
|
|
96
|
-
type: "number"
|
|
97
|
-
}
|
|
92
|
+
type: "number"
|
|
93
|
+
}
|
|
98
94
|
}
|
|
@@ -63,13 +63,12 @@
|
|
|
63
63
|
:disabled="disabled"
|
|
64
64
|
:readonly="readonly"
|
|
65
65
|
v-model="modelValue"
|
|
66
|
-
v-bind="{...$attrs, class:undefined, ...ariaLabel}"
|
|
66
|
+
v-bind="{ ...$attrs, class: undefined, ...ariaLabel }"
|
|
67
67
|
@keydown="handleKeydown"
|
|
68
68
|
@input="emit('input', $event as InputEvent)"
|
|
69
69
|
>
|
|
70
70
|
</template>
|
|
71
71
|
|
|
72
|
-
|
|
73
72
|
<script lang="ts" setup generic="T">
|
|
74
73
|
import { type InputHTMLAttributes, useAttrs } from "vue"
|
|
75
74
|
|
|
@@ -77,12 +76,11 @@ import { useAriaLabel } from "../../composables/useAriaLabel.js"
|
|
|
77
76
|
import { usePreHydrationValue } from "../../composables/usePreHydrationValue.js"
|
|
78
77
|
import { hasModifiers } from "../../helpers/hasModifiers.js"
|
|
79
78
|
import { twMerge } from "../../utils/twMerge.js"
|
|
80
|
-
import { type BaseInteractiveProps, getFallbackId,type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js"
|
|
81
|
-
|
|
79
|
+
import { type BaseInteractiveProps, getFallbackId, type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js"
|
|
82
80
|
|
|
83
81
|
defineOptions({
|
|
84
|
-
name: "
|
|
85
|
-
inheritAttrs: false
|
|
82
|
+
name: "LibSimpleInput",
|
|
83
|
+
inheritAttrs: false
|
|
86
84
|
})
|
|
87
85
|
|
|
88
86
|
const fallbackId = getFallbackId()
|
|
@@ -93,13 +91,13 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
93
91
|
valid: true,
|
|
94
92
|
label: "",
|
|
95
93
|
type: undefined,
|
|
96
|
-
unstyle: false, disabled: false, readonly: false, border: true
|
|
94
|
+
unstyle: false, disabled: false, readonly: false, border: true
|
|
97
95
|
})
|
|
98
96
|
|
|
99
97
|
const modelValue = defineModel<T>({ required: true })
|
|
100
98
|
|
|
101
99
|
const emit = defineEmits<{
|
|
102
|
-
/* User presses enter
|
|
100
|
+
/* User presses enter. */
|
|
103
101
|
(e: "submit", val: T): void
|
|
104
102
|
(e: "input", val: InputEvent): void
|
|
105
103
|
}>()
|
|
@@ -112,22 +110,20 @@ function handleKeydown(e: KeyboardEvent) {
|
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
112
|
usePreHydrationValue(props.id ?? fallbackId, modelValue)
|
|
115
|
-
|
|
116
113
|
</script>
|
|
117
114
|
|
|
118
115
|
<script lang="ts">
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
116
|
+
type RealProps
|
|
117
|
+
= & LinkableByIdProps
|
|
118
|
+
& LabelProps
|
|
119
|
+
& BaseInteractiveProps
|
|
120
|
+
& {
|
|
121
|
+
placeholder?: InputHTMLAttributes["placeholder"]
|
|
122
|
+
disabled?: InputHTMLAttributes["disabled"]
|
|
123
|
+
id?: InputHTMLAttributes["id"]
|
|
124
|
+
type?: InputHTMLAttributes["type"]
|
|
125
|
+
valid?: boolean
|
|
126
|
+
}
|
|
131
127
|
|
|
132
128
|
interface Props
|
|
133
129
|
extends
|
|
@@ -5,7 +5,6 @@ import type { ComponentExposed } from "vue-component-type-helpers"
|
|
|
5
5
|
|
|
6
6
|
import LibSuggestions from "./LibSuggestions.vue"
|
|
7
7
|
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
9
8
|
import * as components from "../index.js"
|
|
10
9
|
|
|
11
10
|
const meta = {
|
|
@@ -16,8 +15,8 @@ const meta = {
|
|
|
16
15
|
modelValue: "",
|
|
17
16
|
label: "Some Label",
|
|
18
17
|
border: true,
|
|
19
|
-
suggestions: ["A", "AB", "ABC", "B", "BC", "C", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
|
|
20
|
-
}
|
|
18
|
+
suggestions: ["A", "AB", "ABC", "B", "BC", "C", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
|
|
19
|
+
}
|
|
21
20
|
} // satisfies Meta<typeof LibSuggestions> & Meta<{ custom: string }>
|
|
22
21
|
|
|
23
22
|
export default meta
|
|
@@ -33,7 +32,7 @@ type Story = StoryObj<typeof LibSuggestions> // & StoryObj<typeof extraArgs>
|
|
|
33
32
|
export const Primary: Story = {
|
|
34
33
|
render: args => ({
|
|
35
34
|
components: { ...components, LibSuggestions },
|
|
36
|
-
|
|
35
|
+
|
|
37
36
|
setup: () => {
|
|
38
37
|
const inputValue = ref(args.modelValue)
|
|
39
38
|
const modelValue = ref(args.modelValue)
|
|
@@ -56,7 +55,7 @@ export const Primary: Story = {
|
|
|
56
55
|
suggestions,
|
|
57
56
|
drawer,
|
|
58
57
|
keydownHandler,
|
|
59
|
-
blurHandler
|
|
58
|
+
blurHandler
|
|
60
59
|
}
|
|
61
60
|
},
|
|
62
61
|
|
|
@@ -88,26 +87,25 @@ export const Primary: Story = {
|
|
|
88
87
|
</template>
|
|
89
88
|
</lib-suggestions>
|
|
90
89
|
</div>
|
|
91
|
-
|
|
92
|
-
})
|
|
90
|
+
`
|
|
91
|
+
})
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
export const RestrictToSuggestions: Story = {
|
|
96
95
|
...Primary,
|
|
97
96
|
args: {
|
|
98
97
|
...Primary.args,
|
|
99
|
-
restrictToSuggestions: true
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
restrictToSuggestions: true
|
|
99
|
+
}
|
|
100
|
+
|
|
103
101
|
}
|
|
104
102
|
export const AlwaysShowAllSuggestions = {
|
|
105
103
|
...Primary,
|
|
106
104
|
args: {
|
|
107
105
|
...Primary.args,
|
|
108
106
|
restrictToSuggestions: true,
|
|
109
|
-
suggestionsFilter: (_input: string, items: string[]) => items
|
|
110
|
-
}
|
|
107
|
+
suggestionsFilter: (_input: string, items: string[]) => items
|
|
108
|
+
}
|
|
111
109
|
|
|
112
110
|
}
|
|
113
111
|
export const AlwaysShowAllSuggestionsAndNoRestrictToSuggestions = {
|
|
@@ -115,8 +113,8 @@ export const AlwaysShowAllSuggestionsAndNoRestrictToSuggestions = {
|
|
|
115
113
|
args: {
|
|
116
114
|
...Primary.args,
|
|
117
115
|
restrictToSuggestions: false,
|
|
118
|
-
suggestionsFilter: (_input: string, items: string[]) => items
|
|
119
|
-
}
|
|
116
|
+
suggestionsFilter: (_input: string, items: string[]) => items
|
|
117
|
+
}
|
|
120
118
|
|
|
121
119
|
}
|
|
122
120
|
export const CustomSuggestionsObject = {
|
|
@@ -128,10 +126,9 @@ export const CustomSuggestionsObject = {
|
|
|
128
126
|
{ label: "A", other: "some data A" },
|
|
129
127
|
{ label: "AB", other: "some data AB" },
|
|
130
128
|
{ label: "ABC", other: "some data ABC" },
|
|
131
|
-
{ label: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", other: "some data ABCDEFGHIJKLMNOPQRSTUVWXYZ" }
|
|
129
|
+
{ label: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", other: "some data ABCDEFGHIJKLMNOPQRSTUVWXYZ" }
|
|
132
130
|
],
|
|
133
|
-
suggestionLabel: (item: any) => item.label
|
|
134
|
-
}
|
|
131
|
+
suggestionLabel: (item: any) => item.label
|
|
132
|
+
}
|
|
135
133
|
|
|
136
134
|
}
|
|
137
|
-
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
:data-open="$open"
|
|
14
14
|
role="listbox"
|
|
15
15
|
ref="el"
|
|
16
|
-
v-bind="{...$.attrs, class:undefined}"
|
|
16
|
+
v-bind="{ ...$.attrs, class: undefined }"
|
|
17
17
|
>
|
|
18
18
|
<!-- Click event is just in case, it should not really be triggered. We can do click selections via the blur handler. -->
|
|
19
|
-
<div
|
|
19
|
+
<div
|
|
20
|
+
:id="`suggestion-${id ?? fallbackId}-${index}`"
|
|
20
21
|
role="option"
|
|
21
22
|
:class="twMerge(`
|
|
22
23
|
suggestions--item
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
`,
|
|
31
32
|
($.itemAttrs as any)?.class
|
|
32
33
|
)"
|
|
33
|
-
v-bind="{...$.itemAttrs, class:undefined}"
|
|
34
|
+
v-bind="{ ...$.itemAttrs, class: undefined }"
|
|
34
35
|
:aria-selected="index === suggestions.active ? true : false"
|
|
35
36
|
:aria-label="suggestions.getLabel(item)"
|
|
36
37
|
v-for="(item, index) in suggestions.filtered"
|
|
@@ -39,7 +40,8 @@
|
|
|
39
40
|
@mousedown.prevent
|
|
40
41
|
@mouseup="suggestions.enterIndex(index, !Array.isArray($modelValue))"
|
|
41
42
|
>
|
|
42
|
-
<slot
|
|
43
|
+
<slot
|
|
44
|
+
name="item"
|
|
43
45
|
:item="item"
|
|
44
46
|
:index="index"
|
|
45
47
|
:is-selected="Array.isArray($modelValue) ? $modelValue.includes(item) : $modelValue === item"
|
|
@@ -57,21 +59,19 @@
|
|
|
57
59
|
</div>
|
|
58
60
|
</template>
|
|
59
61
|
|
|
60
|
-
|
|
61
62
|
<script setup lang="ts" generic="TSuggestion extends string | object, TValue extends string|string[]">
|
|
62
|
-
|
|
63
|
-
import { type HTMLAttributes,reactive, ref } from "vue"
|
|
63
|
+
import { type HTMLAttributes, reactive, ref } from "vue"
|
|
64
64
|
|
|
65
65
|
import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
|
|
66
66
|
import { useSuggestions } from "../../composables/useSuggestions.js"
|
|
67
67
|
import { hasModifiers } from "../../helpers/hasModifiers.js"
|
|
68
68
|
import { twMerge } from "../../utils/twMerge.js"
|
|
69
69
|
import LibCheckbox from "../LibCheckbox/LibCheckbox.vue"
|
|
70
|
-
import { type BaseInteractiveProps, getFallbackId,type LabelProps, type LinkableByIdProps, type SuggestionsEmits, type SuggestionsProps, type WrapperProps } from "../shared/props.js"
|
|
70
|
+
import { type BaseInteractiveProps, getFallbackId, type LabelProps, type LinkableByIdProps, type SuggestionsEmits, type SuggestionsProps, type WrapperProps } from "../shared/props.js"
|
|
71
71
|
|
|
72
72
|
defineOptions({
|
|
73
|
-
name: "
|
|
74
|
-
inheritAttrs: false
|
|
73
|
+
name: "LibSuggestions",
|
|
74
|
+
inheritAttrs: false
|
|
75
75
|
})
|
|
76
76
|
|
|
77
77
|
const $ = useDivideAttrs(["item"] as const)
|
|
@@ -83,7 +83,7 @@ const props = withDefaults(defineProps<Props & SuggestionsProps<TSuggestion>>(),
|
|
|
83
83
|
isValid: true,
|
|
84
84
|
canOpen: true,
|
|
85
85
|
filterKeydown: undefined,
|
|
86
|
-
unstyle: false, disabled: false, readonly: false, border: true
|
|
86
|
+
unstyle: false, disabled: false, readonly: false, border: true
|
|
87
87
|
})
|
|
88
88
|
/**
|
|
89
89
|
* The final valid value. This is *not* the value you want to share with the input. If `restrictToSuggestions` is true this will not update on any invalid values that `inputValue` might be set to.
|
|
@@ -96,11 +96,10 @@ const $modelValue = defineModel<TValue>("modelValue", { required: true })
|
|
|
96
96
|
*
|
|
97
97
|
* It allows the component to read even invalid output, and also to reset that invalid output when either modelValue is set to a new value, or when the component is closed via cancel.
|
|
98
98
|
*/
|
|
99
|
-
const $inputValue = defineModel<string
|
|
99
|
+
const $inputValue = defineModel<string>("inputValue", { default: "" })
|
|
100
100
|
|
|
101
101
|
const $open = defineModel<boolean>("open", { default: false })
|
|
102
102
|
|
|
103
|
-
|
|
104
103
|
if (typeof props.suggestions?.[0] === "object" && !props.suggestionLabel && !props.suggestionsFilter) {
|
|
105
104
|
throw new Error("`suggestionLabel` or `suggestionsFilter` must be passed if suggestions are objects.")
|
|
106
105
|
}
|
|
@@ -148,7 +147,7 @@ const inputKeydownHandler = (e: KeyboardEvent): void => {
|
|
|
148
147
|
}
|
|
149
148
|
const inputBlurHandler = (e: MouseEvent): void => {
|
|
150
149
|
if (props.filterBlur?.(e)) return
|
|
151
|
-
|
|
150
|
+
|
|
152
151
|
if (!$open.value) return
|
|
153
152
|
|
|
154
153
|
if (props.restrictToSuggestions) {
|
|
@@ -175,34 +174,33 @@ defineExpose({
|
|
|
175
174
|
/** A blur handler for the input that controls the component. This also takes care of making clicking on a suggestion work, since otherwise if canOpen is set to false in the blur handler, no click event will fire. */
|
|
176
175
|
inputBlurHandler,
|
|
177
176
|
/** A focus handler for the input that controls the component. */
|
|
178
|
-
inputFocusHandler
|
|
177
|
+
inputFocusHandler
|
|
179
178
|
})
|
|
180
|
-
|
|
181
179
|
</script>
|
|
182
180
|
|
|
183
181
|
<script lang="ts">
|
|
184
|
-
type WrapperTypes = Partial<WrapperProps<"item",HTMLAttributes, {
|
|
182
|
+
type WrapperTypes = Partial<WrapperProps<"item", HTMLAttributes, {
|
|
185
183
|
/** Tailwind classes. */
|
|
186
184
|
class?: string
|
|
187
185
|
}>>
|
|
188
186
|
|
|
189
|
-
type RealProps
|
|
190
|
-
& LinkableByIdProps
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
187
|
+
type RealProps
|
|
188
|
+
= & LinkableByIdProps
|
|
189
|
+
& LabelProps
|
|
190
|
+
& BaseInteractiveProps
|
|
191
|
+
& {
|
|
194
192
|
/** Return true to prevent the keydown event from being handled. */
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
193
|
+
filterKeydown?: (e: KeyboardEvent) => boolean
|
|
194
|
+
/** Return true to prevent the blur event from being handled. */
|
|
195
|
+
filterBlur?: (e: MouseEvent) => boolean
|
|
196
|
+
/** Return true to prevent the focus event from being handled. */
|
|
197
|
+
filterFocus?: (e: FocusEvent) => boolean
|
|
198
|
+
}
|
|
201
199
|
|
|
202
200
|
interface Props
|
|
203
201
|
extends
|
|
204
202
|
/** @vue-ignore */
|
|
205
|
-
Partial<Omit<HTMLAttributes,"class" | "onSubmit"> & {
|
|
203
|
+
Partial<Omit<HTMLAttributes, "class" | "onSubmit"> & {
|
|
206
204
|
/** Tailwind classes. */
|
|
207
205
|
class?: string
|
|
208
206
|
}>,
|
|
@@ -210,5 +208,4 @@ interface Props
|
|
|
210
208
|
WrapperTypes,
|
|
211
209
|
RealProps
|
|
212
210
|
{}
|
|
213
|
-
|
|
214
211
|
</script>
|