Skip to content

Commit

Permalink
Merge pull request #251 from reaviz/feature/add-ralendar-range-header…
Browse files Browse the repository at this point in the history
…-date-format

added format of the date displayed in the calendar header
  • Loading branch information
amcdnl authored Jul 30, 2024
2 parents 4bc4297 + c4f9584 commit 59e787a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/form/Calendar/Calendar.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export const Multiview = () => {
value={range}
onChange={val => setRange(val as [Date, Date])}
showDayOfWeek
headerDateFormat="MMMM yyyy"
/>
<Divider />
<Stack justifyContent="center">
Expand Down
11 changes: 10 additions & 1 deletion src/form/Calendar/CalendarRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export interface CalendarRangeProps
*/
previousYearArrow?: React.ReactNode | string;

/**
* The format of the date displayed in the calendar header.
*/
headerDateFormat?: string;

/**
* Theme for the CalendarRange.
*/
Expand All @@ -67,6 +72,7 @@ export const CalendarRange: FC<CalendarRangeProps> = ({
onChange,
monthsToDisplay = 2,
direction = 'future',
headerDateFormat = 'MMMM',
theme: customTheme,
...rest
}) => {
Expand Down Expand Up @@ -164,7 +170,10 @@ export const CalendarRange: FC<CalendarRangeProps> = ({
<SmallHeading className={theme.title} disableMargins>
{displayMonths.map(i => (
<span key={addMonths(viewValue, showPast ? -i : i).toDateString()}>
{format(addMonths(viewValue, showPast ? -i : i), 'MMMM')}
{format(
addMonths(viewValue, showPast ? -i : i),
headerDateFormat
)}
</span>
))}
</SmallHeading>
Expand Down

0 comments on commit 59e787a

Please sign in to comment.