@react-fabric/date 1.0.0-beta.5 → 1.0.0-beta.51
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.
- package/README.md +2 -9
- package/{src/components/Date.module.css → css/_date.css} +5 -5
- package/{src/superdate/SuperDate.module.css → css/styles.css} +2 -8
- package/dist/cjs/components/DatePage.js +2 -3
- package/dist/cjs/components/TimeSliders.js +5 -6
- package/dist/cjs/display/DateDisplay.js +7 -2
- package/dist/cjs/display/DateDuration.js +127 -0
- package/dist/cjs/hijri/DateConverter.js +154 -0
- package/dist/cjs/hijri/FormatDate.js +115 -0
- package/dist/cjs/hijri/HijriDate.js +531 -0
- package/dist/cjs/hijri/StringDateParser.js +74 -0
- package/dist/cjs/hijri/index.js +17 -1025
- package/dist/cjs/hijri/initializer.js +113 -0
- package/dist/cjs/hijri/locales.js +19 -0
- package/dist/cjs/hijri/safe.js +17 -0
- package/dist/cjs/i18n/ar.json.js +191 -3
- package/dist/cjs/i18n/en.json.js +63 -1
- package/dist/cjs/i18n/index.js +0 -6
- package/dist/cjs/index.js +13 -2
- package/dist/cjs/{superdate → panels}/EventPanel.js +16 -4
- package/dist/cjs/utils/dateUtil.js +3 -3
- package/dist/esm/components/DatePage.js +2 -3
- package/dist/esm/components/TimeSliders.js +5 -6
- package/dist/esm/display/DateDisplay.js +7 -2
- package/dist/esm/display/DateDuration.js +127 -0
- package/dist/esm/hijri/DateConverter.js +152 -0
- package/dist/esm/hijri/FormatDate.js +112 -0
- package/dist/esm/hijri/HijriDate.js +528 -0
- package/dist/esm/hijri/StringDateParser.js +74 -0
- package/dist/esm/hijri/index.js +17 -1025
- package/dist/esm/hijri/initializer.js +113 -0
- package/dist/esm/hijri/locales.js +18 -0
- package/dist/esm/hijri/safe.js +14 -0
- package/dist/esm/i18n/ar.json.js +191 -3
- package/dist/esm/i18n/en.json.js +63 -2
- package/dist/esm/i18n/index.js +0 -6
- package/dist/esm/index.js +6 -1
- package/dist/esm/{superdate → panels}/EventPanel.js +17 -5
- package/dist/esm/utils/dateUtil.js +3 -3
- package/dist/types/display/DateDisplay.d.ts +4 -3
- package/dist/types/display/DateDuration.d.ts +15 -0
- package/dist/types/hijri/DateConverter.d.ts +13 -0
- package/dist/types/hijri/FormatDate.d.ts +19 -0
- package/dist/types/hijri/HijriDate.d.ts +214 -0
- package/dist/types/hijri/StringDateParser.d.ts +11 -0
- package/dist/types/hijri/index.d.ts +2 -2
- package/dist/types/hijri/initializer.d.ts +129 -0
- package/dist/types/hijri/locales.d.ts +19 -0
- package/dist/types/hijri/safe.d.ts +3 -0
- package/dist/types/index.d.ts +6 -1
- package/dist/types/panels/EventPanel.d.ts +17 -0
- package/dist/types/types/index.d.ts +8 -35
- package/dist/types/utils/dateUtil.d.ts +1 -1
- package/package.json +11 -11
- package/src/components/DatePage.tsx +2 -3
- package/src/components/TimeSliders.tsx +5 -6
- package/src/display/DateDisplay.tsx +15 -4
- package/src/display/DateDuration.tsx +164 -0
- package/src/hijri/DateConverter.js +175 -0
- package/src/hijri/FormatDate.js +132 -0
- package/src/hijri/HijriDate.js +477 -0
- package/src/hijri/StringDateParser.js +68 -0
- package/src/hijri/index.js +16 -1535
- package/src/hijri/initializer.js +96 -0
- package/src/hijri/locales.js +109 -0
- package/src/hijri/safe.js +16 -0
- package/src/i18n/ar.json +190 -1
- package/src/i18n/en.json +60 -0
- package/src/i18n/index.ts +0 -3
- package/src/index.ts +7 -1
- package/src/{superdate → panels}/EventPanel.tsx +41 -6
- package/src/types/index.ts +8 -38
- package/src/utils/dateUtil.ts +4 -7
- package/dist/cjs/components/Date.module.css +0 -1
- package/dist/cjs/i18n/superdate/ar.json.js +0 -86
- package/dist/cjs/i18n/superdate/en.json.js +0 -93
- package/dist/cjs/superdate/QuickSelect.js +0 -134
- package/dist/cjs/superdate/RelativeInput.js +0 -79
- package/dist/cjs/superdate/RelativePanel.js +0 -91
- package/dist/cjs/superdate/SuperDate.module.css +0 -1
- package/dist/cjs/superdate/Superdate.js +0 -169
- package/dist/esm/components/Date.module.css +0 -1
- package/dist/esm/i18n/superdate/ar.json.js +0 -79
- package/dist/esm/i18n/superdate/en.json.js +0 -85
- package/dist/esm/superdate/QuickSelect.js +0 -134
- package/dist/esm/superdate/RelativeInput.js +0 -79
- package/dist/esm/superdate/RelativePanel.js +0 -91
- package/dist/esm/superdate/SuperDate.module.css +0 -1
- package/dist/esm/superdate/Superdate.js +0 -168
- package/dist/types/superdate/EventPanel.d.ts +0 -4
- package/dist/types/superdate/QuickSelect.d.ts +0 -1
- package/dist/types/superdate/RelativeInput.d.ts +0 -1
- package/dist/types/superdate/RelativePanel.d.ts +0 -1
- package/dist/types/superdate/Superdate.d.ts +0 -17
- package/src/i18n/superdate/ar.json +0 -70
- package/src/i18n/superdate/en.json +0 -75
- package/src/superdate/QuickSelect.tsx +0 -121
- package/src/superdate/RelativeInput.tsx +0 -64
- package/src/superdate/RelativePanel.tsx +0 -103
- package/src/superdate/Superdate.tsx +0 -186
|
@@ -1,186 +0,0 @@
|
|
|
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 { useFloatingTree } from "@floating-ui/react";
|
|
25
|
-
import {
|
|
26
|
-
Button,
|
|
27
|
-
Chip,
|
|
28
|
-
Content,
|
|
29
|
-
CoreIcons,
|
|
30
|
-
Dropdown,
|
|
31
|
-
Tab,
|
|
32
|
-
TabPanel,
|
|
33
|
-
Tooltip,
|
|
34
|
-
useGlobals,
|
|
35
|
-
} from "@react-fabric/core";
|
|
36
|
-
import classNames from "classnames";
|
|
37
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
38
|
-
import { useTranslation } from "react-i18next";
|
|
39
|
-
import { RangePanel } from "../panels/RangePanel";
|
|
40
|
-
import { type SuperDateProps } from "../types";
|
|
41
|
-
import { DateUtil } from "../utils/dateUtil";
|
|
42
|
-
import { EventPanel } from "./EventPanel";
|
|
43
|
-
import { QuickSelect } from "./QuickSelect";
|
|
44
|
-
import { RelativePanel } from "./RelativePanel";
|
|
45
|
-
import classes from "./SuperDate.module.css";
|
|
46
|
-
|
|
47
|
-
export const SuperDateTabs = ({
|
|
48
|
-
events,
|
|
49
|
-
value,
|
|
50
|
-
presets,
|
|
51
|
-
onChange,
|
|
52
|
-
}: SuperDateProps) => {
|
|
53
|
-
const { t } = useTranslation("superdate");
|
|
54
|
-
const tree = useFloatingTree();
|
|
55
|
-
const { currentCalendar, currentLocale } = useGlobals();
|
|
56
|
-
|
|
57
|
-
const isHijri = useMemo(() => currentCalendar === "hijri", [currentCalendar]);
|
|
58
|
-
|
|
59
|
-
const [currentValue, setCurrentValue] = useState("");
|
|
60
|
-
const [activeTab, setActiveTab] = useState("quick");
|
|
61
|
-
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
if (value?.match(/^(\$\w+)([+-])(\d+)\|(\$\w+)([+-])(\d+)$/))
|
|
64
|
-
setActiveTab("relative");
|
|
65
|
-
else if (value && !value?.match(/^(\$\w+)/)) setActiveTab("absolute");
|
|
66
|
-
else setActiveTab("quick");
|
|
67
|
-
|
|
68
|
-
value && setCurrentValue(value);
|
|
69
|
-
}, [value]);
|
|
70
|
-
|
|
71
|
-
const handleChange = useCallback(
|
|
72
|
-
(value: string) => {
|
|
73
|
-
const parsed = DateUtil.parseRange(value);
|
|
74
|
-
setCurrentValue(value);
|
|
75
|
-
onChange?.(value, [
|
|
76
|
-
parsed[0]?.toISOString?.(),
|
|
77
|
-
parsed[1]?.toISOString?.(),
|
|
78
|
-
]);
|
|
79
|
-
tree?.events.emit("close");
|
|
80
|
-
},
|
|
81
|
-
[isHijri, currentLocale],
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<div
|
|
86
|
-
className={classNames(
|
|
87
|
-
"rounded-capped outline select-none overflow-hidden grid",
|
|
88
|
-
classes.superDate,
|
|
89
|
-
)}
|
|
90
|
-
>
|
|
91
|
-
<TabPanel
|
|
92
|
-
headerClassName="border-b"
|
|
93
|
-
onChange={setActiveTab}
|
|
94
|
-
activeTab={activeTab}
|
|
95
|
-
>
|
|
96
|
-
<Tab id="quick" label={t("label.quick")}>
|
|
97
|
-
<QuickSelect
|
|
98
|
-
value={currentValue}
|
|
99
|
-
onChange={handleChange}
|
|
100
|
-
presets={presets}
|
|
101
|
-
/>
|
|
102
|
-
</Tab>
|
|
103
|
-
<Tab id="relative" label={t("label.relative")}>
|
|
104
|
-
<RelativePanel value={currentValue} onChange={handleChange} />
|
|
105
|
-
</Tab>
|
|
106
|
-
<Tab id="absolute" label={t("label.absolute")}>
|
|
107
|
-
<Content className="p-0">
|
|
108
|
-
<RangePanel
|
|
109
|
-
withTime
|
|
110
|
-
showHijriToggle
|
|
111
|
-
value={
|
|
112
|
-
currentValue ? DateUtil.parseRange(currentValue) : undefined
|
|
113
|
-
}
|
|
114
|
-
{...({ showApply: true } as AnyObject)}
|
|
115
|
-
onChange={([start, end]) => handleChange?.(`${start}|${end}`)}
|
|
116
|
-
/>
|
|
117
|
-
</Content>
|
|
118
|
-
</Tab>
|
|
119
|
-
<Tab id="events" label={t("label.events")}>
|
|
120
|
-
<EventPanel
|
|
121
|
-
isHijri={isHijri}
|
|
122
|
-
onChange={handleChange}
|
|
123
|
-
events={events}
|
|
124
|
-
/>
|
|
125
|
-
</Tab>
|
|
126
|
-
</TabPanel>
|
|
127
|
-
</div>
|
|
128
|
-
);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Superdate panel provides ability to select relative and absolute dates
|
|
133
|
-
*
|
|
134
|
-
* Relative dates parts
|
|
135
|
-
* `$now`,
|
|
136
|
-
* `$minute`,
|
|
137
|
-
* `$hour`,
|
|
138
|
-
* `$day`,
|
|
139
|
-
* `$week`,
|
|
140
|
-
* `$month`,
|
|
141
|
-
* `$quarter`,
|
|
142
|
-
* `$year`,
|
|
143
|
-
* `$decade`
|
|
144
|
-
*/
|
|
145
|
-
export const SuperDate = ({
|
|
146
|
-
as = "button",
|
|
147
|
-
color = "primary",
|
|
148
|
-
variant,
|
|
149
|
-
onChange,
|
|
150
|
-
value,
|
|
151
|
-
...props
|
|
152
|
-
}: SuperDateProps) => {
|
|
153
|
-
const { currentCalendar, currentLocale } = useGlobals();
|
|
154
|
-
|
|
155
|
-
const isHijri = useMemo(() => currentCalendar === "hijri", [currentCalendar]);
|
|
156
|
-
|
|
157
|
-
const [relValue, setRelative] = useState<string>();
|
|
158
|
-
|
|
159
|
-
useEffect(() => {
|
|
160
|
-
setRelative(value);
|
|
161
|
-
}, [value]);
|
|
162
|
-
|
|
163
|
-
const handleChange = useCallback(
|
|
164
|
-
(value: string) => {
|
|
165
|
-
const parsed = DateUtil.parseRange(value);
|
|
166
|
-
setRelative(value);
|
|
167
|
-
onChange?.(value, [
|
|
168
|
-
parsed[0]?.toISOString?.(),
|
|
169
|
-
parsed[1]?.toISOString?.(),
|
|
170
|
-
]);
|
|
171
|
-
},
|
|
172
|
-
[isHijri, currentLocale],
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
const E = as === "button" ? Button : Chip;
|
|
176
|
-
return (
|
|
177
|
-
<Dropdown showArrow>
|
|
178
|
-
<Tooltip content={DateUtil.relativeTooltip(relValue, isHijri)}>
|
|
179
|
-
<E icon={CoreIcons.clock} color={color} variant={variant as AnyObject}>
|
|
180
|
-
{DateUtil.relativeLabel(relValue, isHijri) ?? ""}
|
|
181
|
-
</E>
|
|
182
|
-
</Tooltip>
|
|
183
|
-
<SuperDateTabs {...props} value={relValue} onChange={handleChange} />
|
|
184
|
-
</Dropdown>
|
|
185
|
-
);
|
|
186
|
-
};
|