Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(date-picker): update calendar classNames in useDateRangePicker #3258

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-emus-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/date-picker": patch
---

Fix calendar props on date-range-picker
41 changes: 41 additions & 0 deletions apps/docs/content/components/date-range-picker/custom-styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const App = `import {DateRangePicker} from "@nextui-org/react";

export default function App() {
return (
<DateRangePicker
calendarProps={{
classNames: {
base: "bg-background",
headerWrapper: "pt-4 bg-background",
prevButton: "border-1 border-default-200 rounded-small",
nextButton: "border-1 border-default-200 rounded-small",
gridHeader: "bg-background shadow-none border-b-1 border-default-100",
cellButton: [
"data-[today=true]:bg-default-100 data-[selected=true]:bg-transparent rounded-small",
// start (pseudo)
"data-[range-start=true]:before:rounded-l-small",
"data-[selection-start=true]:before:rounded-l-small",
// end (pseudo)
"data-[range-end=true]:before:rounded-r-small",
"data-[selection-end=true]:before:rounded-r-small",
// start (selected)
"data-[selected=true]:data-[selection-start=true]:data-[range-selection=true]:rounded-small",
// end (selected)
"data-[selected=true]:data-[selection-end=true]:data-[range-selection=true]:rounded-small",
],
},
}}
className="max-w-xs"
label="Stay duration"
variant="bordered"
/>
);
}`;
wingkwong marked this conversation as resolved.
Show resolved Hide resolved

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

export default {
...react,
};
2 changes: 2 additions & 0 deletions apps/docs/content/components/date-range-picker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import visibleMonth from "./visible-month";
import pageBehavior from "./page-behavior";
import nonContigous from "./non-contiguous";
import presets from "./presets";
import customStyles from "./custom-styles";

export const dateRangePickerContent = {
usage,
Expand All @@ -42,4 +43,5 @@ export const dateRangePickerContent = {
pageBehavior,
nonContigous,
presets,
customStyles,
};
6 changes: 6 additions & 0 deletions apps/docs/content/docs/components/date-range-picker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ import {useLocale, useDateFormatter} from "@react-aria/i18n";
- **description**: The description of the date-input.
- **errorMessage**: The error message of the date-input.

### Custom Styles

You can customize the `DateRangePicker` component by passing custom Tailwind CSS classes to the component slots.

<CodeDemo title="Custom Styles" files={dateRangePickerContent.customStyles} />

<Spacer y={4} />

## Data Attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {useDateRangePickerState} from "@react-stately/datepicker";
import {useDateRangePicker as useAriaDateRangePicker} from "@react-aria/datepicker";
import {clsx, dataAttr, objectToDeps} from "@nextui-org/shared-utils";
import {mergeProps} from "@react-aria/utils";
import {dateRangePicker, dateInput} from "@nextui-org/theme";
import {dateRangePicker, dateInput, cn} from "@nextui-org/theme";
import {ariaShouldCloseOnInteractOutside} from "@nextui-org/aria-utils";

import {useDatePickerBase} from "./use-date-picker-base";
Expand Down Expand Up @@ -227,8 +227,11 @@ export function useDateRangePicker<T extends DateValue>({
...ariaCalendarProps,
...calendarProps,
classNames: {
base: slots.calendar({class: classNames?.calendar}),
content: slots.calendarContent({class: classNames?.calendarContent}),
...calendarProps.classNames,
base: slots.calendar({class: cn(calendarProps?.classNames?.base, classNames?.calendar)}),
content: slots.calendarContent({
class: cn(calendarProps?.classNames?.content, classNames?.calendarContent),
}),
},
} as RangeCalendarProps;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,38 @@ export const WithValidation = {
label: "Date Range (Year 2024 or later)",
},
};

export const CustomStyles = {
render: Template,

args: {
...defaultProps,
variant: "bordered",
className: "max-w-xs",
calendarProps: {
classNames: {
base: "bg-background",
headerWrapper: "pt-4 bg-background",
prevButton: "border-1 border-default-200 rounded-small",
nextButton: "border-1 border-default-200 rounded-small",
gridHeader: "bg-background shadow-none border-b-1 border-default-100",
cellButton: [
"data-[today=true]:bg-default-100 data-[selected=true]:bg-transparent rounded-small",
// start (pseudo)
"data-[range-start=true]:before:rounded-l-small",
"data-[selection-start=true]:before:rounded-l-small",

// end (pseudo)
"data-[range-end=true]:before:rounded-r-small",
"data-[selection-end=true]:before:rounded-r-small",

// start (selected)
"data-[selected=true]:data-[selection-start=true]:data-[range-selection=true]:rounded-small",

// end (selected)
"data-[selected=true]:data-[selection-end=true]:data-[range-selection=true]:rounded-small",
],
},
},
},
};
Loading