Skip to content

Commit 56680b0

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 725dd92 + 57c24d0 commit 56680b0

File tree

12 files changed

+298
-78
lines changed

12 files changed

+298
-78
lines changed

CONTRIBUTING.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Contributing
2+
3+
Thanks for your interest in contributing to `react-tailwindcss-datepicker`! Please take a moment to
4+
review this document **before submitting a pull request**.
5+
6+
- [Pull requests](#pull-requests)
7+
- [Installation](#installation)
8+
- [Coding standards](#coding-standards)
9+
- [Running playground](#running-playgrounds)
10+
- [Before you make a Pull Request](#before-you-make-a-pull-request)
11+
12+
## Pull requests
13+
14+
**Please ask first before starting work on any significant new features.**
15+
16+
It's never a fun experience to have your pull request declined after investing a lot of time and
17+
effort into a new feature. To avoid this from happening, we request that contributors create
18+
[an issue](https://github.com/onesine/react-tailwindcss-datepicker/issues) to first discuss any
19+
significant new features.
20+
21+
## Installation
22+
23+
You only require a `yarn install` in the root directory to install everything you need.
24+
25+
```sh
26+
yarn install
27+
```
28+
29+
## Coding standards
30+
31+
We use `prettier` for making sure that the codebase is formatted consistently. To automatically fix
32+
any style violations in your code, you can run:
33+
34+
**Using yarn**
35+
36+
```sh
37+
yarn pret:fix
38+
```
39+
40+
**Using npm**
41+
42+
```sh
43+
npm pret:fix
44+
```
45+
46+
## Running playground
47+
48+
We currently use `next.js` as server for live testing.
49+
50+
You can run the `dev` script and open your browser to `http://localhost:8888`.
51+
52+
See complete `props` usage in `pages/index.js` file.
53+
54+
**Using yarn**
55+
56+
```sh
57+
yarn dev
58+
```
59+
60+
**Using npm**
61+
62+
```sh
63+
npm dev
64+
```
65+
66+
## Before you make a Pull Request
67+
68+
We recommend to run these scripts in sequence before you make your commit message amd open a Pull
69+
Request
70+
71+
**Let's clean the code first**
72+
73+
```sh
74+
yarn pret:fix
75+
```
76+
77+
**Test a build of your changes**
78+
79+
```sh
80+
yarn build
81+
82+
```

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
</div>
1616

1717
## Contents
18-
* [Features](https://github.com/onesine/react-tailwindcss-datepicker/blob/master/README.md#features)
19-
* [Documentation](https://react-tailwindcss-datepicker.vercel.app)
20-
* [Installation](https://github.com/onesine/react-tailwindcss-datepicker/blob/master/README.md#installation)
21-
* [Simple Usage](https://github.com/onesine/react-tailwindcss-datepicker/blob/master/README.md#simple-usage)
22-
* [Theming Options](https://github.com/onesine/react-tailwindcss-datepicker/blob/master/README.md#theming-options)
23-
* [Playground](https://github.com/onesine/react-tailwindcss-datepicker/blob/master/README.md#playground)
18+
* [Features](#features)
19+
* [Documentation](#documentation)
20+
* [Installation](#installation)
21+
* [Simple Usage](#simple-usage)
22+
* [Theming Options](#theming-options)
23+
* [Playground](#playground)
24+
* [Contributing](#contributing)
2425

2526
## Features
2627
- ✅ Theming options
@@ -144,7 +145,11 @@ yarn install && yarn dev
144145
Open a browser and navigate to `http://localhost:8888`
145146

146147
## Contributing
147-
Got ideas on how to make this better? Open an issue!
148+
149+
See [CONTRIBUTING.md](https://github.com/onesine/react-tailwindcss-datepicker/blob/master/CONTRIBUTING.md)
150+
151+
## Official Documentation repo
152+
[https://github.com/onesine/react-tailwindcss-datepicker-doc](https://github.com/onesine/react-tailwindcss-datepicker-doc)
148153

149154
## Thanks to
150155
- [Litepie Datepicker](https://litepie.com/)

pages/index.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ export default function Playground() {
2121
const [disabled, setDisabled] = useState(false);
2222
const [inputClassName, setInputClassName] = useState("");
2323
const [containerClassName, setContainerClassName] = useState("");
24+
const [toggleClassName, setToggleClassName] = useState("");
2425
const [displayFormat, setDisplayFormat] = useState("YYYY-MM-DD");
2526
const [readOnly, setReadOnly] = useState(false);
26-
const [startFrom, setStartFrom] = useState("2023-01-02");
2727
const [minDate, setMinDate] = useState("");
2828
const [maxDate, setMaxDate] = useState("");
2929
const [disabledDates, setDisabledDates] = useState([]);
3030
const [newDisabledDates, setNewDisabledDates] = useState({ startDate: "", endDate: "" });
31+
const [startFrom, setStartFrom] = useState("2023-03-01");
32+
const [startWeekOn, setStartWeekOn] = useState("");
3133

3234
return (
3335
<div className="px-4 py-8">
@@ -60,11 +62,13 @@ export default function Playground() {
6062
disabled={disabled}
6163
inputClassName={inputClassName}
6264
containerClassName={containerClassName}
65+
toggleClassName={toggleClassName}
6366
displayFormat={displayFormat}
6467
readOnly={readOnly}
6568
minDate={minDate}
6669
maxDate={maxDate}
6770
disabledDates={disabledDates}
71+
startWeekOn={startWeekOn}
6872
/>
6973
</div>
7074

@@ -227,6 +231,19 @@ export default function Playground() {
227231
}}
228232
/>
229233
</div>
234+
<div className="mb-2">
235+
<label className="block" htmlFor="maxDate">
236+
Maximum Date
237+
</label>
238+
<input
239+
className="rounded border px-4 py-2 w-full border-gray-200"
240+
id="maxDate"
241+
value={maxDate}
242+
onChange={e => {
243+
setMaxDate(e.target.value);
244+
}}
245+
/>
246+
</div>
230247
</div>
231248
<div className="w-full sm:w-1/3 pr-2 flex flex-col">
232249
<div className="mb-2">
@@ -282,15 +299,28 @@ export default function Playground() {
282299
/>
283300
</div>
284301
<div className="mb-2">
285-
<label className="block" htmlFor="maxDate">
286-
Maximum Date
302+
<label className="block" htmlFor="containerClassName">
303+
Toggle Class
287304
</label>
288305
<input
289306
className="rounded border px-4 py-2 w-full border-gray-200"
290-
id="maxDate"
291-
value={maxDate}
307+
id="toggleClassName"
308+
value={toggleClassName}
292309
onChange={e => {
293-
setMaxDate(e.target.value);
310+
setToggleClassName(e.target.value);
311+
}}
312+
/>
313+
</div>
314+
<div className="mb-2">
315+
<label className="block" htmlFor="startWeekOnClassName">
316+
Start Week On
317+
</label>
318+
<input
319+
className="rounded border px-4 py-2 w-full border-gray-200"
320+
id="startWeekOnClassName"
321+
value={startWeekOn}
322+
onChange={e => {
323+
setStartWeekOn(e.target.value);
294324
}}
295325
/>
296326
</div>

src/components/Calendar/Days.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import dayjs from "dayjs";
22
import React, { useCallback, useContext } from "react";
33

4-
import { BG_COLOR } from "../../constants";
4+
import { BG_COLOR, TEXT_COLOR } from "../../constants";
55
import DatepickerContext from "../../contexts/DatepickerContext";
6-
import {
7-
formatDate,
8-
getTextColorByPrimaryColor,
9-
nextMonth,
10-
previousMonth,
11-
classNames as cn
12-
} from "../../helpers";
6+
import { formatDate, nextMonth, previousMonth, classNames as cn } from "../../helpers";
137

148
const isBetween = require("dayjs/plugin/isBetween");
159
dayjs.extend(isBetween);
@@ -53,7 +47,7 @@ const Days: React.FC<Props> = ({
5347
item >= 10 ? item : "0" + item
5448
}`;
5549
if (formatDate(dayjs()) === formatDate(dayjs(itemDate)))
56-
return getTextColorByPrimaryColor(primaryColor);
50+
return TEXT_COLOR["500"][primaryColor as keyof (typeof TEXT_COLOR)["500"]];
5751
return "";
5852
},
5953
[calendarData.date, primaryColor]
@@ -210,7 +204,7 @@ const Days: React.FC<Props> = ({
210204
day >= 10 ? day : "0" + day
211205
}`;
212206

213-
if (!disabledDates || disabledDates?.length <= 0) {
207+
if (!disabledDates || (Array.isArray(disabledDates) && !disabledDates.length)) {
214208
return false;
215209
}
216210

src/components/Calendar/Week.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,51 @@
11
import dayjs from "dayjs";
2+
import weekday from "dayjs/plugin/weekday";
23
import React, { useContext } from "react";
34

45
import DatepickerContext from "../../contexts/DatepickerContext";
56
import { loadLanguageModule, shortString, ucFirst } from "../../helpers";
67

8+
dayjs.extend(weekday);
9+
710
const Week: React.FC = () => {
8-
const { i18n } = useContext(DatepickerContext);
11+
const { i18n, startWeekOn } = useContext(DatepickerContext);
912
loadLanguageModule(i18n);
13+
let startDateModifier = dayjs().locale(i18n).weekday(0).get("day");
14+
if (startWeekOn) {
15+
switch (startWeekOn) {
16+
case "mon":
17+
startDateModifier = 1;
18+
break;
19+
case "tue":
20+
startDateModifier = 2;
21+
break;
22+
case "wed":
23+
startDateModifier = 3;
24+
break;
25+
case "thu":
26+
startDateModifier = 4;
27+
break;
28+
case "fri":
29+
startDateModifier = 5;
30+
break;
31+
case "sat":
32+
startDateModifier = 6;
33+
break;
34+
case "sun":
35+
startDateModifier = 0;
36+
break;
37+
default:
38+
break;
39+
}
40+
}
1041

1142
return (
1243
<div className="grid grid-cols-7 border-b border-gray-300 dark:border-gray-700 py-2">
1344
{[0, 1, 2, 3, 4, 5, 6].map((item, index) => (
1445
<div key={index} className="tracking-wide text-gray-500 text-center">
1546
{ucFirst(
1647
shortString(
17-
dayjs(`2022-11-${6 + item}`)
48+
dayjs(`2022-11-${6 + (item + startDateModifier)}`)
1849
.locale(i18n)
1950
.format("ddd")
2051
)

src/components/Calendar/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ const Calendar: React.FC<Props> = ({
5151
changeDatepickerValue,
5252
hideDatepicker,
5353
asSingle,
54-
i18n
54+
i18n,
55+
startWeekOn
5556
} = useContext(DatepickerContext);
5657
loadLanguageModule(i18n);
5758

5859
// States
5960
const [showMonths, setShowMonths] = useState(false);
6061
const [showYears, setShowYears] = useState(false);
6162
const [year, setYear] = useState(date.year());
62-
6363
// Functions
6464
const previous = useCallback(() => {
6565
return getLastDaysInMonth(
6666
previousMonth(date),
67-
getNumberOfDay(getFirstDayInMonth(date).ddd) - 1
67+
getNumberOfDay(getFirstDayInMonth(date).ddd, i18n, startWeekOn)
6868
);
69-
}, [date]);
69+
}, [date, i18n, startWeekOn]);
7070

7171
const current = useCallback(() => {
7272
return getDaysInMonth(formatDate(date));

src/components/Datepicker.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ interface Props {
4040
i18n?: string;
4141
disabled?: boolean;
4242
inputClassName?: string | null;
43+
toggleClassName?: string | null;
44+
inputId?: string;
45+
inputName?: string;
4346
containerClassName?: string | null;
4447
displayFormat?: string;
4548
readOnly?: boolean;
4649
minDate?: DateType | null;
4750
maxDate?: DateType | null;
4851
disabledDates?: DateRangeType[] | null;
52+
startWeekOn?: string | null;
4953
}
5054

5155
const Datepicker: React.FC<Props> = ({
@@ -64,11 +68,15 @@ const Datepicker: React.FC<Props> = ({
6468
disabled = false,
6569
inputClassName = null,
6670
containerClassName = null,
71+
toggleClassName = null,
6772
displayFormat = "YYYY-MM-DD",
6873
readOnly = false,
6974
minDate = null,
7075
maxDate = null,
71-
disabledDates = null
76+
disabledDates = null,
77+
inputId,
78+
inputName,
79+
startWeekOn = "sun"
7280
}) => {
7381
// Ref
7482
const containerRef = useRef<HTMLDivElement>(null);
@@ -215,8 +223,8 @@ const Datepicker: React.FC<Props> = ({
215223
validDate && (startDate.isSame(endDate) || startDate.isBefore(endDate));
216224
if (condition) {
217225
setPeriod({
218-
start: formatDate(startDate, displayFormat),
219-
end: formatDate(endDate, displayFormat)
226+
start: formatDate(startDate),
227+
end: formatDate(endDate)
220228
});
221229
setInputText(
222230
`${formatDate(startDate, displayFormat)}${
@@ -277,11 +285,15 @@ const Datepicker: React.FC<Props> = ({
277285
disabled,
278286
inputClassName,
279287
containerClassName,
288+
toggleClassName,
280289
readOnly,
281290
displayFormat,
282291
minDate,
283292
maxDate,
284-
disabledDates
293+
disabledDates,
294+
inputId,
295+
inputName,
296+
startWeekOn
285297
};
286298
}, [
287299
asSingle,
@@ -300,12 +312,16 @@ const Datepicker: React.FC<Props> = ({
300312
disabled,
301313
inputClassName,
302314
containerClassName,
315+
toggleClassName,
303316
readOnly,
304317
displayFormat,
305318
firstGotoDate,
306319
minDate,
307320
maxDate,
308-
disabledDates
321+
disabledDates,
322+
inputId,
323+
inputName,
324+
startWeekOn
309325
]);
310326

311327
return (

0 commit comments

Comments
 (0)