Skip to content

Commit 4a2b77d

Browse files
authoredMar 24, 2025··
feat(Calendar): allow year and month buttons styling (#3672)
1 parent ade16b7 commit 4a2b77d

File tree

4 files changed

+1561
-112
lines changed

4 files changed

+1561
-112
lines changed
 

‎src/runtime/components/Calendar.vue

+25-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { VariantProps } from 'tailwind-variants'
33
import type { CalendarRootProps, CalendarRootEmits, RangeCalendarRootEmits, DateRange, CalendarCellTriggerProps } from 'reka-ui'
44
import type { DateValue } from '@internationalized/date'
55
import type { AppConfig } from '@nuxt/schema'
6+
import type { ButtonProps } from '../types'
67
import _appConfig from '#build/app.config'
78
import theme from '#build/ui/calendar'
89
import { tv } from '../utils/tv'
@@ -32,24 +33,44 @@ export interface CalendarProps<R extends boolean, M extends boolean> extends Omi
3233
* @IconifyIcon
3334
*/
3435
nextYearIcon?: string
36+
/**
37+
* Configure the next year button.
38+
* `{ color: 'neutral', variant: 'ghost' }`{lang="ts-type"}
39+
*/
40+
nextYear?: ButtonProps
3541
/**
3642
* The icon to use for the next month control.
3743
* @defaultValue appConfig.ui.icons.chevronRight
3844
* @IconifyIcon
3945
*/
4046
nextMonthIcon?: string
47+
/**
48+
* Configure the next month button.
49+
* `{ color: 'neutral', variant: 'ghost' }`{lang="ts-type"}
50+
*/
51+
nextMonth?: ButtonProps
4152
/**
4253
* The icon to use for the previous year control.
4354
* @defaultValue appConfig.ui.icons.chevronDoubleLeft
4455
* @IconifyIcon
4556
*/
4657
prevYearIcon?: string
58+
/**
59+
* Configure the prev year button.
60+
* `{ color: 'neutral', variant: 'ghost' }`{lang="ts-type"}
61+
*/
62+
prevYear?: ButtonProps
4763
/**
4864
* The icon to use for the previous month control.
4965
* @defaultValue appConfig.ui.icons.chevronLeft
5066
* @IconifyIcon
5167
*/
5268
prevMonthIcon?: string
69+
/**
70+
* Configure the prev month button.
71+
* `{ color: 'neutral', variant: 'ghost' }`{lang="ts-type"}
72+
*/
73+
prevMonth?: ButtonProps
5374
/**
5475
* @defaultValue 'primary'
5576
*/
@@ -138,21 +159,21 @@ const Calendar = computed(() => props.range ? RangeCalendar : SingleCalendar)
138159
>
139160
<Calendar.Header :class="ui.header({ class: props.ui?.header })">
140161
<Calendar.Prev v-if="props.yearControls" :prev-page="(date: DateValue) => paginateYear(date, -1)" :aria-label="t('calendar.prevYear')" as-child>
141-
<UButton :icon="prevYearIcon" :size="props.size" color="neutral" variant="ghost" />
162+
<UButton :icon="prevYearIcon" :size="props.size" color="neutral" variant="ghost" v-bind="props.prevYear" />
142163
</Calendar.Prev>
143164
<Calendar.Prev v-if="props.monthControls" :aria-label="t('calendar.prevMonth')" as-child>
144-
<UButton :icon="prevMonthIcon" :size="props.size" color="neutral" variant="ghost" />
165+
<UButton :icon="prevMonthIcon" :size="props.size" color="neutral" variant="ghost" v-bind="props.prevMonth" />
145166
</Calendar.Prev>
146167
<Calendar.Heading v-slot="{ headingValue }" :class="ui.heading({ class: props.ui?.heading })">
147168
<slot name="heading" :value="headingValue">
148169
{{ headingValue }}
149170
</slot>
150171
</Calendar.Heading>
151172
<Calendar.Next v-if="props.monthControls" :aria-label="t('calendar.nextMonth')" as-child>
152-
<UButton :icon="nextMonthIcon" :size="props.size" color="neutral" variant="ghost" />
173+
<UButton :icon="nextMonthIcon" :size="props.size" color="neutral" variant="ghost" v-bind="props.nextMonth" />
153174
</Calendar.Next>
154175
<Calendar.Next v-if="props.yearControls" :next-page="(date: DateValue) => paginateYear(date, 1)" :aria-label="t('calendar.nextYear')" as-child>
155-
<UButton :icon="nextYearIcon" :size="props.size" color="neutral" variant="ghost" />
176+
<UButton :icon="nextYearIcon" :size="props.size" color="neutral" variant="ghost" v-bind="props.nextYear" />
156177
</Calendar.Next>
157178
</Calendar.Header>
158179
<div :class="ui.body({ class: props.ui?.body })">

‎test/components/Calendar.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ describe('Calendar', () => {
2828
['with weekStartsOn', { props: { weekStartsOn: 1 } }],
2929
['with weekdayFormat', { props: { weekdayFormat: 'short' } }],
3030
['with numberOfMonths', { props: { numberOfMonths: 2 } }],
31+
['with nextYear', { props: { nextYear: { size: 'lg', color: 'primary' } } }],
32+
['with nextMonth', { props: { nextMonth: { size: 'lg', color: 'primary' } } }],
33+
['with prevYear', { props: { prevYear: { size: 'lg', color: 'primary' } } }],
34+
['with prevMonth', { props: { prevMonth: { size: 'lg', color: 'primary' } } }],
3135
['without fixedWeeks', { props: { fixedWeeks: false } }],
3236
['without monthControls', { props: { monthControls: false } }],
3337
['without yearControls', { props: { yearControls: false } }],

‎test/components/__snapshots__/Calendar-vue.spec.ts.snap

+766-54
Large diffs are not rendered by default.

‎test/components/__snapshots__/Calendar.spec.ts.snap

+766-54
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.