Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Jan 9, 2025
1 parent 6626330 commit 5c728a8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 69 deletions.
103 changes: 42 additions & 61 deletions docs/data/date-pickers/base-calendar/DayRangeCalendarDemo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import clsx from 'clsx';

import { Separator } from '@base-ui-components/react/separator';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
// eslint-disable-next-line no-restricted-imports
Expand All @@ -11,85 +10,67 @@ import {
} from '@mui/x-date-pickers-pro/internals/base/RangeCalendar';
import styles from './calendar.module.css';

function Header(props) {
const { offset } = props;
function Header() {
const { visibleDate } = useRangeCalendarContext();

const date = visibleDate.add(offset, 'month');

return (
<header className={styles.Header}>
<RangeCalendar.SetVisibleMonth
target="previous"
className={clsx(styles.SetVisibleMonth, offset === 1 && styles.Hidden)}
className={clsx(styles.SetVisibleMonth)}
>
</RangeCalendar.SetVisibleMonth>
<span>{date.format('MMMM YYYY')}</span>
<span>{visibleDate.format('MMMM YYYY')}</span>
<RangeCalendar.SetVisibleMonth
target="next"
className={clsx(styles.SetVisibleMonth, offset === 0 && styles.Hidden)}
className={clsx(styles.SetVisibleMonth)}
>
</RangeCalendar.SetVisibleMonth>
</header>
);
}

function DaysGrid(props) {
const { offset } = props;
return (
<div className={styles.Panel}>
<Header offset={offset} />
<RangeCalendar.DaysGrid className={styles.DaysGrid} offset={offset}>
<RangeCalendar.DaysGridHeader className={styles.DaysGridHeader}>
{({ days }) =>
days.map((day) => (
<RangeCalendar.DaysGridHeaderCell
value={day}
key={day.toString()}
className={styles.DaysGridHeaderCell}
/>
))
}
</RangeCalendar.DaysGridHeader>
<RangeCalendar.DaysGridBody className={styles.DaysGridBody}>
{({ weeks }) =>
weeks.map((week) => (
<RangeCalendar.DaysWeekRow
value={week}
key={week.toString()}
className={styles.DaysWeekRow}
>
{({ days }) =>
days.map((day) => (
<RangeCalendar.DaysCell
value={day}
key={day.toString()}
className={clsx(styles.DaysCell, styles.RangeDaysCell)}
/>
))
}
</RangeCalendar.DaysWeekRow>
))
}
</RangeCalendar.DaysGridBody>
</RangeCalendar.DaysGrid>
</div>
);
}

function DayCalendar(props) {
function DayRangeCalendar(props) {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<RangeCalendar.Root
{...props}
monthPageSize={2}
className={clsx(styles.Root, styles.RootWithTwoPanels)}
>
<DaysGrid offset={0} />
<Separator className={styles.DaysGridSeparator} />
<DaysGrid offset={1} />
<RangeCalendar.Root {...props} monthPageSize={2} className={clsx(styles.Root)}>
<Header />
<RangeCalendar.DaysGrid className={styles.DaysGrid}>
<RangeCalendar.DaysGridHeader className={styles.DaysGridHeader}>
{({ days }) =>
days.map((day) => (
<RangeCalendar.DaysGridHeaderCell
value={day}
key={day.toString()}
className={styles.DaysGridHeaderCell}
/>
))
}
</RangeCalendar.DaysGridHeader>
<RangeCalendar.DaysGridBody className={styles.DaysGridBody}>
{({ weeks }) =>
weeks.map((week) => (
<RangeCalendar.DaysWeekRow
value={week}
key={week.toString()}
className={styles.DaysWeekRow}
>
{({ days }) =>
days.map((day) => (
<RangeCalendar.DaysCell
value={day}
key={day.toString()}
className={clsx(styles.DaysCell, styles.RangeDaysCell)}
/>
))
}
</RangeCalendar.DaysWeekRow>
))
}
</RangeCalendar.DaysGridBody>
</RangeCalendar.DaysGrid>
</RangeCalendar.Root>
</LocalizationProvider>
);
Expand All @@ -104,7 +85,7 @@ export default function DayRangeCalendarDemo() {

return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DayCalendar value={value} onValueChange={handleValueChange} />
<DayRangeCalendar value={value} onValueChange={handleValueChange} />
</LocalizationProvider>
);
}
4 changes: 2 additions & 2 deletions docs/data/date-pickers/base-calendar/DayRangeCalendarDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Header() {
);
}

function DayCalendar(props: Omit<RangeCalendar.Root.Props, 'children'>) {
function DayRangeCalendar(props: Omit<RangeCalendar.Root.Props, 'children'>) {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<RangeCalendar.Root {...props} monthPageSize={2} className={clsx(styles.Root)}>
Expand Down Expand Up @@ -91,7 +91,7 @@ export default function DayRangeCalendarDemo() {

return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DayCalendar value={value} onValueChange={handleValueChange} />
<DayRangeCalendar value={value} onValueChange={handleValueChange} />
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<DayCalendar value={value} onValueChange={handleValueChange} />
<DayRangeCalendar value={value} onValueChange={handleValueChange} />
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function DaysGrid(props) {
);
}

function DayCalendar(props) {
function DayRangeCalendar(props) {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<RangeCalendar.Root
Expand All @@ -104,7 +104,7 @@ export default function DayRangeCalendarWithTwoMonthsDemo() {

return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DayCalendar value={value} onValueChange={handleValueChange} />
<DayRangeCalendar value={value} onValueChange={handleValueChange} />
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function DaysGrid(props: { offset: 0 | 1 }) {
);
}

function DayCalendar(props: Omit<RangeCalendar.Root.Props, 'children'>) {
function DayRangeCalendar(props: Omit<RangeCalendar.Root.Props, 'children'>) {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<RangeCalendar.Root
Expand Down Expand Up @@ -110,7 +110,7 @@ export default function DayRangeCalendarWithTwoMonthsDemo() {

return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DayCalendar value={value} onValueChange={handleValueChange} />
<DayRangeCalendar value={value} onValueChange={handleValueChange} />
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<DayCalendar value={value} onValueChange={handleValueChange} />
<DayRangeCalendar value={value} onValueChange={handleValueChange} />

0 comments on commit 5c728a8

Please sign in to comment.