feat(CalendarWidget): add custom DateCell prop
This commit is contained in:
parent
e427da99e3
commit
38457fbcff
@ -6,6 +6,7 @@ import { DateWrapper } from './components/DateWrapper';
|
|||||||
import { DayOfWeekRow } from './components/DayOfWeekRow';
|
import { DayOfWeekRow } from './components/DayOfWeekRow';
|
||||||
import { HeaderRow } from './components/HeaderRow';
|
import { HeaderRow } from './components/HeaderRow';
|
||||||
|
|
||||||
|
import type { DateCellProps } from './components/DateCell';
|
||||||
import type { FC, HTMLAttributes } from 'react';
|
import type { FC, HTMLAttributes } from 'react';
|
||||||
|
|
||||||
type DateCellPropsType = HTMLAttributes<HTMLDivElement>;
|
type DateCellPropsType = HTMLAttributes<HTMLDivElement>;
|
||||||
@ -20,6 +21,7 @@ export type CalendarWidgetProps = {
|
|||||||
highlightValue?: boolean;
|
highlightValue?: boolean;
|
||||||
|
|
||||||
DateCellProps?: DateCellPropsFuncType | DateCellPropsType;
|
DateCellProps?: DateCellPropsFuncType | DateCellPropsType;
|
||||||
|
DateCellComponent?: FC<DateCellProps>;
|
||||||
};
|
};
|
||||||
const CalendarWidget: FC<CalendarWidgetProps> = (props) => (
|
const CalendarWidget: FC<CalendarWidgetProps> = (props) => (
|
||||||
<CalendarWidgetProvider {...props}>
|
<CalendarWidgetProvider {...props}>
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
export { default as DateCell } from './ui/DateCell.ui';
|
export { default as DateCell } from './ui/DateCell.ui';
|
||||||
|
export type { DateCellProps } from './ui/DateCell.ui';
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import classes from './DateCell.style.module.css';
|
|||||||
|
|
||||||
import type { FC, MouseEventHandler, KeyboardEventHandler } from 'react';
|
import type { FC, MouseEventHandler, KeyboardEventHandler } from 'react';
|
||||||
|
|
||||||
type DateCellProps = React.HTMLAttributes<HTMLDivElement> & {
|
export type DateCellProps = React.HTMLAttributes<HTMLDivElement> & {
|
||||||
date: Date;
|
date: Date;
|
||||||
};
|
};
|
||||||
const DateCell: FC<DateCellProps> = (props) => {
|
const DateCell: FC<DateCellProps> = (props) => {
|
||||||
@ -23,6 +23,7 @@ const DateCell: FC<DateCellProps> = (props) => {
|
|||||||
highlightToday,
|
highlightToday,
|
||||||
highlightValue,
|
highlightValue,
|
||||||
DateCellProps = {},
|
DateCellProps = {},
|
||||||
|
DateCellComponent,
|
||||||
} = useContext(CalendarWidgetContext);
|
} = useContext(CalendarWidgetContext);
|
||||||
|
|
||||||
const todayDate = new Date();
|
const todayDate = new Date();
|
||||||
@ -53,6 +54,18 @@ const DateCell: FC<DateCellProps> = (props) => {
|
|||||||
onKeyPress?.(event);
|
onKeyPress?.(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (DateCellComponent) {
|
||||||
|
return (
|
||||||
|
<DateCellComponent
|
||||||
|
{...props}
|
||||||
|
className={className}
|
||||||
|
onClick={onClick}
|
||||||
|
onKeyPress={onKeyPress}
|
||||||
|
{...restProps}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={dataDate}
|
key={dataDate}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user