Skip to content

Commit 28da0df

Browse files
committed
feat(Calendar): add month/year picker modes and view switching
1 parent 6efc7c7 commit 28da0df

8 files changed

Lines changed: 2062 additions & 423 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script setup lang="ts">
2+
import type { CalendarDate } from '@internationalized/date'
3+
4+
const modelValue = shallowRef<CalendarDate>()
5+
6+
const displayValue = computed(() => {
7+
if (!modelValue.value) return 'Select month'
8+
const d = new Date(modelValue.value.year, modelValue.value.month - 1, 1)
9+
return new Intl.DateTimeFormat('en', { month: 'short', year: 'numeric' }).format(d)
10+
})
11+
</script>
12+
13+
<template>
14+
<UPopover>
15+
<UButton variant="outline" color="neutral" trailing-icon="i-lucide-calendar">
16+
{{ displayValue }}
17+
</UButton>
18+
19+
<template #content>
20+
<UCalendar v-model="modelValue" type="month" />
21+
</template>
22+
</UPopover>
23+
</template>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script setup lang="ts">
2+
import type { CalendarDate } from '@internationalized/date'
3+
4+
const modelValue = shallowRef<CalendarDate>()
5+
6+
const displayValue = computed(() => modelValue.value ? String(modelValue.value.year) : 'Select year')
7+
</script>
8+
9+
<template>
10+
<UPopover>
11+
<UButton variant="outline" color="neutral" trailing-icon="i-lucide-calendar">
12+
{{ displayValue }}
13+
</UButton>
14+
15+
<template #content>
16+
<UCalendar v-model="modelValue" type="year" />
17+
</template>
18+
</UPopover>
19+
</template>

docs/content/docs/2.components/calendar.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,65 @@ props:
209209
---
210210
::
211211

212+
### Type
213+
214+
Use the `type` prop to change the calendar picker type. Defaults to `date`.
215+
216+
Set `type="month"` for a month-only picker.
217+
218+
::component-code
219+
---
220+
cast:
221+
modelValue: DateValue
222+
ignore:
223+
- modelValue
224+
- type
225+
external:
226+
- modelValue
227+
props:
228+
type: month
229+
modelValue: [2022, 3, 1]
230+
---
231+
::
232+
233+
Set `type="year"` for a year-only picker.
234+
235+
::component-code
236+
---
237+
cast:
238+
modelValue: DateValue
239+
ignore:
240+
- modelValue
241+
- type
242+
external:
243+
- modelValue
244+
props:
245+
type: year
246+
modelValue: [2022, 1, 1]
247+
---
248+
::
249+
250+
### Default View
251+
252+
Use the `default-view` prop to set the initial view. Defaults to `day`.
253+
254+
::component-code
255+
---
256+
cast:
257+
defaultValue: DateValue
258+
ignore:
259+
- defaultView
260+
- defaultValue
261+
external:
262+
- defaultValue
263+
props:
264+
defaultView: month
265+
defaultValue: [2022, 2, 3]
266+
---
267+
::
268+
269+
The heading is clickable when using `type="date"` (default) and allows switching between day, month, and year views. Selecting a month or year navigates back to the day view.
270+
212271
## Examples
213272

214273
### With chip events
@@ -275,6 +334,26 @@ name: 'calendar-external-controls-example'
275334
---
276335
::
277336

337+
### As a MonthPicker
338+
339+
Use `type="month"` with a [Popover](/docs/components/popover) to create a month picker.
340+
341+
::component-example
342+
---
343+
name: 'calendar-month-picker-example'
344+
---
345+
::
346+
347+
### As a YearPicker
348+
349+
Use `type="year"` with a [Popover](/docs/components/popover) to create a year picker.
350+
351+
::component-example
352+
---
353+
name: 'calendar-year-picker-example'
354+
---
355+
::
356+
278357
### As a DatePicker
279358

280359
Use a [Button](/docs/components/button) and a [Popover](/docs/components/popover) component to create a date picker.

0 commit comments

Comments
 (0)