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

feat(date-picker): add support for DatePicker to apply styles to DateInput #3146

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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/cool-dolls-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/date-picker": patch
---

Add support for apply styles to DateInput (#2770, #2895, #2998)
20 changes: 20 additions & 0 deletions packages/components/date-picker/__tests__/date-picker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ describe("DatePicker", () => {

expect(getByTestId("foo")).toHaveAttribute("role", "group");
});

it("should apply custom dateInput classNames", function () {
const {getByRole, getByText} = render(
<DatePicker
dateInputClassNames={{
inputWrapper: "border-green-500",
label: "text-green-500",
}}
label="Date"
/>,
);

const label = getByText("Date");

expect(label).toHaveClass("text-green-500");

const inputWrapper = getByRole("group");

expect(inputWrapper).toHaveClass("border-green-500");
});
});

describe("Events", () => {
Expand Down
9 changes: 8 additions & 1 deletion packages/components/date-picker/src/use-date-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ interface Props<T extends DateValue>
classNames?: SlotsToClasses<DatePickerSlots> & DateInputProps<T>["classNames"];
}

export type UseDatePickerProps<T extends DateValue> = Props<T> & AriaDatePickerProps<T>;
export type UseDatePickerProps<T extends DateValue> = Props<T> &
AriaDatePickerProps<T> & {
/**
* Classname or List of classes to change the classNames of the date input element.
*/
dateInputClassNames?: DateInputProps<T>["classNames"];
jrgarciadev marked this conversation as resolved.
Show resolved Hide resolved
};

export function useDatePicker<T extends DateValue>({
className,
Expand Down Expand Up @@ -129,6 +135,7 @@ export function useDatePicker<T extends DateValue>({
const getDateInputProps = () => {
return {
...dateInputProps,
classNames: {...originalProps?.dateInputClassNames},
groupProps,
labelProps,
createCalendar,
Expand Down
15 changes: 15 additions & 0 deletions packages/components/date-picker/stories/date-picker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,18 @@ export const WithValidation = {
label: "Date (Year 2024 or later)",
},
};

export const WithDateInputClassNames = {
render: Template,
args: {
...defaultProps,
dateInputClassNames: {
base: "bg-gray-200 p-2 rounded-md",
label: "text-blue-400 font-semibold",
inputWrapper: "border-3 border-solid border-blue-400 p-2 rounded-md",
description: "text-black",
},
isRequired: true,
description: "Please enter your birth date",
},
};
Loading