@commonsku/styles 1.16.3 → 1.16.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +17 -1
- package/dist/index.es.js +249 -227
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +247 -225
- package/dist/index.js.map +1 -1
- package/dist/styles/Popup.d.ts +17 -1
- package/dist/styles/Popup.d.ts.map +1 -1
- package/dist/styles/hooks/index.d.ts +2 -0
- package/dist/styles/hooks/index.d.ts.map +1 -1
- package/dist/styles/hooks/useClickOutside.d.ts +9 -0
- package/dist/styles/hooks/useClickOutside.d.ts.map +1 -0
- package/dist/styles/hooks/useFallbackRef.d.ts +4 -0
- package/dist/styles/hooks/useFallbackRef.d.ts.map +1 -0
- package/package.json +8 -3
package/dist/index.js
CHANGED
|
@@ -3425,6 +3425,241 @@ var THSorted = function (_a) {
|
|
|
3425
3425
|
};
|
|
3426
3426
|
var templateObject_1$m, templateObject_2$d, templateObject_3$6, templateObject_4$5, templateObject_5$5, templateObject_6$4, templateObject_7$2, templateObject_8$1, templateObject_9;
|
|
3427
3427
|
|
|
3428
|
+
var useClickOutside = function (props) {
|
|
3429
|
+
var ref = props.ref, _a = props.eventType, eventType = _a === void 0 ? 'mousedown' : _a, onClick = props.onClick, onCleanup = props.onCleanup;
|
|
3430
|
+
React.useEffect(function () {
|
|
3431
|
+
function handleClickOutside(e) {
|
|
3432
|
+
console.log('handleClickOutside');
|
|
3433
|
+
if (ref.current && !ref.current.contains(e.target)) {
|
|
3434
|
+
console.log('click outside');
|
|
3435
|
+
onClick && onClick(e);
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3438
|
+
document.addEventListener(eventType, handleClickOutside);
|
|
3439
|
+
return function () {
|
|
3440
|
+
document.removeEventListener(eventType, handleClickOutside);
|
|
3441
|
+
onCleanup && onCleanup();
|
|
3442
|
+
};
|
|
3443
|
+
}, []);
|
|
3444
|
+
};
|
|
3445
|
+
|
|
3446
|
+
var QUERY = '(prefers-reduced-motion: no-preference)';
|
|
3447
|
+
var isRenderingOnServer = typeof window$1 === 'undefined';
|
|
3448
|
+
var getInitialState = function () {
|
|
3449
|
+
// For our initial server render, we won't know if the user
|
|
3450
|
+
// prefers reduced motion, but it doesn't matter. This value
|
|
3451
|
+
// will be overwritten on the client, before any animations
|
|
3452
|
+
// occur.
|
|
3453
|
+
return isRenderingOnServer ? true : !window$1.matchMedia(QUERY).matches;
|
|
3454
|
+
};
|
|
3455
|
+
var usePrefersReducedMotion = function () {
|
|
3456
|
+
var _a = React__default.useState(getInitialState), prefersReducedMotion = _a[0], setPrefersReducedMotion = _a[1];
|
|
3457
|
+
React__default.useEffect(function () {
|
|
3458
|
+
var mediaQueryList = window$1.matchMedia(QUERY);
|
|
3459
|
+
var listener = function (event) {
|
|
3460
|
+
setPrefersReducedMotion(!event.matches);
|
|
3461
|
+
};
|
|
3462
|
+
mediaQueryList.addListener(listener);
|
|
3463
|
+
return function () {
|
|
3464
|
+
mediaQueryList.removeListener(listener);
|
|
3465
|
+
};
|
|
3466
|
+
}, []);
|
|
3467
|
+
return prefersReducedMotion;
|
|
3468
|
+
};
|
|
3469
|
+
|
|
3470
|
+
var useRandomInterval = function (callback, minDelay, maxDelay) {
|
|
3471
|
+
var timeoutId = React__default.useRef(null);
|
|
3472
|
+
var savedCallback = React__default.useRef(callback);
|
|
3473
|
+
React__default.useEffect(function () {
|
|
3474
|
+
savedCallback.current = callback;
|
|
3475
|
+
});
|
|
3476
|
+
React__default.useEffect(function () {
|
|
3477
|
+
var isEnabled = typeof minDelay === 'number' && typeof maxDelay === 'number';
|
|
3478
|
+
if (isEnabled) {
|
|
3479
|
+
var handleTick_1 = function () {
|
|
3480
|
+
var nextTickAt = random(minDelay, maxDelay);
|
|
3481
|
+
timeoutId.current = setTimeout(function () {
|
|
3482
|
+
savedCallback.current();
|
|
3483
|
+
handleTick_1();
|
|
3484
|
+
}, nextTickAt);
|
|
3485
|
+
};
|
|
3486
|
+
handleTick_1();
|
|
3487
|
+
}
|
|
3488
|
+
return function () {
|
|
3489
|
+
if (!!timeoutId.current) {
|
|
3490
|
+
clearTimeout(timeoutId.current);
|
|
3491
|
+
}
|
|
3492
|
+
};
|
|
3493
|
+
}, [minDelay, maxDelay]);
|
|
3494
|
+
var cancel = React__default.useCallback(function () {
|
|
3495
|
+
if (!!timeoutId.current) {
|
|
3496
|
+
clearTimeout(timeoutId.current);
|
|
3497
|
+
}
|
|
3498
|
+
}, []);
|
|
3499
|
+
return cancel;
|
|
3500
|
+
};
|
|
3501
|
+
|
|
3502
|
+
var today = new Date();
|
|
3503
|
+
var getDatesBetween = function (startDt, endDt) {
|
|
3504
|
+
var result = [];
|
|
3505
|
+
var currentDt = startDt;
|
|
3506
|
+
while (currentDt <= endDt) {
|
|
3507
|
+
result.push(currentDt);
|
|
3508
|
+
currentDt = dateFns.addDays(currentDt, 1);
|
|
3509
|
+
}
|
|
3510
|
+
return result;
|
|
3511
|
+
};
|
|
3512
|
+
var useCalendar = function (_a) {
|
|
3513
|
+
var onChangeWeek = _a.onChangeWeek, onChangeMonth = _a.onChangeMonth;
|
|
3514
|
+
var _b = React.useState(today), currentMonth = _b[0], setCurrentMonth = _b[1];
|
|
3515
|
+
var _c = React.useState(dateFns.getWeek(currentMonth)), currentWeek = _c[0], setCurrentWeek = _c[1];
|
|
3516
|
+
var _d = React.useState(today), selectedDate = _d[0], setSelectedDate = _d[1];
|
|
3517
|
+
var changeMonth = function (action) {
|
|
3518
|
+
var dt = currentMonth;
|
|
3519
|
+
if (action === "prev") {
|
|
3520
|
+
dt = dateFns.subMonths(currentMonth, 1);
|
|
3521
|
+
}
|
|
3522
|
+
else if (action === "next") {
|
|
3523
|
+
dt = dateFns.addMonths(currentMonth, 1);
|
|
3524
|
+
}
|
|
3525
|
+
else if (action === "reset") {
|
|
3526
|
+
dt = today;
|
|
3527
|
+
}
|
|
3528
|
+
setCurrentMonth(dt);
|
|
3529
|
+
onChangeMonth && onChangeMonth({
|
|
3530
|
+
action: action,
|
|
3531
|
+
date: dt,
|
|
3532
|
+
month: dateFns.getMonth(dt),
|
|
3533
|
+
year: dateFns.getYear(dt),
|
|
3534
|
+
});
|
|
3535
|
+
};
|
|
3536
|
+
var changeWeek = function (action, value) {
|
|
3537
|
+
var dt = currentMonth;
|
|
3538
|
+
if (action === "prev") {
|
|
3539
|
+
dt = dateFns.subWeeks(currentMonth, 1);
|
|
3540
|
+
}
|
|
3541
|
+
else if (action === "next") {
|
|
3542
|
+
dt = dateFns.addWeeks(currentMonth, 1);
|
|
3543
|
+
}
|
|
3544
|
+
else if (action === "reset") {
|
|
3545
|
+
dt = today;
|
|
3546
|
+
}
|
|
3547
|
+
else if (action === "custom" && value) {
|
|
3548
|
+
dt = value;
|
|
3549
|
+
}
|
|
3550
|
+
setCurrentMonth(dt);
|
|
3551
|
+
var week = dateFns.getWeek(dt);
|
|
3552
|
+
setCurrentWeek(week);
|
|
3553
|
+
onChangeWeek && onChangeWeek({
|
|
3554
|
+
action: action,
|
|
3555
|
+
date: dt,
|
|
3556
|
+
week: week,
|
|
3557
|
+
month: dateFns.getMonth(dt),
|
|
3558
|
+
year: dateFns.getYear(dt),
|
|
3559
|
+
});
|
|
3560
|
+
};
|
|
3561
|
+
var changeDate = function (value) {
|
|
3562
|
+
setCurrentMonth(value);
|
|
3563
|
+
var week = dateFns.getWeek(value);
|
|
3564
|
+
setCurrentWeek(week);
|
|
3565
|
+
onChangeWeek && onChangeWeek({
|
|
3566
|
+
action: 'change-date',
|
|
3567
|
+
date: value,
|
|
3568
|
+
week: week,
|
|
3569
|
+
month: dateFns.getMonth(value),
|
|
3570
|
+
year: dateFns.getYear(value),
|
|
3571
|
+
});
|
|
3572
|
+
};
|
|
3573
|
+
var onClickDay = function (day) {
|
|
3574
|
+
if (dateFns.isSameDay(day, selectedDate)) {
|
|
3575
|
+
setSelectedDate(today);
|
|
3576
|
+
}
|
|
3577
|
+
else {
|
|
3578
|
+
setSelectedDate(day);
|
|
3579
|
+
}
|
|
3580
|
+
};
|
|
3581
|
+
// reset to today's date
|
|
3582
|
+
var resetToToday = function () {
|
|
3583
|
+
setSelectedDate(today);
|
|
3584
|
+
changeWeek('reset');
|
|
3585
|
+
};
|
|
3586
|
+
var onNextWeek = function () { return changeWeek("next"); };
|
|
3587
|
+
var onPrevWeek = function () { return changeWeek("prev"); };
|
|
3588
|
+
var onNextMonth = function () { return changeMonth("next"); };
|
|
3589
|
+
var onPrevMonth = function () { return changeMonth("prev"); };
|
|
3590
|
+
return {
|
|
3591
|
+
currentMonth: currentMonth,
|
|
3592
|
+
currentWeek: currentWeek,
|
|
3593
|
+
selectedDate: selectedDate,
|
|
3594
|
+
setSelectedDate: setSelectedDate,
|
|
3595
|
+
setCurrentWeek: setCurrentWeek,
|
|
3596
|
+
setCurrentMonth: setCurrentMonth,
|
|
3597
|
+
onClickDay: onClickDay,
|
|
3598
|
+
onNextWeek: onNextWeek,
|
|
3599
|
+
onPrevWeek: onPrevWeek,
|
|
3600
|
+
onNextMonth: onNextMonth,
|
|
3601
|
+
onPrevMonth: onPrevMonth,
|
|
3602
|
+
changeWeek: changeWeek,
|
|
3603
|
+
changeDate: changeDate,
|
|
3604
|
+
getDatesBetween: getDatesBetween,
|
|
3605
|
+
onReset: resetToToday,
|
|
3606
|
+
};
|
|
3607
|
+
};
|
|
3608
|
+
|
|
3609
|
+
var useWindowSize = function () {
|
|
3610
|
+
var _a = React.useState([0, 0]), size = _a[0], setSize = _a[1]; // [width, height]
|
|
3611
|
+
React.useEffect(function () {
|
|
3612
|
+
function updateSize() {
|
|
3613
|
+
setSize([window.innerWidth, window.innerHeight]);
|
|
3614
|
+
}
|
|
3615
|
+
window.addEventListener('resize', updateSize);
|
|
3616
|
+
updateSize();
|
|
3617
|
+
return function () { return window.removeEventListener('resize', updateSize); };
|
|
3618
|
+
}, []);
|
|
3619
|
+
return size;
|
|
3620
|
+
};
|
|
3621
|
+
|
|
3622
|
+
function useLongPress(callback, ms) {
|
|
3623
|
+
if (callback === void 0) { callback = function () { }; }
|
|
3624
|
+
if (ms === void 0) { ms = 300; }
|
|
3625
|
+
var _a = React.useState(false), startLongPress = _a[0], setStartLongPress = _a[1];
|
|
3626
|
+
React.useEffect(function () {
|
|
3627
|
+
var timeoutId = null;
|
|
3628
|
+
if (startLongPress) {
|
|
3629
|
+
timeoutId = setTimeout(callback, ms);
|
|
3630
|
+
}
|
|
3631
|
+
else {
|
|
3632
|
+
if (timeoutId !== undefined && timeoutId !== null) {
|
|
3633
|
+
clearTimeout(timeoutId);
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
return function () {
|
|
3637
|
+
if (timeoutId !== undefined && timeoutId !== null) {
|
|
3638
|
+
clearTimeout(timeoutId);
|
|
3639
|
+
}
|
|
3640
|
+
};
|
|
3641
|
+
}, [callback, ms, startLongPress]);
|
|
3642
|
+
var start = React.useCallback(function () {
|
|
3643
|
+
setStartLongPress(true);
|
|
3644
|
+
}, []);
|
|
3645
|
+
var stop = React.useCallback(function () {
|
|
3646
|
+
setStartLongPress(false);
|
|
3647
|
+
}, []);
|
|
3648
|
+
return {
|
|
3649
|
+
onMouseDown: start,
|
|
3650
|
+
onMouseUp: stop,
|
|
3651
|
+
onMouseLeave: stop,
|
|
3652
|
+
onTouchStart: start,
|
|
3653
|
+
onTouchEnd: stop,
|
|
3654
|
+
};
|
|
3655
|
+
}
|
|
3656
|
+
|
|
3657
|
+
var useFallbackRef = function (forwardedRef) {
|
|
3658
|
+
var localRef = React.useRef(null);
|
|
3659
|
+
React.useImperativeHandle(forwardedRef, function () { return localRef.current; });
|
|
3660
|
+
return localRef;
|
|
3661
|
+
};
|
|
3662
|
+
|
|
3428
3663
|
var Overlay = styled__default.div(templateObject_1$n || (templateObject_1$n = __makeTemplateObject(["\n &&& {\n position: fixed;\n top: 0px;\n bottom: 0px;\n left: 0px;\n right: 0px;\n background: rgba(42, 56, 63, 0.45);\n display: flex;\n z-index: ", ";\n margin-left: auto;\n margin-right: auto;\n }\n"], ["\n &&& {\n position: fixed;\n top: 0px;\n bottom: 0px;\n left: 0px;\n right: 0px;\n background: rgba(42, 56, 63, 0.45);\n display: flex;\n z-index: ", ";\n margin-left: auto;\n margin-right: auto;\n }\n"])), function (p) { return p.zIndex || 999; });
|
|
3429
3664
|
var PopupWindow = styled__default.div(templateObject_2$e || (templateObject_2$e = __makeTemplateObject(["\n &&& {\n width: ", ";\n height: ", "; \n margin: 0 !important;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n position: fixed;\n ", "\n overflow-y: hidden;\n display: block;\n z-index: ", ";\n\n padding: ", ";\n border: 1px solid #CCD5DA;\n background-color: #fefefe;\n border-radius: 3px;\n\n &:last-child {\n margin-bottom: 0;\n }\n .popup-content {\n overflow-y: auto;\n height: 90%;\n }\n ", "\n ", "\n }\n"], ["\n &&& {\n width: ", ";\n height: ", "; \n margin: 0 !important;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n position: fixed;\n ", "\n overflow-y: hidden;\n display: block;\n z-index: ", ";\n\n padding: ", ";\n border: 1px solid #CCD5DA;\n background-color: #fefefe;\n border-radius: 3px;\n\n &:last-child {\n margin-bottom: 0;\n }\n .popup-content {\n overflow-y: auto;\n height: 90%;\n }\n ", "\n ", "\n }\n"])), function (props) { var _a; return (_a = props.width) !== null && _a !== void 0 ? _a : '90%'; }, function (props) { var _a; return (_a = props.height) !== null && _a !== void 0 ? _a : '75%'; }, function (props) { return props.height ? '' : 'max-height: 700px;'; }, function (p) { return p.zIndex || 1006; }, function (props) { var _a; return (_a = props.padding) !== null && _a !== void 0 ? _a : '1rem'; }, SharedStyles, SizerCss);
|
|
3430
3665
|
var PopupHeader = styled__default.div(templateObject_3$7 || (templateObject_3$7 = __makeTemplateObject(["\n &&& {\n position: sticky;\n top: 0;\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n background: white;\n padding: 3px;\n z-index: 99;\n .title {\n font-size: 1.8rem;\n font-weight: 500;\n text-align: left;\n align-self: center;\n padding-top: 3px;\n padding-left: 3px;\n border-bottom: none;\n font-family: \"skufont-demibold\",sans-serif;\n color: #123952;\n }\n ", "\n ", "\n }\n"], ["\n &&& {\n position: sticky;\n top: 0;\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n background: white;\n padding: 3px;\n z-index: 99;\n .title {\n font-size: 1.8rem;\n font-weight: 500;\n text-align: left;\n align-self: center;\n padding-top: 3px;\n padding-left: 3px;\n border-bottom: none;\n font-family: \"skufont-demibold\",sans-serif;\n color: #123952;\n }\n ", "\n ", "\n }\n"])), SharedStyles, SizerCss);
|
|
@@ -3440,18 +3675,16 @@ var PopupContainer = function (_a) {
|
|
|
3440
3675
|
}, []);
|
|
3441
3676
|
return ReactDOM.createPortal(children, ref.current);
|
|
3442
3677
|
};
|
|
3443
|
-
var Popup = function (_a) {
|
|
3678
|
+
var Popup = React__default.forwardRef(function (_a, forwardedRef) {
|
|
3444
3679
|
var header = _a.header, _b = _a.noHeader, noHeader = _b === void 0 ? false : _b, title = _a.title, controls = _a.controls, children = _a.children, onClose = _a.onClose, _c = _a.noCloseButton, noCloseButton = _c === void 0 ? false : _c, _d = _a.closeOnEsc, closeOnEsc = _d === void 0 ? true : _d, _e = _a.closeOnClickOutside, closeOnClickOutside = _e === void 0 ? false : _e, overlayZIndex = _a.overlayZIndex, props = __rest(_a, ["header", "noHeader", "title", "controls", "children", "onClose", "noCloseButton", "closeOnEsc", "closeOnClickOutside", "overlayZIndex"]);
|
|
3445
|
-
var ref =
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
};
|
|
3454
|
-
*/
|
|
3680
|
+
var ref = useFallbackRef(forwardedRef);
|
|
3681
|
+
useClickOutside({
|
|
3682
|
+
ref: ref,
|
|
3683
|
+
onClick: function (e) {
|
|
3684
|
+
closeOnClickOutside && onClose && onClose(e);
|
|
3685
|
+
},
|
|
3686
|
+
onCleanup: onClose,
|
|
3687
|
+
});
|
|
3455
3688
|
React.useEffect(function () {
|
|
3456
3689
|
var handleKeyDown = function (e) {
|
|
3457
3690
|
// @ts-ignore
|
|
@@ -3479,7 +3712,7 @@ var Popup = function (_a) {
|
|
|
3479
3712
|
React__default.createElement(Col, { style: { textAlign: 'right', alignSelf: 'center' } }, noCloseButton ? null :
|
|
3480
3713
|
controls || React__default.createElement(Button, { onClick: onClose }, "Close")))),
|
|
3481
3714
|
React__default.createElement("div", { className: "popup-content" }, children))));
|
|
3482
|
-
};
|
|
3715
|
+
});
|
|
3483
3716
|
var ShowPopup = function (_a) {
|
|
3484
3717
|
var _b = _a.autoOpen, autoOpen = _b === void 0 ? false : _b, PopupComponent = _a.popup, render = _a.render, _c = _a.closeOnEsc, closeOnEsc = _c === void 0 ? true : _c, _d = _a.closeOnClickOutside, closeOnClickOutside = _d === void 0 ? false : _d, props = __rest(_a, ["autoOpen", "popup", "render", "closeOnEsc", "closeOnClickOutside"]);
|
|
3485
3718
|
var _e = React.useState(autoOpen), showPopup = _e[0], setShowPopup = _e[1];
|
|
@@ -3756,10 +3989,10 @@ var Tabs = /** @class */ (function (_super) {
|
|
|
3756
3989
|
};
|
|
3757
3990
|
Tabs.prototype.render = function () {
|
|
3758
3991
|
var _this = this;
|
|
3759
|
-
var _a = this.props, tabs = _a.tabs, size = _a.size, props = __rest(_a, ["tabs", "size"]);
|
|
3992
|
+
var _a = this.props, tabs = _a.tabs, size = _a.size, padded = _a.padded, props = __rest(_a, ["tabs", "size", "padded"]);
|
|
3760
3993
|
var selectedTab = this.getTab(tabs, this.state.selectedTabIndex);
|
|
3761
3994
|
return React__default.createElement("div", __assign({}, props),
|
|
3762
|
-
React__default.createElement(TabBar, { padded:
|
|
3995
|
+
React__default.createElement(TabBar, { padded: padded === true }, tabs.map(function (tab, index) { return React__default.createElement(Tab, { key: index, size: size, className: index === _this.state.selectedTabIndex ? 'selected' : '', selected: index === _this.state.selectedTabIndex, onClick: function (e) {
|
|
3763
3996
|
_this.setState({ selectedTabIndex: index });
|
|
3764
3997
|
var callback = tabs[index].onClick;
|
|
3765
3998
|
if (callback) {
|
|
@@ -4797,217 +5030,6 @@ function HeadlessTable(_a) {
|
|
|
4797
5030
|
}
|
|
4798
5031
|
var templateObject_1$B, templateObject_2$p, templateObject_3$h;
|
|
4799
5032
|
|
|
4800
|
-
var QUERY = '(prefers-reduced-motion: no-preference)';
|
|
4801
|
-
var isRenderingOnServer = typeof window$1 === 'undefined';
|
|
4802
|
-
var getInitialState = function () {
|
|
4803
|
-
// For our initial server render, we won't know if the user
|
|
4804
|
-
// prefers reduced motion, but it doesn't matter. This value
|
|
4805
|
-
// will be overwritten on the client, before any animations
|
|
4806
|
-
// occur.
|
|
4807
|
-
return isRenderingOnServer ? true : !window$1.matchMedia(QUERY).matches;
|
|
4808
|
-
};
|
|
4809
|
-
var usePrefersReducedMotion = function () {
|
|
4810
|
-
var _a = React__default.useState(getInitialState), prefersReducedMotion = _a[0], setPrefersReducedMotion = _a[1];
|
|
4811
|
-
React__default.useEffect(function () {
|
|
4812
|
-
var mediaQueryList = window$1.matchMedia(QUERY);
|
|
4813
|
-
var listener = function (event) {
|
|
4814
|
-
setPrefersReducedMotion(!event.matches);
|
|
4815
|
-
};
|
|
4816
|
-
mediaQueryList.addListener(listener);
|
|
4817
|
-
return function () {
|
|
4818
|
-
mediaQueryList.removeListener(listener);
|
|
4819
|
-
};
|
|
4820
|
-
}, []);
|
|
4821
|
-
return prefersReducedMotion;
|
|
4822
|
-
};
|
|
4823
|
-
|
|
4824
|
-
var useRandomInterval = function (callback, minDelay, maxDelay) {
|
|
4825
|
-
var timeoutId = React__default.useRef(null);
|
|
4826
|
-
var savedCallback = React__default.useRef(callback);
|
|
4827
|
-
React__default.useEffect(function () {
|
|
4828
|
-
savedCallback.current = callback;
|
|
4829
|
-
});
|
|
4830
|
-
React__default.useEffect(function () {
|
|
4831
|
-
var isEnabled = typeof minDelay === 'number' && typeof maxDelay === 'number';
|
|
4832
|
-
if (isEnabled) {
|
|
4833
|
-
var handleTick_1 = function () {
|
|
4834
|
-
var nextTickAt = random(minDelay, maxDelay);
|
|
4835
|
-
timeoutId.current = setTimeout(function () {
|
|
4836
|
-
savedCallback.current();
|
|
4837
|
-
handleTick_1();
|
|
4838
|
-
}, nextTickAt);
|
|
4839
|
-
};
|
|
4840
|
-
handleTick_1();
|
|
4841
|
-
}
|
|
4842
|
-
return function () {
|
|
4843
|
-
if (!!timeoutId.current) {
|
|
4844
|
-
clearTimeout(timeoutId.current);
|
|
4845
|
-
}
|
|
4846
|
-
};
|
|
4847
|
-
}, [minDelay, maxDelay]);
|
|
4848
|
-
var cancel = React__default.useCallback(function () {
|
|
4849
|
-
if (!!timeoutId.current) {
|
|
4850
|
-
clearTimeout(timeoutId.current);
|
|
4851
|
-
}
|
|
4852
|
-
}, []);
|
|
4853
|
-
return cancel;
|
|
4854
|
-
};
|
|
4855
|
-
|
|
4856
|
-
var today = new Date();
|
|
4857
|
-
var getDatesBetween = function (startDt, endDt) {
|
|
4858
|
-
var result = [];
|
|
4859
|
-
var currentDt = startDt;
|
|
4860
|
-
while (currentDt <= endDt) {
|
|
4861
|
-
result.push(currentDt);
|
|
4862
|
-
currentDt = dateFns.addDays(currentDt, 1);
|
|
4863
|
-
}
|
|
4864
|
-
return result;
|
|
4865
|
-
};
|
|
4866
|
-
var useCalendar = function (_a) {
|
|
4867
|
-
var onChangeWeek = _a.onChangeWeek, onChangeMonth = _a.onChangeMonth;
|
|
4868
|
-
var _b = React.useState(today), currentMonth = _b[0], setCurrentMonth = _b[1];
|
|
4869
|
-
var _c = React.useState(dateFns.getWeek(currentMonth)), currentWeek = _c[0], setCurrentWeek = _c[1];
|
|
4870
|
-
var _d = React.useState(today), selectedDate = _d[0], setSelectedDate = _d[1];
|
|
4871
|
-
var changeMonth = function (action) {
|
|
4872
|
-
var dt = currentMonth;
|
|
4873
|
-
if (action === "prev") {
|
|
4874
|
-
dt = dateFns.subMonths(currentMonth, 1);
|
|
4875
|
-
}
|
|
4876
|
-
else if (action === "next") {
|
|
4877
|
-
dt = dateFns.addMonths(currentMonth, 1);
|
|
4878
|
-
}
|
|
4879
|
-
else if (action === "reset") {
|
|
4880
|
-
dt = today;
|
|
4881
|
-
}
|
|
4882
|
-
setCurrentMonth(dt);
|
|
4883
|
-
onChangeMonth && onChangeMonth({
|
|
4884
|
-
action: action,
|
|
4885
|
-
date: dt,
|
|
4886
|
-
month: dateFns.getMonth(dt),
|
|
4887
|
-
year: dateFns.getYear(dt),
|
|
4888
|
-
});
|
|
4889
|
-
};
|
|
4890
|
-
var changeWeek = function (action, value) {
|
|
4891
|
-
var dt = currentMonth;
|
|
4892
|
-
if (action === "prev") {
|
|
4893
|
-
dt = dateFns.subWeeks(currentMonth, 1);
|
|
4894
|
-
}
|
|
4895
|
-
else if (action === "next") {
|
|
4896
|
-
dt = dateFns.addWeeks(currentMonth, 1);
|
|
4897
|
-
}
|
|
4898
|
-
else if (action === "reset") {
|
|
4899
|
-
dt = today;
|
|
4900
|
-
}
|
|
4901
|
-
else if (action === "custom" && value) {
|
|
4902
|
-
dt = value;
|
|
4903
|
-
}
|
|
4904
|
-
setCurrentMonth(dt);
|
|
4905
|
-
var week = dateFns.getWeek(dt);
|
|
4906
|
-
setCurrentWeek(week);
|
|
4907
|
-
onChangeWeek && onChangeWeek({
|
|
4908
|
-
action: action,
|
|
4909
|
-
date: dt,
|
|
4910
|
-
week: week,
|
|
4911
|
-
month: dateFns.getMonth(dt),
|
|
4912
|
-
year: dateFns.getYear(dt),
|
|
4913
|
-
});
|
|
4914
|
-
};
|
|
4915
|
-
var changeDate = function (value) {
|
|
4916
|
-
setCurrentMonth(value);
|
|
4917
|
-
var week = dateFns.getWeek(value);
|
|
4918
|
-
setCurrentWeek(week);
|
|
4919
|
-
onChangeWeek && onChangeWeek({
|
|
4920
|
-
action: 'change-date',
|
|
4921
|
-
date: value,
|
|
4922
|
-
week: week,
|
|
4923
|
-
month: dateFns.getMonth(value),
|
|
4924
|
-
year: dateFns.getYear(value),
|
|
4925
|
-
});
|
|
4926
|
-
};
|
|
4927
|
-
var onClickDay = function (day) {
|
|
4928
|
-
if (dateFns.isSameDay(day, selectedDate)) {
|
|
4929
|
-
setSelectedDate(today);
|
|
4930
|
-
}
|
|
4931
|
-
else {
|
|
4932
|
-
setSelectedDate(day);
|
|
4933
|
-
}
|
|
4934
|
-
};
|
|
4935
|
-
// reset to today's date
|
|
4936
|
-
var resetToToday = function () {
|
|
4937
|
-
setSelectedDate(today);
|
|
4938
|
-
changeWeek('reset');
|
|
4939
|
-
};
|
|
4940
|
-
var onNextWeek = function () { return changeWeek("next"); };
|
|
4941
|
-
var onPrevWeek = function () { return changeWeek("prev"); };
|
|
4942
|
-
var onNextMonth = function () { return changeMonth("next"); };
|
|
4943
|
-
var onPrevMonth = function () { return changeMonth("prev"); };
|
|
4944
|
-
return {
|
|
4945
|
-
currentMonth: currentMonth,
|
|
4946
|
-
currentWeek: currentWeek,
|
|
4947
|
-
selectedDate: selectedDate,
|
|
4948
|
-
setSelectedDate: setSelectedDate,
|
|
4949
|
-
setCurrentWeek: setCurrentWeek,
|
|
4950
|
-
setCurrentMonth: setCurrentMonth,
|
|
4951
|
-
onClickDay: onClickDay,
|
|
4952
|
-
onNextWeek: onNextWeek,
|
|
4953
|
-
onPrevWeek: onPrevWeek,
|
|
4954
|
-
onNextMonth: onNextMonth,
|
|
4955
|
-
onPrevMonth: onPrevMonth,
|
|
4956
|
-
changeWeek: changeWeek,
|
|
4957
|
-
changeDate: changeDate,
|
|
4958
|
-
getDatesBetween: getDatesBetween,
|
|
4959
|
-
onReset: resetToToday,
|
|
4960
|
-
};
|
|
4961
|
-
};
|
|
4962
|
-
|
|
4963
|
-
var useWindowSize = function () {
|
|
4964
|
-
var _a = React.useState([0, 0]), size = _a[0], setSize = _a[1]; // [width, height]
|
|
4965
|
-
React.useEffect(function () {
|
|
4966
|
-
function updateSize() {
|
|
4967
|
-
setSize([window.innerWidth, window.innerHeight]);
|
|
4968
|
-
}
|
|
4969
|
-
window.addEventListener('resize', updateSize);
|
|
4970
|
-
updateSize();
|
|
4971
|
-
return function () { return window.removeEventListener('resize', updateSize); };
|
|
4972
|
-
}, []);
|
|
4973
|
-
return size;
|
|
4974
|
-
};
|
|
4975
|
-
|
|
4976
|
-
function useLongPress(callback, ms) {
|
|
4977
|
-
if (callback === void 0) { callback = function () { }; }
|
|
4978
|
-
if (ms === void 0) { ms = 300; }
|
|
4979
|
-
var _a = React.useState(false), startLongPress = _a[0], setStartLongPress = _a[1];
|
|
4980
|
-
React.useEffect(function () {
|
|
4981
|
-
var timeoutId = null;
|
|
4982
|
-
if (startLongPress) {
|
|
4983
|
-
timeoutId = setTimeout(callback, ms);
|
|
4984
|
-
}
|
|
4985
|
-
else {
|
|
4986
|
-
if (timeoutId !== undefined && timeoutId !== null) {
|
|
4987
|
-
clearTimeout(timeoutId);
|
|
4988
|
-
}
|
|
4989
|
-
}
|
|
4990
|
-
return function () {
|
|
4991
|
-
if (timeoutId !== undefined && timeoutId !== null) {
|
|
4992
|
-
clearTimeout(timeoutId);
|
|
4993
|
-
}
|
|
4994
|
-
};
|
|
4995
|
-
}, [callback, ms, startLongPress]);
|
|
4996
|
-
var start = React.useCallback(function () {
|
|
4997
|
-
setStartLongPress(true);
|
|
4998
|
-
}, []);
|
|
4999
|
-
var stop = React.useCallback(function () {
|
|
5000
|
-
setStartLongPress(false);
|
|
5001
|
-
}, []);
|
|
5002
|
-
return {
|
|
5003
|
-
onMouseDown: start,
|
|
5004
|
-
onMouseUp: stop,
|
|
5005
|
-
onMouseLeave: stop,
|
|
5006
|
-
onTouchStart: start,
|
|
5007
|
-
onTouchEnd: stop,
|
|
5008
|
-
};
|
|
5009
|
-
}
|
|
5010
|
-
|
|
5011
5033
|
/*
|
|
5012
5034
|
Code from https://www.joshwcomeau.com/react/animated-sparkles-in-react/
|
|
5013
5035
|
Check out his site. It's awesome
|