@commonsku/styles 1.16.2 → 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 CHANGED
@@ -1361,7 +1361,23 @@ declare type PopupProps = React$1.PropsWithChildren<{
1361
1361
  zIndex?: number;
1362
1362
  overlayZIndex?: number;
1363
1363
  } & SharedStyleTypes> & React$1.HTMLAttributes<HTMLDivElement>;
1364
- declare const Popup: ({ header, noHeader, title, controls, children, onClose, noCloseButton, closeOnEsc, closeOnClickOutside, overlayZIndex, ...props }: PopupProps) => JSX.Element;
1364
+ declare const Popup: React$1.ForwardRefExoticComponent<{
1365
+ header?: React$1.Component<{}, {}, any> | undefined;
1366
+ noHeader?: boolean | undefined;
1367
+ title?: string | React$1.Component<{}, {}, any> | undefined;
1368
+ controls?: React$1.ReactNode[] | undefined;
1369
+ onClose?: ((event?: React$1.MouseEvent) => void) | undefined;
1370
+ noCloseButton?: boolean | undefined;
1371
+ closeOnClickOutside?: boolean | undefined;
1372
+ closeOnEsc?: boolean | undefined;
1373
+ width?: string | undefined;
1374
+ height?: string | undefined;
1375
+ padding?: string | undefined;
1376
+ zIndex?: number | undefined;
1377
+ overlayZIndex?: number | undefined;
1378
+ } & SharedStyleTypes & {
1379
+ children?: React$1.ReactNode;
1380
+ } & React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
1365
1381
  declare const ShowPopup: React$1.FC<Omit<PopupProps, 'onClose'> & {
1366
1382
  popup: React$1.ComponentType<PopupProps>;
1367
1383
  autoOpen?: boolean;
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import _, { map, pick, keys, isUndefined, get, toNumber, isString, filter, partial, uniqueId, debounce } from 'lodash';
2
2
  import styled, { css, createGlobalStyle, ThemeProvider, keyframes } from 'styled-components';
3
- import React__default, { Fragment, useState, useEffect, useRef, Component, useCallback, createContext, memo, forwardRef, useLayoutEffect, useMemo } from 'react';
3
+ import React__default, { Fragment, useState, useEffect, useRef, useCallback, useImperativeHandle, Component, createContext, memo, forwardRef, useLayoutEffect, useMemo } from 'react';
4
4
  import { useDropzone } from 'react-dropzone';
5
5
  import BaseSelect from 'react-select';
6
6
  export { components, createFilter, mergeStyles } from 'react-select';
@@ -8,7 +8,7 @@ import BaseCreatableSelect from 'react-select/creatable';
8
8
  import BaseAsyncSelect from 'react-select/async';
9
9
  import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
10
10
  import ReactDOM from 'react-dom';
11
- import { format, addDays, getWeek, subWeeks, addWeeks, getMonth, getYear, isSameDay, subMonths, addMonths, startOfWeek, isDate, lastDayOfWeek } from 'date-fns';
11
+ import { addDays, getWeek, subWeeks, addWeeks, getMonth, getYear, isSameDay, subMonths, addMonths, format, startOfWeek, isDate, lastDayOfWeek } from 'date-fns';
12
12
  import BaseDatePicker from 'react-datepicker';
13
13
  import { useTable, useSortBy, usePagination, useColumnOrder, useBlockLayout, useFlexLayout, useExpanded } from 'react-table';
14
14
  import { useSticky } from 'react-table-sticky';
@@ -1319,16 +1319,18 @@ var themeOptions = {
1319
1319
  },
1320
1320
  };
1321
1321
  function getColor(color, def) {
1322
+ var _a;
1322
1323
  if (!color) {
1323
1324
  return '';
1324
1325
  }
1325
- return _.get(colors, color, _.get(colors, def || '', def));
1326
+ return (_a = _.get(colors, color, _.get(colors, def || '', def))) !== null && _a !== void 0 ? _a : '';
1326
1327
  }
1327
1328
  function getFontStyle(value, def) {
1329
+ var _a;
1328
1330
  if (!value) {
1329
1331
  return '';
1330
1332
  }
1331
- return _.get(fontStyles, value, _.get(fontStyles, def || '', def));
1333
+ return (_a = _.get(fontStyles, value, _.get(fontStyles, def || '', def))) !== null && _a !== void 0 ? _a : '';
1332
1334
  }
1333
1335
  function getThemeColor(props, color, fallbackColor) {
1334
1336
  return getThemeProperty(props, 'colors', color, fallbackColor);
@@ -1344,6 +1346,7 @@ function getThemeFontFamily(props, fallbackValue) {
1344
1346
  return getThemeProperty(props, 'fontFamily', fallbackValue);
1345
1347
  }
1346
1348
  function getThemeProperty(props, prop, value, fallbackValue) {
1349
+ var _a, _b;
1347
1350
  if (_.get(props, "theme.".concat(prop), null)) {
1348
1351
  if (_.isObject(props.theme[prop]) && _.get(props.theme, "".concat(prop, ".").concat(value), null)) {
1349
1352
  return _.get(props.theme, "".concat(prop, ".").concat(value), null);
@@ -1353,7 +1356,7 @@ function getThemeProperty(props, prop, value, fallbackValue) {
1353
1356
  }
1354
1357
  }
1355
1358
  else if (_.get(themeOptions, "".concat(prop, ".").concat(value), null)) {
1356
- return _.get(themeOptions, "".concat(prop, ".").concat(value), null);
1359
+ return (_a = _.get(themeOptions, "".concat(prop, ".").concat(value))) !== null && _a !== void 0 ? _a : '';
1357
1360
  }
1358
1361
  switch (prop) {
1359
1362
  case 'fontStyles':
@@ -1363,7 +1366,7 @@ function getThemeProperty(props, prop, value, fallbackValue) {
1363
1366
  case 'colors':
1364
1367
  return getColor(value, fallbackValue);
1365
1368
  case 'fontFamily':
1366
- return _.get(themeOptions.fontFamilies, "".concat(value, ".fontFamily"), fallbackValue || themeOptions.fontFamily);
1369
+ return (_b = _.get(themeOptions.fontFamilies, "".concat(value, ".fontFamily"), fallbackValue || themeOptions.fontFamily)) !== null && _b !== void 0 ? _b : '';
1367
1370
  default:
1368
1371
  return '';
1369
1372
  }
@@ -3413,6 +3416,241 @@ var THSorted = function (_a) {
3413
3416
  };
3414
3417
  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;
3415
3418
 
3419
+ var useClickOutside = function (props) {
3420
+ var ref = props.ref, _a = props.eventType, eventType = _a === void 0 ? 'mousedown' : _a, onClick = props.onClick, onCleanup = props.onCleanup;
3421
+ useEffect(function () {
3422
+ function handleClickOutside(e) {
3423
+ console.log('handleClickOutside');
3424
+ if (ref.current && !ref.current.contains(e.target)) {
3425
+ console.log('click outside');
3426
+ onClick && onClick(e);
3427
+ }
3428
+ }
3429
+ document.addEventListener(eventType, handleClickOutside);
3430
+ return function () {
3431
+ document.removeEventListener(eventType, handleClickOutside);
3432
+ onCleanup && onCleanup();
3433
+ };
3434
+ }, []);
3435
+ };
3436
+
3437
+ var QUERY = '(prefers-reduced-motion: no-preference)';
3438
+ var isRenderingOnServer = typeof window$1 === 'undefined';
3439
+ var getInitialState = function () {
3440
+ // For our initial server render, we won't know if the user
3441
+ // prefers reduced motion, but it doesn't matter. This value
3442
+ // will be overwritten on the client, before any animations
3443
+ // occur.
3444
+ return isRenderingOnServer ? true : !window$1.matchMedia(QUERY).matches;
3445
+ };
3446
+ var usePrefersReducedMotion = function () {
3447
+ var _a = React__default.useState(getInitialState), prefersReducedMotion = _a[0], setPrefersReducedMotion = _a[1];
3448
+ React__default.useEffect(function () {
3449
+ var mediaQueryList = window$1.matchMedia(QUERY);
3450
+ var listener = function (event) {
3451
+ setPrefersReducedMotion(!event.matches);
3452
+ };
3453
+ mediaQueryList.addListener(listener);
3454
+ return function () {
3455
+ mediaQueryList.removeListener(listener);
3456
+ };
3457
+ }, []);
3458
+ return prefersReducedMotion;
3459
+ };
3460
+
3461
+ var useRandomInterval = function (callback, minDelay, maxDelay) {
3462
+ var timeoutId = React__default.useRef(null);
3463
+ var savedCallback = React__default.useRef(callback);
3464
+ React__default.useEffect(function () {
3465
+ savedCallback.current = callback;
3466
+ });
3467
+ React__default.useEffect(function () {
3468
+ var isEnabled = typeof minDelay === 'number' && typeof maxDelay === 'number';
3469
+ if (isEnabled) {
3470
+ var handleTick_1 = function () {
3471
+ var nextTickAt = random(minDelay, maxDelay);
3472
+ timeoutId.current = setTimeout(function () {
3473
+ savedCallback.current();
3474
+ handleTick_1();
3475
+ }, nextTickAt);
3476
+ };
3477
+ handleTick_1();
3478
+ }
3479
+ return function () {
3480
+ if (!!timeoutId.current) {
3481
+ clearTimeout(timeoutId.current);
3482
+ }
3483
+ };
3484
+ }, [minDelay, maxDelay]);
3485
+ var cancel = React__default.useCallback(function () {
3486
+ if (!!timeoutId.current) {
3487
+ clearTimeout(timeoutId.current);
3488
+ }
3489
+ }, []);
3490
+ return cancel;
3491
+ };
3492
+
3493
+ var today = new Date();
3494
+ var getDatesBetween = function (startDt, endDt) {
3495
+ var result = [];
3496
+ var currentDt = startDt;
3497
+ while (currentDt <= endDt) {
3498
+ result.push(currentDt);
3499
+ currentDt = addDays(currentDt, 1);
3500
+ }
3501
+ return result;
3502
+ };
3503
+ var useCalendar = function (_a) {
3504
+ var onChangeWeek = _a.onChangeWeek, onChangeMonth = _a.onChangeMonth;
3505
+ var _b = useState(today), currentMonth = _b[0], setCurrentMonth = _b[1];
3506
+ var _c = useState(getWeek(currentMonth)), currentWeek = _c[0], setCurrentWeek = _c[1];
3507
+ var _d = useState(today), selectedDate = _d[0], setSelectedDate = _d[1];
3508
+ var changeMonth = function (action) {
3509
+ var dt = currentMonth;
3510
+ if (action === "prev") {
3511
+ dt = subMonths(currentMonth, 1);
3512
+ }
3513
+ else if (action === "next") {
3514
+ dt = addMonths(currentMonth, 1);
3515
+ }
3516
+ else if (action === "reset") {
3517
+ dt = today;
3518
+ }
3519
+ setCurrentMonth(dt);
3520
+ onChangeMonth && onChangeMonth({
3521
+ action: action,
3522
+ date: dt,
3523
+ month: getMonth(dt),
3524
+ year: getYear(dt),
3525
+ });
3526
+ };
3527
+ var changeWeek = function (action, value) {
3528
+ var dt = currentMonth;
3529
+ if (action === "prev") {
3530
+ dt = subWeeks(currentMonth, 1);
3531
+ }
3532
+ else if (action === "next") {
3533
+ dt = addWeeks(currentMonth, 1);
3534
+ }
3535
+ else if (action === "reset") {
3536
+ dt = today;
3537
+ }
3538
+ else if (action === "custom" && value) {
3539
+ dt = value;
3540
+ }
3541
+ setCurrentMonth(dt);
3542
+ var week = getWeek(dt);
3543
+ setCurrentWeek(week);
3544
+ onChangeWeek && onChangeWeek({
3545
+ action: action,
3546
+ date: dt,
3547
+ week: week,
3548
+ month: getMonth(dt),
3549
+ year: getYear(dt),
3550
+ });
3551
+ };
3552
+ var changeDate = function (value) {
3553
+ setCurrentMonth(value);
3554
+ var week = getWeek(value);
3555
+ setCurrentWeek(week);
3556
+ onChangeWeek && onChangeWeek({
3557
+ action: 'change-date',
3558
+ date: value,
3559
+ week: week,
3560
+ month: getMonth(value),
3561
+ year: getYear(value),
3562
+ });
3563
+ };
3564
+ var onClickDay = function (day) {
3565
+ if (isSameDay(day, selectedDate)) {
3566
+ setSelectedDate(today);
3567
+ }
3568
+ else {
3569
+ setSelectedDate(day);
3570
+ }
3571
+ };
3572
+ // reset to today's date
3573
+ var resetToToday = function () {
3574
+ setSelectedDate(today);
3575
+ changeWeek('reset');
3576
+ };
3577
+ var onNextWeek = function () { return changeWeek("next"); };
3578
+ var onPrevWeek = function () { return changeWeek("prev"); };
3579
+ var onNextMonth = function () { return changeMonth("next"); };
3580
+ var onPrevMonth = function () { return changeMonth("prev"); };
3581
+ return {
3582
+ currentMonth: currentMonth,
3583
+ currentWeek: currentWeek,
3584
+ selectedDate: selectedDate,
3585
+ setSelectedDate: setSelectedDate,
3586
+ setCurrentWeek: setCurrentWeek,
3587
+ setCurrentMonth: setCurrentMonth,
3588
+ onClickDay: onClickDay,
3589
+ onNextWeek: onNextWeek,
3590
+ onPrevWeek: onPrevWeek,
3591
+ onNextMonth: onNextMonth,
3592
+ onPrevMonth: onPrevMonth,
3593
+ changeWeek: changeWeek,
3594
+ changeDate: changeDate,
3595
+ getDatesBetween: getDatesBetween,
3596
+ onReset: resetToToday,
3597
+ };
3598
+ };
3599
+
3600
+ var useWindowSize = function () {
3601
+ var _a = useState([0, 0]), size = _a[0], setSize = _a[1]; // [width, height]
3602
+ useEffect(function () {
3603
+ function updateSize() {
3604
+ setSize([window.innerWidth, window.innerHeight]);
3605
+ }
3606
+ window.addEventListener('resize', updateSize);
3607
+ updateSize();
3608
+ return function () { return window.removeEventListener('resize', updateSize); };
3609
+ }, []);
3610
+ return size;
3611
+ };
3612
+
3613
+ function useLongPress(callback, ms) {
3614
+ if (callback === void 0) { callback = function () { }; }
3615
+ if (ms === void 0) { ms = 300; }
3616
+ var _a = useState(false), startLongPress = _a[0], setStartLongPress = _a[1];
3617
+ useEffect(function () {
3618
+ var timeoutId = null;
3619
+ if (startLongPress) {
3620
+ timeoutId = setTimeout(callback, ms);
3621
+ }
3622
+ else {
3623
+ if (timeoutId !== undefined && timeoutId !== null) {
3624
+ clearTimeout(timeoutId);
3625
+ }
3626
+ }
3627
+ return function () {
3628
+ if (timeoutId !== undefined && timeoutId !== null) {
3629
+ clearTimeout(timeoutId);
3630
+ }
3631
+ };
3632
+ }, [callback, ms, startLongPress]);
3633
+ var start = useCallback(function () {
3634
+ setStartLongPress(true);
3635
+ }, []);
3636
+ var stop = useCallback(function () {
3637
+ setStartLongPress(false);
3638
+ }, []);
3639
+ return {
3640
+ onMouseDown: start,
3641
+ onMouseUp: stop,
3642
+ onMouseLeave: stop,
3643
+ onTouchStart: start,
3644
+ onTouchEnd: stop,
3645
+ };
3646
+ }
3647
+
3648
+ var useFallbackRef = function (forwardedRef) {
3649
+ var localRef = useRef(null);
3650
+ useImperativeHandle(forwardedRef, function () { return localRef.current; });
3651
+ return localRef;
3652
+ };
3653
+
3416
3654
  var Overlay = styled.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; });
3417
3655
  var PopupWindow = styled.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);
3418
3656
  var PopupHeader = styled.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);
@@ -3428,18 +3666,16 @@ var PopupContainer = function (_a) {
3428
3666
  }, []);
3429
3667
  return ReactDOM.createPortal(children, ref.current);
3430
3668
  };
3431
- var Popup = function (_a) {
3669
+ var Popup = React__default.forwardRef(function (_a, forwardedRef) {
3432
3670
  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"]);
3433
- var ref = React__default.useRef(null);
3434
- /* there is a bug where this closes popup involuntarily
3435
- const handleClick = (e: Event) => {
3436
- // @ts-ignore
3437
- if (ref.current?.contains(e.target)) {
3438
- return;
3439
- }
3440
- onClose && onClose();
3441
- };
3442
- */
3671
+ var ref = useFallbackRef(forwardedRef);
3672
+ useClickOutside({
3673
+ ref: ref,
3674
+ onClick: function (e) {
3675
+ closeOnClickOutside && onClose && onClose(e);
3676
+ },
3677
+ onCleanup: onClose,
3678
+ });
3443
3679
  useEffect(function () {
3444
3680
  var handleKeyDown = function (e) {
3445
3681
  // @ts-ignore
@@ -3467,7 +3703,7 @@ var Popup = function (_a) {
3467
3703
  React__default.createElement(Col, { style: { textAlign: 'right', alignSelf: 'center' } }, noCloseButton ? null :
3468
3704
  controls || React__default.createElement(Button, { onClick: onClose }, "Close")))),
3469
3705
  React__default.createElement("div", { className: "popup-content" }, children))));
3470
- };
3706
+ });
3471
3707
  var ShowPopup = function (_a) {
3472
3708
  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"]);
3473
3709
  var _e = useState(autoOpen), showPopup = _e[0], setShowPopup = _e[1];
@@ -3744,10 +3980,10 @@ var Tabs = /** @class */ (function (_super) {
3744
3980
  };
3745
3981
  Tabs.prototype.render = function () {
3746
3982
  var _this = this;
3747
- var _a = this.props, tabs = _a.tabs, size = _a.size, props = __rest(_a, ["tabs", "size"]);
3983
+ var _a = this.props, tabs = _a.tabs, size = _a.size, padded = _a.padded, props = __rest(_a, ["tabs", "size", "padded"]);
3748
3984
  var selectedTab = this.getTab(tabs, this.state.selectedTabIndex);
3749
3985
  return React__default.createElement("div", __assign({}, props),
3750
- React__default.createElement(TabBar, { padded: this.props.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) {
3986
+ 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) {
3751
3987
  _this.setState({ selectedTabIndex: index });
3752
3988
  var callback = tabs[index].onClick;
3753
3989
  if (callback) {
@@ -4785,217 +5021,6 @@ function HeadlessTable(_a) {
4785
5021
  }
4786
5022
  var templateObject_1$B, templateObject_2$p, templateObject_3$h;
4787
5023
 
4788
- var QUERY = '(prefers-reduced-motion: no-preference)';
4789
- var isRenderingOnServer = typeof window$1 === 'undefined';
4790
- var getInitialState = function () {
4791
- // For our initial server render, we won't know if the user
4792
- // prefers reduced motion, but it doesn't matter. This value
4793
- // will be overwritten on the client, before any animations
4794
- // occur.
4795
- return isRenderingOnServer ? true : !window$1.matchMedia(QUERY).matches;
4796
- };
4797
- var usePrefersReducedMotion = function () {
4798
- var _a = React__default.useState(getInitialState), prefersReducedMotion = _a[0], setPrefersReducedMotion = _a[1];
4799
- React__default.useEffect(function () {
4800
- var mediaQueryList = window$1.matchMedia(QUERY);
4801
- var listener = function (event) {
4802
- setPrefersReducedMotion(!event.matches);
4803
- };
4804
- mediaQueryList.addListener(listener);
4805
- return function () {
4806
- mediaQueryList.removeListener(listener);
4807
- };
4808
- }, []);
4809
- return prefersReducedMotion;
4810
- };
4811
-
4812
- var useRandomInterval = function (callback, minDelay, maxDelay) {
4813
- var timeoutId = React__default.useRef(null);
4814
- var savedCallback = React__default.useRef(callback);
4815
- React__default.useEffect(function () {
4816
- savedCallback.current = callback;
4817
- });
4818
- React__default.useEffect(function () {
4819
- var isEnabled = typeof minDelay === 'number' && typeof maxDelay === 'number';
4820
- if (isEnabled) {
4821
- var handleTick_1 = function () {
4822
- var nextTickAt = random(minDelay, maxDelay);
4823
- timeoutId.current = setTimeout(function () {
4824
- savedCallback.current();
4825
- handleTick_1();
4826
- }, nextTickAt);
4827
- };
4828
- handleTick_1();
4829
- }
4830
- return function () {
4831
- if (!!timeoutId.current) {
4832
- clearTimeout(timeoutId.current);
4833
- }
4834
- };
4835
- }, [minDelay, maxDelay]);
4836
- var cancel = React__default.useCallback(function () {
4837
- if (!!timeoutId.current) {
4838
- clearTimeout(timeoutId.current);
4839
- }
4840
- }, []);
4841
- return cancel;
4842
- };
4843
-
4844
- var today = new Date();
4845
- var getDatesBetween = function (startDt, endDt) {
4846
- var result = [];
4847
- var currentDt = startDt;
4848
- while (currentDt <= endDt) {
4849
- result.push(currentDt);
4850
- currentDt = addDays(currentDt, 1);
4851
- }
4852
- return result;
4853
- };
4854
- var useCalendar = function (_a) {
4855
- var onChangeWeek = _a.onChangeWeek, onChangeMonth = _a.onChangeMonth;
4856
- var _b = useState(today), currentMonth = _b[0], setCurrentMonth = _b[1];
4857
- var _c = useState(getWeek(currentMonth)), currentWeek = _c[0], setCurrentWeek = _c[1];
4858
- var _d = useState(today), selectedDate = _d[0], setSelectedDate = _d[1];
4859
- var changeMonth = function (action) {
4860
- var dt = currentMonth;
4861
- if (action === "prev") {
4862
- dt = subMonths(currentMonth, 1);
4863
- }
4864
- else if (action === "next") {
4865
- dt = addMonths(currentMonth, 1);
4866
- }
4867
- else if (action === "reset") {
4868
- dt = today;
4869
- }
4870
- setCurrentMonth(dt);
4871
- onChangeMonth && onChangeMonth({
4872
- action: action,
4873
- date: dt,
4874
- month: getMonth(dt),
4875
- year: getYear(dt),
4876
- });
4877
- };
4878
- var changeWeek = function (action, value) {
4879
- var dt = currentMonth;
4880
- if (action === "prev") {
4881
- dt = subWeeks(currentMonth, 1);
4882
- }
4883
- else if (action === "next") {
4884
- dt = addWeeks(currentMonth, 1);
4885
- }
4886
- else if (action === "reset") {
4887
- dt = today;
4888
- }
4889
- else if (action === "custom" && value) {
4890
- dt = value;
4891
- }
4892
- setCurrentMonth(dt);
4893
- var week = getWeek(dt);
4894
- setCurrentWeek(week);
4895
- onChangeWeek && onChangeWeek({
4896
- action: action,
4897
- date: dt,
4898
- week: week,
4899
- month: getMonth(dt),
4900
- year: getYear(dt),
4901
- });
4902
- };
4903
- var changeDate = function (value) {
4904
- setCurrentMonth(value);
4905
- var week = getWeek(value);
4906
- setCurrentWeek(week);
4907
- onChangeWeek && onChangeWeek({
4908
- action: 'change-date',
4909
- date: value,
4910
- week: week,
4911
- month: getMonth(value),
4912
- year: getYear(value),
4913
- });
4914
- };
4915
- var onClickDay = function (day) {
4916
- if (isSameDay(day, selectedDate)) {
4917
- setSelectedDate(today);
4918
- }
4919
- else {
4920
- setSelectedDate(day);
4921
- }
4922
- };
4923
- // reset to today's date
4924
- var resetToToday = function () {
4925
- setSelectedDate(today);
4926
- changeWeek('reset');
4927
- };
4928
- var onNextWeek = function () { return changeWeek("next"); };
4929
- var onPrevWeek = function () { return changeWeek("prev"); };
4930
- var onNextMonth = function () { return changeMonth("next"); };
4931
- var onPrevMonth = function () { return changeMonth("prev"); };
4932
- return {
4933
- currentMonth: currentMonth,
4934
- currentWeek: currentWeek,
4935
- selectedDate: selectedDate,
4936
- setSelectedDate: setSelectedDate,
4937
- setCurrentWeek: setCurrentWeek,
4938
- setCurrentMonth: setCurrentMonth,
4939
- onClickDay: onClickDay,
4940
- onNextWeek: onNextWeek,
4941
- onPrevWeek: onPrevWeek,
4942
- onNextMonth: onNextMonth,
4943
- onPrevMonth: onPrevMonth,
4944
- changeWeek: changeWeek,
4945
- changeDate: changeDate,
4946
- getDatesBetween: getDatesBetween,
4947
- onReset: resetToToday,
4948
- };
4949
- };
4950
-
4951
- var useWindowSize = function () {
4952
- var _a = useState([0, 0]), size = _a[0], setSize = _a[1]; // [width, height]
4953
- useEffect(function () {
4954
- function updateSize() {
4955
- setSize([window.innerWidth, window.innerHeight]);
4956
- }
4957
- window.addEventListener('resize', updateSize);
4958
- updateSize();
4959
- return function () { return window.removeEventListener('resize', updateSize); };
4960
- }, []);
4961
- return size;
4962
- };
4963
-
4964
- function useLongPress(callback, ms) {
4965
- if (callback === void 0) { callback = function () { }; }
4966
- if (ms === void 0) { ms = 300; }
4967
- var _a = useState(false), startLongPress = _a[0], setStartLongPress = _a[1];
4968
- useEffect(function () {
4969
- var timeoutId = null;
4970
- if (startLongPress) {
4971
- timeoutId = setTimeout(callback, ms);
4972
- }
4973
- else {
4974
- if (timeoutId !== undefined && timeoutId !== null) {
4975
- clearTimeout(timeoutId);
4976
- }
4977
- }
4978
- return function () {
4979
- if (timeoutId !== undefined && timeoutId !== null) {
4980
- clearTimeout(timeoutId);
4981
- }
4982
- };
4983
- }, [callback, ms, startLongPress]);
4984
- var start = useCallback(function () {
4985
- setStartLongPress(true);
4986
- }, []);
4987
- var stop = useCallback(function () {
4988
- setStartLongPress(false);
4989
- }, []);
4990
- return {
4991
- onMouseDown: start,
4992
- onMouseUp: stop,
4993
- onMouseLeave: stop,
4994
- onTouchStart: start,
4995
- onTouchEnd: stop,
4996
- };
4997
- }
4998
-
4999
5024
  /*
5000
5025
  Code from https://www.joshwcomeau.com/react/animated-sparkles-in-react/
5001
5026
  Check out his site. It's awesome