@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 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';
@@ -3416,6 +3416,241 @@ var THSorted = function (_a) {
3416
3416
  };
3417
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;
3418
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
+
3419
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; });
3420
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);
3421
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);
@@ -3431,18 +3666,16 @@ var PopupContainer = function (_a) {
3431
3666
  }, []);
3432
3667
  return ReactDOM.createPortal(children, ref.current);
3433
3668
  };
3434
- var Popup = function (_a) {
3669
+ var Popup = React__default.forwardRef(function (_a, forwardedRef) {
3435
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"]);
3436
- var ref = React__default.useRef(null);
3437
- /* there is a bug where this closes popup involuntarily
3438
- const handleClick = (e: Event) => {
3439
- // @ts-ignore
3440
- if (ref.current?.contains(e.target)) {
3441
- return;
3442
- }
3443
- onClose && onClose();
3444
- };
3445
- */
3671
+ var ref = useFallbackRef(forwardedRef);
3672
+ useClickOutside({
3673
+ ref: ref,
3674
+ onClick: function (e) {
3675
+ closeOnClickOutside && onClose && onClose(e);
3676
+ },
3677
+ onCleanup: onClose,
3678
+ });
3446
3679
  useEffect(function () {
3447
3680
  var handleKeyDown = function (e) {
3448
3681
  // @ts-ignore
@@ -3470,7 +3703,7 @@ var Popup = function (_a) {
3470
3703
  React__default.createElement(Col, { style: { textAlign: 'right', alignSelf: 'center' } }, noCloseButton ? null :
3471
3704
  controls || React__default.createElement(Button, { onClick: onClose }, "Close")))),
3472
3705
  React__default.createElement("div", { className: "popup-content" }, children))));
3473
- };
3706
+ });
3474
3707
  var ShowPopup = function (_a) {
3475
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"]);
3476
3709
  var _e = useState(autoOpen), showPopup = _e[0], setShowPopup = _e[1];
@@ -3747,10 +3980,10 @@ var Tabs = /** @class */ (function (_super) {
3747
3980
  };
3748
3981
  Tabs.prototype.render = function () {
3749
3982
  var _this = this;
3750
- 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"]);
3751
3984
  var selectedTab = this.getTab(tabs, this.state.selectedTabIndex);
3752
3985
  return React__default.createElement("div", __assign({}, props),
3753
- 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) {
3754
3987
  _this.setState({ selectedTabIndex: index });
3755
3988
  var callback = tabs[index].onClick;
3756
3989
  if (callback) {
@@ -4788,217 +5021,6 @@ function HeadlessTable(_a) {
4788
5021
  }
4789
5022
  var templateObject_1$B, templateObject_2$p, templateObject_3$h;
4790
5023
 
4791
- var QUERY = '(prefers-reduced-motion: no-preference)';
4792
- var isRenderingOnServer = typeof window$1 === 'undefined';
4793
- var getInitialState = function () {
4794
- // For our initial server render, we won't know if the user
4795
- // prefers reduced motion, but it doesn't matter. This value
4796
- // will be overwritten on the client, before any animations
4797
- // occur.
4798
- return isRenderingOnServer ? true : !window$1.matchMedia(QUERY).matches;
4799
- };
4800
- var usePrefersReducedMotion = function () {
4801
- var _a = React__default.useState(getInitialState), prefersReducedMotion = _a[0], setPrefersReducedMotion = _a[1];
4802
- React__default.useEffect(function () {
4803
- var mediaQueryList = window$1.matchMedia(QUERY);
4804
- var listener = function (event) {
4805
- setPrefersReducedMotion(!event.matches);
4806
- };
4807
- mediaQueryList.addListener(listener);
4808
- return function () {
4809
- mediaQueryList.removeListener(listener);
4810
- };
4811
- }, []);
4812
- return prefersReducedMotion;
4813
- };
4814
-
4815
- var useRandomInterval = function (callback, minDelay, maxDelay) {
4816
- var timeoutId = React__default.useRef(null);
4817
- var savedCallback = React__default.useRef(callback);
4818
- React__default.useEffect(function () {
4819
- savedCallback.current = callback;
4820
- });
4821
- React__default.useEffect(function () {
4822
- var isEnabled = typeof minDelay === 'number' && typeof maxDelay === 'number';
4823
- if (isEnabled) {
4824
- var handleTick_1 = function () {
4825
- var nextTickAt = random(minDelay, maxDelay);
4826
- timeoutId.current = setTimeout(function () {
4827
- savedCallback.current();
4828
- handleTick_1();
4829
- }, nextTickAt);
4830
- };
4831
- handleTick_1();
4832
- }
4833
- return function () {
4834
- if (!!timeoutId.current) {
4835
- clearTimeout(timeoutId.current);
4836
- }
4837
- };
4838
- }, [minDelay, maxDelay]);
4839
- var cancel = React__default.useCallback(function () {
4840
- if (!!timeoutId.current) {
4841
- clearTimeout(timeoutId.current);
4842
- }
4843
- }, []);
4844
- return cancel;
4845
- };
4846
-
4847
- var today = new Date();
4848
- var getDatesBetween = function (startDt, endDt) {
4849
- var result = [];
4850
- var currentDt = startDt;
4851
- while (currentDt <= endDt) {
4852
- result.push(currentDt);
4853
- currentDt = addDays(currentDt, 1);
4854
- }
4855
- return result;
4856
- };
4857
- var useCalendar = function (_a) {
4858
- var onChangeWeek = _a.onChangeWeek, onChangeMonth = _a.onChangeMonth;
4859
- var _b = useState(today), currentMonth = _b[0], setCurrentMonth = _b[1];
4860
- var _c = useState(getWeek(currentMonth)), currentWeek = _c[0], setCurrentWeek = _c[1];
4861
- var _d = useState(today), selectedDate = _d[0], setSelectedDate = _d[1];
4862
- var changeMonth = function (action) {
4863
- var dt = currentMonth;
4864
- if (action === "prev") {
4865
- dt = subMonths(currentMonth, 1);
4866
- }
4867
- else if (action === "next") {
4868
- dt = addMonths(currentMonth, 1);
4869
- }
4870
- else if (action === "reset") {
4871
- dt = today;
4872
- }
4873
- setCurrentMonth(dt);
4874
- onChangeMonth && onChangeMonth({
4875
- action: action,
4876
- date: dt,
4877
- month: getMonth(dt),
4878
- year: getYear(dt),
4879
- });
4880
- };
4881
- var changeWeek = function (action, value) {
4882
- var dt = currentMonth;
4883
- if (action === "prev") {
4884
- dt = subWeeks(currentMonth, 1);
4885
- }
4886
- else if (action === "next") {
4887
- dt = addWeeks(currentMonth, 1);
4888
- }
4889
- else if (action === "reset") {
4890
- dt = today;
4891
- }
4892
- else if (action === "custom" && value) {
4893
- dt = value;
4894
- }
4895
- setCurrentMonth(dt);
4896
- var week = getWeek(dt);
4897
- setCurrentWeek(week);
4898
- onChangeWeek && onChangeWeek({
4899
- action: action,
4900
- date: dt,
4901
- week: week,
4902
- month: getMonth(dt),
4903
- year: getYear(dt),
4904
- });
4905
- };
4906
- var changeDate = function (value) {
4907
- setCurrentMonth(value);
4908
- var week = getWeek(value);
4909
- setCurrentWeek(week);
4910
- onChangeWeek && onChangeWeek({
4911
- action: 'change-date',
4912
- date: value,
4913
- week: week,
4914
- month: getMonth(value),
4915
- year: getYear(value),
4916
- });
4917
- };
4918
- var onClickDay = function (day) {
4919
- if (isSameDay(day, selectedDate)) {
4920
- setSelectedDate(today);
4921
- }
4922
- else {
4923
- setSelectedDate(day);
4924
- }
4925
- };
4926
- // reset to today's date
4927
- var resetToToday = function () {
4928
- setSelectedDate(today);
4929
- changeWeek('reset');
4930
- };
4931
- var onNextWeek = function () { return changeWeek("next"); };
4932
- var onPrevWeek = function () { return changeWeek("prev"); };
4933
- var onNextMonth = function () { return changeMonth("next"); };
4934
- var onPrevMonth = function () { return changeMonth("prev"); };
4935
- return {
4936
- currentMonth: currentMonth,
4937
- currentWeek: currentWeek,
4938
- selectedDate: selectedDate,
4939
- setSelectedDate: setSelectedDate,
4940
- setCurrentWeek: setCurrentWeek,
4941
- setCurrentMonth: setCurrentMonth,
4942
- onClickDay: onClickDay,
4943
- onNextWeek: onNextWeek,
4944
- onPrevWeek: onPrevWeek,
4945
- onNextMonth: onNextMonth,
4946
- onPrevMonth: onPrevMonth,
4947
- changeWeek: changeWeek,
4948
- changeDate: changeDate,
4949
- getDatesBetween: getDatesBetween,
4950
- onReset: resetToToday,
4951
- };
4952
- };
4953
-
4954
- var useWindowSize = function () {
4955
- var _a = useState([0, 0]), size = _a[0], setSize = _a[1]; // [width, height]
4956
- useEffect(function () {
4957
- function updateSize() {
4958
- setSize([window.innerWidth, window.innerHeight]);
4959
- }
4960
- window.addEventListener('resize', updateSize);
4961
- updateSize();
4962
- return function () { return window.removeEventListener('resize', updateSize); };
4963
- }, []);
4964
- return size;
4965
- };
4966
-
4967
- function useLongPress(callback, ms) {
4968
- if (callback === void 0) { callback = function () { }; }
4969
- if (ms === void 0) { ms = 300; }
4970
- var _a = useState(false), startLongPress = _a[0], setStartLongPress = _a[1];
4971
- useEffect(function () {
4972
- var timeoutId = null;
4973
- if (startLongPress) {
4974
- timeoutId = setTimeout(callback, ms);
4975
- }
4976
- else {
4977
- if (timeoutId !== undefined && timeoutId !== null) {
4978
- clearTimeout(timeoutId);
4979
- }
4980
- }
4981
- return function () {
4982
- if (timeoutId !== undefined && timeoutId !== null) {
4983
- clearTimeout(timeoutId);
4984
- }
4985
- };
4986
- }, [callback, ms, startLongPress]);
4987
- var start = useCallback(function () {
4988
- setStartLongPress(true);
4989
- }, []);
4990
- var stop = useCallback(function () {
4991
- setStartLongPress(false);
4992
- }, []);
4993
- return {
4994
- onMouseDown: start,
4995
- onMouseUp: stop,
4996
- onMouseLeave: stop,
4997
- onTouchStart: start,
4998
- onTouchEnd: stop,
4999
- };
5000
- }
5001
-
5002
5024
  /*
5003
5025
  Code from https://www.joshwcomeau.com/react/animated-sparkles-in-react/
5004
5026
  Check out his site. It's awesome