@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.
- package/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/cjs/components/Date.module.css +1 -0
- package/dist/cjs/components/DateCell.js +98 -0
- package/dist/cjs/components/DateHeader.js +142 -0
- package/dist/cjs/components/DatePage.js +59 -0
- package/dist/cjs/components/DecadePage.js +34 -0
- package/dist/cjs/components/MonthPage.js +33 -0
- package/dist/cjs/components/TimeSliders.js +131 -0
- package/dist/cjs/components/YearPage.js +34 -0
- package/dist/cjs/display/DateDisplay.js +35 -0
- package/dist/cjs/hijri/index.js +1029 -0
- package/dist/cjs/i18n/ar.json.js +25 -0
- package/dist/cjs/i18n/en.json.js +21 -0
- package/dist/cjs/i18n/index.js +39 -0
- package/dist/cjs/i18n/superdate/ar.json.js +86 -0
- package/dist/cjs/i18n/superdate/en.json.js +93 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/panels/BasePanel.js +73 -0
- package/dist/cjs/panels/DatePanel.js +205 -0
- package/dist/cjs/panels/RangePanel.js +340 -0
- package/dist/cjs/superdate/EventPanel.js +173 -0
- package/dist/cjs/superdate/QuickSelect.js +134 -0
- package/dist/cjs/superdate/RelativeInput.js +79 -0
- package/dist/cjs/superdate/RelativePanel.js +91 -0
- package/dist/cjs/superdate/SuperDate.module.css +1 -0
- package/dist/cjs/superdate/Superdate.js +169 -0
- package/dist/cjs/types/index.js +61 -0
- package/dist/cjs/utils/dateUtil.js +436 -0
- package/dist/esm/components/Date.module.css +1 -0
- package/dist/esm/components/DateCell.js +98 -0
- package/dist/esm/components/DateHeader.js +142 -0
- package/dist/esm/components/DatePage.js +59 -0
- package/dist/esm/components/DecadePage.js +34 -0
- package/dist/esm/components/MonthPage.js +33 -0
- package/dist/esm/components/TimeSliders.js +131 -0
- package/dist/esm/components/YearPage.js +34 -0
- package/dist/esm/display/DateDisplay.js +35 -0
- package/dist/esm/hijri/index.js +1029 -0
- package/dist/esm/i18n/ar.json.js +21 -0
- package/dist/esm/i18n/en.json.js +18 -0
- package/dist/esm/i18n/index.js +39 -0
- package/dist/esm/i18n/superdate/ar.json.js +79 -0
- package/dist/esm/i18n/superdate/en.json.js +85 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/panels/BasePanel.js +73 -0
- package/dist/esm/panels/DatePanel.js +205 -0
- package/dist/esm/panels/RangePanel.js +340 -0
- package/dist/esm/superdate/EventPanel.js +173 -0
- package/dist/esm/superdate/QuickSelect.js +134 -0
- package/dist/esm/superdate/RelativeInput.js +79 -0
- package/dist/esm/superdate/RelativePanel.js +91 -0
- package/dist/esm/superdate/SuperDate.module.css +1 -0
- package/dist/esm/superdate/Superdate.js +168 -0
- package/dist/esm/types/index.js +60 -0
- package/dist/esm/utils/dateUtil.js +438 -0
- package/dist/types/components/DateCell.d.ts +15 -0
- package/dist/types/components/DateHeader.d.ts +14 -0
- package/dist/types/components/DatePage.d.ts +6 -0
- package/dist/types/components/DecadePage.d.ts +6 -0
- package/dist/types/components/MonthPage.d.ts +6 -0
- package/dist/types/components/TimeSliders.d.ts +10 -0
- package/dist/types/components/YearPage.d.ts +6 -0
- package/dist/types/display/DateDisplay.d.ts +15 -0
- package/dist/types/hijri/index.d.ts +2 -0
- package/dist/types/i18n/index.d.ts +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/panels/BasePanel.d.ts +25 -0
- package/dist/types/panels/DatePanel.d.ts +2 -0
- package/dist/types/panels/RangePanel.d.ts +2 -0
- package/dist/types/superdate/EventPanel.d.ts +4 -0
- package/dist/types/superdate/QuickSelect.d.ts +1 -0
- package/dist/types/superdate/RelativeInput.d.ts +1 -0
- package/dist/types/superdate/RelativePanel.d.ts +1 -0
- package/dist/types/superdate/Superdate.d.ts +17 -0
- package/dist/types/types/index.d.ts +70 -0
- package/dist/types/utils/dateUtil.d.ts +30 -0
- package/package.json +58 -0
- package/src/components/Date.module.css +75 -0
- package/src/components/DateCell.tsx +181 -0
- package/src/components/DateHeader.tsx +223 -0
- package/src/components/DatePage.tsx +107 -0
- package/src/components/DecadePage.tsx +53 -0
- package/src/components/MonthPage.tsx +52 -0
- package/src/components/TimeSliders.tsx +196 -0
- package/src/components/YearPage.tsx +53 -0
- package/src/display/DateDisplay.tsx +88 -0
- package/src/hijri/index.js +1540 -0
- package/src/i18n/ar.json +14 -0
- package/src/i18n/en.json +13 -0
- package/src/i18n/index.ts +31 -0
- package/src/i18n/superdate/ar.json +70 -0
- package/src/i18n/superdate/en.json +75 -0
- package/src/index.ts +32 -0
- package/src/panels/BasePanel.tsx +130 -0
- package/src/panels/DatePanel.tsx +235 -0
- package/src/panels/RangePanel.tsx +400 -0
- package/src/superdate/EventPanel.tsx +200 -0
- package/src/superdate/QuickSelect.tsx +121 -0
- package/src/superdate/RelativeInput.tsx +64 -0
- package/src/superdate/RelativePanel.tsx +103 -0
- package/src/superdate/SuperDate.module.css +30 -0
- package/src/superdate/Superdate.tsx +186 -0
- package/src/types/index.ts +121 -0
- package/src/utils/dateUtil.ts +551 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
var label = {
|
|
4
|
+
prevMonth: "الشهر الماضى",
|
|
5
|
+
prevYear: "السنة الماضية",
|
|
6
|
+
prevDecade: "العقد السابق",
|
|
7
|
+
nextMonth: "الشهر القادم",
|
|
8
|
+
nextYear: "العام القادم",
|
|
9
|
+
nextDecade: "العقد القادم",
|
|
10
|
+
today: "اليوم",
|
|
11
|
+
hijri: "هجري",
|
|
12
|
+
gregorian: "ميلادي"
|
|
13
|
+
};
|
|
14
|
+
var number = {
|
|
15
|
+
};
|
|
16
|
+
var ar = {
|
|
17
|
+
label: label,
|
|
18
|
+
number: number
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { ar as default, label, number };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
var label = {
|
|
4
|
+
prevMonth: "Previous Month",
|
|
5
|
+
prevYear: "Previous Year",
|
|
6
|
+
prevDecade: "Previous Decade",
|
|
7
|
+
nextMonth: "Next Month",
|
|
8
|
+
nextYear: "Next Year",
|
|
9
|
+
nextDecade: "Next Decade",
|
|
10
|
+
today: "Today",
|
|
11
|
+
hijri: "Hijri",
|
|
12
|
+
gregorian: "Gregorian"
|
|
13
|
+
};
|
|
14
|
+
var en = {
|
|
15
|
+
label: label
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { en as default, label };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { addTranslationBundle } from '@react-fabric/core';
|
|
4
|
+
import ar from './ar.json.js';
|
|
5
|
+
import en from './en.json.js';
|
|
6
|
+
import arSuper from './superdate/ar.json.js';
|
|
7
|
+
import enSuper from './superdate/en.json.js';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* React Fabric
|
|
11
|
+
* @version: 1.0.0
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* The MIT License (MIT)
|
|
15
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
16
|
+
*
|
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
18
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
19
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
20
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
21
|
+
* subject to the following conditions:
|
|
22
|
+
*
|
|
23
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
24
|
+
* portions of the Software.
|
|
25
|
+
*
|
|
26
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
27
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
28
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
29
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
addTranslationBundle("date", {
|
|
33
|
+
en: en,
|
|
34
|
+
ar: ar
|
|
35
|
+
});
|
|
36
|
+
addTranslationBundle("superdate", {
|
|
37
|
+
en: enSuper,
|
|
38
|
+
ar: arSuper
|
|
39
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
var separator = " ⇽ ";
|
|
4
|
+
var label = {
|
|
5
|
+
quick: "حدد مسرعا",
|
|
6
|
+
relative: "نسبيا",
|
|
7
|
+
events: "الأحداث",
|
|
8
|
+
absolute: "مطلق",
|
|
9
|
+
preset: "المسبقة",
|
|
10
|
+
current: "تيار",
|
|
11
|
+
previous: "السابق",
|
|
12
|
+
from: "من عند",
|
|
13
|
+
to: "إلى",
|
|
14
|
+
"+": "من الان",
|
|
15
|
+
"-": "منذ",
|
|
16
|
+
apply: "يتقدم",
|
|
17
|
+
$now: "الآن",
|
|
18
|
+
$minute: "دقيقة",
|
|
19
|
+
$hour: "ساعة",
|
|
20
|
+
$day: "يوم",
|
|
21
|
+
$week: "أسبوع",
|
|
22
|
+
$month: "شهر",
|
|
23
|
+
$quarter: "ربع",
|
|
24
|
+
$year: "عام",
|
|
25
|
+
$decade: "عقد"
|
|
26
|
+
};
|
|
27
|
+
var now = {
|
|
28
|
+
$day: "اليوم",
|
|
29
|
+
$week: "هذا الاسبوع",
|
|
30
|
+
$month: "هذا الشهر",
|
|
31
|
+
$quarter: "هذا الربع",
|
|
32
|
+
$year: "هذه السنة",
|
|
33
|
+
$decade: "هذا العقد"
|
|
34
|
+
};
|
|
35
|
+
var next = {
|
|
36
|
+
$day: "غدا",
|
|
37
|
+
$week: "الاسبوع القادم",
|
|
38
|
+
$month: "الشهر القادم",
|
|
39
|
+
$quarter: "الربع القادم",
|
|
40
|
+
$year: "العام القادم",
|
|
41
|
+
$decade: "العقد القادم",
|
|
42
|
+
$minute: "بعد دقيقة",
|
|
43
|
+
$hour: "بعد ساعة",
|
|
44
|
+
$minute_plural: "بعد {{count}} دقائق",
|
|
45
|
+
$hour_plural: "بعد {{count}} ساعات",
|
|
46
|
+
$day_plural: "بعد {{count}} أيام",
|
|
47
|
+
$week_plural: "بعد {{count}} أسابيع",
|
|
48
|
+
$month_plural: "بعد {{count}} أشهر",
|
|
49
|
+
$quarter_plural: "بعد {{count}} أرباع",
|
|
50
|
+
$year_plural: "بعد {{count}} سنوات",
|
|
51
|
+
$decade_plural: "بعد {{count}} عقود"
|
|
52
|
+
};
|
|
53
|
+
var prev = {
|
|
54
|
+
$day: "في الامس",
|
|
55
|
+
$week: "الاسبوع الماضي",
|
|
56
|
+
$month: "الشهر الماضي",
|
|
57
|
+
$quarter: "الربع الأخير",
|
|
58
|
+
$year: "العام الماضي",
|
|
59
|
+
$decade: "العقد الماضي",
|
|
60
|
+
$minute: "منذ دقيقة",
|
|
61
|
+
$hour: "منذ ساعة",
|
|
62
|
+
$minute_plural: "منذ {{count}} دقيقة",
|
|
63
|
+
$hour_plural: "منذ {{count}} ساعات",
|
|
64
|
+
$day_plural: "منذ {{count}} أيام",
|
|
65
|
+
$week_plural: "من {{count}} اسابيع",
|
|
66
|
+
$month_plural: "قبل {{count}} أشهر",
|
|
67
|
+
$quarter_plural: "منذ {{count}} أرباع",
|
|
68
|
+
$year_plural: "منذ {{count}} سنوات",
|
|
69
|
+
$decade_plural: "منذ {{count}} عقود"
|
|
70
|
+
};
|
|
71
|
+
var arSuper = {
|
|
72
|
+
separator: separator,
|
|
73
|
+
label: label,
|
|
74
|
+
now: now,
|
|
75
|
+
next: next,
|
|
76
|
+
prev: prev
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export { arSuper as default, label, next, now, prev, separator };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
var separator = " ⇾ ";
|
|
4
|
+
var event = {
|
|
5
|
+
ramadan: "Ramadan",
|
|
6
|
+
christmas: "Christmas",
|
|
7
|
+
newYear: "New Year"
|
|
8
|
+
};
|
|
9
|
+
var label = {
|
|
10
|
+
quick: "Quick Select",
|
|
11
|
+
relative: "Relative",
|
|
12
|
+
absolute: "Absolute",
|
|
13
|
+
events: "Events",
|
|
14
|
+
preset: "Presets",
|
|
15
|
+
current: "Current",
|
|
16
|
+
previous: "Previous",
|
|
17
|
+
from: "From",
|
|
18
|
+
to: "To",
|
|
19
|
+
"+": "From now",
|
|
20
|
+
"-": "Ago",
|
|
21
|
+
apply: "Apply",
|
|
22
|
+
$now: "Now",
|
|
23
|
+
$minute: "Minute",
|
|
24
|
+
$hour: "Hour",
|
|
25
|
+
$day: "Day",
|
|
26
|
+
$week: "Week",
|
|
27
|
+
$month: "Month",
|
|
28
|
+
$quarter: "Quarter",
|
|
29
|
+
$year: "Year",
|
|
30
|
+
$decade: "Decade"
|
|
31
|
+
};
|
|
32
|
+
var now = {
|
|
33
|
+
$day: "Today",
|
|
34
|
+
$week: "This week",
|
|
35
|
+
$month: "This month",
|
|
36
|
+
$quarter: "This quarter",
|
|
37
|
+
$year: "This year",
|
|
38
|
+
$decade: "This decade"
|
|
39
|
+
};
|
|
40
|
+
var next = {
|
|
41
|
+
$day: "Tomorrow",
|
|
42
|
+
$week: "Next week",
|
|
43
|
+
$month: "Next month",
|
|
44
|
+
$quarter: "Next quarter",
|
|
45
|
+
$year: "Next year",
|
|
46
|
+
$decade: "Next decade",
|
|
47
|
+
$minute: "A minute later",
|
|
48
|
+
$hour: "An hour later",
|
|
49
|
+
$minute_other: "{{count}} minutes later",
|
|
50
|
+
$hour_other: "{{count}} hours later",
|
|
51
|
+
$day_other: "{{count}} days later",
|
|
52
|
+
$week_other: "{{count}} weeks later",
|
|
53
|
+
$month_other: "{{count}} months later",
|
|
54
|
+
$quarter_other: "{{count}} quarters later",
|
|
55
|
+
$year_other: "{{count}} years later",
|
|
56
|
+
$decade_other: "{{count}} decades later"
|
|
57
|
+
};
|
|
58
|
+
var prev = {
|
|
59
|
+
$day: "Yesterday",
|
|
60
|
+
$week: "Last week",
|
|
61
|
+
$month: "Last month",
|
|
62
|
+
$quarter: "Last quarter",
|
|
63
|
+
$year: "Last year",
|
|
64
|
+
$decade: "Last decade",
|
|
65
|
+
$minute: "A minute ago",
|
|
66
|
+
$hour: "An hour ago",
|
|
67
|
+
$minute_other: "{{count}} minutes ago",
|
|
68
|
+
$hour_other: "{{count}} hours ago",
|
|
69
|
+
$day_other: "{{count}} days ago",
|
|
70
|
+
$week_other: "{{count}} weeks ago",
|
|
71
|
+
$month_other: "{{count}} months ago",
|
|
72
|
+
$quarter_other: "{{count}} quarters ago",
|
|
73
|
+
$year_other: "{{count}} years ago",
|
|
74
|
+
$decade_other: "{{count}} decades ago"
|
|
75
|
+
};
|
|
76
|
+
var enSuper = {
|
|
77
|
+
separator: separator,
|
|
78
|
+
event: event,
|
|
79
|
+
label: label,
|
|
80
|
+
now: now,
|
|
81
|
+
next: next,
|
|
82
|
+
prev: prev
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export { enSuper as default, event, label, next, now, prev, separator };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import './hijri/index.js';
|
|
4
|
+
import './i18n/index.js';
|
|
5
|
+
export { DateDisplay } from './display/DateDisplay.js';
|
|
6
|
+
export { DatePanel } from './panels/DatePanel.js';
|
|
7
|
+
export { RangePanel } from './panels/RangePanel.js';
|
|
8
|
+
export { SuperDate } from './superdate/Superdate.js';
|
|
9
|
+
export { DateUtil } from './utils/dateUtil.js';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
5
|
+
import { DateHeader } from '../components/DateHeader.js';
|
|
6
|
+
import { DatePage } from '../components/DatePage.js';
|
|
7
|
+
import { DecadePage } from '../components/DecadePage.js';
|
|
8
|
+
import { MonthPage } from '../components/MonthPage.js';
|
|
9
|
+
import { TimeSlider } from '../components/TimeSliders.js';
|
|
10
|
+
import { YearPage } from '../components/YearPage.js';
|
|
11
|
+
import { PageType } from '../types/index.js';
|
|
12
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
var _excluded = ["min", "max", "isHijri", "withTime", "hideNext", "hidePrevious", "changePage", "changePageDate", "changeTime", "selectDate", "isDateDisabled"];
|
|
15
|
+
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; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).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; }
|
|
17
|
+
var BasePanel = function BasePanel(_ref) {
|
|
18
|
+
var min = _ref.min,
|
|
19
|
+
max = _ref.max,
|
|
20
|
+
isHijri = _ref.isHijri,
|
|
21
|
+
withTime = _ref.withTime,
|
|
22
|
+
hideNext = _ref.hideNext,
|
|
23
|
+
hidePrevious = _ref.hidePrevious,
|
|
24
|
+
changePage = _ref.changePage,
|
|
25
|
+
_changePageDate = _ref.changePageDate,
|
|
26
|
+
changeTime = _ref.changeTime,
|
|
27
|
+
selectDate = _ref.selectDate,
|
|
28
|
+
isDateDisabled = _ref.isDateDisabled,
|
|
29
|
+
state = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
+
return /*#__PURE__*/jsxs("div", {
|
|
31
|
+
className: "grid overflow-hidden select-none",
|
|
32
|
+
style: {
|
|
33
|
+
gridTemplate: "\"head head\" auto \"content time\" 1fr / 1fr auto"
|
|
34
|
+
},
|
|
35
|
+
children: [/*#__PURE__*/jsx(DateHeader, _objectSpread(_objectSpread({}, state), {}, {
|
|
36
|
+
min: min,
|
|
37
|
+
max: max,
|
|
38
|
+
hideNext: hideNext,
|
|
39
|
+
hidePrevious: hidePrevious,
|
|
40
|
+
isHijri: isHijri,
|
|
41
|
+
changePage: changePage,
|
|
42
|
+
changePageDate: function changePageDate(dt) {
|
|
43
|
+
return _changePageDate(dt, false);
|
|
44
|
+
}
|
|
45
|
+
})), /*#__PURE__*/jsx(DatePage, _objectSpread(_objectSpread({}, state), {}, {
|
|
46
|
+
isHijri: isHijri,
|
|
47
|
+
selectDate: selectDate,
|
|
48
|
+
dateDisabled: isDateDisabled,
|
|
49
|
+
changePageDate: _changePageDate
|
|
50
|
+
})), state.page === PageType.MONTH && /*#__PURE__*/jsx(MonthPage, _objectSpread(_objectSpread({}, state), {}, {
|
|
51
|
+
isHijri: isHijri,
|
|
52
|
+
selectDate: selectDate,
|
|
53
|
+
dateDisabled: isDateDisabled,
|
|
54
|
+
changePageDate: _changePageDate
|
|
55
|
+
})), state.page === PageType.YEAR && /*#__PURE__*/jsx(YearPage, _objectSpread(_objectSpread({}, state), {}, {
|
|
56
|
+
isHijri: isHijri,
|
|
57
|
+
selectDate: selectDate,
|
|
58
|
+
dateDisabled: isDateDisabled,
|
|
59
|
+
changePageDate: _changePageDate
|
|
60
|
+
})), state.page === PageType.DECADE && /*#__PURE__*/jsx(DecadePage, _objectSpread(_objectSpread({}, state), {}, {
|
|
61
|
+
isHijri: isHijri,
|
|
62
|
+
selectDate: selectDate,
|
|
63
|
+
dateDisabled: isDateDisabled,
|
|
64
|
+
changePageDate: _changePageDate
|
|
65
|
+
})), withTime && state.page === PageType.DATE && /*#__PURE__*/jsx(TimeSlider, {
|
|
66
|
+
hour: state.hour,
|
|
67
|
+
minute: state.minute,
|
|
68
|
+
onTimeChange: changeTime
|
|
69
|
+
})]
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { BasePanel };
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
6
|
+
import { useGlobals, useDebounce, Button } from '@react-fabric/core';
|
|
7
|
+
import { isEmpty, isArray } from '@react-fabric/utilities';
|
|
8
|
+
import classNames from 'classnames';
|
|
9
|
+
import { isBefore, isAfter, isSameDay } from 'date-fns';
|
|
10
|
+
import { useState, useEffect, useReducer, useCallback } from 'react';
|
|
11
|
+
import { useTranslation } from 'react-i18next';
|
|
12
|
+
import { PageType } from '../types/index.js';
|
|
13
|
+
import { DateUtil } from '../utils/dateUtil.js';
|
|
14
|
+
import { BasePanel } from './BasePanel.js';
|
|
15
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
16
|
+
|
|
17
|
+
var _excluded = ["className", "max", "min", "dateDisabled", "onChange", "showHijriToggle", "value", "withTime"];
|
|
18
|
+
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; }
|
|
19
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).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; }
|
|
20
|
+
var DatePanel = function DatePanel(_ref) {
|
|
21
|
+
var className = _ref.className,
|
|
22
|
+
max = _ref.max,
|
|
23
|
+
min = _ref.min,
|
|
24
|
+
dateDisabled = _ref.dateDisabled,
|
|
25
|
+
onChange = _ref.onChange,
|
|
26
|
+
showHijriToggle = _ref.showHijriToggle,
|
|
27
|
+
value = _ref.value,
|
|
28
|
+
withTime = _ref.withTime,
|
|
29
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
+
var _useTranslation = useTranslation("date"),
|
|
31
|
+
t = _useTranslation.t;
|
|
32
|
+
var _useGlobals = useGlobals(),
|
|
33
|
+
currentCalendar = _useGlobals.currentCalendar;
|
|
34
|
+
var _useState = useState(currentCalendar === "hijri"),
|
|
35
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
36
|
+
isHijri = _useState2[0],
|
|
37
|
+
setHijri = _useState2[1];
|
|
38
|
+
var _useState3 = useState(true),
|
|
39
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
40
|
+
canSelectToday = _useState4[0],
|
|
41
|
+
setCanSelectToday = _useState4[1];
|
|
42
|
+
var fireChange = useDebounce(onChange, [onChange]);
|
|
43
|
+
useEffect(function () {
|
|
44
|
+
setHijri(currentCalendar === "hijri");
|
|
45
|
+
}, [currentCalendar]);
|
|
46
|
+
var _useReducer = useReducer(function (state, action) {
|
|
47
|
+
if (action.type === "reset") {
|
|
48
|
+
if (!isEmpty(action.date)) {
|
|
49
|
+
var date = new Date(action.date);
|
|
50
|
+
state.selected = date;
|
|
51
|
+
state.pageDate = date;
|
|
52
|
+
state.hour = date.getHours();
|
|
53
|
+
state.minute = date.getMinutes();
|
|
54
|
+
} else {
|
|
55
|
+
state.selected = undefined;
|
|
56
|
+
state.pageDate = new Date();
|
|
57
|
+
state.hour = 0;
|
|
58
|
+
state.minute = 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (action.type === "changeDate") {
|
|
62
|
+
action.date.setHours(state.hour);
|
|
63
|
+
action.date.setMinutes(state.minute);
|
|
64
|
+
state.selected = action.date;
|
|
65
|
+
state.pageDate = action.date;
|
|
66
|
+
}
|
|
67
|
+
if (action.type === "changeTime") {
|
|
68
|
+
var _state$selected, _state$selected2;
|
|
69
|
+
(_state$selected = state.selected) === null || _state$selected === void 0 || _state$selected.setHours(action.hour);
|
|
70
|
+
(_state$selected2 = state.selected) === null || _state$selected2 === void 0 || _state$selected2.setMinutes(action.minute);
|
|
71
|
+
state.hour = action.hour;
|
|
72
|
+
state.minute = action.minute;
|
|
73
|
+
}
|
|
74
|
+
if (action.type === "changePage") {
|
|
75
|
+
state.page = action.page;
|
|
76
|
+
}
|
|
77
|
+
if (action.type === "changePageDate") {
|
|
78
|
+
state.pageDate = action.date;
|
|
79
|
+
action.pageChange && (state.page = Math.max(state.page - 1, 0));
|
|
80
|
+
}
|
|
81
|
+
if (action.type === "changeDate" || action.type === "changeTime") {
|
|
82
|
+
if (min && state.selected && isBefore(state.selected, new Date(min))) {
|
|
83
|
+
state.selected = new Date(min);
|
|
84
|
+
state.hour = state.selected.getHours();
|
|
85
|
+
state.minute = state.selected.getMinutes();
|
|
86
|
+
}
|
|
87
|
+
if (max && state.selected && isAfter(state.selected, new Date(max))) {
|
|
88
|
+
state.selected = new Date(max);
|
|
89
|
+
state.hour = state.selected.getHours();
|
|
90
|
+
state.minute = state.selected.getMinutes();
|
|
91
|
+
}
|
|
92
|
+
state.selected && (fireChange === null || fireChange === void 0 ? void 0 : fireChange(state.selected.toISOString()));
|
|
93
|
+
}
|
|
94
|
+
return _objectSpread({}, state);
|
|
95
|
+
}, {
|
|
96
|
+
page: PageType.DATE,
|
|
97
|
+
pageDate: new Date(),
|
|
98
|
+
hour: 0,
|
|
99
|
+
minute: 0
|
|
100
|
+
}),
|
|
101
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
102
|
+
state = _useReducer2[0],
|
|
103
|
+
dispatch = _useReducer2[1];
|
|
104
|
+
useEffect(function () {
|
|
105
|
+
var canSelect = true;
|
|
106
|
+
if (min && canSelect) {
|
|
107
|
+
canSelect = isAfter(new Date(), min);
|
|
108
|
+
}
|
|
109
|
+
if (max && canSelect) {
|
|
110
|
+
canSelect = isBefore(new Date(), max);
|
|
111
|
+
}
|
|
112
|
+
setCanSelectToday(canSelect);
|
|
113
|
+
}, [min, max]);
|
|
114
|
+
useEffect(function () {
|
|
115
|
+
dispatch({
|
|
116
|
+
type: "reset",
|
|
117
|
+
date: value
|
|
118
|
+
});
|
|
119
|
+
}, [value]);
|
|
120
|
+
var isDateDisabled = useCallback(function (dt) {
|
|
121
|
+
if (state.page === PageType.DATE) {
|
|
122
|
+
if (isArray(dateDisabled)) {
|
|
123
|
+
return !!dateDisabled.find(function (dd) {
|
|
124
|
+
return isSameDay(new Date(dd), dt);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return DateUtil.isDisabled(dt, state.page, min, max);
|
|
129
|
+
}, [state.page, min, max, dateDisabled]);
|
|
130
|
+
var changePageDate = useCallback(function (date) {
|
|
131
|
+
var pageChange = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
132
|
+
dispatch({
|
|
133
|
+
type: "changePageDate",
|
|
134
|
+
pageChange: pageChange,
|
|
135
|
+
date: date
|
|
136
|
+
});
|
|
137
|
+
}, []);
|
|
138
|
+
var selectDate = useCallback(function (date) {
|
|
139
|
+
dispatch({
|
|
140
|
+
type: "changeDate",
|
|
141
|
+
date: date
|
|
142
|
+
});
|
|
143
|
+
}, []);
|
|
144
|
+
return /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
|
|
145
|
+
className: classNames("block overflow-hidden bg-base rounded-capped", className)
|
|
146
|
+
}, rest), {}, {
|
|
147
|
+
children: [/*#__PURE__*/jsx(BasePanel, _objectSpread(_objectSpread({}, state), {}, {
|
|
148
|
+
max: max,
|
|
149
|
+
min: min,
|
|
150
|
+
withTime: withTime,
|
|
151
|
+
isHijri: isHijri,
|
|
152
|
+
selectDate: selectDate,
|
|
153
|
+
isDateDisabled: isDateDisabled,
|
|
154
|
+
changeTime: function changeTime(time) {
|
|
155
|
+
return dispatch(_objectSpread({
|
|
156
|
+
type: "changeTime"
|
|
157
|
+
}, time));
|
|
158
|
+
},
|
|
159
|
+
changePage: function changePage(page) {
|
|
160
|
+
return dispatch({
|
|
161
|
+
type: "changePage",
|
|
162
|
+
page: page
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
changePageDate: changePageDate
|
|
166
|
+
})), /*#__PURE__*/jsxs("div", {
|
|
167
|
+
className: "border-t flex flex-nowrap justify-between px-2",
|
|
168
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
169
|
+
children: showHijriToggle && /*#__PURE__*/jsx(Button, {
|
|
170
|
+
size: "sm",
|
|
171
|
+
variant: "link",
|
|
172
|
+
color: "primary",
|
|
173
|
+
className: "my-1",
|
|
174
|
+
onClick: function onClick() {
|
|
175
|
+
setHijri(!isHijri);
|
|
176
|
+
},
|
|
177
|
+
children: t(isHijri ? "label.gregorian" : "label.hijri")
|
|
178
|
+
})
|
|
179
|
+
}), state.page === PageType.DATE && canSelectToday && /*#__PURE__*/jsx(Button, {
|
|
180
|
+
size: "sm",
|
|
181
|
+
variant: "link",
|
|
182
|
+
color: "primary",
|
|
183
|
+
className: "my-1",
|
|
184
|
+
onClick: function onClick() {
|
|
185
|
+
return selectDate(new Date());
|
|
186
|
+
},
|
|
187
|
+
children: t("label.today")
|
|
188
|
+
}), state.page !== PageType.DATE && /*#__PURE__*/jsx(Button, {
|
|
189
|
+
size: "sm",
|
|
190
|
+
variant: "link",
|
|
191
|
+
color: "primary",
|
|
192
|
+
className: "my-1",
|
|
193
|
+
onClick: function onClick() {
|
|
194
|
+
return dispatch({
|
|
195
|
+
type: "changePage",
|
|
196
|
+
page: PageType.DATE
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
children: t("core:action.cancel")
|
|
200
|
+
})]
|
|
201
|
+
})]
|
|
202
|
+
}));
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export { DatePanel };
|