Skip to content

Commit dabc4f8

Browse files
hywaxbenjamincanac
andauthored
feat(InputDate): new component (#5387)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
1 parent 936253f commit dabc4f8

File tree

17 files changed

+1355
-5
lines changed

17 files changed

+1355
-5
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup lang="ts">
2+
import { CalendarDate } from '@internationalized/date'
3+
4+
const modelValue = shallowRef(new CalendarDate(2023, 9, 10))
5+
const minDate = new CalendarDate(2023, 9, 1)
6+
const maxDate = new CalendarDate(2023, 9, 30)
7+
</script>
8+
9+
<template>
10+
<UInputDate v-model="modelValue" :min-value="minDate" :max-value="maxDate" />
11+
</template>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script setup lang="ts">
2+
import type { DateValue } from '@internationalized/date'
3+
import { CalendarDate } from '@internationalized/date'
4+
5+
const modelValue = shallowRef({
6+
start: new CalendarDate(2022, 1, 1),
7+
end: new CalendarDate(2022, 1, 9)
8+
})
9+
10+
const isDateUnavailable = (date: DateValue) => {
11+
return date.day >= 10 && date.day <= 16
12+
}
13+
</script>
14+
15+
<template>
16+
<UInputDate v-model="modelValue" :is-date-unavailable="isDateUnavailable" range />
17+
</template>
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
---
2+
title: InputDate
3+
description: 'An input component for date selection.'
4+
category: form
5+
links:
6+
- label: DateField
7+
icon: i-custom-reka-ui
8+
to: https://reka-ui.com/docs/components/date-field
9+
- label: GitHub
10+
icon: i-simple-icons-github
11+
to: https://github.com/nuxt/ui/blob/v4/src/runtime/components/InputDate.vue
12+
navigation.badge: Soon
13+
---
14+
15+
## Usage
16+
17+
Use the `v-model` directive to control the selected date.
18+
19+
::component-code
20+
---
21+
cast:
22+
modelValue: DateValue
23+
ignore:
24+
- modelValue
25+
external:
26+
- modelValue
27+
props:
28+
modelValue: [2022, 2, 3]
29+
---
30+
::
31+
32+
Use the `default-value` prop to set the initial value when you do not need to control its state.
33+
34+
::component-code
35+
---
36+
cast:
37+
defaultValue: DateValue
38+
ignore:
39+
- defaultValue
40+
external:
41+
- defaultValue
42+
props:
43+
defaultValue: [2022, 2, 6]
44+
---
45+
::
46+
47+
### Range
48+
49+
Use the `range` prop to select a range of dates.
50+
51+
::component-code
52+
---
53+
prettier: true
54+
cast:
55+
modelValue: DateRange
56+
ignore:
57+
- range
58+
- modelValue.start
59+
- modelValue.end
60+
external:
61+
- modelValue
62+
props:
63+
range: true
64+
modelValue:
65+
start: [2022, 2, 3]
66+
end: [2022, 2, 20]
67+
---
68+
::
69+
70+
### Color
71+
72+
Use the `color` prop to change the color of the InputDate.
73+
74+
::component-code
75+
---
76+
props:
77+
color: neutral
78+
highlight: true
79+
---
80+
::
81+
82+
### Variant
83+
84+
Use the `variant` prop to change the variant of the InputDate.
85+
86+
::component-code
87+
---
88+
props:
89+
variant: subtle
90+
---
91+
::
92+
93+
### Size
94+
95+
Use the `size` prop to change the size of the InputDate.
96+
97+
::component-code
98+
---
99+
props:
100+
size: xl
101+
---
102+
::
103+
104+
### Separator Icon
105+
106+
Use the `separator-icon` prop to change the icon of the range separator.
107+
108+
::component-code
109+
---
110+
props:
111+
range: true
112+
separatorIcon: 'i-lucide-arrow-right'
113+
---
114+
::
115+
116+
### Disabled
117+
118+
Use the `disabled` prop to disable the InputDate.
119+
120+
::component-code
121+
---
122+
props:
123+
disabled: true
124+
---
125+
::
126+
127+
## Examples
128+
129+
### With unavailable dates
130+
131+
Use the `is-date-unavailable` prop with a function to mark specific dates as unavailable.
132+
133+
::component-example
134+
---
135+
name: 'input-date-unavailable-dates-example'
136+
---
137+
::
138+
139+
### With min/max dates
140+
141+
Use the `min-value` and `max-value` props to limit the dates.
142+
143+
::component-example
144+
---
145+
name: 'input-date-min-max-dates-example'
146+
---
147+
::
148+
149+
## API
150+
151+
### Props
152+
153+
:component-props
154+
155+
### Slots
156+
157+
:component-slots
158+
159+
### Emits
160+
161+
:component-emits
162+
163+
## Theme
164+
165+
:component-theme
166+
167+
## Changelog
168+
169+
:component-changelog
5.29 KB
Loading
5.22 KB
Loading

playgrounds/nuxt/app/composables/useNavigation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const components = [
3535
'form-field',
3636
'form',
3737
'header',
38+
'input-date',
3839
'input-menu',
3940
'input-number',
4041
'input-tags',
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<script setup lang="ts">
2+
import { CalendarDate } from '@internationalized/date'
3+
import theme from '#build/ui/input-date'
4+
5+
const colors = Object.keys(theme.variants.color)
6+
const variants = Object.keys(theme.variants.variant)
7+
const sizes = Object.keys(theme.variants.size)
8+
9+
const attrs = reactive({
10+
color: [theme.defaultVariants.color],
11+
variant: [theme.defaultVariants.variant],
12+
size: [theme.defaultVariants.size]
13+
})
14+
15+
const value = shallowRef(new CalendarDate(2022, 1, 10))
16+
const range = shallowRef({
17+
start: new CalendarDate(2022, 1, 10),
18+
end: new CalendarDate(2022, 1, 20)
19+
})
20+
</script>
21+
22+
<template>
23+
<Navbar>
24+
<USelect v-model="attrs.color" :items="colors" multiple />
25+
<USelect v-model="attrs.variant" :items="variants" multiple />
26+
<USelect v-model="attrs.size" :items="sizes" multiple />
27+
</Navbar>
28+
29+
<Matrix v-slot="props" :attrs="attrs">
30+
<UInputDate v-model="value" autofocus v-bind="props" />
31+
<UInputDate :default-value="new CalendarDate(2022, 1, 10)" v-bind="props" />
32+
<UInputDate v-model="range" range v-bind="props" />
33+
<UInputDate :default-value="{ start: new CalendarDate(2022, 1, 10), end: new CalendarDate(2022, 1, 20) }" range v-bind="props" />
34+
<UInputDate highlight v-bind="props" />
35+
<UInputDate disabled v-bind="props" />
36+
<UInputDate required v-bind="props" />
37+
<UInputDate icon="i-lucide-clock" v-bind="props" />
38+
<UInputDate icon="i-lucide-clock" trailing v-bind="props" />
39+
<UInputDate :avatar="{ src: 'https://github.com/benjamincanac.png' }" icon="i-lucide-clock" trailing v-bind="props" />
40+
<UInputDate loading v-bind="props" />
41+
<UInputDate loading trailing v-bind="props" />
42+
<UInputDate loading icon="i-lucide-clock" trailing-icon="i-lucide-chevron-down" v-bind="props" />
43+
</Matrix>
44+
</template>

0 commit comments

Comments
 (0)