diff --git a/packages/react-calendar/src/Calendar.tsx b/packages/react-calendar/src/Calendar.tsx index eec48ddf..971936dd 100644 --- a/packages/react-calendar/src/Calendar.tsx +++ b/packages/react-calendar/src/Calendar.tsx @@ -20,7 +20,7 @@ import { isView, rangeOf, } from './shared/propTypes.js'; -import { between } from './shared/utils.js'; +import { between, mergeTileClassNames, type TileClassNames } from './shared/utils.js'; import type { Action, @@ -60,6 +60,15 @@ defaultMinDate.setFullYear(1, 0, 1); defaultMinDate.setHours(0, 0, 0, 0); const defaultMaxDate = new Date(8.64e15); +type CenturyClassNames = React.ComponentProps['classNames']; +type DecadeClassNames = React.ComponentProps['classNames']; +type MonthClassNames = React.ComponentProps['classNames']; +type YearClassNames = React.ComponentProps['classNames']; +type NavigationClassNames = React.ComponentProps['classNames']; + +const localSlotNames = ['base', 'selectRange', 'doubleView', 'viewContainer'] as const; +type LocalSlotName = (typeof localSlotNames)[number]; + export type CalendarProps = { /** * The beginning of a period that shall be displayed. If you wish to use react-calendar in an uncontrolled way, use `defaultActiveStartDate` instead. @@ -87,6 +96,22 @@ export type CalendarProps = { * @example ['class1', 'class2 class3'] */ className?: ClassName; + /** + * Class names that will be added to appropriate slots. + * + * @example {} + */ + classNames?: Partial< + Record & { + decade: DecadeClassNames; + century: CenturyClassNames; + month: MonthClassNames; + year: YearClassNames; + navigation: NavigationClassNames; + tileGroup: ClassName; + tile: TileClassNames; + } + >; /** * The beginning of a period that shall be displayed by default. If you wish to use react-calendar in a controlled way, use `activeStartDate` instead. * @@ -614,6 +639,7 @@ const Calendar = forwardRef(function Calendar(props: CalendarProps, ref) { allowPartialRange, calendarType, className, + classNames = {}, defaultActiveStartDate, defaultValue, defaultView, @@ -1042,6 +1068,10 @@ const Calendar = forwardRef(function Calendar(props: CalendarProps, ref) { ); @@ -1051,13 +1081,25 @@ const Calendar = forwardRef(function Calendar(props: CalendarProps, ref) { ); } case 'year': { return ( - + ); } case 'month': { @@ -1077,6 +1119,10 @@ const Calendar = forwardRef(function Calendar(props: CalendarProps, ref) { } showNeighboringMonth={showNeighboringMonth} showWeekNumbers={showWeekNumbers} + classNames={{ + ...classNames.month, + tile: mergeTileClassNames(classNames.tile, classNames.month?.tile), + }} {...commonProps} /> ); @@ -1115,6 +1161,7 @@ const Calendar = forwardRef(function Calendar(props: CalendarProps, ref) { showDoubleView={showDoubleView} view={view} views={views} + classNames={classNames.navigation} /> ); } @@ -1124,16 +1171,16 @@ const Calendar = forwardRef(function Calendar(props: CalendarProps, ref) { return (
{renderNavigation()}
diff --git a/packages/react-calendar/src/Calendar/Navigation.tsx b/packages/react-calendar/src/Calendar/Navigation.tsx index 2d8a726b..f2d3dcf4 100644 --- a/packages/react-calendar/src/Calendar/Navigation.tsx +++ b/packages/react-calendar/src/Calendar/Navigation.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { getUserLocale } from 'get-user-locale'; +import clsx from 'clsx'; import { getCenturyLabel, @@ -18,11 +19,27 @@ import { formatYear as defaultFormatYear, } from '../shared/dateFormatter.js'; -import type { Action, NavigationLabelFunc, RangeType } from '../shared/types.js'; +import type { Action, ClassName, NavigationLabelFunc, RangeType } from '../shared/types.js'; const className = 'react-calendar__navigation'; +const slotNames = [ + 'base', + 'label', + 'divider', + 'labelText', + 'labelTextFrom', + 'labelTextTo', + 'arrow', + 'prev2Button', + 'prevButton', + 'nextButton', + 'next2Button', +] as const; +type SlotName = (typeof slotNames)[number]; + type NavigationProps = { + classNames?: Partial>; /** * The beginning of a period that shall be displayed. If you wish to use react-calendar in an uncontrolled way, use `defaultActiveStartDate` instead. * @@ -173,6 +190,7 @@ export default function Navigation({ showDoubleView, view, views, + classNames = {}, }: NavigationProps) { const drillUpAvailable = views.indexOf(view) > 0; const shouldShowPrevNext2Buttons = view !== 'century'; @@ -257,19 +275,33 @@ export default function Navigation({