Skip to content

Commit

Permalink
feat: add renderDayProps
Browse files Browse the repository at this point in the history
  • Loading branch information
MikitaLisavets committed Dec 30, 2020
1 parent 3cd4dfc commit 773218e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/calendar/src/Month.tsx
Expand Up @@ -18,13 +18,15 @@ type Props = {
locale?: Locale;
};
cursorDate: Date;
renderDayProps?: (date: Date) => object;
renderDayContent?: (date: Date) => React.ReactNode;
renderNearDayNumber?: (date: Date) => React.ReactNode;
};

const Month: React.FC<Props> = ({
config = {},
cursorDate,
renderDayProps = () => {},
renderDayContent = () => null,
renderNearDayNumber = () => null,
}) => {
Expand All @@ -38,7 +40,7 @@ const Month: React.FC<Props> = ({
<WeekDayLabels config={conf} />
{getMonthDays({ date: cursorDate, weekStartsOn: conf.weekStartsOn }).map(
date => (
<Day key={date.toString()}>
<Day key={date.toString()} {...renderDayProps(date)}>
<DayInner>
<DayNumber>
<Text size={20} color={getDayNumberColor(cursorDate, date)}>
Expand Down
3 changes: 2 additions & 1 deletion packages/calendar/src/README.mdx
@@ -1,6 +1,6 @@
---
name: Calendar
menu: Components
menu: Calendar
route: /Calendar/calendar
---

Expand All @@ -12,6 +12,7 @@ Week and Month calendar components have the same api
| :------------------ | :------------------------------------: | :-------------------------------------------------------------------------------- |
| cursorDate | Date | **Required**. Will display month of cursorDate |
| config | {weekStartsOn: number, locale: Locale} | **weekStartsOn** - first day of week(sunday=0), **locale** - Locale from date fns |
| renderDayProps | (date:Date) => object | you can provide custom props to each day |
| renderDayContent | (date:Date) => JSX.Element | you can render something on the left to the day number |
| renderNearDayNumber | (date:Date) => JSX.Element | you can render something under day number |

Expand Down
4 changes: 3 additions & 1 deletion packages/calendar/src/Week.tsx
Expand Up @@ -17,13 +17,15 @@ type Props = {
locale?: Locale;
};
cursorDate: Date;
renderDayProps?: (date: Date) => object;
renderDayContent?: (date: Date) => React.ReactNode;
renderNearDayNumber?: (date: Date) => React.ReactNode;
};

const Week: React.FC<Props> = ({
config = {},
cursorDate,
renderDayProps = () => {},
renderDayContent = () => null,
renderNearDayNumber = () => null,
}) => {
Expand All @@ -37,7 +39,7 @@ const Week: React.FC<Props> = ({
<WeekDayLabels config={conf} />
{getWeekDays({ cursorDate, weekStartsOn: conf.weekStartsOn }).map(
date => (
<WeekDay key={date.toString()}>
<WeekDay key={date.toString()} {...renderDayProps(date)}>
<DayNumber>
<Text size={20} color={getDayNumberColor(cursorDate, date)}>
{getDayNumberLabel(cursorDate, date)}
Expand Down

0 comments on commit 773218e

Please sign in to comment.