@onesy/ui-react 1.0.150 → 1.0.152
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/Calendar/Calendar.d.ts +2 -3
- package/CalendarMonth/CalendarMonth.d.ts +28 -3
- package/CalendarMonth/CalendarMonth.js +170 -44
- package/Transition/Transition.js +3 -9
- package/Transitions/Transitions.js +0 -3
- package/esm/CalendarMonth/CalendarMonth.js +170 -41
- package/esm/Transition/Transition.js +3 -9
- package/esm/Transitions/Transitions.js +0 -3
- package/esm/index.js +1 -1
- package/esm/utils.js +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/utils.d.ts +1 -1
- package/utils.js +1 -1
package/Calendar/Calendar.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { OnesyDate } from '@onesy/date';
|
|
3
|
-
import {
|
|
3
|
+
import { ICalendarMonth, TCalendarMonthCalendar, TCalendarMonthValue } from '../CalendarMonth/CalendarMonth';
|
|
4
4
|
import { ISurface } from '../Surface/Surface';
|
|
5
5
|
import { IElementReference, IPropsAny } from '../types';
|
|
6
6
|
export type TGetOnesyDates = (value: TCalendarMonthValue, calendar: TCalendarMonthCalendar, props: IPropsAny) => Array<{
|
|
@@ -35,8 +35,7 @@ export type ICalendar = Omit<ISurface, 'version' | 'onChange'> & {
|
|
|
35
35
|
IconPrevious?: IElementReference;
|
|
36
36
|
IconNext?: IElementReference;
|
|
37
37
|
IconDropDown?: IElementReference;
|
|
38
|
-
CalendarMonthProps?:
|
|
39
|
-
CalendarDayProps?: ICalenarDays;
|
|
38
|
+
CalendarMonthProps?: ICalendarMonth;
|
|
40
39
|
OptionButtonProps?: any;
|
|
41
40
|
PaginationItemsProps?: any;
|
|
42
41
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { OnesyDate } from '@onesy/date';
|
|
3
3
|
import { ILine } from '../Line/Line';
|
|
4
|
-
import { IPropsAny } from '../types';
|
|
4
|
+
import { IColor, IPropsAny } from '../types';
|
|
5
5
|
import { ICalendarViewsView } from '../CalendarViews/CalendarViews';
|
|
6
6
|
export type TCalendarMonthValue = OnesyDate | [OnesyDate, OnesyDate];
|
|
7
7
|
export type TCalendarMonthCalendar = OnesyDate;
|
|
@@ -17,13 +17,15 @@ export type ICalendarMonthValuesValue = {
|
|
|
17
17
|
move: 'previous' | 'next';
|
|
18
18
|
};
|
|
19
19
|
export type TCalendarMonthValues = [ICalendarMonthValuesValue, ICalendarMonthValuesValue];
|
|
20
|
-
export type
|
|
20
|
+
export type ICalendarMonth = Omit<ILine, 'onChange'> & {
|
|
21
21
|
value?: TCalendarMonthValue;
|
|
22
22
|
valueDefault?: TCalendarMonthValue;
|
|
23
23
|
onChange?: (value: TCalendarMonthValue) => any;
|
|
24
24
|
calendar?: TCalendarMonthCalendar;
|
|
25
25
|
calendarDefault?: TCalendarMonthCalendar;
|
|
26
26
|
onChangeCalendar?: (value: TCalendarMonthCalendar) => any;
|
|
27
|
+
colorSelected?: IColor;
|
|
28
|
+
selected?: Array<[OnesyDate, OnesyDate?]>;
|
|
27
29
|
onTimeClick?: (date: OnesyDate, view: ICalendarViewsView, event: MouseEvent) => any;
|
|
28
30
|
now?: boolean;
|
|
29
31
|
outside?: boolean;
|
|
@@ -44,5 +46,28 @@ export type ICalenarDays = Omit<ILine, 'onChange'> & {
|
|
|
44
46
|
TransitionProps?: IPropsAny;
|
|
45
47
|
TransitionsProps?: IPropsAny;
|
|
46
48
|
};
|
|
47
|
-
|
|
49
|
+
export interface IDay {
|
|
50
|
+
value: number;
|
|
51
|
+
in: boolean;
|
|
52
|
+
dayWeek: number;
|
|
53
|
+
weekend: boolean;
|
|
54
|
+
today: boolean;
|
|
55
|
+
is: {
|
|
56
|
+
start: boolean;
|
|
57
|
+
between: boolean;
|
|
58
|
+
end: boolean;
|
|
59
|
+
same: boolean;
|
|
60
|
+
selected: boolean;
|
|
61
|
+
outside: boolean;
|
|
62
|
+
fromSelected: boolean;
|
|
63
|
+
monthStart: boolean;
|
|
64
|
+
monthEnd: boolean;
|
|
65
|
+
selectedIndex: number;
|
|
66
|
+
selectedSame: boolean;
|
|
67
|
+
};
|
|
68
|
+
start: boolean;
|
|
69
|
+
end: boolean;
|
|
70
|
+
onesyDate: OnesyDate;
|
|
71
|
+
}
|
|
72
|
+
declare const CalendarMonth: React.FC<ICalendarMonth>;
|
|
48
73
|
export default CalendarMonth;
|
|
@@ -19,12 +19,14 @@ var _PaginationItem = _interopRequireDefault(require("../PaginationItem"));
|
|
|
19
19
|
var _Transitions = _interopRequireDefault(require("../Transitions"));
|
|
20
20
|
var _Transition = _interopRequireDefault(require("../Transition"));
|
|
21
21
|
var _utils2 = require("../utils");
|
|
22
|
-
const _excluded = ["tonal", "color", "size", "value", "valueDefault", "onChange", "calendar", "calendarDefault", "onChangeCalendar", "onTimeClick", "range", "offset", "outside", "weekStartDay", "now", "min", "max", "validate", "labels", "dayNamesFull", "noTransition", "valid", "renderDay", "renderDayName", "disabled", "DayNameProps", "PaginationItemProps", "TransitionProps", "TransitionsProps", "className"];
|
|
22
|
+
const _excluded = ["tonal", "color", "size", "value", "valueDefault", "onChange", "calendar", "calendarDefault", "onChangeCalendar", "colorSelected", "selected", "onTimeClick", "range", "offset", "outside", "weekStartDay", "now", "min", "max", "validate", "labels", "dayNamesFull", "noTransition", "valid", "renderDay", "renderDayName", "disabled", "DayNameProps", "PaginationItemProps", "TransitionProps", "TransitionsProps", "className"];
|
|
23
23
|
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; }
|
|
24
24
|
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) { (0, _defineProperty2.default)(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; }
|
|
25
25
|
const useStyle = (0, _styleReact.style)(theme => ({
|
|
26
26
|
root: {
|
|
27
|
-
|
|
27
|
+
position: 'relative'
|
|
28
|
+
},
|
|
29
|
+
root_transition: {
|
|
28
30
|
overflow: 'hidden',
|
|
29
31
|
position: 'relative'
|
|
30
32
|
},
|
|
@@ -82,6 +84,11 @@ const useStyle = (0, _styleReact.style)(theme => ({
|
|
|
82
84
|
visibility: 'hidden',
|
|
83
85
|
opacity: '0'
|
|
84
86
|
},
|
|
87
|
+
daySelected: {
|
|
88
|
+
'&.onesy-Button-disabled': {
|
|
89
|
+
opacity: 1
|
|
90
|
+
}
|
|
91
|
+
},
|
|
85
92
|
dayStart: {
|
|
86
93
|
borderRadius: `${theme.methods.shape.radius.value(40, 'px')} 0 0 ${theme.methods.shape.radius.value(40, 'px')}`
|
|
87
94
|
},
|
|
@@ -91,18 +98,24 @@ const useStyle = (0, _styleReact.style)(theme => ({
|
|
|
91
98
|
dayStartEnd: {
|
|
92
99
|
borderRadius: theme.methods.shape.radius.value(40, 'px')
|
|
93
100
|
},
|
|
94
|
-
|
|
95
|
-
'&::
|
|
101
|
+
dayStartSelection: {
|
|
102
|
+
'&::after': {
|
|
96
103
|
content: '""',
|
|
97
104
|
position: 'absolute',
|
|
98
105
|
left: '50%',
|
|
99
106
|
top: '0',
|
|
100
107
|
height: '100%',
|
|
101
108
|
width: '50%',
|
|
102
|
-
|
|
109
|
+
zIndex: 0
|
|
110
|
+
},
|
|
111
|
+
'&.onesy-enabled::after': {
|
|
112
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 85 : 25})`
|
|
113
|
+
},
|
|
114
|
+
'&.onesy-disabled::after': {
|
|
115
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 90 : 20})`
|
|
103
116
|
}
|
|
104
117
|
},
|
|
105
|
-
|
|
118
|
+
dayEndSelection: {
|
|
106
119
|
'&::before': {
|
|
107
120
|
content: '""',
|
|
108
121
|
position: 'absolute',
|
|
@@ -111,7 +124,13 @@ const useStyle = (0, _styleReact.style)(theme => ({
|
|
|
111
124
|
top: '0',
|
|
112
125
|
height: '100%',
|
|
113
126
|
width: '50%',
|
|
114
|
-
|
|
127
|
+
zIndex: 0
|
|
128
|
+
},
|
|
129
|
+
'&.onesy-enabled::before': {
|
|
130
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 85 : 25})`
|
|
131
|
+
},
|
|
132
|
+
'&.onesy-disabled::before': {
|
|
133
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 90 : 20})`
|
|
115
134
|
}
|
|
116
135
|
},
|
|
117
136
|
weeks: {
|
|
@@ -172,6 +191,7 @@ const useStyle = (0, _styleReact.style)(theme => ({
|
|
|
172
191
|
}
|
|
173
192
|
},
|
|
174
193
|
dayValue: {
|
|
194
|
+
zIndex: 1,
|
|
175
195
|
'&:hover': {
|
|
176
196
|
boxShadow: 'inset 0px 0px 0px 1px currentColor'
|
|
177
197
|
}
|
|
@@ -225,6 +245,8 @@ const CalendarMonth = /*#__PURE__*/_react.default.forwardRef((props__, ref) => {
|
|
|
225
245
|
calendar: calendar_,
|
|
226
246
|
calendarDefault,
|
|
227
247
|
onChangeCalendar,
|
|
248
|
+
colorSelected = 'secondary',
|
|
249
|
+
selected,
|
|
228
250
|
onTimeClick,
|
|
229
251
|
range,
|
|
230
252
|
offset = 0,
|
|
@@ -361,13 +383,105 @@ const CalendarMonth = /*#__PURE__*/_react.default.forwardRef((props__, ref) => {
|
|
|
361
383
|
const previousMonthEnd = (0, _date.endOf)(previousMonth, 'month');
|
|
362
384
|
const nextMonth = (0, _date.add)(1, 'month', month);
|
|
363
385
|
const monthSame = ((_refs$previous$curren = refs.previous.current) === null || _refs$previous$curren === void 0 ? void 0 : _refs$previous$curren.year) === (calendar === null || calendar === void 0 ? void 0 : calendar.year) && ((_refs$previous$curren2 = refs.previous.current) === null || _refs$previous$curren2 === void 0 ? void 0 : _refs$previous$curren2.month) === (calendar === null || calendar === void 0 ? void 0 : calendar.month);
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
386
|
+
const getRanges = _react.default.useCallback(ranges => {
|
|
387
|
+
// Convert all ranges to start/end timestamps
|
|
388
|
+
const rangeTimestamps = ranges.map(itemRange => ({
|
|
389
|
+
start: itemRange[0].milliseconds,
|
|
390
|
+
end: (itemRange[1] || itemRange[0]).milliseconds
|
|
391
|
+
}));
|
|
392
|
+
|
|
393
|
+
// Sort by start time
|
|
394
|
+
rangeTimestamps.sort((a, b) => a.start - b.start);
|
|
395
|
+
|
|
396
|
+
// Merge overlapping ranges
|
|
397
|
+
const mergedRanges = [];
|
|
398
|
+
let currentRange = rangeTimestamps[0];
|
|
399
|
+
for (let i = 1; i < rangeTimestamps.length; i++) {
|
|
400
|
+
if (rangeTimestamps[i].start <= currentRange.end) {
|
|
401
|
+
// Ranges overlap, merge them
|
|
402
|
+
currentRange.end = Math.max(currentRange.end, rangeTimestamps[i].end);
|
|
403
|
+
} else {
|
|
404
|
+
// No overlap, push current range and start new one
|
|
405
|
+
mergedRanges.push(currentRange);
|
|
406
|
+
currentRange = rangeTimestamps[i];
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
mergedRanges.push(currentRange);
|
|
410
|
+
return mergedRanges.filter(Boolean);
|
|
411
|
+
}, []);
|
|
412
|
+
const rangesValue = _react.default.useMemo(() => {
|
|
413
|
+
const ranges = [value].map(item => {
|
|
414
|
+
return item.map((itemRange, index) => !index ? (0, _date.startOf)(itemRange, 'day') : (0, _date.endOf)(itemRange, 'day'));
|
|
415
|
+
});
|
|
416
|
+
return getRanges(ranges);
|
|
417
|
+
}, [value]);
|
|
418
|
+
const rangesSelected = _react.default.useMemo(() => {
|
|
419
|
+
const ranges = [...(selected || [])].map(item => {
|
|
420
|
+
return item.map((itemRange, index) => !index ? (0, _date.startOf)(itemRange, 'day') : (0, _date.endOf)(itemRange, 'day'));
|
|
421
|
+
});
|
|
422
|
+
return getRanges(ranges);
|
|
423
|
+
}, [selected]);
|
|
424
|
+
const getDetails = _react.default.useCallback(day => {
|
|
425
|
+
const dayFormat = (0, _date.format)(day, 'DD-MM-YYYY');
|
|
426
|
+
const dayMonthStart = (0, _date.format)((0, _date.startOf)(day, 'month'), 'DD-MM-YYYY');
|
|
427
|
+
const dayMonthEnd = (0, _date.format)((0, _date.endOf)(day, 'month'), 'DD-MM-YYYY');
|
|
428
|
+
const result = {
|
|
429
|
+
start: false,
|
|
430
|
+
between: false,
|
|
431
|
+
end: false,
|
|
432
|
+
same: false,
|
|
433
|
+
selected: false,
|
|
434
|
+
outside: false,
|
|
435
|
+
fromSelected: false,
|
|
436
|
+
monthStart: dayMonthStart === dayFormat,
|
|
437
|
+
monthEnd: dayMonthEnd === dayFormat,
|
|
438
|
+
selectedIndex: value.findIndex(item => item.year === day.year && item.month === day.month && item.day === day.day),
|
|
439
|
+
selectedSame: value.filter(item => item.year === day.year && item.month === day.month && item.day === day.day).length === 2
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
// selected
|
|
443
|
+
for (const itemRange of rangesSelected) {
|
|
444
|
+
const rangeStartDay = (0, _date.format)(new _date.OnesyDate(itemRange.start), 'DD-MM-YYYY');
|
|
445
|
+
const rangeEndDay = (0, _date.format)(new _date.OnesyDate(itemRange.end), 'DD-MM-YYYY');
|
|
446
|
+
|
|
447
|
+
// start
|
|
448
|
+
if (dayFormat === rangeStartDay) result.selected = result.start = true;
|
|
449
|
+
|
|
450
|
+
// end
|
|
451
|
+
if (dayFormat === rangeEndDay) result.selected = result.end = true;
|
|
452
|
+
|
|
453
|
+
// between
|
|
454
|
+
if (day.milliseconds >= itemRange.start && day.milliseconds <= itemRange.end) result.selected = result.between = true;
|
|
455
|
+
|
|
456
|
+
// same
|
|
457
|
+
result.same = result.start && result.end;
|
|
458
|
+
if (result.selected) {
|
|
459
|
+
result.fromSelected = true;
|
|
460
|
+
return result;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// value
|
|
465
|
+
for (const itemRange of rangesValue) {
|
|
466
|
+
const rangeStartDay = (0, _date.format)(new _date.OnesyDate(itemRange.start), 'DD-MM-YYYY');
|
|
467
|
+
const rangeEndDay = (0, _date.format)(new _date.OnesyDate(itemRange.end), 'DD-MM-YYYY');
|
|
468
|
+
|
|
469
|
+
// start
|
|
470
|
+
if (dayFormat === rangeStartDay) result.selected = result.start = true;
|
|
471
|
+
|
|
472
|
+
// end
|
|
473
|
+
if (dayFormat === rangeEndDay) result.selected = result.end = true;
|
|
474
|
+
|
|
475
|
+
// between
|
|
476
|
+
if (day.milliseconds >= itemRange.start && day.milliseconds <= itemRange.end) result.selected = result.between = true;
|
|
477
|
+
|
|
478
|
+
// same
|
|
479
|
+
result.same = result.start && result.end;
|
|
480
|
+
if (result.selected) return result;
|
|
481
|
+
}
|
|
482
|
+
result.outside = true;
|
|
483
|
+
return result;
|
|
484
|
+
}, [value, selected, rangesSelected, rangesValue]);
|
|
371
485
|
let isMonthFrom = false;
|
|
372
486
|
let isMonthTo = false;
|
|
373
487
|
|
|
@@ -375,18 +489,15 @@ const CalendarMonth = /*#__PURE__*/_react.default.forwardRef((props__, ref) => {
|
|
|
375
489
|
for (let i = 0; i < month.daysInMonth; i++) {
|
|
376
490
|
let day = (0, _date.set)(i + 1, 'day', month);
|
|
377
491
|
day = (0, _date.set)(14, 'hour', day);
|
|
378
|
-
const
|
|
379
|
-
if (
|
|
492
|
+
const details = getDetails(day);
|
|
493
|
+
if (details.selectedIndex === 0) isMonthFrom = true;else if (details.selectedIndex === 1) isMonthTo = true;
|
|
380
494
|
days.push({
|
|
381
495
|
value: i + 1,
|
|
382
496
|
in: true,
|
|
383
497
|
dayWeek: day.dayWeek,
|
|
384
498
|
weekend: [0, 6].includes(day.dayWeek),
|
|
385
499
|
today: day.year === monthNow.year && day.dayYear === monthNow.dayYear,
|
|
386
|
-
|
|
387
|
-
selected: isSelected(day),
|
|
388
|
-
selectedIndex: selectedIndex_,
|
|
389
|
-
selectedSame: selectedSame(day),
|
|
500
|
+
is: _objectSpread({}, details),
|
|
390
501
|
onesyDate: day
|
|
391
502
|
});
|
|
392
503
|
}
|
|
@@ -399,16 +510,14 @@ const CalendarMonth = /*#__PURE__*/_react.default.forwardRef((props__, ref) => {
|
|
|
399
510
|
if (weekStartDay === 'Sunday') toAdd++;
|
|
400
511
|
for (let i = 0; i < toAdd; i++) {
|
|
401
512
|
const day = (0, _date.set)(previousMonthEnd.day - i, 'day', previousMonth);
|
|
513
|
+
const details = getDetails(day);
|
|
402
514
|
days.unshift({
|
|
403
515
|
value: day.day,
|
|
404
516
|
in: false,
|
|
405
517
|
dayWeek: day.dayWeek,
|
|
406
518
|
weekend: [0, 6].includes(day.dayWeek),
|
|
407
519
|
today: day.year === monthNow.year && day.dayYear === monthNow.dayYear,
|
|
408
|
-
|
|
409
|
-
selected: isSelected(day),
|
|
410
|
-
selectedIndex: selectedIndex(day),
|
|
411
|
-
selectedSame: selectedSame(day),
|
|
520
|
+
is: _objectSpread({}, details),
|
|
412
521
|
start: true,
|
|
413
522
|
onesyDate: day
|
|
414
523
|
});
|
|
@@ -422,21 +531,25 @@ const CalendarMonth = /*#__PURE__*/_react.default.forwardRef((props__, ref) => {
|
|
|
422
531
|
if (days.length + toAdd - 1 < 42) toAdd += 41 - (days.length + toAdd - 1);
|
|
423
532
|
for (let i = 0; i < toAdd; i++) {
|
|
424
533
|
const day = (0, _date.set)(i + 1, 'day', nextMonth);
|
|
534
|
+
const details = getDetails(day);
|
|
425
535
|
days.push({
|
|
426
536
|
value: i + 1,
|
|
427
537
|
in: false,
|
|
428
538
|
dayWeek: day.dayWeek,
|
|
429
539
|
weekend: [0, 6].includes(day.dayWeek),
|
|
430
540
|
today: day.year === monthNow.year && day.dayYear === monthNow.dayYear,
|
|
431
|
-
|
|
432
|
-
selected: isSelected(day),
|
|
433
|
-
selectedIndex: selectedIndex(day),
|
|
434
|
-
selectedSame: selectedSame(day),
|
|
541
|
+
is: _objectSpread({}, details),
|
|
435
542
|
end: true,
|
|
436
543
|
onesyDate: day
|
|
437
544
|
});
|
|
438
545
|
}
|
|
439
546
|
}
|
|
547
|
+
const colorTheme = _react.default.useMemo(() => {
|
|
548
|
+
return theme.palette.color[color] || theme.methods.color(color);
|
|
549
|
+
}, [color, theme]);
|
|
550
|
+
const colorSelectedTheme = _react.default.useMemo(() => {
|
|
551
|
+
return theme.palette.color[colorSelected] || theme.methods.color(colorSelected);
|
|
552
|
+
}, [colorSelected, theme]);
|
|
440
553
|
|
|
441
554
|
// noTransition
|
|
442
555
|
refs.noTransition.current = monthSame;
|
|
@@ -451,7 +564,10 @@ const CalendarMonth = /*#__PURE__*/_react.default.forwardRef((props__, ref) => {
|
|
|
451
564
|
}
|
|
452
565
|
const weeks = (0, _utils.arrayToParts)(days, 7);
|
|
453
566
|
const getCalendar = status => {
|
|
454
|
-
return /*#__PURE__*/_react.default.createElement(Surface,
|
|
567
|
+
return /*#__PURE__*/_react.default.createElement(Surface, {
|
|
568
|
+
color: color,
|
|
569
|
+
tonal: tonal
|
|
570
|
+
}, ({
|
|
455
571
|
palette
|
|
456
572
|
}) => /*#__PURE__*/_react.default.createElement(Line, {
|
|
457
573
|
gap: 0.5,
|
|
@@ -476,6 +592,7 @@ const CalendarMonth = /*#__PURE__*/_react.default.forwardRef((props__, ref) => {
|
|
|
476
592
|
// not prior to 1970, we may potentially update this in the future
|
|
477
593
|
day.onesyDate.year < 1970
|
|
478
594
|
};
|
|
595
|
+
const isEdge = day.is.same || (day.is.monthStart || day.is.monthEnd) && day.is.selected;
|
|
479
596
|
return /*#__PURE__*/_react.default.createElement(Line, {
|
|
480
597
|
key: index_,
|
|
481
598
|
direction: "row",
|
|
@@ -485,12 +602,18 @@ const CalendarMonth = /*#__PURE__*/_react.default.forwardRef((props__, ref) => {
|
|
|
485
602
|
const timeDate = (0, _date.startOf)(day.onesyDate, 'hour');
|
|
486
603
|
onTimeClick === null || onTimeClick === void 0 || onTimeClick(timeDate, 'month', event);
|
|
487
604
|
},
|
|
488
|
-
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('CalendarMonth', theme) && ['onesy-CalendarMonth-day', `onesy-CalendarMonth-day-${day.in ? 'in' : 'out'}`], classes.day, classes[`day_size_${size}`], classes[`day_${day.in ? 'in' : 'out'}`], !day.in && !outside && classes.day_out_no, !
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
605
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('CalendarMonth', theme) && ['onesy-CalendarMonth-day', `onesy-CalendarMonth-day-${day.in ? 'in' : 'out'}`], classes.day, classes[`day_size_${size}`], classes[`day_${day.in ? 'in' : 'out'}`], !day.in && !outside && classes.day_out_no, !propsDay.disabled ? 'onesy-enabled' : 'onesy-disabled',
|
|
606
|
+
// same day
|
|
607
|
+
// (day.is.same || ((day.is.monthStart || day.is.monthEnd) && day.is.selected)) && classes.dayStartEnd,
|
|
608
|
+
// start
|
|
609
|
+
day.is.start && !isEdge && classes.dayStart,
|
|
610
|
+
// end
|
|
611
|
+
day.is.end && !isEdge && classes.dayEnd,
|
|
612
|
+
// between
|
|
613
|
+
day.is.between && !day.is.same && [!day.is.end && day.dayWeek !== 0 && !day.is.monthEnd && classes.dayStartSelection, !day.is.start && day.dayWeek !== 1 && !day.is.monthStart && classes.dayEndSelection]]),
|
|
614
|
+
style: {
|
|
615
|
+
'--onesy-color': day.is.fromSelected ? colorSelectedTheme.main : colorTheme.main
|
|
616
|
+
}
|
|
494
617
|
}, (0, _utils.is)('function', renderDay) ? renderDay(day.onesyDate, propsDay, day, outside) : /*#__PURE__*/_react.default.createElement(PaginationItem, (0, _extends2.default)({
|
|
495
618
|
tonal: tonal,
|
|
496
619
|
color: "inherit",
|
|
@@ -500,19 +623,22 @@ const CalendarMonth = /*#__PURE__*/_react.default.forwardRef((props__, ref) => {
|
|
|
500
623
|
},
|
|
501
624
|
TypeProps: {
|
|
502
625
|
version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b3',
|
|
503
|
-
priority: !day.selected ? !day.weekend ? 'primary' : 'secondary' : undefined
|
|
626
|
+
priority: !day.is.selected ? !day.weekend ? 'primary' : 'secondary' : undefined
|
|
504
627
|
},
|
|
505
628
|
"aria-label": (0, _date.format)(day.onesyDate, 'DD-MM-YYYY', {
|
|
506
629
|
l
|
|
507
630
|
})
|
|
508
631
|
}, PaginationItemProps, {
|
|
509
|
-
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('CalendarMonth', theme) && ['onesy-CalendarMonth-day-value', day.in && 'onesy-CalendarMonth-day-in', day.dayWeek && 'onesy-CalendarMonth-day-day-week', day.weekend && 'onesy-CalendarMonth-day-weekend', day.today && 'onesy-CalendarMonth-day-today', day.between && 'onesy-CalendarMonth-day-between', day.selected && 'onesy-CalendarMonth-day-selected', day.start && 'onesy-CalendarMonth-day-start', day.end && 'onesy-CalendarMonth-day-end'], PaginationItemProps === null || PaginationItemProps === void 0 ? void 0 : PaginationItemProps.className, classes.dayValue]),
|
|
510
|
-
style: _objectSpread(_objectSpread(_objectSpread({}, day.today ? {
|
|
511
|
-
boxShadow: `inset 0px 0px 0px 1px ${
|
|
512
|
-
} : undefined), day.selected
|
|
513
|
-
color: theme.
|
|
514
|
-
backgroundColor: theme.
|
|
515
|
-
}
|
|
632
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('CalendarMonth', theme) && ['onesy-CalendarMonth-day-value', day.in && 'onesy-CalendarMonth-day-in', day.dayWeek && 'onesy-CalendarMonth-day-day-week', day.weekend && 'onesy-CalendarMonth-day-weekend', day.today && 'onesy-CalendarMonth-day-today', day.is.between && 'onesy-CalendarMonth-day-between', day.is.selected && 'onesy-CalendarMonth-day-selected', day.is.start && 'onesy-CalendarMonth-day-start', day.is.end && 'onesy-CalendarMonth-day-end'], PaginationItemProps === null || PaginationItemProps === void 0 ? void 0 : PaginationItemProps.className, classes.dayValue, day.is.selected && classes.daySelected, classes[`day_size_${size}`]]),
|
|
633
|
+
style: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, day.today ? {
|
|
634
|
+
boxShadow: `inset 0px 0px 0px 1px ${colorTheme[40]}`
|
|
635
|
+
} : undefined), day.is.selected && day.is.between && {
|
|
636
|
+
color: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 10 : 98})`,
|
|
637
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? propsDay.disabled ? 90 : 85 : propsDay.disabled ? 20 : 25})`
|
|
638
|
+
}), day.is.selected && (day.is.start || day.is.end) && {
|
|
639
|
+
color: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 98 : 10})`,
|
|
640
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? propsDay.disabled ? 40 : 50 : propsDay.disabled ? 60 : 70})`
|
|
641
|
+
}), PaginationItemProps === null || PaginationItemProps === void 0 ? void 0 : PaginationItemProps.style)
|
|
516
642
|
}, propsDay), day.value));
|
|
517
643
|
})))));
|
|
518
644
|
};
|
|
@@ -520,7 +646,7 @@ const CalendarMonth = /*#__PURE__*/_react.default.forwardRef((props__, ref) => {
|
|
|
520
646
|
ref: ref,
|
|
521
647
|
gap: 0,
|
|
522
648
|
direction: "column",
|
|
523
|
-
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('CalendarMonth', theme) && ['onesy-CalendarMonth-root', `onesy-CalendarMonth-size-${size}`], className, classes.root, classes[`size_${size}`], classes[`move_${refs.move.current}`], !labels && classes.root_no_labels, disabled && classes.disabled])
|
|
649
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('CalendarMonth', theme) && ['onesy-CalendarMonth-root', `onesy-CalendarMonth-size-${size}`], className, noTransition ? classes.root : classes.root_transition, classes[`size_${size}`], classes[`move_${refs.move.current}`], !labels && classes.root_no_labels, disabled && classes.disabled])
|
|
524
650
|
}, isMonthFrom && {
|
|
525
651
|
'data-month-from': true
|
|
526
652
|
}, isMonthTo && {
|
package/Transition/Transition.js
CHANGED
|
@@ -195,9 +195,6 @@ const Transition = props_ => {
|
|
|
195
195
|
const add = async status_ => {
|
|
196
196
|
if (!add_ || refs.status.current !== status_) return;
|
|
197
197
|
updateStatus('add');
|
|
198
|
-
|
|
199
|
-
// Reflow
|
|
200
|
-
(0, _utils2.reflow)(refs.root.current);
|
|
201
198
|
await delay('add');
|
|
202
199
|
|
|
203
200
|
// Prevent update batches
|
|
@@ -212,9 +209,6 @@ const Transition = props_ => {
|
|
|
212
209
|
var _refs$status$current;
|
|
213
210
|
if (!enter_ || status_ !== 'appended' && (refs.status.current !== status_ || !refs.inProp.current)) return;
|
|
214
211
|
updateStatus('enter');
|
|
215
|
-
|
|
216
|
-
// Reflow
|
|
217
|
-
(0, _utils2.reflow)(refs.root.current);
|
|
218
212
|
await delay('enter');
|
|
219
213
|
|
|
220
214
|
// Prevent update batches
|
|
@@ -227,9 +221,6 @@ const Transition = props_ => {
|
|
|
227
221
|
var _refs$status$current2;
|
|
228
222
|
if (!exit_ || refs.status.current !== status_ || refs.inProp.current) return;
|
|
229
223
|
updateStatus('exit');
|
|
230
|
-
|
|
231
|
-
// Reflow
|
|
232
|
-
(0, _utils2.reflow)(refs.root.current);
|
|
233
224
|
await delay('exit');
|
|
234
225
|
|
|
235
226
|
// Prevent update batches
|
|
@@ -309,6 +300,9 @@ const Transition = props_ => {
|
|
|
309
300
|
className_ = className_.replace(/ +/g, ' ').trim();
|
|
310
301
|
if ((_refs$root$current$cl2 = refs.root.current.className) !== null && _refs$root$current$cl2 !== void 0 && _refs$root$current$cl2.baseVal) refs.root.current.className.baseVal = className_;else refs.root.current.className = className_;
|
|
311
302
|
}
|
|
303
|
+
|
|
304
|
+
// reflow
|
|
305
|
+
(0, _utils2.reflow)(refs.root.current);
|
|
312
306
|
};
|
|
313
307
|
if (status === 'removed') return null;
|
|
314
308
|
const value_ = {
|
|
@@ -43,9 +43,6 @@ const Transitions = props_ => {
|
|
|
43
43
|
};
|
|
44
44
|
refs.element.current = element;
|
|
45
45
|
refs.status.current = status;
|
|
46
|
-
|
|
47
|
-
// No transition controll
|
|
48
|
-
// bug solve in nextjs
|
|
49
46
|
_react.default.useEffect(() => {
|
|
50
47
|
if (id !== undefined) {
|
|
51
48
|
if (id !== refs.id.current) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
const _excluded = ["tonal", "color", "size", "value", "valueDefault", "onChange", "calendar", "calendarDefault", "onChangeCalendar", "onTimeClick", "range", "offset", "outside", "weekStartDay", "now", "min", "max", "validate", "labels", "dayNamesFull", "noTransition", "valid", "renderDay", "renderDayName", "disabled", "DayNameProps", "PaginationItemProps", "TransitionProps", "TransitionsProps", "className"];
|
|
4
|
+
const _excluded = ["tonal", "color", "size", "value", "valueDefault", "onChange", "calendar", "calendarDefault", "onChangeCalendar", "colorSelected", "selected", "onTimeClick", "range", "offset", "outside", "weekStartDay", "now", "min", "max", "validate", "labels", "dayNamesFull", "noTransition", "valid", "renderDay", "renderDayName", "disabled", "DayNameProps", "PaginationItemProps", "TransitionProps", "TransitionsProps", "className"];
|
|
5
5
|
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; }
|
|
6
6
|
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; }
|
|
7
7
|
import React from 'react';
|
|
@@ -17,7 +17,9 @@ import TransitionElement from '../Transition';
|
|
|
17
17
|
import { staticClassName } from '../utils';
|
|
18
18
|
const useStyle = style(theme => ({
|
|
19
19
|
root: {
|
|
20
|
-
|
|
20
|
+
position: 'relative'
|
|
21
|
+
},
|
|
22
|
+
root_transition: {
|
|
21
23
|
overflow: 'hidden',
|
|
22
24
|
position: 'relative'
|
|
23
25
|
},
|
|
@@ -75,6 +77,11 @@ const useStyle = style(theme => ({
|
|
|
75
77
|
visibility: 'hidden',
|
|
76
78
|
opacity: '0'
|
|
77
79
|
},
|
|
80
|
+
daySelected: {
|
|
81
|
+
'&.onesy-Button-disabled': {
|
|
82
|
+
opacity: 1
|
|
83
|
+
}
|
|
84
|
+
},
|
|
78
85
|
dayStart: {
|
|
79
86
|
borderRadius: `${theme.methods.shape.radius.value(40, 'px')} 0 0 ${theme.methods.shape.radius.value(40, 'px')}`
|
|
80
87
|
},
|
|
@@ -84,18 +91,24 @@ const useStyle = style(theme => ({
|
|
|
84
91
|
dayStartEnd: {
|
|
85
92
|
borderRadius: theme.methods.shape.radius.value(40, 'px')
|
|
86
93
|
},
|
|
87
|
-
|
|
88
|
-
'&::
|
|
94
|
+
dayStartSelection: {
|
|
95
|
+
'&::after': {
|
|
89
96
|
content: '""',
|
|
90
97
|
position: 'absolute',
|
|
91
98
|
left: '50%',
|
|
92
99
|
top: '0',
|
|
93
100
|
height: '100%',
|
|
94
101
|
width: '50%',
|
|
95
|
-
|
|
102
|
+
zIndex: 0
|
|
103
|
+
},
|
|
104
|
+
'&.onesy-enabled::after': {
|
|
105
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 85 : 25})`
|
|
106
|
+
},
|
|
107
|
+
'&.onesy-disabled::after': {
|
|
108
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 90 : 20})`
|
|
96
109
|
}
|
|
97
110
|
},
|
|
98
|
-
|
|
111
|
+
dayEndSelection: {
|
|
99
112
|
'&::before': {
|
|
100
113
|
content: '""',
|
|
101
114
|
position: 'absolute',
|
|
@@ -104,7 +117,13 @@ const useStyle = style(theme => ({
|
|
|
104
117
|
top: '0',
|
|
105
118
|
height: '100%',
|
|
106
119
|
width: '50%',
|
|
107
|
-
|
|
120
|
+
zIndex: 0
|
|
121
|
+
},
|
|
122
|
+
'&.onesy-enabled::before': {
|
|
123
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 85 : 25})`
|
|
124
|
+
},
|
|
125
|
+
'&.onesy-disabled::before': {
|
|
126
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 90 : 20})`
|
|
108
127
|
}
|
|
109
128
|
},
|
|
110
129
|
weeks: {
|
|
@@ -165,6 +184,7 @@ const useStyle = style(theme => ({
|
|
|
165
184
|
}
|
|
166
185
|
},
|
|
167
186
|
dayValue: {
|
|
187
|
+
zIndex: 1,
|
|
168
188
|
'&:hover': {
|
|
169
189
|
boxShadow: 'inset 0px 0px 0px 1px currentColor'
|
|
170
190
|
}
|
|
@@ -196,6 +216,8 @@ const CalendarMonth = /*#__PURE__*/React.forwardRef((props__, ref) => {
|
|
|
196
216
|
calendar: calendar_,
|
|
197
217
|
calendarDefault,
|
|
198
218
|
onChangeCalendar,
|
|
219
|
+
colorSelected = 'secondary',
|
|
220
|
+
selected,
|
|
199
221
|
onTimeClick,
|
|
200
222
|
range,
|
|
201
223
|
offset = 0,
|
|
@@ -332,10 +354,105 @@ const CalendarMonth = /*#__PURE__*/React.forwardRef((props__, ref) => {
|
|
|
332
354
|
const previousMonthEnd = endOf(previousMonth, 'month');
|
|
333
355
|
const nextMonth = add(1, 'month', month);
|
|
334
356
|
const monthSame = refs.previous.current?.year === calendar?.year && refs.previous.current?.month === calendar?.month;
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
357
|
+
const getRanges = React.useCallback(ranges => {
|
|
358
|
+
// Convert all ranges to start/end timestamps
|
|
359
|
+
const rangeTimestamps = ranges.map(itemRange => ({
|
|
360
|
+
start: itemRange[0].milliseconds,
|
|
361
|
+
end: (itemRange[1] || itemRange[0]).milliseconds
|
|
362
|
+
}));
|
|
363
|
+
|
|
364
|
+
// Sort by start time
|
|
365
|
+
rangeTimestamps.sort((a, b) => a.start - b.start);
|
|
366
|
+
|
|
367
|
+
// Merge overlapping ranges
|
|
368
|
+
const mergedRanges = [];
|
|
369
|
+
let currentRange = rangeTimestamps[0];
|
|
370
|
+
for (let i = 1; i < rangeTimestamps.length; i++) {
|
|
371
|
+
if (rangeTimestamps[i].start <= currentRange.end) {
|
|
372
|
+
// Ranges overlap, merge them
|
|
373
|
+
currentRange.end = Math.max(currentRange.end, rangeTimestamps[i].end);
|
|
374
|
+
} else {
|
|
375
|
+
// No overlap, push current range and start new one
|
|
376
|
+
mergedRanges.push(currentRange);
|
|
377
|
+
currentRange = rangeTimestamps[i];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
mergedRanges.push(currentRange);
|
|
381
|
+
return mergedRanges.filter(Boolean);
|
|
382
|
+
}, []);
|
|
383
|
+
const rangesValue = React.useMemo(() => {
|
|
384
|
+
const ranges = [value].map(item => {
|
|
385
|
+
return item.map((itemRange, index) => !index ? startOf(itemRange, 'day') : endOf(itemRange, 'day'));
|
|
386
|
+
});
|
|
387
|
+
return getRanges(ranges);
|
|
388
|
+
}, [value]);
|
|
389
|
+
const rangesSelected = React.useMemo(() => {
|
|
390
|
+
const ranges = [...(selected || [])].map(item => {
|
|
391
|
+
return item.map((itemRange, index) => !index ? startOf(itemRange, 'day') : endOf(itemRange, 'day'));
|
|
392
|
+
});
|
|
393
|
+
return getRanges(ranges);
|
|
394
|
+
}, [selected]);
|
|
395
|
+
const getDetails = React.useCallback(day => {
|
|
396
|
+
const dayFormat = format(day, 'DD-MM-YYYY');
|
|
397
|
+
const dayMonthStart = format(startOf(day, 'month'), 'DD-MM-YYYY');
|
|
398
|
+
const dayMonthEnd = format(endOf(day, 'month'), 'DD-MM-YYYY');
|
|
399
|
+
const result = {
|
|
400
|
+
start: false,
|
|
401
|
+
between: false,
|
|
402
|
+
end: false,
|
|
403
|
+
same: false,
|
|
404
|
+
selected: false,
|
|
405
|
+
outside: false,
|
|
406
|
+
fromSelected: false,
|
|
407
|
+
monthStart: dayMonthStart === dayFormat,
|
|
408
|
+
monthEnd: dayMonthEnd === dayFormat,
|
|
409
|
+
selectedIndex: value.findIndex(item => item.year === day.year && item.month === day.month && item.day === day.day),
|
|
410
|
+
selectedSame: value.filter(item => item.year === day.year && item.month === day.month && item.day === day.day).length === 2
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
// selected
|
|
414
|
+
for (const itemRange of rangesSelected) {
|
|
415
|
+
const rangeStartDay = format(new OnesyDate(itemRange.start), 'DD-MM-YYYY');
|
|
416
|
+
const rangeEndDay = format(new OnesyDate(itemRange.end), 'DD-MM-YYYY');
|
|
417
|
+
|
|
418
|
+
// start
|
|
419
|
+
if (dayFormat === rangeStartDay) result.selected = result.start = true;
|
|
420
|
+
|
|
421
|
+
// end
|
|
422
|
+
if (dayFormat === rangeEndDay) result.selected = result.end = true;
|
|
423
|
+
|
|
424
|
+
// between
|
|
425
|
+
if (day.milliseconds >= itemRange.start && day.milliseconds <= itemRange.end) result.selected = result.between = true;
|
|
426
|
+
|
|
427
|
+
// same
|
|
428
|
+
result.same = result.start && result.end;
|
|
429
|
+
if (result.selected) {
|
|
430
|
+
result.fromSelected = true;
|
|
431
|
+
return result;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// value
|
|
436
|
+
for (const itemRange of rangesValue) {
|
|
437
|
+
const rangeStartDay = format(new OnesyDate(itemRange.start), 'DD-MM-YYYY');
|
|
438
|
+
const rangeEndDay = format(new OnesyDate(itemRange.end), 'DD-MM-YYYY');
|
|
439
|
+
|
|
440
|
+
// start
|
|
441
|
+
if (dayFormat === rangeStartDay) result.selected = result.start = true;
|
|
442
|
+
|
|
443
|
+
// end
|
|
444
|
+
if (dayFormat === rangeEndDay) result.selected = result.end = true;
|
|
445
|
+
|
|
446
|
+
// between
|
|
447
|
+
if (day.milliseconds >= itemRange.start && day.milliseconds <= itemRange.end) result.selected = result.between = true;
|
|
448
|
+
|
|
449
|
+
// same
|
|
450
|
+
result.same = result.start && result.end;
|
|
451
|
+
if (result.selected) return result;
|
|
452
|
+
}
|
|
453
|
+
result.outside = true;
|
|
454
|
+
return result;
|
|
455
|
+
}, [value, selected, rangesSelected, rangesValue]);
|
|
339
456
|
let isMonthFrom = false;
|
|
340
457
|
let isMonthTo = false;
|
|
341
458
|
|
|
@@ -343,18 +460,15 @@ const CalendarMonth = /*#__PURE__*/React.forwardRef((props__, ref) => {
|
|
|
343
460
|
for (let i = 0; i < month.daysInMonth; i++) {
|
|
344
461
|
let day = set(i + 1, 'day', month);
|
|
345
462
|
day = set(14, 'hour', day);
|
|
346
|
-
const
|
|
347
|
-
if (
|
|
463
|
+
const details = getDetails(day);
|
|
464
|
+
if (details.selectedIndex === 0) isMonthFrom = true;else if (details.selectedIndex === 1) isMonthTo = true;
|
|
348
465
|
days.push({
|
|
349
466
|
value: i + 1,
|
|
350
467
|
in: true,
|
|
351
468
|
dayWeek: day.dayWeek,
|
|
352
469
|
weekend: [0, 6].includes(day.dayWeek),
|
|
353
470
|
today: day.year === monthNow.year && day.dayYear === monthNow.dayYear,
|
|
354
|
-
|
|
355
|
-
selected: isSelected(day),
|
|
356
|
-
selectedIndex: selectedIndex_,
|
|
357
|
-
selectedSame: selectedSame(day),
|
|
471
|
+
is: _objectSpread({}, details),
|
|
358
472
|
onesyDate: day
|
|
359
473
|
});
|
|
360
474
|
}
|
|
@@ -367,16 +481,14 @@ const CalendarMonth = /*#__PURE__*/React.forwardRef((props__, ref) => {
|
|
|
367
481
|
if (weekStartDay === 'Sunday') toAdd++;
|
|
368
482
|
for (let i = 0; i < toAdd; i++) {
|
|
369
483
|
const day = set(previousMonthEnd.day - i, 'day', previousMonth);
|
|
484
|
+
const details = getDetails(day);
|
|
370
485
|
days.unshift({
|
|
371
486
|
value: day.day,
|
|
372
487
|
in: false,
|
|
373
488
|
dayWeek: day.dayWeek,
|
|
374
489
|
weekend: [0, 6].includes(day.dayWeek),
|
|
375
490
|
today: day.year === monthNow.year && day.dayYear === monthNow.dayYear,
|
|
376
|
-
|
|
377
|
-
selected: isSelected(day),
|
|
378
|
-
selectedIndex: selectedIndex(day),
|
|
379
|
-
selectedSame: selectedSame(day),
|
|
491
|
+
is: _objectSpread({}, details),
|
|
380
492
|
start: true,
|
|
381
493
|
onesyDate: day
|
|
382
494
|
});
|
|
@@ -390,21 +502,25 @@ const CalendarMonth = /*#__PURE__*/React.forwardRef((props__, ref) => {
|
|
|
390
502
|
if (days.length + toAdd - 1 < 42) toAdd += 41 - (days.length + toAdd - 1);
|
|
391
503
|
for (let i = 0; i < toAdd; i++) {
|
|
392
504
|
const day = set(i + 1, 'day', nextMonth);
|
|
505
|
+
const details = getDetails(day);
|
|
393
506
|
days.push({
|
|
394
507
|
value: i + 1,
|
|
395
508
|
in: false,
|
|
396
509
|
dayWeek: day.dayWeek,
|
|
397
510
|
weekend: [0, 6].includes(day.dayWeek),
|
|
398
511
|
today: day.year === monthNow.year && day.dayYear === monthNow.dayYear,
|
|
399
|
-
|
|
400
|
-
selected: isSelected(day),
|
|
401
|
-
selectedIndex: selectedIndex(day),
|
|
402
|
-
selectedSame: selectedSame(day),
|
|
512
|
+
is: _objectSpread({}, details),
|
|
403
513
|
end: true,
|
|
404
514
|
onesyDate: day
|
|
405
515
|
});
|
|
406
516
|
}
|
|
407
517
|
}
|
|
518
|
+
const colorTheme = React.useMemo(() => {
|
|
519
|
+
return theme.palette.color[color] || theme.methods.color(color);
|
|
520
|
+
}, [color, theme]);
|
|
521
|
+
const colorSelectedTheme = React.useMemo(() => {
|
|
522
|
+
return theme.palette.color[colorSelected] || theme.methods.color(colorSelected);
|
|
523
|
+
}, [colorSelected, theme]);
|
|
408
524
|
|
|
409
525
|
// noTransition
|
|
410
526
|
refs.noTransition.current = monthSame;
|
|
@@ -418,7 +534,10 @@ const CalendarMonth = /*#__PURE__*/React.forwardRef((props__, ref) => {
|
|
|
418
534
|
}
|
|
419
535
|
const weeks = arrayToParts(days, 7);
|
|
420
536
|
const getCalendar = status => {
|
|
421
|
-
return /*#__PURE__*/React.createElement(Surface,
|
|
537
|
+
return /*#__PURE__*/React.createElement(Surface, {
|
|
538
|
+
color: color,
|
|
539
|
+
tonal: tonal
|
|
540
|
+
}, ({
|
|
422
541
|
palette
|
|
423
542
|
}) => /*#__PURE__*/React.createElement(Line, {
|
|
424
543
|
gap: 0.5,
|
|
@@ -443,6 +562,7 @@ const CalendarMonth = /*#__PURE__*/React.forwardRef((props__, ref) => {
|
|
|
443
562
|
// not prior to 1970, we may potentially update this in the future
|
|
444
563
|
day.onesyDate.year < 1970
|
|
445
564
|
};
|
|
565
|
+
const isEdge = day.is.same || (day.is.monthStart || day.is.monthEnd) && day.is.selected;
|
|
446
566
|
return /*#__PURE__*/React.createElement(Line, {
|
|
447
567
|
key: index_,
|
|
448
568
|
direction: "row",
|
|
@@ -452,12 +572,18 @@ const CalendarMonth = /*#__PURE__*/React.forwardRef((props__, ref) => {
|
|
|
452
572
|
const timeDate = startOf(day.onesyDate, 'hour');
|
|
453
573
|
onTimeClick?.(timeDate, 'month', event);
|
|
454
574
|
},
|
|
455
|
-
className: classNames([staticClassName('CalendarMonth', theme) && ['onesy-CalendarMonth-day', `onesy-CalendarMonth-day-${day.in ? 'in' : 'out'}`], classes.day, classes[`day_size_${size}`], classes[`day_${day.in ? 'in' : 'out'}`], !day.in && !outside && classes.day_out_no, !
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
575
|
+
className: classNames([staticClassName('CalendarMonth', theme) && ['onesy-CalendarMonth-day', `onesy-CalendarMonth-day-${day.in ? 'in' : 'out'}`], classes.day, classes[`day_size_${size}`], classes[`day_${day.in ? 'in' : 'out'}`], !day.in && !outside && classes.day_out_no, !propsDay.disabled ? 'onesy-enabled' : 'onesy-disabled',
|
|
576
|
+
// same day
|
|
577
|
+
// (day.is.same || ((day.is.monthStart || day.is.monthEnd) && day.is.selected)) && classes.dayStartEnd,
|
|
578
|
+
// start
|
|
579
|
+
day.is.start && !isEdge && classes.dayStart,
|
|
580
|
+
// end
|
|
581
|
+
day.is.end && !isEdge && classes.dayEnd,
|
|
582
|
+
// between
|
|
583
|
+
day.is.between && !day.is.same && [!day.is.end && day.dayWeek !== 0 && !day.is.monthEnd && classes.dayStartSelection, !day.is.start && day.dayWeek !== 1 && !day.is.monthStart && classes.dayEndSelection]]),
|
|
584
|
+
style: {
|
|
585
|
+
'--onesy-color': day.is.fromSelected ? colorSelectedTheme.main : colorTheme.main
|
|
586
|
+
}
|
|
461
587
|
}, is('function', renderDay) ? renderDay(day.onesyDate, propsDay, day, outside) : /*#__PURE__*/React.createElement(PaginationItem, _extends({
|
|
462
588
|
tonal: tonal,
|
|
463
589
|
color: "inherit",
|
|
@@ -467,19 +593,22 @@ const CalendarMonth = /*#__PURE__*/React.forwardRef((props__, ref) => {
|
|
|
467
593
|
},
|
|
468
594
|
TypeProps: {
|
|
469
595
|
version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b3',
|
|
470
|
-
priority: !day.selected ? !day.weekend ? 'primary' : 'secondary' : undefined
|
|
596
|
+
priority: !day.is.selected ? !day.weekend ? 'primary' : 'secondary' : undefined
|
|
471
597
|
},
|
|
472
598
|
"aria-label": format(day.onesyDate, 'DD-MM-YYYY', {
|
|
473
599
|
l
|
|
474
600
|
})
|
|
475
601
|
}, PaginationItemProps, {
|
|
476
|
-
className: classNames([staticClassName('CalendarMonth', theme) && ['onesy-CalendarMonth-day-value', day.in && 'onesy-CalendarMonth-day-in', day.dayWeek && 'onesy-CalendarMonth-day-day-week', day.weekend && 'onesy-CalendarMonth-day-weekend', day.today && 'onesy-CalendarMonth-day-today', day.between && 'onesy-CalendarMonth-day-between', day.selected && 'onesy-CalendarMonth-day-selected', day.start && 'onesy-CalendarMonth-day-start', day.end && 'onesy-CalendarMonth-day-end'], PaginationItemProps?.className, classes.dayValue]),
|
|
477
|
-
style: _objectSpread(_objectSpread(_objectSpread({}, day.today ? {
|
|
478
|
-
boxShadow: `inset 0px 0px 0px 1px ${
|
|
479
|
-
} : undefined), day.selected
|
|
480
|
-
color: theme.
|
|
481
|
-
backgroundColor: theme.
|
|
482
|
-
}
|
|
602
|
+
className: classNames([staticClassName('CalendarMonth', theme) && ['onesy-CalendarMonth-day-value', day.in && 'onesy-CalendarMonth-day-in', day.dayWeek && 'onesy-CalendarMonth-day-day-week', day.weekend && 'onesy-CalendarMonth-day-weekend', day.today && 'onesy-CalendarMonth-day-today', day.is.between && 'onesy-CalendarMonth-day-between', day.is.selected && 'onesy-CalendarMonth-day-selected', day.is.start && 'onesy-CalendarMonth-day-start', day.is.end && 'onesy-CalendarMonth-day-end'], PaginationItemProps?.className, classes.dayValue, day.is.selected && classes.daySelected, classes[`day_size_${size}`]]),
|
|
603
|
+
style: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, day.today ? {
|
|
604
|
+
boxShadow: `inset 0px 0px 0px 1px ${colorTheme[40]}`
|
|
605
|
+
} : undefined), day.is.selected && day.is.between && {
|
|
606
|
+
color: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 10 : 98})`,
|
|
607
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? propsDay.disabled ? 90 : 85 : propsDay.disabled ? 20 : 25})`
|
|
608
|
+
}), day.is.selected && (day.is.start || day.is.end) && {
|
|
609
|
+
color: `hsl(from var(--onesy-color) h s ${theme.palette.light ? 98 : 10})`,
|
|
610
|
+
backgroundColor: `hsl(from var(--onesy-color) h s ${theme.palette.light ? propsDay.disabled ? 40 : 50 : propsDay.disabled ? 60 : 70})`
|
|
611
|
+
}), PaginationItemProps?.style)
|
|
483
612
|
}, propsDay), day.value));
|
|
484
613
|
})))));
|
|
485
614
|
};
|
|
@@ -487,7 +616,7 @@ const CalendarMonth = /*#__PURE__*/React.forwardRef((props__, ref) => {
|
|
|
487
616
|
ref: ref,
|
|
488
617
|
gap: 0,
|
|
489
618
|
direction: "column",
|
|
490
|
-
className: classNames([staticClassName('CalendarMonth', theme) && ['onesy-CalendarMonth-root', `onesy-CalendarMonth-size-${size}`], className, classes.root, classes[`size_${size}`], classes[`move_${refs.move.current}`], !labels && classes.root_no_labels, disabled && classes.disabled])
|
|
619
|
+
className: classNames([staticClassName('CalendarMonth', theme) && ['onesy-CalendarMonth-root', `onesy-CalendarMonth-size-${size}`], className, noTransition ? classes.root : classes.root_transition, classes[`size_${size}`], classes[`move_${refs.move.current}`], !labels && classes.root_no_labels, disabled && classes.disabled])
|
|
491
620
|
}, isMonthFrom && {
|
|
492
621
|
'data-month-from': true
|
|
493
622
|
}, isMonthTo && {
|
|
@@ -184,9 +184,6 @@ const Transition = props_ => {
|
|
|
184
184
|
const add = async status_ => {
|
|
185
185
|
if (!add_ || refs.status.current !== status_) return;
|
|
186
186
|
updateStatus('add');
|
|
187
|
-
|
|
188
|
-
// Reflow
|
|
189
|
-
reflow(refs.root.current);
|
|
190
187
|
await delay('add');
|
|
191
188
|
|
|
192
189
|
// Prevent update batches
|
|
@@ -200,9 +197,6 @@ const Transition = props_ => {
|
|
|
200
197
|
const enter = async status_ => {
|
|
201
198
|
if (!enter_ || status_ !== 'appended' && (refs.status.current !== status_ || !refs.inProp.current)) return;
|
|
202
199
|
updateStatus('enter');
|
|
203
|
-
|
|
204
|
-
// Reflow
|
|
205
|
-
reflow(refs.root.current);
|
|
206
200
|
await delay('enter');
|
|
207
201
|
|
|
208
202
|
// Prevent update batches
|
|
@@ -214,9 +208,6 @@ const Transition = props_ => {
|
|
|
214
208
|
const exit = async status_ => {
|
|
215
209
|
if (!exit_ || refs.status.current !== status_ || refs.inProp.current) return;
|
|
216
210
|
updateStatus('exit');
|
|
217
|
-
|
|
218
|
-
// Reflow
|
|
219
|
-
reflow(refs.root.current);
|
|
220
211
|
await delay('exit');
|
|
221
212
|
|
|
222
213
|
// Prevent update batches
|
|
@@ -295,6 +286,9 @@ const Transition = props_ => {
|
|
|
295
286
|
className_ = className_.replace(/ +/g, ' ').trim();
|
|
296
287
|
if (refs.root.current.className?.baseVal) refs.root.current.className.baseVal = className_;else refs.root.current.className = className_;
|
|
297
288
|
}
|
|
289
|
+
|
|
290
|
+
// reflow
|
|
291
|
+
reflow(refs.root.current);
|
|
298
292
|
};
|
|
299
293
|
if (status === 'removed') return null;
|
|
300
294
|
const value_ = {
|
package/esm/index.js
CHANGED
package/esm/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { is, canvasFilterBrightness, canvasFilterContrast, canvasFilterSaturation, canvasFilterFade, canvasFilterInvert, canvasFilterOldPhoto, download, clamp, isEnvironment } from '@onesy/utils';
|
|
2
2
|
export function reflow(element) {
|
|
3
|
-
element?.offsetHeight;
|
|
3
|
+
return element?.offsetHeight;
|
|
4
4
|
}
|
|
5
5
|
export const staticClassName = (name, theme) => {
|
|
6
6
|
return theme?.ui?.elements?.[`onesy-${name}`]?.className?.static !== undefined ? theme?.ui?.elements?.[`onesy-${name}`]?.className?.static : theme?.ui?.className.static;
|
package/index.js
CHANGED
package/package.json
CHANGED
package/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IPoint } from './types';
|
|
2
|
-
export declare function reflow(element: HTMLElement):
|
|
2
|
+
export declare function reflow(element: HTMLElement): number;
|
|
3
3
|
export declare const staticClassName: (name: string, theme: any) => any;
|
|
4
4
|
export declare const iconSizeToFontSize: (value: string | number) => any;
|
|
5
5
|
export declare const valueBreakpoints: (item: any, value: any, breakpoints: any, theme: any) => any;
|
package/utils.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.reflow = reflow;
|
|
|
8
8
|
exports.valueBreakpoints = exports.toNumber = exports.staticClassName = exports.save = exports.sanitize = exports.replace = void 0;
|
|
9
9
|
var _utils = require("@onesy/utils");
|
|
10
10
|
function reflow(element) {
|
|
11
|
-
element === null || element === void 0
|
|
11
|
+
return element === null || element === void 0 ? void 0 : element.offsetHeight;
|
|
12
12
|
}
|
|
13
13
|
const staticClassName = (name, theme) => {
|
|
14
14
|
var _theme$ui, _theme$ui2, _theme$ui3;
|