Skip to content

Commit f58c597

Browse files
authored
Merge pull request #79 from JefteCaro/master
[Fix] className overrides accept functions
2 parents dcd09bf + 751e29f commit f58c597

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

pages/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useState } from "react";
33
import { COLORS } from "../src/constants";
44
import dayjs from "dayjs";
55
import Head from "next/head";
6+
import { twMerge } from "tailwind-merge";
67

78
export default function Playground() {
89
const [value, setValue] = useState({
@@ -62,7 +63,7 @@ export default function Playground() {
6263
yesterday: "YText",
6364
past: period => `P-${period} Text`,
6465
currentMonth: "CMText",
65-
pastMonth: "PMText",
66+
pastMonth: "PMText"
6667
},
6768
footer: {
6869
cancel: "CText",
@@ -78,6 +79,10 @@ export default function Playground() {
7879
i18n={i18n}
7980
disabled={disabled}
8081
inputClassName={inputClassName}
82+
/**
83+
* `twMerge` Test
84+
*/
85+
// inputClassName={twMerge(inputClassName, 'dark:bg-white')}
8186
containerClassName={containerClassName}
8287
toggleClassName={toggleClassName}
8388
displayFormat={displayFormat}

src/components/Datepicker.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ import { COLORS, DATE_FORMAT, DEFAULT_COLOR, LANGUAGE } from "../constants";
99
import DatepickerContext from "../contexts/DatepickerContext";
1010
import { formatDate, nextMonth, previousMonth } from "../helpers";
1111
import useOnClickOutside from "../hooks";
12-
import { Period, DateValueType, DateType, DateRangeType, ClassNamesTypeProp } from "../types";
12+
import {
13+
Period,
14+
DateValueType,
15+
DateType,
16+
DateRangeType,
17+
ClassNamesTypeProp,
18+
ClassNameParam
19+
} from "../types";
1320

1421
import { Arrow, VerticalDash } from "./utils";
1522

@@ -40,12 +47,12 @@ interface Props {
4047
i18n?: string;
4148
disabled?: boolean;
4249
classNames?: ClassNamesTypeProp | undefined;
43-
inputClassName?: string | null;
50+
inputClassName?: ((args?: ClassNameParam) => string) | string | null;
4451
toggleClassName?: string | null;
45-
toggleIcon?: ((open: boolean) => React.ReactNode) | undefined;
52+
toggleIcon?: ((open: ClassNameParam) => React.ReactNode) | undefined;
4653
inputId?: string;
4754
inputName?: string;
48-
containerClassName?: string | null;
55+
containerClassName?: ((args?: ClassNameParam) => string) | string | null;
4956
displayFormat?: string;
5057
readOnly?: boolean;
5158
minDate?: DateType | null;

src/components/Input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dayjs from "dayjs";
22
import React, { useCallback, useContext, useEffect, useRef } from "react";
33

4-
import {BORDER_COLOR, DATE_FORMAT, RING_COLOR} from "../constants";
4+
import { BORDER_COLOR, DATE_FORMAT, RING_COLOR } from "../constants";
55
import DatepickerContext from "../contexts/DatepickerContext";
66
import { dateIsValid } from "../helpers";
77

src/contexts/DatepickerContext.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
DateValueType,
99
DateType,
1010
DateRangeType,
11-
ClassNamesTypeProp
11+
ClassNamesTypeProp,
12+
ClassNameParam
1213
} from "../types";
1314

1415
interface DatepickerStore {
@@ -33,9 +34,9 @@ interface DatepickerStore {
3334
i18n: string;
3435
value: DateValueType;
3536
disabled?: boolean;
36-
inputClassName?: string | null;
37-
containerClassName?: string | null;
38-
toggleClassName?: string | null;
37+
inputClassName?: ((args?: ClassNameParam) => string) | string | null;
38+
containerClassName?: ((args?: ClassNameParam) => string) | string | null;
39+
toggleClassName?: ((args?: ClassNameParam) => string) | string | null;
3940
toggleIcon?: (open: boolean) => React.ReactNode;
4041
readOnly?: boolean;
4142
startWeekOn?: string | null;

src/types/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ export type DateRangeType = {
3636
export type DateValueType = DateRangeType | null;
3737

3838
export type ClassNamesTypeProp = {
39-
container: (p?: object | null | undefined) => string | undefined;
40-
input: (p?: object | null | undefined) => string | undefined;
41-
toggleButton: (p?: object | null | undefined) => string | undefined;
42-
footer: (p?: object | null | undefined) => string | undefined;
39+
container?: (p?: object | null | undefined) => string | undefined;
40+
input?: (p?: object | null | undefined) => string | undefined;
41+
toggleButton?: (p?: object | null | undefined) => string | undefined;
42+
footer?: (p?: object | null | undefined) => string | undefined;
4343
};
44+
45+
export type ClassNameParam = ClassNameParam[] | string | number | boolean | undefined;

0 commit comments

Comments
 (0)