Skip to content

Commit 99ce644

Browse files
committed
Resolve conflicts.
2 parents 0a50124 + 9065b07 commit 99ce644

File tree

13 files changed

+135
-128
lines changed

13 files changed

+135
-128
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ yarn pret:fix
4040
**Using npm**
4141

4242
```sh
43-
npm pret:fix
43+
npm run pret:fix
4444
```
4545

4646
## Running playground
@@ -60,7 +60,7 @@ yarn dev
6060
**Using npm**
6161

6262
```sh
63-
npm dev
63+
npm run dev
6464
```
6565

6666
## Before you make a Pull Request

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ Go to [full documentation](https://react-tailwindcss-datepicker.vercel.app/)
5151
### Install via npm
5252

5353
```
54-
$ npm install react-tailwindcss-datepicker
54+
npm install react-tailwindcss-datepicker
5555
```
5656

5757
### Install via yarn
5858

5959
```
60-
$ yarn add react-tailwindcss-datepicker
60+
yarn add react-tailwindcss-datepicker
6161
```
6262

6363
Make sure you have installed the peer dependencies as well with the below versions.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@
7373
},
7474
"lint-staged": {
7575
"*.{ts,tsx}": [
76-
"npm run lint"
76+
"eslint",
77+
"prettier --write"
7778
],
78-
"*.{ts,tsx,css,scss,md}": [
79-
"npm run pret:fix"
79+
"*.{css,scss,json,md}": [
80+
"prettier --write"
8081
]
8182
}
8283
}

pages/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default function Playground() {
3232
const [newDisabledDates, setNewDisabledDates] = useState({ startDate: "", endDate: "" });
3333
const [startFrom, setStartFrom] = useState("2023-03-01");
3434
const [startWeekOn, setStartWeekOn] = useState("");
35+
const [required, setRequired] = useState(false);
3536

3637
const handleChange = (value, e) => {
3738
setValue(value);
@@ -115,6 +116,7 @@ export default function Playground() {
115116
return isEmpty ? "Select Date" : "Clear";
116117
}}
117118
popoverDirection={"down"}
119+
required={required}
118120
// classNames={{
119121
// input: ({ disabled, readOnly, className }) => {
120122
// if (disabled) {
@@ -231,6 +233,20 @@ export default function Playground() {
231233
</label>
232234
</div>
233235
</div>
236+
<div className="mb-2 w-1/2 sm:w-full">
237+
<div className="inline-flex items-center">
238+
<input
239+
type="checkbox"
240+
className="mr-2 rounded"
241+
id="required"
242+
checked={required}
243+
onChange={e => setRequired(e.target.checked)}
244+
/>
245+
<label className="block" htmlFor="required">
246+
Required
247+
</label>
248+
</div>
249+
</div>
234250
</div>
235251
<div className="w-full sm:w-1/3 pr-2 flex flex-col">
236252
<div className="mb-2">

src/components/Calendar/Days.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ interface Props {
2323
onClickNextDays: (day: number) => void;
2424
}
2525

26-
const Days: React.FC<Props> = ({
27-
calendarData,
28-
onClickPreviousDays,
29-
onClickDay,
30-
onClickNextDays
31-
}) => {
26+
const Days: React.FC<Props> = props => {
27+
// Props
28+
const { calendarData, onClickPreviousDays, onClickDay, onClickNextDays } = props;
29+
3230
// Contexts
3331
const {
3432
primaryColor,

src/components/Calendar/index.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,10 @@ interface Props {
3939
changeYear: (year: number) => void;
4040
}
4141

42-
const Calendar: React.FC<Props> = ({
43-
date,
44-
minDate,
45-
maxDate,
46-
onClickPrevious,
47-
onClickNext,
48-
changeMonth,
49-
changeYear
50-
}) => {
42+
const Calendar: React.FC<Props> = props => {
43+
// Props
44+
const { date, minDate, maxDate, onClickPrevious, onClickNext, changeMonth, changeYear } = props;
45+
5146
// Contexts
5247
const {
5348
hour,
@@ -71,6 +66,7 @@ const Calendar: React.FC<Props> = ({
7166
const [showMonths, setShowMonths] = useState(false);
7267
const [showYears, setShowYears] = useState(false);
7368
const [year, setYear] = useState(date.year());
69+
7470
// Functions
7571
const previous = useCallback(() => {
7672
return getLastDaysInMonth(
@@ -157,7 +153,9 @@ const Calendar: React.FC<Props> = ({
157153
newStart = fullDay;
158154
if (asSingle) {
159155
newEnd = fullDay;
160-
chosePeriod(fullDay, fullDay);
156+
if (!showFooter) {
157+
chosePeriod(fullDay, fullDay);
158+
}
161159
}
162160
} else {
163161
if (period.start && !period.end) {

src/components/Datepicker.tsx

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,48 @@ import { ColorKeys, DatepickerType, Period, PeriodDay } from "../types";
1414
import Time from "./Time";
1515
import { Arrow, VerticalDash } from "./utils";
1616

17-
const Datepicker: React.FC<DatepickerType> = ({
18-
primaryColor = "blue",
19-
value = null,
20-
onChange,
21-
useRange = true,
22-
showFooter = false,
23-
showShortcuts = false,
24-
configs = undefined,
25-
asSingle = false,
26-
asTimePicker = false,
27-
placeholder = null,
28-
separator = "~",
29-
startFrom = null,
30-
i18n = LANGUAGE,
31-
disabled = false,
32-
inputClassName = null,
33-
containerClassName = null,
34-
toggleClassName = null,
35-
toggleIcon = undefined,
36-
displayFormat = DATE_FORMAT,
37-
readOnly = false,
38-
minDate = null,
39-
maxDate = null,
40-
dateLooking = "forward",
41-
disabledDates = null,
42-
inputId,
43-
inputName,
44-
startWeekOn = "sun",
45-
classNames = undefined,
46-
popoverDirection = undefined
47-
}) => {
48-
// Ref
17+
const Datepicker = (props: DatepickerType) => {
18+
// Props
19+
const {
20+
primaryColor = "blue",
21+
value = null,
22+
onChange,
23+
useRange = true,
24+
showFooter = false,
25+
showShortcuts = false,
26+
configs = undefined,
27+
asSingle = false,
28+
placeholder = null,
29+
separator = "~",
30+
startFrom = null,
31+
asTimePicker = false,
32+
i18n = LANGUAGE,
33+
disabled = false,
34+
inputClassName = null,
35+
containerClassName = null,
36+
toggleClassName = null,
37+
popupClassName = null,
38+
toggleIcon = undefined,
39+
displayFormat = DATE_FORMAT,
40+
readOnly = false,
41+
minDate = null,
42+
maxDate = null,
43+
dateLooking = "forward",
44+
disabledDates = null,
45+
inputId,
46+
inputName,
47+
startWeekOn = "sun",
48+
classNames = undefined,
49+
popoverDirection = undefined,
50+
required = false
51+
} = props;
52+
53+
// Refs
4954
const containerRef = useRef<HTMLDivElement | null>(null);
5055
const calendarContainerRef = useRef<HTMLDivElement | null>(null);
5156
const arrowRef = useRef<HTMLDivElement | null>(null);
5257

53-
// State
58+
// States
5459
const [firstDate, setFirstDate] = useState<dayjs.Dayjs>(
5560
startFrom && dayjs(startFrom).isValid() ? dayjs(startFrom) : dayjs()
5661
);
@@ -258,6 +263,7 @@ const Datepicker: React.FC<DatepickerType> = ({
258263
}
259264
return DEFAULT_COLOR;
260265
}, [primaryColor]);
266+
261267
const contextValues = useMemo(() => {
262268
return {
263269
asSingle,
@@ -303,7 +309,8 @@ const Datepicker: React.FC<DatepickerType> = ({
303309
classNames,
304310
onChange,
305311
input: inputRef,
306-
popoverDirection
312+
popoverDirection,
313+
required
307314
};
308315
}, [
309316
asSingle,
@@ -343,6 +350,7 @@ const Datepicker: React.FC<DatepickerType> = ({
343350
classNames,
344351
inputRef,
345352
popoverDirection,
353+
required,
346354
firstGotoDate
347355
]);
348356

@@ -355,15 +363,22 @@ const Datepicker: React.FC<DatepickerType> = ({
355363
: defaultContainerClassName;
356364
}, [containerClassName]);
357365

366+
const popupClassNameOverload = useMemo(() => {
367+
const defaultPopupClassName =
368+
"transition-all ease-out duration-300 absolute z-10 mt-[1px] text-sm lg:text-xs 2xl:text-sm translate-y-4 opacity-0 hidden";
369+
return typeof popupClassName === "function"
370+
? popupClassName(defaultPopupClassName)
371+
: typeof popupClassName === "string" && popupClassName !== ""
372+
? popupClassName
373+
: defaultPopupClassName;
374+
}, [popupClassName]);
375+
358376
return (
359377
<DatepickerContext.Provider value={contextValues}>
360378
<div className={containerClassNameOverload} ref={containerRef}>
361379
<Input setContextRef={setInputRef} />
362380

363-
<div
364-
className="absolute z-10 mt-[1px] hidden translate-y-4 text-sm opacity-0 transition-all duration-300 ease-out lg:text-xs 2xl:text-sm"
365-
ref={calendarContainerRef}
366-
>
381+
<div className={popupClassNameOverload} ref={calendarContainerRef}>
367382
<Arrow ref={arrowRef} />
368383

369384
<div className="mt-2.5 rounded-lg border border-gray-300 bg-white px-1 py-0.5 shadow-sm dark:border-slate-600 dark:bg-slate-800 dark:text-white">

src/components/Input.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ const Input: FC<Props> = (e: Props) => {
4747
inputId,
4848
inputName,
4949
classNames,
50-
popoverDirection
50+
popoverDirection,
51+
required
5152
} = useContext(DatepickerContext);
5253

5354
// UseRefs
@@ -292,6 +293,7 @@ const Input: FC<Props> = (e: Props) => {
292293
className={getClassName()}
293294
disabled={disabled}
294295
readOnly={readOnly}
296+
required={required}
295297
placeholder={
296298
placeholder
297299
? placeholder

src/components/Shortcuts.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import dayjs from "dayjs";
2-
import React, { useCallback, useContext, useMemo } from "react";
2+
import React, { ReactNode, useCallback, useContext, useMemo } from "react";
33

44
import { DATE_FORMAT, TEXT_COLOR } from "../constants";
55
import DEFAULT_SHORTCUTS from "../constants/shortcuts";
66
import DatepickerContext from "../contexts/DatepickerContext";
77
import { Period, ShortcutsItem } from "../types";
88

99
interface ItemTemplateProps {
10-
children: JSX.Element;
10+
children: ReactNode;
1111
key: number;
1212
item: ShortcutsItem | ShortcutsItem[];
1313
}
@@ -26,7 +26,7 @@ const ItemTemplate = React.memo((props: ItemTemplateProps) => {
2626
} = useContext(DatepickerContext);
2727

2828
// Functions
29-
const getClassName: () => string = useCallback(() => {
29+
const getClassName = useCallback(() => {
3030
const textColor = TEXT_COLOR["600"][primaryColor as keyof (typeof TEXT_COLOR)["600"]];
3131
const textColorHover = TEXT_COLOR.hover[primaryColor as keyof typeof TEXT_COLOR.hover];
3232
return `whitespace-nowrap w-1/2 md:w-1/3 lg:w-auto transition-all duration-300 hover:bg-gray-100 dark:hover:bg-white/10 p-2 rounded cursor-pointer ${textColor} ${textColorHover}`;
@@ -132,9 +132,9 @@ const Shortcuts: React.FC = () => {
132132
}, []);
133133

134134
return shortcutOptions?.length ? (
135-
<div className="mb-3 border-gray-300 pr-1 dark:border-gray-700 md:border-b lg:mb-0 lg:border-b-0 lg:border-r">
136-
<ul className="flex w-full flex-wrap pb-1 tracking-wide lg:flex-col lg:pb-0">
137-
{shortcutOptions.map(([key, item], index: number) =>
135+
<div className="md:border-b mb-3 lg:mb-0 lg:border-r lg:border-b-0 border-gray-300 dark:border-gray-700 pr-1">
136+
<ul className="w-full tracking-wide flex flex-wrap lg:flex-col pb-1 lg:pb-0">
137+
{shortcutOptions.map(([key, item], index) =>
138138
Array.isArray(item) ? (
139139
item.map((item, index) => (
140140
<ItemTemplate key={index} item={item}>

src/components/utils.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useContext } from "react";
1+
import React, { ReactNode, useCallback, useContext } from "react";
22

33
import { BG_COLOR, BORDER_COLOR, BUTTON_COLOR, RING_COLOR } from "../constants";
44
import DatepickerContext from "../contexts/DatepickerContext";
@@ -8,7 +8,7 @@ interface IconProps {
88
}
99

1010
interface Button {
11-
children: JSX.Element | JSX.Element[];
11+
children: ReactNode;
1212
onClick: React.MouseEventHandler<HTMLButtonElement>;
1313
disabled?: boolean;
1414
roundedFull?: boolean;
@@ -204,5 +204,5 @@ export const VerticalDash = () => {
204204
const { primaryColor } = useContext(DatepickerContext);
205205
const bgColor = BG_COLOR["500"][primaryColor as keyof (typeof BG_COLOR)["500"]];
206206

207-
return <div className={`h-7 w-1 rounded-full bg-blue-500 md:block ${bgColor}`} />;
207+
return <div className={`h-7 w-1 rounded-full hidden md:block ${bgColor || "bg-blue-500"}`} />;
208208
};

0 commit comments

Comments
 (0)