Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script setup lang="ts">
import type { CalendarDate } from '@internationalized/date'
import { DateFormatter, getLocalTimeZone } from '@internationalized/date'

const modelValue = shallowRef<CalendarDate>()
const formatter = new DateFormatter('en-US', {
month: 'long',
year: 'numeric'
})

const label = computed(() => {
if (!modelValue.value) {
return 'Select month'
}

return formatter.format(modelValue.value.toDate(getLocalTimeZone()))
})
</script>

<template>
<UPopover>
<UButton variant="outline" color="neutral" trailing-icon="i-lucide-calendar">
{{ label }}
</UButton>

<template #content>
<UCalendar v-model="modelValue" type="month" />
</template>
</UPopover>
</template>
69 changes: 69 additions & 0 deletions docs/content/docs/2.components/calendar.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,65 @@ props:
---
::

### Type

Use the `type` prop to change the calendar picker type. Defaults to `date`.

Set `type="month"` for a month-only picker.

::component-code
---
cast:
modelValue: DateValue
ignore:
- modelValue
- type
external:
- modelValue
props:
type: month
modelValue: [2022, 3, 1]
---
::

Set `type="year"` for a year-only picker.

::component-code
---
cast:
modelValue: DateValue
ignore:
- modelValue
- type
external:
- modelValue
props:
type: year
modelValue: [2022, 1, 1]
---
::

### Default View

Use the `default-view` prop to set the initial view. Defaults to `day` when `type="date"`.

::component-code
---
cast:
defaultValue: DateValue
ignore:
- defaultView
- defaultValue
external:
- defaultValue
props:
defaultView: month
defaultValue: [2022, 2, 3]
---
::

When using `type="date"`, the heading buttons let users switch between day, month, and year views.

## Examples

### With chip events
Expand Down Expand Up @@ -275,6 +334,16 @@ name: 'calendar-external-controls-example'
---
::

### As a month picker

Use `type="month"` with a [Popover](/docs/components/popover) to create a month picker.

::component-example
---
name: 'calendar-month-picker-example'
---
::
Comment thread
onmax marked this conversation as resolved.

### As a date picker

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