@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
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3";
|
|
2
|
+
import LibDarkModeSwitcher from "./LibDarkModeSwitcher.vue.js";
|
|
3
|
+
declare const meta: Meta<typeof LibDarkModeSwitcher>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof LibDarkModeSwitcher>;
|
|
6
|
+
export declare const Primary: Story;
|
|
7
|
+
export declare const WithoutLabel: Story;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import LibDarkModeSwitcher from "./LibDarkModeSwitcher.vue";
|
|
3
|
+
import * as components from "../index.js";
|
|
4
|
+
const meta = {
|
|
5
|
+
component: LibDarkModeSwitcher,
|
|
6
|
+
title: "Components/DarkModeSwitcher",
|
|
7
|
+
args: {}
|
|
8
|
+
};
|
|
9
|
+
export default meta;
|
|
10
|
+
export const Primary = {
|
|
11
|
+
render: (args) => ({
|
|
12
|
+
components,
|
|
13
|
+
setup: () => {
|
|
14
|
+
const darkMode = ref(false);
|
|
15
|
+
return {
|
|
16
|
+
args,
|
|
17
|
+
darkMode
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
template: `
|
|
21
|
+
Value: {{darkMode}}
|
|
22
|
+
<LibDarkModeSwitcher
|
|
23
|
+
@update:darkMode="darkMode = $event"
|
|
24
|
+
v-bind="{...args}"
|
|
25
|
+
></LibDarkModeSwitcher>
|
|
26
|
+
|
|
27
|
+
`
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
export const WithoutLabel = {
|
|
31
|
+
...Primary,
|
|
32
|
+
args: {
|
|
33
|
+
...Primary.args,
|
|
34
|
+
showLabel: false
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<lib-button
|
|
3
|
-
v-bind="{
|
|
4
|
-
:class="
|
|
5
|
-
`
|
|
3
|
+
v-bind="{...$attrs, class:undefined}"
|
|
4
|
+
:class="!($attrs as any).unstyle && twMerge(`
|
|
6
5
|
dark-mode-switcher
|
|
7
6
|
rounded-full
|
|
8
7
|
after:rounded-full
|
|
9
8
|
`,
|
|
10
|
-
|
|
11
|
-
)"
|
|
9
|
+
($attrs as any)?.class
|
|
10
|
+
)"
|
|
12
11
|
:title="`${t('dark-mode-switcher.title')}${t(`dark-mode-switcher.${darkModeState}`)}`"
|
|
13
12
|
@click="cycleDarkMode"
|
|
14
13
|
>
|
|
15
14
|
<!-- content-vertical-holder will keep the icon the height of a text line regardless of the svg used -->
|
|
16
15
|
<template #icon>
|
|
17
16
|
<icon
|
|
18
|
-
v-if="darkModeState
|
|
17
|
+
v-if="darkModeState==='dark'"
|
|
19
18
|
class="w-[1em] flex items-center content-vertical-holder"
|
|
20
19
|
>
|
|
21
20
|
<i-fa-solid-moon/>
|
|
22
21
|
</icon>
|
|
23
22
|
<icon
|
|
24
|
-
v-else-if="darkModeState
|
|
23
|
+
v-else-if="darkModeState==='light'"
|
|
25
24
|
class="w-[1em] content-vertical-holder"
|
|
26
25
|
>
|
|
27
26
|
<i-ph-sun-bold/>
|
|
@@ -40,34 +39,59 @@
|
|
|
40
39
|
</template>
|
|
41
40
|
</lib-button>
|
|
42
41
|
</template>
|
|
42
|
+
<script lang="ts" setup>
|
|
43
|
+
import { type ButtonHTMLAttributes,onMounted,useAttrs, watch } from "vue"
|
|
44
|
+
|
|
45
|
+
import { useInjectedDarkMode } from "../../composables/useInjectedDarkMode.js"
|
|
46
|
+
import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
|
|
47
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
48
|
+
import Icon from "../Icon/Icon.vue"
|
|
49
|
+
import LibButton from "../LibButton/LibButton.vue"
|
|
50
|
+
import type { TailwindClassProp } from "../shared/props.js"
|
|
51
|
+
|
|
52
|
+
const t = useInjectedI18n()
|
|
53
|
+
|
|
54
|
+
const emit = defineEmits<{
|
|
55
|
+
/** Emits whether dark mode should be enabled. */
|
|
56
|
+
(e: "update:darkMode", value: boolean): void
|
|
57
|
+
/** Emits the change, but as a state string (dark, light, system) */
|
|
58
|
+
(e: "update:darkModeState", value: "dark" | "light" | "system"): void
|
|
59
|
+
}>()
|
|
60
|
+
const $attrs = useAttrs()
|
|
61
|
+
|
|
62
|
+
withDefaults(defineProps<Props>(), { showLabel: true })
|
|
63
|
+
|
|
43
64
|
|
|
44
|
-
<script setup>
|
|
45
|
-
import { onMounted, useAttrs, watch } from "vue";
|
|
46
|
-
import { useInjectedDarkMode } from "../../composables/useInjectedDarkMode.js";
|
|
47
|
-
import { useInjectedI18n } from "../../composables/useInjectedI18n.js";
|
|
48
|
-
import { twMerge } from "../../utils/twMerge.js";
|
|
49
|
-
import Icon from "../Icon/Icon.vue";
|
|
50
|
-
import LibButton from "../LibButton/LibButton.vue";
|
|
51
|
-
const t = useInjectedI18n();
|
|
52
|
-
const emit = defineEmits(["update:darkMode", "update:darkModeState"]);
|
|
53
|
-
const $attrs = useAttrs();
|
|
54
|
-
defineProps({
|
|
55
|
-
showLabel: { type: Boolean, required: false, default: true }
|
|
56
|
-
});
|
|
57
65
|
const {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
} = useInjectedDarkMode()
|
|
62
|
-
|
|
63
|
-
watch(
|
|
66
|
+
darkMode,
|
|
67
|
+
cycleDarkMode,
|
|
68
|
+
darkModeState,
|
|
69
|
+
} = useInjectedDarkMode()
|
|
70
|
+
|
|
71
|
+
watch(darkMode, value => emit("update:darkMode", value))
|
|
72
|
+
watch(darkModeState, value => emit("update:darkModeState", value))
|
|
73
|
+
|
|
64
74
|
onMounted(() => {
|
|
65
|
-
|
|
66
|
-
})
|
|
75
|
+
emit("update:darkMode", darkMode.value)
|
|
76
|
+
})
|
|
67
77
|
</script>
|
|
68
|
-
|
|
69
|
-
<script>
|
|
78
|
+
<script lang="ts">
|
|
70
79
|
export default {
|
|
71
|
-
|
|
72
|
-
}
|
|
80
|
+
name: "lib-dark-mode-switcher"
|
|
81
|
+
}
|
|
82
|
+
type RealProps = {
|
|
83
|
+
showLabel?: boolean
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface Props
|
|
87
|
+
extends
|
|
88
|
+
/** @vue-ignore */
|
|
89
|
+
Partial<Omit<ButtonHTMLAttributes,"class" | "color" | "disabled">
|
|
90
|
+
& TailwindClassProp
|
|
91
|
+
& {
|
|
92
|
+
disabled?: boolean
|
|
93
|
+
unstyle?: boolean
|
|
94
|
+
}>,
|
|
95
|
+
RealProps
|
|
96
|
+
{ }
|
|
73
97
|
</script>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3";
|
|
2
|
+
import * as components from "../index.js.js";
|
|
3
|
+
declare const singleMeta: Meta<typeof components.LibDatePicker>;
|
|
4
|
+
export default singleMeta;
|
|
5
|
+
type Story = StoryObj<typeof components.LibDatePicker>;
|
|
6
|
+
export declare const Primary: Story;
|
|
7
|
+
export declare const DateRange: Story;
|
|
8
|
+
export declare const IconTriggerFirst: Story;
|
|
9
|
+
export declare const BottomSlot: Story;
|
|
10
|
+
export declare const DateWithTime: Story;
|
|
11
|
+
export declare const WithDifferentFallbackDate: Story;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { CalendarDate, fromDate, getLocalTimeZone, toTimeZone } from "@internationalized/date";
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
|
+
import { createNoonUtcDate } from "../../helpers/createNoonUtcDate.js";
|
|
4
|
+
import * as components from "../index.js";
|
|
5
|
+
function html(strings, ...values) {
|
|
6
|
+
return String.raw(strings, ...values);
|
|
7
|
+
}
|
|
8
|
+
const singleMeta = {
|
|
9
|
+
component: components.LibDatePicker,
|
|
10
|
+
title: "Components/DatePicker",
|
|
11
|
+
args: {
|
|
12
|
+
// @ts-expect-error custom prop just for story
|
|
13
|
+
slot: "",
|
|
14
|
+
timeZone: getLocalTimeZone()
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export default singleMeta;
|
|
18
|
+
function toUTC(m, timeZone) {
|
|
19
|
+
return toTimeZone(fromDate(m, timeZone), "UTC").toAbsoluteString();
|
|
20
|
+
}
|
|
21
|
+
export const Primary = {
|
|
22
|
+
render: (args) => ({
|
|
23
|
+
components: {
|
|
24
|
+
...components
|
|
25
|
+
},
|
|
26
|
+
setup: () => {
|
|
27
|
+
const modelValue = ref(args.modelValue);
|
|
28
|
+
const timeZone = ref(args.timeZone);
|
|
29
|
+
const debugUtcDate = computed(() => {
|
|
30
|
+
const m = modelValue.value;
|
|
31
|
+
const z = timeZone.value;
|
|
32
|
+
return m instanceof Date ? toUTC(m, z) : typeof m === "object" ? `Start: ${m.start ? toUTC(m.start, z) : "undefined"}, End: ${m.end ? toUTC(m.end, z) : "undefined"}` : "undefined";
|
|
33
|
+
});
|
|
34
|
+
return { args, getLocalTimeZone, modelValue, timeZone, debugUtcDate };
|
|
35
|
+
},
|
|
36
|
+
template: `
|
|
37
|
+
<div>Date: {{modelValue ?? "undefined"}}</div>
|
|
38
|
+
<div>Date UTC: {{debugUtcDate}}</div>
|
|
39
|
+
<div>Detected timezone (via @internationalized/date): {{getLocalTimeZone()}}</div>
|
|
40
|
+
<LibTimeZonePicker
|
|
41
|
+
v-model="timeZone"
|
|
42
|
+
label="Override Time Zone"
|
|
43
|
+
wrapper-class="[&_.suggestions]:max-h-[200px] [&_.suggestions]:overflow-y-auto"
|
|
44
|
+
/>
|
|
45
|
+
<div>
|
|
46
|
+
This component has no border, added here to see it's size.
|
|
47
|
+
</div>
|
|
48
|
+
<div class="border border-neutral-500">
|
|
49
|
+
<LibDatePicker v-bind="args" v-model="modelValue" :time-zone="timeZone">
|
|
50
|
+
${args.slot}
|
|
51
|
+
</LibDatePicker>
|
|
52
|
+
</div>
|
|
53
|
+
`
|
|
54
|
+
})
|
|
55
|
+
};
|
|
56
|
+
export const DateRange = {
|
|
57
|
+
...Primary,
|
|
58
|
+
args: {
|
|
59
|
+
modelValue: { start: void 0, end: void 0 }
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export const IconTriggerFirst = {
|
|
63
|
+
...Primary,
|
|
64
|
+
args: {
|
|
65
|
+
...Primary.args,
|
|
66
|
+
class: "[&_.trigger]:order-first"
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
export const BottomSlot = {
|
|
70
|
+
...Primary,
|
|
71
|
+
args: {
|
|
72
|
+
// @ts-expect-error see above
|
|
73
|
+
slot: html`
|
|
74
|
+
<template #default="slotProps">
|
|
75
|
+
<LibButton>Custom content can be added here.</LibButton>
|
|
76
|
+
<p class="break-all">
|
|
77
|
+
Content has access to the internal temporary/suggested date value and can change it (e.g. set it to today).
|
|
78
|
+
</p>
|
|
79
|
+
<p>Temp value:</p>
|
|
80
|
+
{{ slotProps.tempValue }}
|
|
81
|
+
</template>
|
|
82
|
+
`
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
export const DateWithTime = {
|
|
86
|
+
...Primary,
|
|
87
|
+
args: {
|
|
88
|
+
...Primary.args,
|
|
89
|
+
showTime: true
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export const WithDifferentFallbackDate = {
|
|
93
|
+
...Primary,
|
|
94
|
+
args: {
|
|
95
|
+
...Primary.args,
|
|
96
|
+
fallbackDate: createNoonUtcDate(new CalendarDate(2e3, 1, 1)).toDate()
|
|
97
|
+
}
|
|
98
|
+
};
|
|
@@ -1,19 +1,40 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { getLocalTimeZone } from "@internationalized/date"
|
|
3
|
-
import { computed, useAttrs } from "vue"
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { getLocalTimeZone } from "@internationalized/date"
|
|
3
|
+
import { computed, useAttrs } from "vue"
|
|
4
|
+
|
|
5
|
+
import LibRangeDatePicker from "./LibRangeDatePicker.vue"
|
|
6
|
+
import LibSingleDatePicker from "./LibSingleDatePicker.vue"
|
|
7
|
+
|
|
8
|
+
import type { RangeDate,SingleDate } from "../../types/index.js"
|
|
9
|
+
import { getFallbackId } from "../shared/props.js"
|
|
10
|
+
|
|
11
|
+
const attrs = useAttrs()
|
|
12
|
+
|
|
13
|
+
withDefaults(defineProps<{
|
|
14
|
+
showTime?: boolean
|
|
15
|
+
id?: string
|
|
16
|
+
/** The fallback suggested date when the modelValue is undefined (it will not update modelValue, it only serves as a suggestions and is used internally in the temporary value). If ignoring the time element, you should probably use the {@link createNoonTodayUtc} function (`createNonTodayUtc().toDate(())`) in the helpers, otherwise `new Date()` (the default) will do. */
|
|
17
|
+
fallbackDate?: Date
|
|
18
|
+
/** The local user's timezone, defaults to @internationalized/date's getLocalTimeZone(). */
|
|
19
|
+
timeZone?: string
|
|
20
|
+
}>(), {
|
|
21
|
+
showTime: false,
|
|
22
|
+
id: undefined,
|
|
23
|
+
fallbackDate: () => new Date(),
|
|
24
|
+
timeZone: getLocalTimeZone()
|
|
25
|
+
})
|
|
26
|
+
const fallbackId = getFallbackId()
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* modelValue can be undefined or an object with start/end undefined, but it must be passed, otherwise we can't tell the difference between a single date and a range date.
|
|
30
|
+
*
|
|
31
|
+
* In the case of an undefined date, the current date at NOON UTC will be used to avoid the date changing.
|
|
32
|
+
*
|
|
33
|
+
* The @internationalized/date library's fromDate function is used internally to convert the date given (should be UTC) to the local time zone. It's converted back via it's toDate function.
|
|
34
|
+
*/
|
|
35
|
+
const date = defineModel<SingleDate | RangeDate>({ required: true })
|
|
36
|
+
const isRange = computed(() => date.value !== undefined && !(date.value instanceof Date))
|
|
37
|
+
|
|
17
38
|
</script>
|
|
18
39
|
|
|
19
40
|
<template>
|
|
@@ -24,7 +45,7 @@ const isRange = computed(() => date.value !== void 0 && !(date.value instanceof
|
|
|
24
45
|
:time-zone="timeZone"
|
|
25
46
|
:fallback-date="fallbackDate"
|
|
26
47
|
:is="isRange ? LibRangeDatePicker : LibSingleDatePicker"
|
|
27
|
-
v-model="date"
|
|
48
|
+
v-model="date as any"
|
|
28
49
|
>
|
|
29
50
|
<template #default="slotProps">
|
|
30
51
|
<slot v-bind="slotProps"/>
|
|
@@ -1,55 +1,84 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { CalendarDate, getLocalTimeZone, ZonedDateTime } from "@internationalized/date"
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { CalendarDate, type DateValue, getLocalTimeZone, ZonedDateTime } from "@internationalized/date"
|
|
3
|
+
import type { DateRange } from "reka-ui"
|
|
4
|
+
import { DateRangePickerArrow, DateRangePickerCalendar, DateRangePickerCell, DateRangePickerCellTrigger, DateRangePickerContent, DateRangePickerField, DateRangePickerGrid, DateRangePickerGridBody, DateRangePickerGridHead, DateRangePickerGridRow, DateRangePickerHeadCell,DateRangePickerHeader, DateRangePickerHeading, DateRangePickerInput, DateRangePickerNext, DateRangePickerPrev, DateRangePickerRoot, DateRangePickerTrigger } from "reka-ui"
|
|
5
|
+
import { onBeforeUnmount, ref, toRaw, useAttrs, watch } from "vue"
|
|
6
|
+
|
|
7
|
+
import { convertDateWithFallback, getNow,toEmittableDate } from "./helpers.js"
|
|
8
|
+
|
|
9
|
+
import { useInjectedLocale } from "../../composables/useInjectedLocale.js"
|
|
10
|
+
import type { RangeDate } from "../../types/index.js"
|
|
11
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
12
|
+
import Icon from "../Icon/Icon.vue"
|
|
13
|
+
const attrs = useAttrs()
|
|
14
|
+
|
|
15
|
+
const props = withDefaults(defineProps<{
|
|
16
|
+
useTime?: boolean
|
|
17
|
+
id: string
|
|
18
|
+
fallbackDate?: Date
|
|
19
|
+
timeZone?: string
|
|
20
|
+
updateInterval?: number
|
|
21
|
+
}>(), {
|
|
22
|
+
timeZone: getLocalTimeZone(),
|
|
23
|
+
useTime: false,
|
|
24
|
+
fallbackDate: _ => getNow({ withTime: _.useTime ?? false }).toDate(_.timeZone ?? getLocalTimeZone()),
|
|
25
|
+
updateInterval: 10000
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const date = defineModel<RangeDate>({ required: true })
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
let justSet = false
|
|
32
|
+
|
|
33
|
+
const tempDate = ref<{
|
|
34
|
+
start?: CalendarDate | ZonedDateTime
|
|
35
|
+
end?: CalendarDate | ZonedDateTime
|
|
36
|
+
}>({})
|
|
37
|
+
function updateTempDate(keys: ("start" | "end")[] = ["start", "end"]) {
|
|
38
|
+
const newValue = { ...tempDate.value }
|
|
39
|
+
for (const key of keys) {
|
|
40
|
+
newValue[key] = convertDateWithFallback(date.value?.[key], props)
|
|
41
|
+
}
|
|
42
|
+
// the WHOLE object must be updated due to how the reka date picker works
|
|
43
|
+
tempDate.value = newValue
|
|
26
44
|
}
|
|
45
|
+
|
|
46
|
+
// to avoid too deep of a watch
|
|
27
47
|
watch([() => date.value.start, () => date.value.end], () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
})
|
|
48
|
+
if (!justSet) {
|
|
49
|
+
updateTempDate()
|
|
50
|
+
} else {
|
|
51
|
+
justSet = false
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
|
|
34
55
|
watch(tempDate, () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})
|
|
56
|
+
if (!tempDate.value.start || !tempDate.value.end) return
|
|
57
|
+
justSet = true
|
|
58
|
+
date.value = {
|
|
59
|
+
start: tempDate.value.start ? toEmittableDate(toRaw(tempDate.value.start) as any) : undefined,
|
|
60
|
+
end: tempDate.value.end ? toEmittableDate(toRaw(tempDate.value.end) as any) : undefined
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
42
64
|
watch(() => props.timeZone, () => {
|
|
43
|
-
|
|
44
|
-
})
|
|
65
|
+
updateTempDate()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
|
|
45
69
|
const interval = setInterval(() => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
70
|
+
// update suggested date if none is set
|
|
71
|
+
if (!date.value.start) updateTempDate(["start"])
|
|
72
|
+
if (!date.value.end) updateTempDate(["end"])
|
|
73
|
+
}, props.updateInterval)
|
|
74
|
+
|
|
49
75
|
onBeforeUnmount(() => {
|
|
50
|
-
|
|
51
|
-
})
|
|
52
|
-
|
|
76
|
+
clearInterval(interval)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const locale = useInjectedLocale().timeLocale
|
|
80
|
+
|
|
81
|
+
|
|
53
82
|
</script>
|
|
54
83
|
|
|
55
84
|
<template>
|
|
@@ -57,7 +86,7 @@ const locale = useInjectedLocale().timeLocale;
|
|
|
57
86
|
:id="id"
|
|
58
87
|
:locale="locale"
|
|
59
88
|
class="date-range-picker--root"
|
|
60
|
-
v-model="tempDate"
|
|
89
|
+
v-model="tempDate as DateRange"
|
|
61
90
|
>
|
|
62
91
|
<DateRangePickerField
|
|
63
92
|
v-slot="{ segments }"
|
|
@@ -68,14 +97,14 @@ const locale = useInjectedLocale().timeLocale;
|
|
|
68
97
|
data-[invalid]:border-red-500
|
|
69
98
|
metadata-input-border
|
|
70
99
|
rounded-sm
|
|
71
|
-
`, attrs.class)"
|
|
100
|
+
`, (attrs as any).class)"
|
|
72
101
|
>
|
|
73
102
|
<div class="date-range-picker--segments-input flex items-center flex-1 overflow-scroll scrollbar-hidden whitespace-nowrap">
|
|
74
103
|
<div :class="twMerge(`
|
|
75
104
|
date-range-picker--start-segment
|
|
76
105
|
flex
|
|
77
106
|
items-center
|
|
78
|
-
`, date.start ===
|
|
107
|
+
`, date.start === undefined && 'text-neutral-400')"
|
|
79
108
|
>
|
|
80
109
|
<template
|
|
81
110
|
v-for="item in segments.start"
|
|
@@ -122,7 +151,7 @@ const locale = useInjectedLocale().timeLocale;
|
|
|
122
151
|
date-range-picker--end-segment
|
|
123
152
|
flex
|
|
124
153
|
items-center
|
|
125
|
-
`, date.end ===
|
|
154
|
+
`, date.end === undefined && 'text-neutral-400')"
|
|
126
155
|
>
|
|
127
156
|
<template
|
|
128
157
|
v-for="item in segments.end"
|
|
@@ -229,7 +258,7 @@ const locale = useInjectedLocale().timeLocale;
|
|
|
229
258
|
outlined
|
|
230
259
|
px-1
|
|
231
260
|
"
|
|
232
|
-
:prev-page="(
|
|
261
|
+
:prev-page="(date: DateValue) => date.subtract({ years: 1 })"
|
|
233
262
|
>
|
|
234
263
|
<Icon class="scale-150">
|
|
235
264
|
<i-radix-icons-double-arrow-left/>
|
|
@@ -283,7 +312,7 @@ const locale = useInjectedLocale().timeLocale;
|
|
|
283
312
|
outlined
|
|
284
313
|
px-1
|
|
285
314
|
"
|
|
286
|
-
:next-page="(
|
|
315
|
+
:next-page="(date: DateValue) => date.add({ years: 1 })"
|
|
287
316
|
>
|
|
288
317
|
<Icon class="scale-150">
|
|
289
318
|
<i-radix-icons-double-arrow-right/>
|
|
@@ -395,7 +424,7 @@ const locale = useInjectedLocale().timeLocale;
|
|
|
395
424
|
</DateRangePickerGridBody>
|
|
396
425
|
</DateRangePickerGrid>
|
|
397
426
|
</div>
|
|
398
|
-
<slot v-bind="{
|
|
427
|
+
<slot v-bind="{tempValue: tempDate}"/>
|
|
399
428
|
</DateRangePickerCalendar>
|
|
400
429
|
</DateRangePickerContent>
|
|
401
430
|
</DateRangePickerRoot>
|