@react-fabric/date 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/dist/cjs/components/Date.module.css +1 -0
  4. package/dist/cjs/components/DateCell.js +98 -0
  5. package/dist/cjs/components/DateHeader.js +142 -0
  6. package/dist/cjs/components/DatePage.js +59 -0
  7. package/dist/cjs/components/DecadePage.js +34 -0
  8. package/dist/cjs/components/MonthPage.js +33 -0
  9. package/dist/cjs/components/TimeSliders.js +131 -0
  10. package/dist/cjs/components/YearPage.js +34 -0
  11. package/dist/cjs/display/DateDisplay.js +35 -0
  12. package/dist/cjs/hijri/index.js +1029 -0
  13. package/dist/cjs/i18n/ar.json.js +25 -0
  14. package/dist/cjs/i18n/en.json.js +21 -0
  15. package/dist/cjs/i18n/index.js +39 -0
  16. package/dist/cjs/i18n/superdate/ar.json.js +86 -0
  17. package/dist/cjs/i18n/superdate/en.json.js +93 -0
  18. package/dist/cjs/index.js +20 -0
  19. package/dist/cjs/panels/BasePanel.js +73 -0
  20. package/dist/cjs/panels/DatePanel.js +205 -0
  21. package/dist/cjs/panels/RangePanel.js +340 -0
  22. package/dist/cjs/superdate/EventPanel.js +173 -0
  23. package/dist/cjs/superdate/QuickSelect.js +134 -0
  24. package/dist/cjs/superdate/RelativeInput.js +79 -0
  25. package/dist/cjs/superdate/RelativePanel.js +91 -0
  26. package/dist/cjs/superdate/SuperDate.module.css +1 -0
  27. package/dist/cjs/superdate/Superdate.js +169 -0
  28. package/dist/cjs/types/index.js +61 -0
  29. package/dist/cjs/utils/dateUtil.js +436 -0
  30. package/dist/esm/components/Date.module.css +1 -0
  31. package/dist/esm/components/DateCell.js +98 -0
  32. package/dist/esm/components/DateHeader.js +142 -0
  33. package/dist/esm/components/DatePage.js +59 -0
  34. package/dist/esm/components/DecadePage.js +34 -0
  35. package/dist/esm/components/MonthPage.js +33 -0
  36. package/dist/esm/components/TimeSliders.js +131 -0
  37. package/dist/esm/components/YearPage.js +34 -0
  38. package/dist/esm/display/DateDisplay.js +35 -0
  39. package/dist/esm/hijri/index.js +1029 -0
  40. package/dist/esm/i18n/ar.json.js +21 -0
  41. package/dist/esm/i18n/en.json.js +18 -0
  42. package/dist/esm/i18n/index.js +39 -0
  43. package/dist/esm/i18n/superdate/ar.json.js +79 -0
  44. package/dist/esm/i18n/superdate/en.json.js +85 -0
  45. package/dist/esm/index.js +9 -0
  46. package/dist/esm/panels/BasePanel.js +73 -0
  47. package/dist/esm/panels/DatePanel.js +205 -0
  48. package/dist/esm/panels/RangePanel.js +340 -0
  49. package/dist/esm/superdate/EventPanel.js +173 -0
  50. package/dist/esm/superdate/QuickSelect.js +134 -0
  51. package/dist/esm/superdate/RelativeInput.js +79 -0
  52. package/dist/esm/superdate/RelativePanel.js +91 -0
  53. package/dist/esm/superdate/SuperDate.module.css +1 -0
  54. package/dist/esm/superdate/Superdate.js +168 -0
  55. package/dist/esm/types/index.js +60 -0
  56. package/dist/esm/utils/dateUtil.js +438 -0
  57. package/dist/types/components/DateCell.d.ts +15 -0
  58. package/dist/types/components/DateHeader.d.ts +14 -0
  59. package/dist/types/components/DatePage.d.ts +6 -0
  60. package/dist/types/components/DecadePage.d.ts +6 -0
  61. package/dist/types/components/MonthPage.d.ts +6 -0
  62. package/dist/types/components/TimeSliders.d.ts +10 -0
  63. package/dist/types/components/YearPage.d.ts +6 -0
  64. package/dist/types/display/DateDisplay.d.ts +15 -0
  65. package/dist/types/hijri/index.d.ts +2 -0
  66. package/dist/types/i18n/index.d.ts +1 -0
  67. package/dist/types/index.d.ts +7 -0
  68. package/dist/types/panels/BasePanel.d.ts +25 -0
  69. package/dist/types/panels/DatePanel.d.ts +2 -0
  70. package/dist/types/panels/RangePanel.d.ts +2 -0
  71. package/dist/types/superdate/EventPanel.d.ts +4 -0
  72. package/dist/types/superdate/QuickSelect.d.ts +1 -0
  73. package/dist/types/superdate/RelativeInput.d.ts +1 -0
  74. package/dist/types/superdate/RelativePanel.d.ts +1 -0
  75. package/dist/types/superdate/Superdate.d.ts +17 -0
  76. package/dist/types/types/index.d.ts +70 -0
  77. package/dist/types/utils/dateUtil.d.ts +30 -0
  78. package/package.json +58 -0
  79. package/src/components/Date.module.css +75 -0
  80. package/src/components/DateCell.tsx +181 -0
  81. package/src/components/DateHeader.tsx +223 -0
  82. package/src/components/DatePage.tsx +107 -0
  83. package/src/components/DecadePage.tsx +53 -0
  84. package/src/components/MonthPage.tsx +52 -0
  85. package/src/components/TimeSliders.tsx +196 -0
  86. package/src/components/YearPage.tsx +53 -0
  87. package/src/display/DateDisplay.tsx +88 -0
  88. package/src/hijri/index.js +1540 -0
  89. package/src/i18n/ar.json +14 -0
  90. package/src/i18n/en.json +13 -0
  91. package/src/i18n/index.ts +31 -0
  92. package/src/i18n/superdate/ar.json +70 -0
  93. package/src/i18n/superdate/en.json +75 -0
  94. package/src/index.ts +32 -0
  95. package/src/panels/BasePanel.tsx +130 -0
  96. package/src/panels/DatePanel.tsx +235 -0
  97. package/src/panels/RangePanel.tsx +400 -0
  98. package/src/superdate/EventPanel.tsx +200 -0
  99. package/src/superdate/QuickSelect.tsx +121 -0
  100. package/src/superdate/RelativeInput.tsx +64 -0
  101. package/src/superdate/RelativePanel.tsx +103 -0
  102. package/src/superdate/SuperDate.module.css +30 -0
  103. package/src/superdate/Superdate.tsx +186 -0
  104. package/src/types/index.ts +121 -0
  105. package/src/utils/dateUtil.ts +551 -0
@@ -0,0 +1,107 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { getDay } from "date-fns";
25
+ import i18next from "i18next";
26
+ import { Fragment, useMemo } from "react";
27
+ import { DateUtil } from "../utils/dateUtil";
28
+ import { DateCell, type DateCellProps } from "./DateCell";
29
+ import classNames from "classnames";
30
+ import { PageType } from "../types";
31
+ import classes from "./Date.module.css";
32
+
33
+ const rows = [0, 1, 2, 3, 4, 5];
34
+ const cols = [0, 1, 2, 3, 4, 5, 6];
35
+
36
+ interface Props extends Omit<DateCellProps, "date"> {
37
+ pageDate: Date;
38
+ }
39
+
40
+ export const DatePage = ({ pageDate, isHijri, ...props }: Props) => {
41
+ const startDate = useMemo(() => {
42
+ const first = DateUtil.startOfMonth(pageDate, isHijri);
43
+ const current = getDay(first);
44
+ return DateUtil.addDays(
45
+ first,
46
+ (current < 3 ? -7 : 0) + current * -1,
47
+ isHijri,
48
+ );
49
+ }, [isHijri, pageDate]);
50
+
51
+ return (
52
+ <div
53
+ className={classNames(
54
+ "grid grid-cols-8 area-content",
55
+ props.page !== PageType.DATE && "invisible",
56
+ )}
57
+ >
58
+ <div
59
+ className={classNames(
60
+ classes.dateHeader,
61
+ "px-1 text-center bg-tint-50 h-7",
62
+ )}
63
+ ></div>
64
+ {cols.map((col) => {
65
+ const dt = DateUtil.addDays(startDate, col, isHijri);
66
+ return (
67
+ <div
68
+ key={dt.toISOString()}
69
+ className={classNames(
70
+ classes.dateHeader,
71
+ "font-medium text-sm p-1 mx-px text-center text-muted bg-tint-50 h-7",
72
+ )}
73
+ >
74
+ {DateUtil.format(dt, "eeeeee", i18next.language, isHijri)}
75
+ </div>
76
+ );
77
+ })}
78
+ {rows.map((row) => (
79
+ <Fragment key={row}>
80
+ <div
81
+ key={row}
82
+ className="px-1 py-1.5 m-px text-xs text-center text-tint-300"
83
+ >
84
+ {DateUtil.getWeek(
85
+ DateUtil.addDays(startDate, row * 7, isHijri),
86
+ i18next.language,
87
+ isHijri,
88
+ )}
89
+ </div>
90
+ {cols.map((col) => {
91
+ const dt = DateUtil.addDays(startDate, row * 7 + col, isHijri);
92
+ return (
93
+ <DateCell
94
+ {...props}
95
+ date={dt}
96
+ page={PageType.DATE}
97
+ isHijri={isHijri}
98
+ key={dt.toISOString()}
99
+ isMuted={!DateUtil.isSameMonth(dt, pageDate, isHijri)}
100
+ />
101
+ );
102
+ })}
103
+ </Fragment>
104
+ ))}
105
+ </div>
106
+ );
107
+ };
@@ -0,0 +1,53 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { useMemo } from "react";
25
+ import { DateUtil } from "../utils/dateUtil";
26
+ import { DateCell, type DateCellProps } from "./DateCell";
27
+
28
+ const cols = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
29
+
30
+ interface Props extends Omit<DateCellProps, "date"> {
31
+ pageDate: Date;
32
+ }
33
+
34
+ export const DecadePage = ({ pageDate, isHijri, ...props }: Props) => {
35
+ const startDate = useMemo(() => {
36
+ return DateUtil.startOfCentury(pageDate, isHijri);
37
+ }, [isHijri, pageDate]);
38
+
39
+ return (
40
+ <div className="grid grid-cols-3 area-content place-content-center">
41
+ {cols.map((col) => (
42
+ <DateCell
43
+ key={col}
44
+ isHijri={isHijri}
45
+ className="px-1 py-3"
46
+ date={DateUtil.addYears(startDate, col * 10, isHijri)}
47
+ isMuted={col === -1 || col === 10}
48
+ {...props}
49
+ />
50
+ ))}
51
+ </div>
52
+ );
53
+ };
@@ -0,0 +1,52 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { useMemo } from "react";
25
+ import { DateUtil } from "../utils/dateUtil";
26
+ import { DateCell, type DateCellProps } from "./DateCell";
27
+
28
+ const cols = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
29
+
30
+ interface Props extends Omit<DateCellProps, "date"> {
31
+ pageDate: Date;
32
+ }
33
+
34
+ export const MonthPage = ({ pageDate, isHijri, ...props }: Props) => {
35
+ const startDate = useMemo(() => {
36
+ return DateUtil.startOfYear(pageDate, isHijri);
37
+ }, [isHijri, pageDate]);
38
+
39
+ return (
40
+ <div className="grid grid-cols-3 area-content place-content-center">
41
+ {cols.map((col) => (
42
+ <DateCell
43
+ key={col}
44
+ isHijri={isHijri}
45
+ className="px-1 py-3"
46
+ date={DateUtil.addMonths(startDate, col, isHijri)}
47
+ {...props}
48
+ />
49
+ ))}
50
+ </div>
51
+ );
52
+ };
@@ -0,0 +1,196 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { useDebounce } from "@react-fabric/core";
25
+ import classNames from "classnames";
26
+ import { useCallback, useEffect, useRef, useState } from "react";
27
+ import classes from "./Date.module.css";
28
+
29
+ interface Props {
30
+ hour: number;
31
+ minute: number;
32
+ onTimeChange: (time: { hour: number; minute: number }) => void;
33
+ }
34
+
35
+ export const TimeSlider = ({ hour = 0, minute = 0, onTimeChange }: Props) => {
36
+ const hourRef = useRef<HTMLDivElement>(null);
37
+ const minuteRef = useRef<HTMLDivElement>(null);
38
+
39
+ const [h, setH] = useState(hour);
40
+ const [m, setM] = useState(minute);
41
+
42
+ useEffect(() => {
43
+ setH(hour);
44
+ hourRef.current?.children
45
+ .item(hour + 1)
46
+ ?.scrollIntoView({ block: "center" });
47
+ }, [hour]);
48
+ useEffect(() => {
49
+ setM(minute);
50
+ minuteRef.current?.children
51
+ .item(minute + 1)
52
+ ?.scrollIntoView({ block: "center" });
53
+ }, [minute]);
54
+
55
+ const fireChange = useDebounce(onTimeChange, [onTimeChange]);
56
+
57
+ const calculateTime = useCallback(() => {
58
+ const hourTop = hourRef.current?.scrollTop ?? 0;
59
+ const hourHeight =
60
+ (hourRef.current?.children.item(1) as HTMLElement)?.offsetHeight ?? 0;
61
+ const minuteTop = minuteRef.current?.scrollTop ?? 0;
62
+ const minuteHeight =
63
+ (minuteRef.current?.children.item(1) as HTMLElement)?.offsetHeight ?? 0;
64
+
65
+ const hour = Math.round(hourTop / hourHeight);
66
+ const minute = Math.round(minuteTop / minuteHeight);
67
+
68
+ setH(hour);
69
+ setM(minute);
70
+
71
+ fireChange({ hour, minute });
72
+ }, [onTimeChange]);
73
+
74
+ return (
75
+ <div
76
+ className={classNames(
77
+ "area-[time] flex flex-col flex-nowrap border-s border-s-tint-50 overflow-hidden bg-base",
78
+ )}
79
+ >
80
+ <div className="flex">
81
+ <div
82
+ className={classNames(
83
+ classes.dateHeader,
84
+ "flex-1 font-medium text-muted text-sm p-1 mx-px text-center bg-tint-50",
85
+ )}
86
+ >
87
+ H
88
+ </div>
89
+ <div
90
+ className={classNames(
91
+ classes.dateHeader,
92
+ "flex-1 font-medium text-muted text-sm p-1 mx-px text-center bg-tint-50",
93
+ )}
94
+ >
95
+ M
96
+ </div>
97
+ </div>
98
+ <div className="flex flex-1 flex-nowrap overflow-hidden relative">
99
+ <div
100
+ className={classNames(
101
+ "flex-1 overflow-auto scroll-hide snap-y snap-mandatory",
102
+ classes.timeSlider,
103
+ )}
104
+ onScroll={calculateTime}
105
+ ref={hourRef}
106
+ >
107
+ <div className="w-full" />
108
+ {Array(24)
109
+ .fill(0)
110
+ .map((_, i) => (
111
+ <div
112
+ role="none"
113
+ className={classNames(
114
+ "ps-2 pe-1 snap-center outline outline-muted",
115
+ i === h && "font-medium text-primary-600",
116
+ )}
117
+ key={i}
118
+ data-skew={
119
+ i === h - 5 || i === h + 5
120
+ ? 5
121
+ : i === h - 4 || i === h + 4
122
+ ? 4
123
+ : i === h - 3 || i === h + 3
124
+ ? 3
125
+ : i === h - 2 || i === h + 2
126
+ ? 2
127
+ : i === h - 1 || i === h + 1
128
+ ? 1
129
+ : undefined
130
+ }
131
+ data-selected={i === h}
132
+ onClick={(e) => {
133
+ e.currentTarget.scrollIntoView({
134
+ block: "center",
135
+ behavior: "smooth",
136
+ });
137
+ }}
138
+ >
139
+ <div>{i.toString(10).padStart(2, "0")}</div>
140
+ </div>
141
+ ))}
142
+ <div className="w-full" />
143
+ </div>
144
+ <div
145
+ className={classNames(
146
+ "flex-1 overflow-auto scroll-hide snap-y snap-mandatory",
147
+ classes.timeSlider,
148
+ )}
149
+ onScroll={calculateTime}
150
+ ref={minuteRef}
151
+ >
152
+ <div className="w-full" />
153
+ {Array(60)
154
+ .fill(0)
155
+ .map((_, i) => (
156
+ <div
157
+ role="none"
158
+ className={classNames(
159
+ "ps-1 pe-2 snap-center outline outline-muted",
160
+ i === m && "font-medium text-primary-600",
161
+ )}
162
+ key={i}
163
+ data-skew={
164
+ i === m - 5 || i === m + 5
165
+ ? 5
166
+ : i === m - 4 || i === m + 4
167
+ ? 4
168
+ : i === m - 3 || i === m + 3
169
+ ? 3
170
+ : i === m - 2 || i === m + 2
171
+ ? 2
172
+ : i === m - 1 || i === m + 1
173
+ ? 1
174
+ : undefined
175
+ }
176
+ data-selected={i === m}
177
+ onClick={(e) => {
178
+ e.currentTarget.scrollIntoView({
179
+ block: "center",
180
+ behavior: "smooth",
181
+ });
182
+ }}
183
+ >
184
+ <div>{i.toString(10).padStart(2, "0")}</div>
185
+ </div>
186
+ ))}
187
+ <div className="w-full" />
188
+ </div>
189
+ <div className="border rounded border-primary-500 absolute top-1/2 -translate-y-1/2 h-6 w-full flex items-center justify-between bg-primary-200/10">
190
+ <div className="border-s-4 border-t-4 border-b-4 border-transparent border-s-primary-500" />
191
+ <div className="border-e-4 border-t-4 border-b-4 border-transparent border-e-primary-500" />
192
+ </div>
193
+ </div>
194
+ </div>
195
+ );
196
+ };
@@ -0,0 +1,53 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { useMemo } from "react";
25
+ import { DateUtil } from "../utils/dateUtil";
26
+ import { DateCell, type DateCellProps } from "./DateCell";
27
+
28
+ const cols = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
29
+
30
+ interface Props extends Omit<DateCellProps, "date"> {
31
+ pageDate: Date;
32
+ }
33
+
34
+ export const YearPage = ({ pageDate, isHijri, ...props }: Props) => {
35
+ const startDate = useMemo(() => {
36
+ return DateUtil.startOfDecade(pageDate, isHijri);
37
+ }, [isHijri, pageDate]);
38
+
39
+ return (
40
+ <div className="grid grid-cols-3 area-content place-content-center">
41
+ {cols.map((col) => (
42
+ <DateCell
43
+ key={col}
44
+ isHijri={isHijri}
45
+ className="px-1 py-3"
46
+ date={DateUtil.addYears(startDate, col, isHijri)}
47
+ isMuted={col === -1 || col === 10}
48
+ {...props}
49
+ />
50
+ ))}
51
+ </div>
52
+ );
53
+ };
@@ -0,0 +1,88 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { Dropdown, Tooltip, useGlobals } from "@react-fabric/core";
25
+ import { type MenuItemProps } from "@react-fabric/core/dist/types/components/menu/types";
26
+ import {
27
+ type AriaProps,
28
+ type ChildrenProp,
29
+ type CssProp,
30
+ type TestProps,
31
+ } from "@react-fabric/core/dist/types/types";
32
+ import { type ElementType } from "react";
33
+ import { type DateLike } from "../types";
34
+ import { DateUtil } from "../utils/dateUtil";
35
+
36
+ export interface Props
37
+ extends CssProp,
38
+ AriaProps,
39
+ TestProps,
40
+ Partial<ChildrenProp<ElementType<MenuItemProps>>> {
41
+ /**
42
+ * date like value
43
+ */
44
+ date?: DateLike;
45
+ /**
46
+ * date format
47
+ */
48
+ format?: string;
49
+ }
50
+
51
+ export const DateDisplay = ({
52
+ date,
53
+ className,
54
+ format = "eee, PPpp",
55
+ children,
56
+ ...aria
57
+ }: Props) => {
58
+ const { currentCalendar, currentLocale } = useGlobals();
59
+
60
+ const dtLabel = (
61
+ <Tooltip
62
+ content={DateUtil.format(
63
+ date,
64
+ format,
65
+ currentLocale,
66
+ currentCalendar !== "hijri",
67
+ )}
68
+ >
69
+ <span className={className} {...aria}>
70
+ {DateUtil.format(
71
+ date,
72
+ format,
73
+ currentLocale,
74
+ currentCalendar === "hijri",
75
+ )}
76
+ </span>
77
+ </Tooltip>
78
+ );
79
+
80
+ return children ? (
81
+ <Dropdown>
82
+ {dtLabel}
83
+ {children}
84
+ </Dropdown>
85
+ ) : (
86
+ dtLabel
87
+ );
88
+ };