Skip to content

Commit

Permalink
refactor(calendar): use React components for calendar cell content
Browse files Browse the repository at this point in the history
  • Loading branch information
1amageek committed Jan 2, 2025
2 parents 84a85d7 + d92468a commit de1e4fa
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 154 deletions.
50 changes: 50 additions & 0 deletions apps/docs/content/components/calendar/custom-cell-content.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";
import {
Calendar,
CalendarCellContent,
CalendarCellHeader,
CalendarCellBody,
} from "@nextui-org/react";

export default function App() {
return (
<Calendar calendarWidth={400}>
{(date) => (
<CalendarCellContent>
<CalendarCellHeader />
<CalendarCellBody>
<div className="flex flex-col w-full text-tiny gap-0.5 px-0.5">
{date.day % 7 === 0 && (
<span
aria-label="Calendar event"
className="bg-red-500/20 w-full rounded-md px-1 text-red-400 line-clamp-1"
role="status"
>
MTG
</span>
)}
{date.day % 5 === 0 && (
<span
aria-label="calendar event"
className="bg-green-500/20 w-full rounded-md px-1 text-green-400 line-clamp-1"
role="status"
>
MTG
</span>
)}
{date.day % 3 === 0 && (
<span
aria-label="calendar event"
className="bg-yellow-500/20 w-full rounded-md px-1 text-yellow-400 line-clamp-1"
role="status"
>
MTG
</span>
)}
</div>
</CalendarCellBody>
</CalendarCellContent>
)}
</Calendar>
);
}
72 changes: 0 additions & 72 deletions apps/docs/content/components/calendar/custom-cell-content.ts

This file was deleted.

9 changes: 9 additions & 0 deletions apps/docs/content/components/calendar/custom-cell-content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import App from "./custom-cell-content.raw.jsx?raw";

const react = {
"/App.jsx": App,
};

export default {
...react,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
RangeCalendar,
CalendarCellContent,
CalendarCellHeader,
CalendarCellBody,
} from "@nextui-org/react";

export default function App() {
return (
<RangeCalendar calendarWidth={400}>
{(date) => (
<CalendarCellContent>
<CalendarCellHeader />
<CalendarCellBody>
<div className="flex flex-col w-full text-tiny gap-0.5 px-0.5">
{date.day % 7 === 0 && (
<span
aria-label="calendar event"
className="bg-red-500/20 w-full rounded-md px-1 text-red-400 line-clamp-1"
role="status"
>
MTG
</span>
)}
{date.day % 5 === 0 && (
<span
aria-label="calendar event"
className="bg-green-500/20 w-full rounded-md px-1 text-green-400 line-clamp-1"
role="status"
>
MTG
</span>
)}
{date.day % 3 === 0 && (
<span
aria-label="calendar event"
className="bg-yellow-500/20 w-full rounded-md px-1 text-yellow-400 line-clamp-1"
role="status"
>
MTG
</span>
)}
</div>
</CalendarCellBody>
</CalendarCellContent>
)}
</RangeCalendar>
);
}
72 changes: 0 additions & 72 deletions apps/docs/content/components/range-calendar/custom-cell-content.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import App from "./custom-cell-content.raw.jsx?raw";

const react = {
"/App.jsx": App,
};

export default {
...react,
};
4 changes: 2 additions & 2 deletions packages/components/calendar/src/calendar-cell-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const CalendarCellHeader = ({children}: CalendarCellHeaderProps) => {
data-selection-start={dataAttr(isSelectionStart)}
>
<span
className={slots?.cellHeader({class: classNames?.cellButton})}
className={slots?.cellHeader({class: classNames?.cellHeader})}
data-disabled={dataAttr(isDisabled && !isInvalid)}
data-focus-visible={dataAttr(isFocused && isFocusVisible)}
data-hover={dataAttr(isHovered)}
Expand All @@ -61,7 +61,7 @@ export const CalendarCellHeader = ({children}: CalendarCellHeaderProps) => {
data-today={dataAttr(isToday)}
data-unavailable={dataAttr(isUnavailable)}
>
{children ? children : date.day}
{children || date.day}
</span>
</div>
);
Expand Down
8 changes: 4 additions & 4 deletions packages/components/calendar/stories/calendar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,16 @@ const CustomCellTemplate = (args: CalendarProps) => {
<div className="flex flex-col w-full text-tiny gap-0.5 px-0.5">
{date.day % 7 === 0 && (
<span
aria-label="Birthday event"
aria-label="calendar event"
className="bg-red-500/20 w-full rounded-md px-1 text-red-400 line-clamp-1"
role="status"
>
Birth day
MTG
</span>
)}
{date.day % 5 === 0 && (
<span
aria-label="Birthday event"
aria-label="calendar event"
className="bg-green-500/20 w-full rounded-md px-1 text-green-400 line-clamp-1"
role="status"
>
Expand All @@ -302,7 +302,7 @@ const CustomCellTemplate = (args: CalendarProps) => {
)}
{date.day % 3 === 0 && (
<span
aria-label="Birthday event"
aria-label="calendar event"
className="bg-yellow-500/20 w-full rounded-md px-1 text-yellow-400 line-clamp-1"
role="status"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,16 @@ const CustomCellTemplate = (args: RangeCalendarProps) => {
<div className="flex flex-col w-full text-tiny gap-0.5 px-0.5">
{date.day % 7 === 0 && (
<span
aria-label="Birthday event"
aria-label="calendar event"
className="bg-red-500/20 w-full rounded-md px-1 text-red-400 line-clamp-1"
role="status"
>
Birth day
MTG
</span>
)}
{date.day % 5 === 0 && (
<span
aria-label="Birthday event"
aria-label="calendar event"
className="bg-green-500/20 w-full rounded-md px-1 text-green-400 line-clamp-1"
role="status"
>
Expand All @@ -337,7 +337,7 @@ const CustomCellTemplate = (args: RangeCalendarProps) => {
)}
{date.day % 3 === 0 && (
<span
aria-label="Birthday event"
aria-label="calendar event"
className="bg-yellow-500/20 w-full rounded-md px-1 text-yellow-400 line-clamp-1"
role="status"
>
Expand Down
1 change: 1 addition & 0 deletions packages/core/theme/src/components/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const calendar = tv({
"data-[unavailable=true]:text-default-300",
"data-[unavailable=true]:cursor-default",
"data-[unavailable=true]:line-through",
...dataFocusVisibleClasses,
],
cellBody: "w-full h-full",
pickerWrapper:
Expand Down

0 comments on commit de1e4fa

Please sign in to comment.