Skip to content

Commit febff8d

Browse files
committed
fixing the date picker to start with sunday
1 parent 150388c commit febff8d

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/ui-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdacurry/component-library",
3-
"version": "6.3.16",
3+
"version": "6.3.17",
44
"description": "A React component library created by Lambda Curry.",
55
"author": "Lambda Curry",
66
"license": "ISC",

packages/ui-components/src/lib/inputs/InputDate/InputDate.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,38 @@ import { InputText } from '../InputText/InputText';
99
import { InputProps } from '../InputBase';
1010
import { useEffect } from 'react';
1111

12+
// https://github.com/mui/material-ui/issues/30591#issuecomment-1377997824
13+
class Adapter extends AdapterLuxon {
14+
public getWeekdays = () => {
15+
return ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
16+
};
17+
18+
getWeekArray = (date: DateTime) => {
19+
const { days } = date.endOf('month').endOf('week').diff(date.startOf('month').startOf('week'), 'days').toObject();
20+
21+
let weeks: DateTime[][] = [];
22+
new Array(Math.round(days ?? 0))
23+
.fill(0)
24+
.map((_, i) => i)
25+
.map(day => date.startOf('month').startOf('week').minus({ days: 1 }).plus({ days: day }))
26+
.forEach((v, i) => {
27+
if (i === 0 || (i % 7 === 0 && i > 6)) {
28+
weeks.push([v]);
29+
return;
30+
}
31+
32+
weeks[weeks.length - 1].push(v);
33+
});
34+
35+
weeks = weeks.filter(week => {
36+
// do not allow weeks with start or end outside of current month
37+
return week[0].hasSame(date, 'month') || week[week.length - 1].hasSame(date, 'month');
38+
});
39+
40+
return weeks;
41+
};
42+
}
43+
1244
export type InputDateProps = Omit<InputProps, 'onChange'> & {
1345
value?: Date | string;
1446
onChange?: (date: Date | string | null) => void;
@@ -44,7 +76,7 @@ export const InputDate: FC<InputDateProps> = ({
4476
}, [fieldValue]);
4577

4678
return (
47-
<LocalizationProvider dateAdapter={AdapterLuxon}>
79+
<LocalizationProvider dateAdapter={Adapter}>
4880
<DatePicker
4981
{...datePickerProps}
5082
label={label}

0 commit comments

Comments
 (0)