@falcondev-oss/nuxt-layers-base 0.6.2 → 0.7.0

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.
@@ -12,17 +12,13 @@ import type {
12
12
  InferInput,
13
13
  InferOutput,
14
14
  } from '@nuxt/ui'
15
- import type { Merge } from 'type-fest'
16
15
  import type { Reactive } from 'vue'
17
16
  import { useForwardProps } from 'reka-ui'
18
17
 
19
18
  const props = defineProps<
20
- Merge<
21
- AuthFormProps<T, F>,
22
- {
23
- onSubmit?: (event: FormSubmitEvent<InferOutput<T>>) => void | Promise<void>
24
- }
25
- >
19
+ Omit<AuthFormProps<T, F>, 'onSubmit'> & {
20
+ onSubmit?: (event: FormSubmitEvent<InferOutput<T>>) => void | Promise<void>
21
+ }
26
22
  >()
27
23
  const slots = defineSlots<AuthFormSlots<Reactive<InferInput<T>>, F>>()
28
24
 
@@ -8,31 +8,48 @@ const open = ref(false)
8
8
  </script>
9
9
 
10
10
  <template>
11
- <UInputDate ref="inputDate" v-model="model">
11
+ <UInputDate
12
+ ref="inputDate"
13
+ :model-value="model"
14
+ :range="false"
15
+ @update:model-value="
16
+ (val) => {
17
+ model = val ?? null
18
+ }
19
+ "
20
+ >
12
21
  <template #trailing>
13
22
  <UPopover v-model:open="open" :reference="inputDate?.inputsRef[3]?.$el">
14
- <UButton
15
- color="neutral"
16
- variant="link"
17
- size="sm"
18
- icon="i-lucide-calendar"
19
- aria-label="Datum auswählen"
20
- class="px-0"
21
- />
23
+ <UButton color="neutral" variant="link" size="sm" icon="i-lucide-calendar" class="px-0" />
22
24
 
23
25
  <template #content>
24
- <UCalendar
25
- :model-value="model ?? undefined"
26
- :multiple="false"
27
- :range="false"
28
- class="p-2"
29
- @update:model-value="
30
- (val) => {
31
- model = val ?? null
32
- open = false
33
- }
34
- "
35
- />
26
+ <div class="p-2">
27
+ <UCalendar
28
+ :model-value="model ?? undefined"
29
+ :multiple="false"
30
+ :range="false"
31
+ @update:model-value="
32
+ (val) => {
33
+ model = val ?? null
34
+ open = false
35
+ }
36
+ "
37
+ />
38
+ <div v-if="model" class="flex justify-end">
39
+ <UButton
40
+ variant="ghost"
41
+ icon="tabler:trash"
42
+ color="error"
43
+ label="Löschen"
44
+ size="sm"
45
+ @click="
46
+ () => {
47
+ model = null
48
+ }
49
+ "
50
+ />
51
+ </div>
52
+ </div>
36
53
  </template>
37
54
  </UPopover>
38
55
  </template>
@@ -0,0 +1,100 @@
1
+ <script setup lang="ts">
2
+ import type { CalendarDate, DateValue } from '@internationalized/date'
3
+ import { toCalendarDate } from '@internationalized/date'
4
+
5
+ const inputDate = useTemplateRef('inputDate')
6
+
7
+ const model = defineModel<{
8
+ start: CalendarDate
9
+ end: CalendarDate
10
+ } | null>({
11
+ required: true,
12
+ })
13
+
14
+ const localModel = shallowRef({
15
+ // eslint-disable-next-line vue/no-ref-object-reactivity-loss
16
+ start: model.value?.start,
17
+ // eslint-disable-next-line vue/no-ref-object-reactivity-loss
18
+ end: model.value?.end,
19
+ } as
20
+ | {
21
+ start: DateValue | undefined
22
+ end: DateValue | undefined
23
+ }
24
+ | undefined
25
+ | null)
26
+
27
+ const open = ref(false)
28
+
29
+ let syncingModelValue = false
30
+ watch(
31
+ localModel,
32
+ (newValue) => {
33
+ // prevent infinite loop
34
+ if (syncingModelValue) return
35
+
36
+ if (newValue?.start && newValue.end) {
37
+ model.value = {
38
+ start: toCalendarDate(newValue.start),
39
+ end: toCalendarDate(newValue.end),
40
+ }
41
+ open.value = false
42
+ } else if (!newValue?.start && !newValue?.end) {
43
+ model.value = null
44
+ open.value = false
45
+ }
46
+ },
47
+ {
48
+ flush: 'sync',
49
+ },
50
+ )
51
+
52
+ watch(model, (newValue) => {
53
+ syncingModelValue = true
54
+ if (newValue) {
55
+ localModel.value = {
56
+ start: newValue.start,
57
+ end: newValue.end,
58
+ }
59
+ } else {
60
+ localModel.value = {
61
+ start: undefined,
62
+ end: undefined,
63
+ }
64
+ }
65
+ syncingModelValue = false
66
+ })
67
+ </script>
68
+
69
+ <template>
70
+ <UInputDate ref="inputDate" v-model="localModel" range>
71
+ <template #trailing>
72
+ <UPopover v-model:open="open" :reference="inputDate?.inputsRef[0]?.$el">
73
+ <UButton color="neutral" variant="link" size="sm" icon="i-lucide-calendar" class="px-0" />
74
+
75
+ <template #content>
76
+ <div class="p-2">
77
+ <UCalendar v-model="localModel" :number-of-months="2" range />
78
+ <div v-if="model" class="flex justify-end">
79
+ <UButton
80
+ variant="ghost"
81
+ icon="tabler:trash"
82
+ color="error"
83
+ label="Löschen"
84
+ size="sm"
85
+ @click="
86
+ () => {
87
+ localModel = {
88
+ start: undefined,
89
+ end: undefined,
90
+ }
91
+ }
92
+ "
93
+ />
94
+ </div>
95
+ </div>
96
+ </template>
97
+ </UPopover>
98
+ </template>
99
+ </UInputDate>
100
+ </template>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@falcondev-oss/nuxt-layers-base",
3
3
  "type": "module",
4
- "version": "0.6.2",
4
+ "version": "0.7.0",
5
5
  "description": "Nuxt layer with lots of useful helpers and @nuxt/ui components",
6
6
  "license": "MIT",
7
7
  "repository": "github:falcondev-oss/nuxt-layers",