@react-fabric/date 1.0.0-beta.46 → 1.0.0-beta.48

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.
@@ -4,6 +4,7 @@ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
4
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
5
5
  var core = require('@react-fabric/core');
6
6
  var dateUtil = require('../utils/dateUtil.js');
7
+ var classNames = require('classnames');
7
8
  var jsxRuntime = require('react/jsx-runtime');
8
9
 
9
10
  var _excluded = ["date", "className", "format", "children", "showAlternateDate"];
@@ -24,7 +25,7 @@ var DateDisplay = function DateDisplay(_ref) {
24
25
  disabled: !showAlternateDate,
25
26
  content: dateUtil.DateUtil.format(date, format, currentLocale, currentCalendar !== "hijri"),
26
27
  children: /*#__PURE__*/jsxRuntime.jsx("span", _objectSpread(_objectSpread({
27
- className: className
28
+ className: classNames(className, children && "underline decoration-dotted cursor-pointer")
28
29
  }, aria), {}, {
29
30
  children: dateUtil.DateUtil.format(date, format, currentLocale, currentCalendar === "hijri")
30
31
  }))
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
+ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
5
+ var core = require('@react-fabric/core');
6
+ var utilities = require('@react-fabric/utilities');
7
+ var classNames = require('classnames');
8
+ var dateFns = require('date-fns');
9
+ var react = require('react');
10
+ var reactI18next = require('react-i18next');
11
+ var dateUtil = require('../utils/dateUtil.js');
12
+ var jsxRuntime = require('react/jsx-runtime');
13
+
14
+ var _excluded = ["date", "children", "className", "format"];
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 DateDuration = function DateDuration(_ref) {
18
+ var date = _ref.date,
19
+ children = _ref.children,
20
+ className = _ref.className,
21
+ _ref$format = _ref.format,
22
+ format = _ref$format === void 0 ? "PPpp" : _ref$format,
23
+ props = _objectWithoutProperties(_ref, _excluded);
24
+ var _useTranslation = reactI18next.useTranslation("date"),
25
+ t = _useTranslation.t;
26
+ var interval = react.useMemo(function () {
27
+ return dateFns.intervalToDuration({
28
+ start: new Date(date),
29
+ end: new Date()
30
+ });
31
+ }, [date]);
32
+ var label = react.useMemo(function () {
33
+ var before = dateFns.isBefore(dateUtil.DateUtil.parseDate(date), new Date());
34
+ var tkey = before ? "relative.before" : "relative.after";
35
+ var part = "now";
36
+ var count = 0;
37
+ if (interval.years && interval.years > 0) {
38
+ var _interval$months;
39
+ part = "years";
40
+ count = interval.years;
41
+ if (((_interval$months = interval.months) !== null && _interval$months !== void 0 ? _interval$months : 0) > 10) {
42
+ part = "yearsX";
43
+ count += 1;
44
+ }
45
+ } else if (interval.months && interval.months > 0) {
46
+ var _interval$weeks;
47
+ part = "months";
48
+ count = interval.months;
49
+ if (interval.months > 10) {
50
+ part = "yearsX";
51
+ count = 1;
52
+ } else if (((_interval$weeks = interval.weeks) !== null && _interval$weeks !== void 0 ? _interval$weeks : 0) > 3) {
53
+ part = "monthsX";
54
+ count += 1;
55
+ }
56
+ } else if (interval.weeks && interval.weeks > 0) {
57
+ var _interval$days;
58
+ part = "weeks";
59
+ count = interval.weeks;
60
+ if (interval.weeks > 3) {
61
+ part = "monthsX";
62
+ count = 1;
63
+ } else if (((_interval$days = interval.days) !== null && _interval$days !== void 0 ? _interval$days : 0) > 5) {
64
+ part = "weeksX";
65
+ count += 1;
66
+ }
67
+ } else if (interval.days && interval.days > 0) {
68
+ var _interval$hours;
69
+ part = "days";
70
+ count = interval.days;
71
+ if (interval.days > 5) {
72
+ part = "weeksX";
73
+ count = 1;
74
+ } else if (((_interval$hours = interval.hours) !== null && _interval$hours !== void 0 ? _interval$hours : 0) > 20) {
75
+ part = "daysX";
76
+ count += 1;
77
+ }
78
+ } else if (interval.hours && interval.hours > 0) {
79
+ var _interval$minutes;
80
+ part = "hours";
81
+ count = interval.hours;
82
+ if (interval.hours > 20) {
83
+ part = "daysX";
84
+ count = 1;
85
+ } else if (((_interval$minutes = interval.minutes) !== null && _interval$minutes !== void 0 ? _interval$minutes : 0) > 45) {
86
+ part = "hoursX";
87
+ count += 1;
88
+ }
89
+ } else if (interval.minutes && interval.minutes > 0) {
90
+ var _interval$seconds;
91
+ part = "minutes";
92
+ count = interval.minutes;
93
+ if (interval.minutes > 45) {
94
+ part = "hoursX";
95
+ count = 1;
96
+ } else if (((_interval$seconds = interval.seconds) !== null && _interval$seconds !== void 0 ? _interval$seconds : 0) > 45) {
97
+ part = "minuteX";
98
+ count += 1;
99
+ }
100
+ } else if (interval.seconds && interval.seconds > 15) {
101
+ part = "seconds";
102
+ count = interval.seconds;
103
+ if (interval.seconds > 45) {
104
+ part = "minutesX";
105
+ count = 1;
106
+ }
107
+ }
108
+ return t("".concat(tkey, ".").concat(part), {
109
+ count: count
110
+ });
111
+ }, [interval, date]);
112
+ var dtLabel = /*#__PURE__*/jsxRuntime.jsx(core.Tooltip, {
113
+ content: utilities.Format.date(date, format),
114
+ children: /*#__PURE__*/jsxRuntime.jsx("span", _objectSpread(_objectSpread({
115
+ className: classNames(className, children && "underline decoration-dotted cursor-pointer")
116
+ }, props), {}, {
117
+ children: label
118
+ }))
119
+ });
120
+ return children ? /*#__PURE__*/jsxRuntime.jsxs(core.Dropdown, {
121
+ showArrow: true,
122
+ closeOnClick: true,
123
+ children: [dtLabel, children]
124
+ }) : dtLabel;
125
+ };
126
+
127
+ exports.DateDuration = DateDuration;
@@ -13,13 +13,201 @@ var label = {
13
13
  hijri: "هجري",
14
14
  gregorian: "ميلادي"
15
15
  };
16
- var number = {
16
+ var relative = {
17
+ before: {
18
+ now: "الآن",
19
+ years: "{{count}} منذ عام",
20
+ months: "{{count}} منذ شهر",
21
+ weeks: "{{count}} قبل أسبوع",
22
+ days: "{{count}} منذ يوم",
23
+ hours: "{{count}} منذ ساعة",
24
+ minutes: "{{count}} منذ دقيقة",
25
+ seconds: "{{count}} قبل الثاني",
26
+ yearsX: "بالكاد {{count}} منذ عام",
27
+ monthsX: "بالكاد {{count}} منذ شهر",
28
+ weeksX: "بالكاد {{count}} قبل أسبوع",
29
+ daysX: "بالكاد {{count}} منذ يوم",
30
+ hoursX: "بالكاد {{count}} منذ ساعة",
31
+ minutesX: "بالكاد {{count}} منذ دقيقة",
32
+ years_zero: "{{count}} منذ سنوات",
33
+ years_one: "{{count}} منذ عام",
34
+ years_two: "{{count}} منذ سنوات",
35
+ years_few: "{{count}} منذ سنوات",
36
+ years_many: "{{count}} منذ سنوات",
37
+ years_other: "{{count}} منذ سنوات",
38
+ months_zero: "{{count}} منذ أشهر",
39
+ months_one: "{{count}} منذ شهر",
40
+ months_two: "{{count}} منذ أشهر",
41
+ months_few: "{{count}} منذ أشهر",
42
+ months_many: "{{count}} منذ أشهر",
43
+ months_other: "{{count}} منذ أشهر",
44
+ weeks_zero: "{{count}} منذ أسابيع",
45
+ weeks_one: "{{count}} قبل أسبوع",
46
+ weeks_two: "{{count}} منذ أسابيع",
47
+ weeks_few: "{{count}} منذ أسابيع",
48
+ weeks_many: "{{count}} منذ أسابيع",
49
+ weeks_other: "{{count}} منذ أسابيع",
50
+ days_zero: "{{count}} منذ أيام",
51
+ days_one: "{{count}} منذ يوم",
52
+ days_two: "{{count}} منذ أيام",
53
+ days_few: "{{count}} منذ أيام",
54
+ days_many: "{{count}} منذ أيام",
55
+ days_other: "{{count}} منذ أيام",
56
+ hours_zero: "{{count}} منذ ساعات",
57
+ hours_one: "{{count}} منذ ساعة",
58
+ hours_two: "{{count}} منذ ساعات",
59
+ hours_few: "{{count}} منذ ساعات",
60
+ hours_many: "{{count}} منذ ساعات",
61
+ hours_other: "{{count}} منذ ساعات",
62
+ minutes_zero: "{{count}} منذ دقائق",
63
+ minutes_one: "{{count}} منذ دقيقة",
64
+ minutes_two: "{{count}} منذ دقائق",
65
+ minutes_few: "{{count}} منذ دقائق",
66
+ minutes_many: "{{count}} منذ دقائق",
67
+ minutes_other: "{{count}} منذ دقائق",
68
+ seconds_zero: "{{count}} قبل ثوان",
69
+ seconds_one: "{{count}} قبل الثاني",
70
+ seconds_two: "{{count}} قبل ثوان",
71
+ seconds_few: "{{count}} قبل ثوان",
72
+ seconds_many: "{{count}} قبل ثوان",
73
+ seconds_other: "{{count}} قبل ثوان",
74
+ yearsX_zero: "بالكاد {{count}} منذ سنوات",
75
+ yearsX_one: "بالكاد {{count}} منذ عام",
76
+ yearsX_two: "بالكاد {{count}} منذ سنوات",
77
+ yearsX_few: "بالكاد {{count}} منذ سنوات",
78
+ yearsX_many: "بالكاد {{count}} منذ سنوات",
79
+ yearsX_other: "بالكاد {{count}} منذ سنوات",
80
+ monthsX_zero: "بالكاد {{count}} منذ أشهر",
81
+ monthsX_one: "بالكاد {{count}} منذ شهر",
82
+ monthsX_two: "بالكاد {{count}} منذ أشهر",
83
+ monthsX_few: "بالكاد {{count}} منذ أشهر",
84
+ monthsX_many: "بالكاد {{count}} منذ أشهر",
85
+ monthsX_other: "بالكاد {{count}} منذ أشهر",
86
+ weeksX_zero: "بالكاد {{count}} منذ أسابيع",
87
+ weeksX_one: "بالكاد {{count}} قبل أسبوع",
88
+ weeksX_two: "بالكاد {{count}} منذ أسابيع",
89
+ weeksX_few: "بالكاد {{count}} منذ أسابيع",
90
+ weeksX_many: "بالكاد {{count}} منذ أسابيع",
91
+ weeksX_other: "بالكاد {{count}} منذ أسابيع",
92
+ daysX_zero: "بالكاد {{count}} منذ أيام",
93
+ daysX_one: "بالكاد {{count}} منذ يوم",
94
+ daysX_two: "بالكاد {{count}} منذ أيام",
95
+ daysX_few: "بالكاد {{count}} منذ أيام",
96
+ daysX_many: "بالكاد {{count}} منذ أيام",
97
+ daysX_other: "بالكاد {{count}} منذ أيام",
98
+ hoursX_zero: "بالكاد {{count}} منذ ساعات",
99
+ hoursX_one: "بالكاد {{count}} منذ ساعة",
100
+ hoursX_two: "بالكاد {{count}} منذ ساعات",
101
+ hoursX_few: "بالكاد {{count}} منذ ساعات",
102
+ hoursX_many: "بالكاد {{count}} منذ ساعات",
103
+ hoursX_other: "بالكاد {{count}} منذ ساعات",
104
+ minutesX_zero: "بالكاد {{count}} منذ دقائق",
105
+ minutesX_one: "بالكاد {{count}} منذ دقيقة",
106
+ minutesX_two: "بالكاد {{count}} منذ دقائق",
107
+ minutesX_few: "بالكاد {{count}} منذ دقائق",
108
+ minutesX_many: "بالكاد {{count}} منذ دقائق",
109
+ minutesX_other: "بالكاد {{count}} منذ دقائق"
110
+ },
111
+ after: {
112
+ now: "قريباً",
113
+ years: "{{count}} بعد عام",
114
+ months: "{{count}} بعد شهر",
115
+ weeks: "{{count}} بعد أسبوع",
116
+ days: "{{count}} بعد يوم",
117
+ hours: "{{count}} بعد ساعة",
118
+ minutes: "{{count}} بعد دقيقة",
119
+ seconds: "{{count}} الثاني في وقت لاحق",
120
+ yearsX: "بالكاد {{count}} بعد عام",
121
+ monthsX: "بالكاد {{count}} بعد شهر",
122
+ weeksX: "بالكاد {{count}} بعد أسبوع",
123
+ daysX: "بالكاد {{count}} بعد يوم",
124
+ hoursX: "بالكاد {{count}} بعد ساعة",
125
+ minutesX: "بالكاد {{count}} بعد دقيقة",
126
+ years_zero: "{{count}} بعد سنوات",
127
+ years_one: "{{count}} بعد عام",
128
+ years_two: "{{count}} بعد سنوات",
129
+ years_few: "{{count}} بعد سنوات",
130
+ years_many: "{{count}} بعد سنوات",
131
+ years_other: "{{count}} بعد سنوات",
132
+ months_zero: "{{count}} بعد أشهر",
133
+ months_one: "{{count}} بعد شهر",
134
+ months_two: "{{count}} بعد أشهر",
135
+ months_few: "{{count}} بعد أشهر",
136
+ months_many: "{{count}} بعد أشهر",
137
+ months_other: "{{count}} بعد أشهر",
138
+ weeks_zero: "{{count}} بعد أسابيع",
139
+ weeks_one: "{{count}} بعد أسبوع",
140
+ weeks_two: "{{count}} بعد أسابيع",
141
+ weeks_few: "{{count}} بعد أسابيع",
142
+ weeks_many: "{{count}} بعد أسابيع",
143
+ weeks_other: "{{count}} بعد أسابيع",
144
+ days_zero: "{{count}} بعد أيام",
145
+ days_one: "{{count}} بعد يوم",
146
+ days_two: "{{count}} بعد أيام",
147
+ days_few: "{{count}} بعد أيام",
148
+ days_many: "{{count}} بعد أيام",
149
+ days_other: "{{count}} بعد أيام",
150
+ hours_zero: "{{count}} بعد ساعات",
151
+ hours_one: "{{count}} بعد ساعة",
152
+ hours_two: "{{count}} بعد ساعات",
153
+ hours_few: "{{count}} بعد ساعات",
154
+ hours_many: "{{count}} بعد ساعات",
155
+ hours_other: "{{count}} بعد ساعات",
156
+ minutes_zero: "{{count}} بعد دقائق",
157
+ minutes_one: "{{count}} بعد دقيقة",
158
+ minutes_two: "{{count}} بعد دقائق",
159
+ minutes_few: "{{count}} بعد دقائق",
160
+ minutes_many: "{{count}} بعد دقائق",
161
+ minutes_other: "{{count}} بعد دقائق",
162
+ seconds_zero: "{{count}} بعد ثوان",
163
+ seconds_one: "{{count}} الثاني في وقت لاحق",
164
+ seconds_two: "{{count}} بعد ثوان",
165
+ seconds_few: "{{count}} بعد ثوان",
166
+ seconds_many: "{{count}} بعد ثوان",
167
+ seconds_other: "{{count}} بعد ثوان",
168
+ yearsX_zero: "بالكاد {{count}} بعد سنوات",
169
+ yearsX_one: "بالكاد {{count}} بعد عام",
170
+ yearsX_two: "بالكاد {{count}} بعد سنوات",
171
+ yearsX_few: "بالكاد {{count}} بعد سنوات",
172
+ yearsX_many: "بالكاد {{count}} بعد سنوات",
173
+ yearsX_other: "بالكاد {{count}} بعد سنوات",
174
+ monthsX_zero: "بالكاد {{count}} بعد أشهر",
175
+ monthsX_one: "بالكاد {{count}} بعد شهر",
176
+ monthsX_two: "بالكاد {{count}} بعد أشهر",
177
+ monthsX_few: "بالكاد {{count}} بعد أشهر",
178
+ monthsX_many: "بالكاد {{count}} بعد أشهر",
179
+ monthsX_other: "بالكاد {{count}} بعد أشهر",
180
+ weeksX_zero: "بالكاد {{count}} بعد أسابيع",
181
+ weeksX_one: "بالكاد {{count}} بعد أسبوع",
182
+ weeksX_two: "بالكاد {{count}} بعد أسابيع",
183
+ weeksX_few: "بالكاد {{count}} بعد أسابيع",
184
+ weeksX_many: "بالكاد {{count}} بعد أسابيع",
185
+ weeksX_other: "بالكاد {{count}} بعد أسابيع",
186
+ daysX_zero: "بالكاد {{count}} بعد أيام",
187
+ daysX_one: "بالكاد {{count}} بعد يوم",
188
+ daysX_two: "بالكاد {{count}} بعد أيام",
189
+ daysX_few: "بالكاد {{count}} بعد أيام",
190
+ daysX_many: "بالكاد {{count}} بعد أيام",
191
+ daysX_other: "بالكاد {{count}} بعد أيام",
192
+ hoursX_zero: "بالكاد {{count}} بعد ساعات",
193
+ hoursX_one: "بالكاد {{count}} بعد ساعة",
194
+ hoursX_two: "بالكاد {{count}} بعد ساعات",
195
+ hoursX_few: "بالكاد {{count}} بعد ساعات",
196
+ hoursX_many: "بالكاد {{count}} بعد ساعات",
197
+ hoursX_other: "بالكاد {{count}} بعد ساعات",
198
+ minutesX_zero: "بالكاد {{count}} بعد دقائق",
199
+ minutesX_one: "بالكاد {{count}} بعد دقيقة",
200
+ minutesX_two: "بالكاد {{count}} بعد دقائق",
201
+ minutesX_few: "بالكاد {{count}} بعد دقائق",
202
+ minutesX_many: "بالكاد {{count}} بعد دقائق",
203
+ minutesX_other: "بالكاد {{count}} بعد دقائق"
204
+ }
17
205
  };
18
206
  var ar = {
19
207
  label: label,
20
- number: number
208
+ relative: relative
21
209
  };
22
210
 
23
211
  exports.default = ar;
24
212
  exports.label = label;
25
- exports.number = number;
213
+ exports.relative = relative;
@@ -13,9 +13,71 @@ var label = {
13
13
  hijri: "Hijri",
14
14
  gregorian: "Gregorian"
15
15
  };
16
+ var relative = {
17
+ before: {
18
+ now: "Just now",
19
+ years: "Last year",
20
+ years_other: "{{count}} years ago",
21
+ months: "Last month",
22
+ months_other: "{{count}} months ago",
23
+ weeks: "Last week",
24
+ weeks_other: "{{count}} weeks ago",
25
+ days: "Yesterday",
26
+ days_other: "{{count}} days ago",
27
+ hours: "{{count}} hour ago",
28
+ hours_other: "{{count}} hours ago",
29
+ minutes: "{{count}} minute ago",
30
+ minutes_other: "{{count}} minutes ago",
31
+ seconds: "{{count}} second ago",
32
+ seconds_other: "{{count}} seconds ago",
33
+ yearsX: "Almost {{count}} year ago",
34
+ yearsX_other: "Almost {{count}} years ago",
35
+ monthsX: "Almost {{count}} month ago",
36
+ monthsX_other: "Almost {{count}} months ago",
37
+ weeksX: "Almost {{count}} week ago",
38
+ weeksX_other: "Almost {{count}} weeks ago",
39
+ daysX: "Almost {{count}} day ago",
40
+ daysX_other: "Almost {{count}} days ago",
41
+ hoursX: "Almost {{count}} hour ago",
42
+ hoursX_other: "Almost {{count}} hours ago",
43
+ minutesX: "Almost {{count}} minute ago",
44
+ minutesX_other: "Almost {{count}} minutes ago"
45
+ },
46
+ after: {
47
+ now: "Soon",
48
+ years: "Next year",
49
+ years_other: "{{count}} years later",
50
+ months: "Next month",
51
+ months_other: "{{count}} months later",
52
+ weeks: "Next week",
53
+ weeks_other: "{{count}} weeks later",
54
+ days: "Tomorrow",
55
+ days_other: "{{count}} days later",
56
+ hours: "{{count}} hour later",
57
+ hours_other: "{{count}} hours later",
58
+ minutes: "{{count}} minute later",
59
+ minutes_other: "{{count}} minutes later",
60
+ seconds: "{{count}} second later",
61
+ seconds_other: "{{count}} seconds later",
62
+ yearsX: "Almost {{count}} year later",
63
+ yearsX_other: "Almost {{count}} years later",
64
+ monthsX: "Almost {{count}} month later",
65
+ monthsX_other: "Almost {{count}} months later",
66
+ weeksX: "Almost {{count}} week later",
67
+ weeksX_other: "Almost {{count}} weeks later",
68
+ daysX: "Almost {{count}} day later",
69
+ daysX_other: "Almost {{count}} days later",
70
+ hoursX: "Almost {{count}} hour later",
71
+ hoursX_other: "Almost {{count}} hours later",
72
+ minutesX: "Almost {{count}} minute later",
73
+ minutesX_other: "Almost {{count}} minutes later"
74
+ }
75
+ };
16
76
  var en = {
17
- label: label
77
+ label: label,
78
+ relative: relative
18
79
  };
19
80
 
20
81
  exports.default = en;
21
82
  exports.label = label;
83
+ exports.relative = relative;
package/dist/cjs/index.js CHANGED
@@ -6,6 +6,7 @@ var DateHeader = require('./components/DateHeader.js');
6
6
  var DecadePage = require('./components/DecadePage.js');
7
7
  var YearPage = require('./components/YearPage.js');
8
8
  var DateDisplay = require('./display/DateDisplay.js');
9
+ var DateDuration = require('./display/DateDuration.js');
9
10
  var DatePanel = require('./panels/DatePanel.js');
10
11
  var EventPanel = require('./panels/EventPanel.js');
11
12
  var RangePanel = require('./panels/RangePanel.js');
@@ -18,6 +19,7 @@ exports.DateHeader = DateHeader.DateHeader;
18
19
  exports.DecadePage = DecadePage.DecadePage;
19
20
  exports.YearPage = YearPage.YearPage;
20
21
  exports.DateDisplay = DateDisplay.DateDisplay;
22
+ exports.DateDuration = DateDuration.DateDuration;
21
23
  exports.DatePanel = DatePanel.DatePanel;
22
24
  exports.EventPanel = EventPanel.EventPanel;
23
25
  exports.RangePanel = RangePanel.RangePanel;
@@ -4,6 +4,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
5
  import { useGlobals, Tooltip, Dropdown } from '@react-fabric/core';
6
6
  import { DateUtil } from '../utils/dateUtil.js';
7
+ import classNames from 'classnames';
7
8
  import { jsx, jsxs } from 'react/jsx-runtime';
8
9
 
9
10
  var _excluded = ["date", "className", "format", "children", "showAlternateDate"];
@@ -24,7 +25,7 @@ var DateDisplay = function DateDisplay(_ref) {
24
25
  disabled: !showAlternateDate,
25
26
  content: DateUtil.format(date, format, currentLocale, currentCalendar !== "hijri"),
26
27
  children: /*#__PURE__*/jsx("span", _objectSpread(_objectSpread({
27
- className: className
28
+ className: classNames(className, children && "underline decoration-dotted cursor-pointer")
28
29
  }, aria), {}, {
29
30
  children: DateUtil.format(date, format, currentLocale, currentCalendar === "hijri")
30
31
  }))
@@ -0,0 +1,127 @@
1
+ 'use client';
2
+
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
+ import { Tooltip, Dropdown } from '@react-fabric/core';
6
+ import { Format } from '@react-fabric/utilities';
7
+ import classNames from 'classnames';
8
+ import { intervalToDuration, isBefore } from 'date-fns';
9
+ import { useMemo } from 'react';
10
+ import { useTranslation } from 'react-i18next';
11
+ import { DateUtil } from '../utils/dateUtil.js';
12
+ import { jsx, jsxs } from 'react/jsx-runtime';
13
+
14
+ var _excluded = ["date", "children", "className", "format"];
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 DateDuration = function DateDuration(_ref) {
18
+ var date = _ref.date,
19
+ children = _ref.children,
20
+ className = _ref.className,
21
+ _ref$format = _ref.format,
22
+ format = _ref$format === void 0 ? "PPpp" : _ref$format,
23
+ props = _objectWithoutProperties(_ref, _excluded);
24
+ var _useTranslation = useTranslation("date"),
25
+ t = _useTranslation.t;
26
+ var interval = useMemo(function () {
27
+ return intervalToDuration({
28
+ start: new Date(date),
29
+ end: new Date()
30
+ });
31
+ }, [date]);
32
+ var label = useMemo(function () {
33
+ var before = isBefore(DateUtil.parseDate(date), new Date());
34
+ var tkey = before ? "relative.before" : "relative.after";
35
+ var part = "now";
36
+ var count = 0;
37
+ if (interval.years && interval.years > 0) {
38
+ var _interval$months;
39
+ part = "years";
40
+ count = interval.years;
41
+ if (((_interval$months = interval.months) !== null && _interval$months !== void 0 ? _interval$months : 0) > 10) {
42
+ part = "yearsX";
43
+ count += 1;
44
+ }
45
+ } else if (interval.months && interval.months > 0) {
46
+ var _interval$weeks;
47
+ part = "months";
48
+ count = interval.months;
49
+ if (interval.months > 10) {
50
+ part = "yearsX";
51
+ count = 1;
52
+ } else if (((_interval$weeks = interval.weeks) !== null && _interval$weeks !== void 0 ? _interval$weeks : 0) > 3) {
53
+ part = "monthsX";
54
+ count += 1;
55
+ }
56
+ } else if (interval.weeks && interval.weeks > 0) {
57
+ var _interval$days;
58
+ part = "weeks";
59
+ count = interval.weeks;
60
+ if (interval.weeks > 3) {
61
+ part = "monthsX";
62
+ count = 1;
63
+ } else if (((_interval$days = interval.days) !== null && _interval$days !== void 0 ? _interval$days : 0) > 5) {
64
+ part = "weeksX";
65
+ count += 1;
66
+ }
67
+ } else if (interval.days && interval.days > 0) {
68
+ var _interval$hours;
69
+ part = "days";
70
+ count = interval.days;
71
+ if (interval.days > 5) {
72
+ part = "weeksX";
73
+ count = 1;
74
+ } else if (((_interval$hours = interval.hours) !== null && _interval$hours !== void 0 ? _interval$hours : 0) > 20) {
75
+ part = "daysX";
76
+ count += 1;
77
+ }
78
+ } else if (interval.hours && interval.hours > 0) {
79
+ var _interval$minutes;
80
+ part = "hours";
81
+ count = interval.hours;
82
+ if (interval.hours > 20) {
83
+ part = "daysX";
84
+ count = 1;
85
+ } else if (((_interval$minutes = interval.minutes) !== null && _interval$minutes !== void 0 ? _interval$minutes : 0) > 45) {
86
+ part = "hoursX";
87
+ count += 1;
88
+ }
89
+ } else if (interval.minutes && interval.minutes > 0) {
90
+ var _interval$seconds;
91
+ part = "minutes";
92
+ count = interval.minutes;
93
+ if (interval.minutes > 45) {
94
+ part = "hoursX";
95
+ count = 1;
96
+ } else if (((_interval$seconds = interval.seconds) !== null && _interval$seconds !== void 0 ? _interval$seconds : 0) > 45) {
97
+ part = "minuteX";
98
+ count += 1;
99
+ }
100
+ } else if (interval.seconds && interval.seconds > 15) {
101
+ part = "seconds";
102
+ count = interval.seconds;
103
+ if (interval.seconds > 45) {
104
+ part = "minutesX";
105
+ count = 1;
106
+ }
107
+ }
108
+ return t("".concat(tkey, ".").concat(part), {
109
+ count: count
110
+ });
111
+ }, [interval, date]);
112
+ var dtLabel = /*#__PURE__*/jsx(Tooltip, {
113
+ content: Format.date(date, format),
114
+ children: /*#__PURE__*/jsx("span", _objectSpread(_objectSpread({
115
+ className: classNames(className, children && "underline decoration-dotted cursor-pointer")
116
+ }, props), {}, {
117
+ children: label
118
+ }))
119
+ });
120
+ return children ? /*#__PURE__*/jsxs(Dropdown, {
121
+ showArrow: true,
122
+ closeOnClick: true,
123
+ children: [dtLabel, children]
124
+ }) : dtLabel;
125
+ };
126
+
127
+ export { DateDuration };