-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Calendar): implement component (#2618)
Co-authored-by: Benjamin Canac <[email protected]>
- Loading branch information
1 parent
86f2b48
commit 2e9aeb5
Showing
40 changed files
with
10,278 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
docs/app/components/content/examples/calendar/CalendarDatePickerExample.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script setup lang="ts"> | ||
import { CalendarDate, DateFormatter, getLocalTimeZone } from '@internationalized/date' | ||
const df = new DateFormatter('en-US', { | ||
dateStyle: 'medium' | ||
}) | ||
const modelValue = shallowRef(new CalendarDate(2022, 1, 10)) | ||
</script> | ||
|
||
<template> | ||
<UPopover> | ||
<UButton color="neutral" variant="subtle" icon="i-lucide-calendar"> | ||
{{ df.format(modelValue.toDate(getLocalTimeZone())) }} | ||
</UButton> | ||
|
||
<template #content> | ||
<UCalendar v-model="modelValue" class="p-2" /> | ||
</template> | ||
</UPopover> | ||
</template> |
35 changes: 35 additions & 0 deletions
35
docs/app/components/content/examples/calendar/CalendarDateRangePickerExample.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script setup lang="ts"> | ||
import { CalendarDate, DateFormatter, getLocalTimeZone } from '@internationalized/date' | ||
const df = new DateFormatter('en-US', { | ||
dateStyle: 'medium' | ||
}) | ||
const modelValue = shallowRef({ | ||
start: new CalendarDate(2022, 1, 20), | ||
end: new CalendarDate(2022, 2, 10) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<UPopover> | ||
<UButton color="neutral" variant="subtle" icon="i-lucide-calendar"> | ||
<template v-if="modelValue.start"> | ||
<template v-if="modelValue.end"> | ||
{{ df.format(modelValue.start.toDate(getLocalTimeZone())) }} - {{ df.format(modelValue.end.toDate(getLocalTimeZone())) }} | ||
</template> | ||
|
||
<template v-else> | ||
{{ df.format(modelValue.start.toDate(getLocalTimeZone())) }} | ||
</template> | ||
</template> | ||
<template v-else> | ||
Pick a date | ||
</template> | ||
</UButton> | ||
|
||
<template #content> | ||
<UCalendar v-model="modelValue" class="p-2" :number-of-months="2" range /> | ||
</template> | ||
</UPopover> | ||
</template> |
17 changes: 17 additions & 0 deletions
17
docs/app/components/content/examples/calendar/CalendarDisabledDatesExample.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script setup lang="ts"> | ||
import { CalendarDate } from '@internationalized/date' | ||
import type { Matcher } from 'radix-vue/date' | ||
const modelValue = shallowRef({ | ||
start: new CalendarDate(2022, 1, 1), | ||
end: new CalendarDate(2022, 1, 9) | ||
}) | ||
const isDateDisabled: Matcher = (date) => { | ||
return date.day >= 10 && date.day <= 16 | ||
} | ||
</script> | ||
|
||
<template> | ||
<UCalendar v-model="modelValue" :is-date-disabled="isDateDisabled" range /> | ||
</template> |
30 changes: 30 additions & 0 deletions
30
docs/app/components/content/examples/calendar/CalendarEventsExample.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<script setup lang="ts"> | ||
import { CalendarDate } from '@internationalized/date' | ||
const modelValue = shallowRef(new CalendarDate(2022, 1, 10)) | ||
function getColorByDate(date: Date) { | ||
const isWeekend = date.getDay() % 6 == 0 | ||
const isDayMeeting = date.getDay() % 3 == 0 | ||
if (isWeekend) { | ||
return undefined | ||
} | ||
if (isDayMeeting) { | ||
return 'error' | ||
} | ||
return 'success' | ||
} | ||
</script> | ||
|
||
<template> | ||
<UCalendar v-model="modelValue"> | ||
<template #day="{ day }"> | ||
<UChip :show="!!getColorByDate(day.toDate('UTC'))" :color="getColorByDate(day.toDate('UTC'))" size="2xs"> | ||
{{ day.day }} | ||
</UChip> | ||
</template> | ||
</UCalendar> | ||
</template> |
11 changes: 11 additions & 0 deletions
11
docs/app/components/content/examples/calendar/CalendarMinMaxDatesExample.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
import { CalendarDate } from '@internationalized/date' | ||
const modelValue = shallowRef(new CalendarDate(2023, 9, 10)) | ||
const minDate = new CalendarDate(2023, 9, 1) | ||
const maxDate = new CalendarDate(2023, 9, 30) | ||
</script> | ||
|
||
<template> | ||
<UCalendar v-model="modelValue" :min-value="minDate" :max-value="maxDate" /> | ||
</template> |
17 changes: 17 additions & 0 deletions
17
docs/app/components/content/examples/calendar/CalendarUnavailableDatesExample.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script setup lang="ts"> | ||
import { CalendarDate } from '@internationalized/date' | ||
import type { Matcher } from 'radix-vue/date' | ||
const modelValue = shallowRef({ | ||
start: new CalendarDate(2022, 1, 1), | ||
end: new CalendarDate(2022, 1, 9) | ||
}) | ||
const isDateUnavailable: Matcher = (date) => { | ||
return date.day >= 10 && date.day <= 16 | ||
} | ||
</script> | ||
|
||
<template> | ||
<UCalendar v-model="modelValue" :is-date-unavailable="isDateUnavailable" range /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
--- | ||
title: Calendar | ||
description: A calendar component for selecting single dates, multiple dates or date ranges. | ||
links: | ||
- label: Calendar | ||
icon: i-custom-radix-vue | ||
to: https://www.radix-vue.com/components/calendar.html | ||
- label: GitHub | ||
icon: i-simple-icons-github | ||
to: https://github.com/nuxt/ui/tree/v3/src/runtime/components/Calendar.vue | ||
navigation.badge: New | ||
--- | ||
|
||
::note | ||
This component relies on the [@internationalized/date](https://react-spectrum.adobe.com/internationalized/date/index.html) package which provides objects and functions for representing and manipulating dates and times in a locale-aware manner. | ||
:: | ||
|
||
## Usage | ||
|
||
Use the `v-model` directive to control the selected date. | ||
|
||
::component-code | ||
--- | ||
--- | ||
:: | ||
|
||
<!-- TODO: Add example with default value --> | ||
|
||
### Multiple | ||
|
||
Use the `multiple` prop to allow multiple selections. | ||
|
||
::component-code | ||
--- | ||
ignore: | ||
- multiple | ||
props: | ||
multiple: true | ||
--- | ||
:: | ||
|
||
### Range | ||
|
||
Use the `range` prop to select a range of dates. | ||
|
||
::component-code | ||
--- | ||
ignore: | ||
- range | ||
props: | ||
range: true | ||
--- | ||
:: | ||
|
||
### Color | ||
|
||
Use the `color` prop to change the color of the calendar. | ||
|
||
::component-code | ||
--- | ||
props: | ||
color: neutral | ||
--- | ||
:: | ||
|
||
### Size | ||
|
||
Use the `size` prop to change the size of the calendar. | ||
|
||
::component-code | ||
--- | ||
props: | ||
size: xl | ||
--- | ||
:: | ||
|
||
### Disabled | ||
|
||
Use the `disabled` prop to disable the calendar. | ||
|
||
::component-code | ||
--- | ||
props: | ||
disabled: true | ||
--- | ||
:: | ||
|
||
### Number Of Months | ||
|
||
Use the `numberOfMonths` prop to change the number of months in the calendar. | ||
|
||
::component-code | ||
--- | ||
props: | ||
numberOfMonths: 3 | ||
--- | ||
:: | ||
|
||
### Month Controls | ||
|
||
Use the `month-controls` prop to show the month controls. Defaults to `true`. | ||
|
||
::component-code | ||
--- | ||
props: | ||
monthControls: false | ||
--- | ||
:: | ||
|
||
### Year Controls | ||
|
||
Use the `year-controls` prop to show the year controls. Defaults to `true`. | ||
|
||
::component-code | ||
--- | ||
props: | ||
yearControls: false | ||
--- | ||
:: | ||
|
||
### Fixed Weeks | ||
|
||
Use the `fixed-weeks` prop to display the calendar with fixed weeks. | ||
|
||
::component-code | ||
--- | ||
props: | ||
fixedWeeks: false | ||
--- | ||
:: | ||
|
||
## Examples | ||
|
||
### With chip events | ||
|
||
Use the [Chip](/components/chip) component to add events to specific days. | ||
|
||
::component-example | ||
--- | ||
name: 'calendar-events-example' | ||
--- | ||
:: | ||
|
||
### With disabled dates | ||
|
||
Use the `is-date-disabled` prop with a function to mark specific dates as disabled. | ||
|
||
::component-example | ||
--- | ||
name: 'calendar-disabled-dates-example' | ||
--- | ||
:: | ||
|
||
### With unavailable dates | ||
|
||
Use the `is-date-unavailable` prop with a function to mark specific dates as unavailable. | ||
|
||
::component-example | ||
--- | ||
name: 'calendar-unavailable-dates-example' | ||
--- | ||
:: | ||
|
||
### With min/max dates | ||
|
||
Use the `min-value` and `max-value` props to limit the dates. | ||
|
||
::component-example | ||
--- | ||
name: 'calendar-min-max-dates-example' | ||
--- | ||
:: | ||
|
||
### As a DatePicker | ||
|
||
Use a [Button](/components/button) and a [Popover](/components/popover) component to create a date picker. | ||
|
||
::component-example | ||
--- | ||
name: 'calendar-date-picker-example' | ||
--- | ||
:: | ||
|
||
### As a DateRangePicker | ||
|
||
Use a [Button](/components/button) and a [Popover](/components/popover) component to create a date range picker. | ||
|
||
::component-example | ||
--- | ||
name: 'calendar-date-range-picker-example' | ||
--- | ||
:: | ||
|
||
## API | ||
|
||
### Props | ||
|
||
:component-props | ||
|
||
### Slots | ||
|
||
:component-slots | ||
|
||
### Emits | ||
|
||
:component-emits | ||
|
||
## Theme | ||
|
||
:component-theme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.