feat: add highlight props

This commit is contained in:
Sergey Krylov 2024-04-25 06:18:36 +03:00
parent 8c5e4a08bf
commit 46e1cd5d4a
4 changed files with 16 additions and 10 deletions

View File

@ -9,12 +9,7 @@ const CalendarPage = () => (
</h1> </h1>
<div className={classes.calendarWrapper}> <div className={classes.calendarWrapper}>
<CalendarWidget <CalendarWidget />
locale="en"
maxDate={new Date(2027, 2, 15)}
minDate={new Date(1996, 9, 15)}
value={new Date(2023, 9, 15)}
/>
</div> </div>
</div> </div>
); );

View File

@ -11,6 +11,8 @@ export type CalendarWidgetProps = {
minDate?: Date; minDate?: Date;
value?: Date; value?: Date;
locale?: 'en' | 'ru'; locale?: 'en' | 'ru';
highlightToday?: boolean;
highlightValue?: boolean;
}; };
const CalendarWidget: FC<CalendarWidgetProps> = (props) => ( const CalendarWidget: FC<CalendarWidgetProps> = (props) => (
<CalendarWidgetProvider {...props}> <CalendarWidgetProvider {...props}>

View File

@ -21,6 +21,8 @@ export const CalendarWidgetProvider: FC<CalendarWidgetProviderProps> = (props) =
minDate = new Date(1990, 0, 1), minDate = new Date(1990, 0, 1),
locale = 'ru', locale = 'ru',
value = new Date(), value = new Date(),
highlightToday = false,
highlightValue = false,
...restProps ...restProps
} = props; } = props;
@ -35,8 +37,10 @@ export const CalendarWidgetProvider: FC<CalendarWidgetProviderProps> = (props) =
maxDate, maxDate,
locale, locale,
value, value,
highlightToday,
highlightValue,
...restProps, ...restProps,
}), [maxDate, minDate, targetDate, locale, restProps, value]); }), [highlightValue, targetDate, minDate, maxDate, locale, value, highlightToday, restProps]);
return ( return (
<CalendarWidgetContext.Provider value={contextValue}> <CalendarWidgetContext.Provider value={contextValue}>

View File

@ -16,7 +16,12 @@ const DateCell: FC<DateCellProps> = (props) => {
} = props; } = props;
const format = 'en-En'; const format = 'en-En';
const { targetMonthIndex, value } = useContext(CalendarWidgetContext); const {
targetMonthIndex,
value,
highlightToday,
highlightValue,
} = useContext(CalendarWidgetContext);
const todayDate = new Date(); const todayDate = new Date();
const dataDate = new Intl.DateTimeFormat(format).format(date); const dataDate = new Intl.DateTimeFormat(format).format(date);
@ -34,9 +39,9 @@ const DateCell: FC<DateCellProps> = (props) => {
<span <span
className={classnames( className={classnames(
{ {
[classes.today as string]: dataDate === dataToday, [classes.today as string]: highlightToday && dataDate === dataToday,
[classes.outMothRange as string]: isOutMonthRange, [classes.outMothRange as string]: isOutMonthRange,
[classes.valueDate as string]: dataDate === dataValue, [classes.valueDate as string]: highlightValue && dataDate === dataValue,
}, },
)} )}
> >