@react-fabric/superdate 1.0.0-beta.63 → 1.0.1
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/dist/cjs/i18n/index.js +4 -4
- package/dist/cjs/index.js +28 -0
- package/dist/cjs/superdate/QuickSelect.js +6 -6
- package/dist/cjs/superdate/RelativeInput.js +5 -5
- package/dist/cjs/superdate/RelativePanel.js +10 -10
- package/dist/cjs/superdate/Superdate.js +27 -31
- package/dist/esm/index.js +30 -0
- package/dist/esm/superdate/QuickSelect.js +6 -6
- package/dist/esm/superdate/RelativeInput.js +5 -5
- package/dist/esm/superdate/RelativePanel.js +10 -10
- package/dist/esm/superdate/Superdate.js +28 -32
- package/dist/types/index.d.ts +26 -0
- package/dist/types/superdate/QuickSelect.d.ts +10 -1
- package/dist/types/superdate/RelativeInput.d.ts +5 -1
- package/dist/types/superdate/RelativePanel.d.ts +4 -1
- package/dist/types/superdate/Superdate.d.ts +2 -7
- package/dist/types/types/index.d.ts +3 -4
- package/package.json +15 -19
- package/src/index.ts +22 -17
- package/src/superdate/QuickSelect.tsx +18 -36
- package/src/superdate/RelativeInput.tsx +6 -12
- package/src/superdate/RelativePanel.tsx +14 -34
- package/src/superdate/Superdate.tsx +31 -75
- package/src/types/index.ts +3 -8
|
@@ -4,19 +4,19 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
|
4
4
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
5
5
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
6
6
|
import { useFloatingTree } from '@floating-ui/react';
|
|
7
|
-
import { useApplicationContext, Dropdown, Tooltip,
|
|
7
|
+
import { useApplicationContext, Dropdown, Tooltip, Button, Chip, TabPanel, Tab } from '@react-fabric/core';
|
|
8
8
|
import { DateUtil, RangePanel, EventPanel } from '@react-fabric/date';
|
|
9
|
-
import
|
|
9
|
+
import { cn } from '@react-fabric/utilities';
|
|
10
10
|
import { useMemo, useState, useEffect, useCallback } from 'react';
|
|
11
11
|
import { useTranslation } from 'react-i18next';
|
|
12
12
|
import { QuickSelect } from './QuickSelect.js';
|
|
13
13
|
import { RelativePanel } from './RelativePanel.js';
|
|
14
14
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
15
15
|
|
|
16
|
-
var _excluded = ["as", "color", "size", "variant", "disabled", "
|
|
16
|
+
var _excluded = ["as", "color", "size", "variant", "disabled", "onChange", "value", "data-test-value", "data-testid"];
|
|
17
17
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t),
|
|
19
|
-
|
|
18
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
+
function SuperDateTabs(_ref) {
|
|
20
20
|
var events = _ref.events,
|
|
21
21
|
value = _ref.value,
|
|
22
22
|
presets = _ref.presets,
|
|
@@ -26,8 +26,7 @@ var SuperDateTabs = function SuperDateTabs(_ref) {
|
|
|
26
26
|
t = _useTranslation.t;
|
|
27
27
|
var tree = useFloatingTree();
|
|
28
28
|
var _useApplicationContex = useApplicationContext(),
|
|
29
|
-
currentCalendar = _useApplicationContex.currentCalendar
|
|
30
|
-
currentLocale = _useApplicationContex.currentLocale;
|
|
29
|
+
currentCalendar = _useApplicationContex.currentCalendar;
|
|
31
30
|
var isHijri = useMemo(function () {
|
|
32
31
|
return currentCalendar === "hijri";
|
|
33
32
|
}, [currentCalendar]);
|
|
@@ -41,7 +40,7 @@ var SuperDateTabs = function SuperDateTabs(_ref) {
|
|
|
41
40
|
setActiveTab = _useState4[1];
|
|
42
41
|
useEffect(function () {
|
|
43
42
|
if (value !== null && value !== void 0 && value.match(/^(\$\w+)([+-])(\d+)\|(\$\w+)([+-])(\d+)$/)) setActiveTab("relative");else if (value && !(value !== null && value !== void 0 && value.match(/^(\$\w+)/))) setActiveTab("absolute");else setActiveTab("quick");
|
|
44
|
-
value
|
|
43
|
+
if (value) setCurrentValue(value);
|
|
45
44
|
}, [value]);
|
|
46
45
|
var handleChange = useCallback(function (value) {
|
|
47
46
|
var _parsed$, _parsed$$toISOString, _parsed$2, _parsed$2$toISOString;
|
|
@@ -49,11 +48,12 @@ var SuperDateTabs = function SuperDateTabs(_ref) {
|
|
|
49
48
|
setCurrentValue(value);
|
|
50
49
|
onChange === null || onChange === void 0 || onChange(value, [(_parsed$ = parsed[0]) === null || _parsed$ === void 0 || (_parsed$$toISOString = _parsed$.toISOString) === null || _parsed$$toISOString === void 0 ? void 0 : _parsed$$toISOString.call(_parsed$), (_parsed$2 = parsed[1]) === null || _parsed$2 === void 0 || (_parsed$2$toISOString = _parsed$2.toISOString) === null || _parsed$2$toISOString === void 0 ? void 0 : _parsed$2$toISOString.call(_parsed$2)]);
|
|
51
50
|
tree === null || tree === void 0 || tree.events.emit("close");
|
|
52
|
-
},
|
|
51
|
+
},
|
|
52
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
53
|
+
[onChange]);
|
|
53
54
|
return /*#__PURE__*/jsx("div", {
|
|
54
|
-
className:
|
|
55
|
+
className: cn("rounded-capped outline select-none overflow-hidden grid", "fabric-superDate"),
|
|
55
56
|
children: /*#__PURE__*/jsxs(TabPanel, {
|
|
56
|
-
headerClassName: "border-b",
|
|
57
57
|
onChange: setActiveTab,
|
|
58
58
|
activeTab: activeTab,
|
|
59
59
|
children: [/*#__PURE__*/jsx(Tab, {
|
|
@@ -74,8 +74,8 @@ var SuperDateTabs = function SuperDateTabs(_ref) {
|
|
|
74
74
|
}), /*#__PURE__*/jsx(Tab, {
|
|
75
75
|
id: "absolute",
|
|
76
76
|
label: t("label.absolute"),
|
|
77
|
-
children: /*#__PURE__*/jsx(
|
|
78
|
-
className: "p-0",
|
|
77
|
+
children: /*#__PURE__*/jsx("div", {
|
|
78
|
+
className: "p-0 overflow-hidden area-content",
|
|
79
79
|
children: /*#__PURE__*/jsx(RangePanel, {
|
|
80
80
|
withTime: true,
|
|
81
81
|
showHijriToggle: true,
|
|
@@ -101,7 +101,7 @@ var SuperDateTabs = function SuperDateTabs(_ref) {
|
|
|
101
101
|
})]
|
|
102
102
|
})
|
|
103
103
|
});
|
|
104
|
-
}
|
|
104
|
+
}
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
107
|
* SuperDate component provides a date selection interface with quick, relative, and absolute date options.
|
|
@@ -128,9 +128,6 @@ var SuperDateTabs = function SuperDateTabs(_ref) {
|
|
|
128
128
|
* - `$week|$now`: Represents the current week starting from the beginning of the week to now.
|
|
129
129
|
* - `$month|$week`: Represents the current month starting from the beginning of the month to the end of current week.
|
|
130
130
|
*
|
|
131
|
-
* @param {SuperDateProps} props - The properties for the SuperDate component.
|
|
132
|
-
* @returns {React.ReactElement} The rendered SuperDate component.
|
|
133
|
-
*
|
|
134
131
|
* @example
|
|
135
132
|
* ```jsx
|
|
136
133
|
* <SuperDate
|
|
@@ -146,10 +143,8 @@ var SuperDateTabs = function SuperDateTabs(_ref) {
|
|
|
146
143
|
* data-testid="superdate"
|
|
147
144
|
* />
|
|
148
145
|
* ```
|
|
149
|
-
*
|
|
150
|
-
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/superdate-superdate--docs}
|
|
151
146
|
*/
|
|
152
|
-
|
|
147
|
+
function SuperDate(_ref4) {
|
|
153
148
|
var _DateUtil$relativeLab;
|
|
154
149
|
var _ref4$as = _ref4.as,
|
|
155
150
|
as = _ref4$as === void 0 ? "button" : _ref4$as,
|
|
@@ -158,31 +153,29 @@ var SuperDate = function SuperDate(_ref4) {
|
|
|
158
153
|
size = _ref4.size,
|
|
159
154
|
variant = _ref4.variant,
|
|
160
155
|
disabled = _ref4.disabled,
|
|
161
|
-
fullWidth = _ref4.fullWidth,
|
|
162
156
|
onChange = _ref4.onChange,
|
|
163
157
|
value = _ref4.value,
|
|
164
158
|
testValue = _ref4["data-test-value"],
|
|
165
159
|
testId = _ref4["data-testid"],
|
|
166
160
|
props = _objectWithoutProperties(_ref4, _excluded);
|
|
167
161
|
var _useApplicationContex2 = useApplicationContext(),
|
|
168
|
-
currentCalendar = _useApplicationContex2.currentCalendar
|
|
169
|
-
currentLocale = _useApplicationContex2.currentLocale;
|
|
162
|
+
currentCalendar = _useApplicationContex2.currentCalendar;
|
|
170
163
|
var isHijri = useMemo(function () {
|
|
171
164
|
return currentCalendar === "hijri";
|
|
172
165
|
}, [currentCalendar]);
|
|
173
166
|
var _useState5 = useState(),
|
|
174
167
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
175
168
|
relValue = _useState6[0],
|
|
176
|
-
|
|
169
|
+
setRelValue = _useState6[1];
|
|
177
170
|
useEffect(function () {
|
|
178
|
-
|
|
171
|
+
setRelValue(value);
|
|
179
172
|
}, [value]);
|
|
180
173
|
var handleChange = useCallback(function (value) {
|
|
181
174
|
var _parsed$3, _parsed$3$toISOString, _parsed$4, _parsed$4$toISOString;
|
|
182
175
|
var parsed = DateUtil.parseRange(value);
|
|
183
|
-
|
|
176
|
+
setRelValue(value);
|
|
184
177
|
onChange === null || onChange === void 0 || onChange(value, [(_parsed$3 = parsed[0]) === null || _parsed$3 === void 0 || (_parsed$3$toISOString = _parsed$3.toISOString) === null || _parsed$3$toISOString === void 0 ? void 0 : _parsed$3$toISOString.call(_parsed$3), (_parsed$4 = parsed[1]) === null || _parsed$4 === void 0 || (_parsed$4$toISOString = _parsed$4.toISOString) === null || _parsed$4$toISOString === void 0 ? void 0 : _parsed$4$toISOString.call(_parsed$4)]);
|
|
185
|
-
}, [
|
|
178
|
+
}, [onChange]);
|
|
186
179
|
var E = as === "button" ? Button : Chip;
|
|
187
180
|
return /*#__PURE__*/jsxs(Dropdown, {
|
|
188
181
|
showArrow: true,
|
|
@@ -190,11 +183,14 @@ var SuperDate = function SuperDate(_ref4) {
|
|
|
190
183
|
content: DateUtil.relativeTooltip(relValue, isHijri),
|
|
191
184
|
children: /*#__PURE__*/jsx(E, {
|
|
192
185
|
icon: "icon-[mdi--clock-outline]",
|
|
193
|
-
size: size
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
186
|
+
size: size
|
|
187
|
+
// @ts-expect-error ignore
|
|
188
|
+
,
|
|
189
|
+
color: color
|
|
190
|
+
// @ts-expect-error ignore
|
|
191
|
+
,
|
|
197
192
|
variant: variant,
|
|
193
|
+
disabled: disabled,
|
|
198
194
|
"data-test-value": testValue,
|
|
199
195
|
"data-testid": testId,
|
|
200
196
|
children: (_DateUtil$relativeLab = DateUtil.relativeLabel(relValue, isHijri)) !== null && _DateUtil$relativeLab !== void 0 ? _DateUtil$relativeLab : ""
|
|
@@ -204,6 +200,6 @@ var SuperDate = function SuperDate(_ref4) {
|
|
|
204
200
|
onChange: handleChange
|
|
205
201
|
}))]
|
|
206
202
|
});
|
|
207
|
-
}
|
|
203
|
+
}
|
|
208
204
|
|
|
209
205
|
export { SuperDate, SuperDateTabs };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
export declare const SUPERDATE_PACKAGE = "@react-fabric/superdate";
|
|
26
|
+
export declare const SUPERDATE_VERSION = "1.0.0";
|
|
1
27
|
import "./i18n";
|
|
2
28
|
export { SuperDate } from "./superdate/Superdate";
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
declare const DEFAULT_PRESETS: {
|
|
2
|
+
value: string;
|
|
3
|
+
label: string;
|
|
4
|
+
}[];
|
|
5
|
+
export declare function QuickSelect({ presets, value, onChange, }: {
|
|
6
|
+
presets?: typeof DEFAULT_PRESETS;
|
|
7
|
+
value: string;
|
|
8
|
+
onChange: (value: string) => void;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare function RelativeInput({ label, prefix, showApply }: {
|
|
2
|
+
label: string;
|
|
3
|
+
prefix: string;
|
|
4
|
+
showApply?: boolean;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SuperDateProps } from "../types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function SuperDateTabs({ events, value, presets, recurringEvents, onChange }: SuperDateProps): import("react").JSX.Element;
|
|
3
3
|
/**
|
|
4
4
|
* SuperDate component provides a date selection interface with quick, relative, and absolute date options.
|
|
5
5
|
* It allows users to select dates using predefined presets, relative date calculations, or absolute date ranges.
|
|
@@ -25,9 +25,6 @@ export declare const SuperDateTabs: ({ events, value, presets, recurringEvents,
|
|
|
25
25
|
* - `$week|$now`: Represents the current week starting from the beginning of the week to now.
|
|
26
26
|
* - `$month|$week`: Represents the current month starting from the beginning of the month to the end of current week.
|
|
27
27
|
*
|
|
28
|
-
* @param {SuperDateProps} props - The properties for the SuperDate component.
|
|
29
|
-
* @returns {React.ReactElement} The rendered SuperDate component.
|
|
30
|
-
*
|
|
31
28
|
* @example
|
|
32
29
|
* ```jsx
|
|
33
30
|
* <SuperDate
|
|
@@ -43,7 +40,5 @@ export declare const SuperDateTabs: ({ events, value, presets, recurringEvents,
|
|
|
43
40
|
* data-testid="superdate"
|
|
44
41
|
* />
|
|
45
42
|
* ```
|
|
46
|
-
*
|
|
47
|
-
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/superdate-superdate--docs}
|
|
48
43
|
*/
|
|
49
|
-
export declare
|
|
44
|
+
export declare function SuperDate({ as, color, size, variant, disabled, onChange, value, "data-test-value": testValue, "data-testid": testId, ...props }: SuperDateProps): import("react").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CustomColors, SizeType, TestProps } from "@react-fabric/core/dist/types/types";
|
|
2
2
|
import { type EventType } from "@react-fabric/date/dist/types/types";
|
|
3
3
|
export interface PresetType {
|
|
4
4
|
value: string;
|
|
@@ -6,11 +6,10 @@ export interface PresetType {
|
|
|
6
6
|
}
|
|
7
7
|
export interface SuperDateProps extends TestProps {
|
|
8
8
|
as?: "button" | "chip";
|
|
9
|
-
color?:
|
|
9
|
+
color?: CustomColors;
|
|
10
10
|
size?: SizeType;
|
|
11
|
-
variant?: "solid" | "
|
|
11
|
+
variant?: "solid" | "outlined" | "link" | "soft";
|
|
12
12
|
disabled?: boolean;
|
|
13
|
-
fullWidth?: boolean;
|
|
14
13
|
/**
|
|
15
14
|
* relative date value
|
|
16
15
|
*/
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/superdate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "RUF: Superdate package for relative dates",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"repository": "https://github.com/adarshpastakia/react-
|
|
7
|
+
"repository": "https://github.com/adarshpastakia/react-fabric/tree/main/packages/superdate",
|
|
8
8
|
"source": "src/index.ts",
|
|
9
9
|
"main": "dist/cjs/index.js",
|
|
10
10
|
"module": "dist/esm/index.js",
|
|
@@ -24,8 +24,6 @@
|
|
|
24
24
|
"registry": "https://registry.npmjs.org/"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"makelink": "yarn link",
|
|
28
|
-
"removelink": "yarn unlink",
|
|
29
27
|
"prebuild": "rm -rf ./dist",
|
|
30
28
|
"build:dts": "tsc -p ./tsconfig.build.json",
|
|
31
29
|
"build:rollup": "rollup -c ../../rollup.config.mjs",
|
|
@@ -35,24 +33,22 @@
|
|
|
35
33
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
36
34
|
},
|
|
37
35
|
"dependencies": {
|
|
38
|
-
"@floating-ui/react": "~0.27.
|
|
39
|
-
"@hookform/resolvers": "~5.
|
|
40
|
-
"@react-fabric/core": "^1.0.
|
|
41
|
-
"@react-fabric/date": "^1.0.
|
|
42
|
-
"@react-fabric/form": "^1.0.
|
|
43
|
-
"@react-fabric/utilities": "^1.0.
|
|
44
|
-
"classnames": "~2.5.1",
|
|
45
|
-
"react-hook-form": "~7.71.2"
|
|
36
|
+
"@floating-ui/react": "~0.27.20",
|
|
37
|
+
"@hookform/resolvers": "~5.9.1",
|
|
38
|
+
"@react-fabric/core": "^1.0.1",
|
|
39
|
+
"@react-fabric/date": "^1.0.1",
|
|
40
|
+
"@react-fabric/form": "^1.0.1",
|
|
41
|
+
"@react-fabric/utilities": "^1.0.1"
|
|
46
42
|
},
|
|
47
43
|
"peerDependencies": {
|
|
48
|
-
"i18next": "~
|
|
49
|
-
"react": "~19.
|
|
50
|
-
"react-dom": "~19.
|
|
51
|
-
"react-i18next": "~
|
|
44
|
+
"i18next": "~26.3.6",
|
|
45
|
+
"react": "~19.3.0",
|
|
46
|
+
"react-dom": "~19.3.0",
|
|
47
|
+
"react-i18next": "~17.0.11"
|
|
52
48
|
},
|
|
53
49
|
"engines": {
|
|
54
|
-
"node": ">=
|
|
55
|
-
"npm": ">=
|
|
50
|
+
"node": ">=24.0.0",
|
|
51
|
+
"npm": ">=11.0.0"
|
|
56
52
|
},
|
|
57
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "1419a9df05b5e3850e1d2b4e896ab63df702c7e8"
|
|
58
54
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* React Fabric
|
|
3
|
-
* @version
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
4
6
|
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
5
13
|
*
|
|
6
|
-
* The
|
|
7
|
-
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
8
16
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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.
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
22
24
|
*/
|
|
23
25
|
|
|
26
|
+
export const SUPERDATE_PACKAGE = "@react-fabric/superdate";
|
|
27
|
+
export const SUPERDATE_VERSION = "1.0.0";
|
|
28
|
+
|
|
24
29
|
import "./i18n";
|
|
25
30
|
|
|
26
31
|
export { SuperDate } from "./superdate/Superdate";
|
|
@@ -52,26 +52,26 @@ const schema = yup.object({
|
|
|
52
52
|
rel: yup.object({
|
|
53
53
|
diff: yup.number().required().label("Difference"),
|
|
54
54
|
op: yup.string().required().oneOf(["+", "-"]).label("Operator"),
|
|
55
|
-
part: yup
|
|
56
|
-
.string()
|
|
57
|
-
.required()
|
|
58
|
-
.oneOf(Object.values(DatePart))
|
|
59
|
-
.label("Date part"),
|
|
55
|
+
part: yup.string().required().oneOf(Object.values(DatePart)).label("Date part"),
|
|
60
56
|
}),
|
|
61
57
|
});
|
|
62
58
|
|
|
63
|
-
export
|
|
59
|
+
export function QuickSelect({
|
|
64
60
|
presets = DEFAULT_PRESETS,
|
|
65
61
|
value = "",
|
|
66
62
|
onChange,
|
|
67
|
-
}:
|
|
63
|
+
}: {
|
|
64
|
+
presets?: typeof DEFAULT_PRESETS;
|
|
65
|
+
value: string;
|
|
66
|
+
onChange: (value: string) => void;
|
|
67
|
+
}) {
|
|
68
68
|
const { t } = useTranslation();
|
|
69
69
|
|
|
70
70
|
const handleChange = useCallback(
|
|
71
71
|
({ rel: { part, diff, op } }: yup.InferType<typeof schema>) => {
|
|
72
72
|
onChange(`${part}${op}${diff}|${DatePart.NOW}`);
|
|
73
73
|
},
|
|
74
|
-
[],
|
|
74
|
+
[onChange],
|
|
75
75
|
);
|
|
76
76
|
|
|
77
77
|
const defaultValue = useMemo(() => {
|
|
@@ -80,46 +80,28 @@ export const QuickSelect = ({
|
|
|
80
80
|
value
|
|
81
81
|
.split("|")
|
|
82
82
|
.shift()
|
|
83
|
-
|
|
83
|
+
?.match(/^(\$\w+)([+-])(\d+)?$/) ?? [];
|
|
84
84
|
return {
|
|
85
|
-
rel: { part, op, diff },
|
|
86
|
-
}
|
|
85
|
+
rel: { part, op, diff: +diff },
|
|
86
|
+
} as yup.InferType<typeof schema>;
|
|
87
87
|
}
|
|
88
88
|
}, [value]);
|
|
89
89
|
|
|
90
90
|
return (
|
|
91
91
|
<Content>
|
|
92
|
-
<div
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
>
|
|
96
|
-
<Form
|
|
97
|
-
resolver={yupResolver(schema)}
|
|
98
|
-
onSubmit={handleChange}
|
|
99
|
-
defaultValues={defaultValue}
|
|
100
|
-
>
|
|
101
|
-
<RelativeInput
|
|
102
|
-
label={t("superdate:label.relative")}
|
|
103
|
-
prefix="rel"
|
|
104
|
-
showApply
|
|
105
|
-
/>
|
|
92
|
+
<div className="inline-block origin-left rtl:origin-right" style={{ zoom: 0.85 }}>
|
|
93
|
+
<Form resolver={yupResolver(schema)} onSubmit={handleChange} defaultValues={defaultValue}>
|
|
94
|
+
<RelativeInput label={t("superdate:label.relative")} prefix="rel" showApply />
|
|
106
95
|
</Form>
|
|
107
96
|
</div>
|
|
108
97
|
<Divider>{t("superdate:label.preset")}</Divider>
|
|
109
|
-
<div
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
>
|
|
113
|
-
{presets.map((pr: KeyValue) => (
|
|
114
|
-
<button
|
|
115
|
-
key={pr.value}
|
|
116
|
-
className="link appearance-none text-start"
|
|
117
|
-
onClick={() => onChange?.(pr.value)}
|
|
118
|
-
>
|
|
98
|
+
<div data-dropdown-dismiss="true" className="grid grid-cols-3 flex-row text-sm gap-2">
|
|
99
|
+
{presets.map((pr) => (
|
|
100
|
+
<button key={pr.value} className="link appearance-none text-start" onClick={() => onChange?.(pr.value)}>
|
|
119
101
|
{t(pr.label, { defaultValue: pr.label })}
|
|
120
102
|
</button>
|
|
121
103
|
))}
|
|
122
104
|
</div>
|
|
123
105
|
</Content>
|
|
124
106
|
);
|
|
125
|
-
}
|
|
107
|
+
}
|
|
@@ -26,7 +26,7 @@ import { DatePart } from "@react-fabric/date";
|
|
|
26
26
|
import { Controller, Field, Number, Select } from "@react-fabric/form";
|
|
27
27
|
import { useTranslation } from "react-i18next";
|
|
28
28
|
|
|
29
|
-
export
|
|
29
|
+
export function RelativeInput({ label, prefix, showApply }: { label: string; prefix: string; showApply?: boolean }) {
|
|
30
30
|
const { t } = useTranslation("superdate");
|
|
31
31
|
|
|
32
32
|
return (
|
|
@@ -39,7 +39,7 @@ export const RelativeInput = ({ label, prefix, showApply }: KeyValue) => {
|
|
|
39
39
|
options={Object.values<string>(DatePart)
|
|
40
40
|
.slice(1)
|
|
41
41
|
.map((dt) => ({
|
|
42
|
-
|
|
42
|
+
value: dt,
|
|
43
43
|
label: t(`label.${dt}`),
|
|
44
44
|
}))}
|
|
45
45
|
/>
|
|
@@ -48,22 +48,16 @@ export const RelativeInput = ({ label, prefix, showApply }: KeyValue) => {
|
|
|
48
48
|
<Select
|
|
49
49
|
width="7rem"
|
|
50
50
|
options={[
|
|
51
|
-
{
|
|
52
|
-
{
|
|
51
|
+
{ value: "-", label: t("label.-") },
|
|
52
|
+
{ value: "+", label: t("label.+") },
|
|
53
53
|
]}
|
|
54
54
|
/>
|
|
55
55
|
</Controller>
|
|
56
56
|
{showApply && (
|
|
57
|
-
<Button
|
|
58
|
-
variant="solid"
|
|
59
|
-
color="primary"
|
|
60
|
-
size="sm"
|
|
61
|
-
type="submit"
|
|
62
|
-
data-dropdown-dismiss="true"
|
|
63
|
-
>
|
|
57
|
+
<Button variant="solid" color="primary" size="sm" type="submit" data-dropdown-dismiss="true">
|
|
64
58
|
{t("label.apply")}
|
|
65
59
|
</Button>
|
|
66
60
|
)}
|
|
67
61
|
</Field>
|
|
68
62
|
);
|
|
69
|
-
}
|
|
63
|
+
}
|
|
@@ -34,72 +34,52 @@ const schema = yup.object({
|
|
|
34
34
|
from: yup.object({
|
|
35
35
|
diff: yup.number().required().label("Difference"),
|
|
36
36
|
op: yup.string().required().oneOf(["+", "-"]).label("Operator"),
|
|
37
|
-
part: yup
|
|
38
|
-
.string()
|
|
39
|
-
.required()
|
|
40
|
-
.oneOf(Object.values(DatePart))
|
|
41
|
-
.label("Date part"),
|
|
37
|
+
part: yup.string().required().oneOf(Object.values(DatePart)).label("Date part"),
|
|
42
38
|
}),
|
|
43
39
|
to: yup.object({
|
|
44
40
|
diff: yup.number().required().label("Difference"),
|
|
45
41
|
op: yup.string().required().oneOf(["+", "-"]).label("Operator"),
|
|
46
|
-
part: yup
|
|
47
|
-
.string()
|
|
48
|
-
.required()
|
|
49
|
-
.oneOf(Object.values(DatePart))
|
|
50
|
-
.label("Date part"),
|
|
42
|
+
part: yup.string().required().oneOf(Object.values(DatePart)).label("Date part"),
|
|
51
43
|
}),
|
|
52
44
|
});
|
|
53
45
|
|
|
54
|
-
export
|
|
46
|
+
export function RelativePanel({ value = "", onChange }: { value: string; onChange?: (value: string) => void }) {
|
|
55
47
|
const { t } = useTranslation("superdate");
|
|
56
48
|
|
|
57
49
|
const handleChange = useCallback(
|
|
58
50
|
({ to, from }: yup.InferType<typeof schema>) => {
|
|
59
|
-
onChange(
|
|
60
|
-
`${from.part}${from.op}${from.diff}|${to.part}${to.op}${to.diff}`,
|
|
61
|
-
);
|
|
51
|
+
onChange?.(`${from.part}${from.op}${from.diff}|${to.part}${to.op}${to.diff}`);
|
|
62
52
|
},
|
|
63
|
-
[],
|
|
53
|
+
[onChange],
|
|
64
54
|
);
|
|
65
55
|
|
|
66
56
|
const defaultValue = useMemo(() => {
|
|
67
|
-
if (value
|
|
57
|
+
if (value.match(/^(\$\w+)([+-])(\d+)?\|(\$\w+)([+-])(\d+)?$/)) {
|
|
68
58
|
const [, part, op, diff = "0"] =
|
|
69
59
|
value
|
|
70
60
|
.split("|")
|
|
71
61
|
.shift()
|
|
72
|
-
|
|
62
|
+
?.match(/^(\$\w+)([+-])(\d+)?$/) ?? [];
|
|
73
63
|
const [, toPart, toOp, toDiff = "0"] =
|
|
74
64
|
value
|
|
75
65
|
.split("|")
|
|
76
66
|
.pop()
|
|
77
|
-
|
|
67
|
+
?.match(/^(\$\w+)([+-])(\d+)?$/) ?? [];
|
|
78
68
|
return {
|
|
79
|
-
from: { part, op, diff },
|
|
80
|
-
to: { part: toPart, op: toOp, diff: toDiff },
|
|
81
|
-
}
|
|
69
|
+
from: { part, op, diff: +diff },
|
|
70
|
+
to: { part: toPart, op: toOp, diff: +toDiff },
|
|
71
|
+
} as yup.InferType<typeof schema>;
|
|
82
72
|
}
|
|
83
73
|
}, [value]);
|
|
84
74
|
|
|
85
75
|
return (
|
|
86
76
|
<Content>
|
|
87
77
|
<div className="scale-90">
|
|
88
|
-
<Form
|
|
89
|
-
resolver={yupResolver(schema)}
|
|
90
|
-
defaultValues={defaultValue}
|
|
91
|
-
onSubmit={handleChange}
|
|
92
|
-
>
|
|
78
|
+
<Form resolver={yupResolver(schema)} defaultValues={defaultValue} onSubmit={handleChange}>
|
|
93
79
|
<RelativeInput label={t("label.from")} prefix="from" />
|
|
94
80
|
<RelativeInput label={t("label.to")} prefix="to" />
|
|
95
81
|
<div className="flex justify-end">
|
|
96
|
-
<Button
|
|
97
|
-
variant="solid"
|
|
98
|
-
color="primary"
|
|
99
|
-
size="sm"
|
|
100
|
-
type="submit"
|
|
101
|
-
data-dropdown-dismiss="true"
|
|
102
|
-
>
|
|
82
|
+
<Button variant="solid" color="primary" size="sm" type="submit" data-dropdown-dismiss="true">
|
|
103
83
|
{t("label.apply")}
|
|
104
84
|
</Button>
|
|
105
85
|
</div>
|
|
@@ -107,4 +87,4 @@ export const RelativePanel = ({ value = "", onChange }: KeyValue) => {
|
|
|
107
87
|
</div>
|
|
108
88
|
</Content>
|
|
109
89
|
);
|
|
110
|
-
}
|
|
90
|
+
}
|