mimir-ui-kit 1.13.7 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +62 -62
- package/dist/{NavigationButtons-DuOoqaPo.js → NavigationButtons-B8tMfqrg.js} +20 -20
- package/dist/assets/Button.css +1 -1
- package/dist/assets/Input.css +1 -1
- package/dist/assets/MergedButton.css +1 -1
- package/dist/assets/OtpInput.css +1 -1
- package/dist/assets/RadioGroup.css +1 -1
- package/dist/assets/Slider.css +1 -1
- package/dist/assets/index.css +1 -1
- package/dist/components/Button/Button.d.ts +1 -0
- package/dist/components/Button/Button.js +25 -26
- package/dist/components/Button/constants.d.ts +1 -2
- package/dist/components/Button/constants.js +0 -1
- package/dist/components/Input/Input.d.ts +2 -2
- package/dist/components/Input/Input.js +16 -17
- package/dist/components/InputPassword/InputPassword.js +2 -2
- package/dist/components/InputPhoneNumber/InputPhoneNumber.js +1 -1
- package/dist/components/MergedButton/MergedButton.d.ts +1 -1
- package/dist/components/MergedButton/MergedButton.js +19 -17
- package/dist/components/OtpInput/OtpInput.js +6 -6
- package/dist/components/RadioGroup/RadioGroup.d.ts +2 -18
- package/dist/components/RadioGroup/RadioGroup.js +1061 -130
- package/dist/components/RadioGroup/index.d.ts +1 -1
- package/dist/components/Slider/NavigationButtons/NavigationButtons.js +1 -1
- package/dist/components/Slider/NavigationButtons/index.js +1 -1
- package/dist/components/Slider/Slider.js +10 -10
- package/dist/components/Tag/Tag.d.ts +57 -19
- package/dist/components/Tag/Tag.js +84 -39
- package/dist/components/Tag/constants.d.ts +37 -5
- package/dist/components/Tag/constants.js +53 -13
- package/dist/components/Tag/index.d.ts +3 -2
- package/dist/components/Tag/index.js +6 -5
- package/dist/components/Tag/types.d.ts +6 -0
- package/dist/components/index.d.ts +1 -15
- package/dist/components/index.js +0 -29
- package/dist/hooks/index.d.ts +0 -3
- package/dist/hooks/index.js +1 -7
- package/dist/icons/Icon.js +1 -1
- package/dist/icons/components/index.d.ts +0 -1
- package/dist/icons/components/index.js +559 -560
- package/dist/{index-Cxiikb7g.js → index-_ACzPKPw.js} +558 -561
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -38
- package/package.json +128 -128
- package/dist/DatePickerModal-BM0BgzTb.js +0 -204
- package/dist/assets/Accordion.css +0 -1
- package/dist/assets/AccordionItem.css +0 -1
- package/dist/assets/DatePickerModal.css +0 -1
- package/dist/assets/Drawer.css +0 -1
- package/dist/assets/ListPhotos.css +0 -1
- package/dist/assets/SelectSearch.css +0 -1
- package/dist/assets/Switch.css +0 -1
- package/dist/assets/TabTrail.css +0 -1
- package/dist/assets/Tag.css +0 -1
- package/dist/assets/Timer.css +0 -1
- package/dist/assets/Uploader.css +0 -1
- package/dist/assets/UploaderPhotos.css +0 -1
- package/dist/bugs-CSBdWk0R.js +0 -18
- package/dist/components/Accordion/Accordion.d.ts +0 -10
- package/dist/components/Accordion/Accordion.js +0 -176
- package/dist/components/Accordion/AccordionItem/AccordionItem.d.ts +0 -8
- package/dist/components/Accordion/AccordionItem/AccordionItem.js +0 -16
- package/dist/components/Accordion/AccordionItem/index.d.ts +0 -1
- package/dist/components/Accordion/AccordionItem/index.js +0 -4
- package/dist/components/Accordion/constants.d.ts +0 -8
- package/dist/components/Accordion/constants.js +0 -14
- package/dist/components/Accordion/index.d.ts +0 -3
- package/dist/components/Accordion/index.js +0 -8
- package/dist/components/DatePicker/DatePicker.d.ts +0 -44
- package/dist/components/DatePicker/DatePicker.js +0 -69
- package/dist/components/DatePicker/DatePickerModal.d.ts +0 -8
- package/dist/components/DatePicker/DatePickerModal.js +0 -9
- package/dist/components/DatePicker/constants.d.ts +0 -6
- package/dist/components/DatePicker/constants.js +0 -11
- package/dist/components/DatePicker/index.d.ts +0 -2
- package/dist/components/DatePicker/index.js +0 -4
- package/dist/components/Drawer/Drawer.d.ts +0 -38
- package/dist/components/Drawer/Drawer.js +0 -144
- package/dist/components/Drawer/constants.d.ts +0 -5
- package/dist/components/Drawer/constants.js +0 -9
- package/dist/components/Drawer/index.d.ts +0 -2
- package/dist/components/Drawer/index.js +0 -6
- package/dist/components/ListPhotos/ListPhotos.d.ts +0 -23
- package/dist/components/ListPhotos/ListPhotos.js +0 -33
- package/dist/components/ListPhotos/constants.d.ts +0 -3
- package/dist/components/ListPhotos/constants.js +0 -21
- package/dist/components/ListPhotos/index.d.ts +0 -2
- package/dist/components/ListPhotos/index.js +0 -4
- package/dist/components/Portal/Portal.d.ts +0 -7
- package/dist/components/Portal/Portal.js +0 -10
- package/dist/components/Portal/index.d.ts +0 -1
- package/dist/components/Portal/index.js +0 -4
- package/dist/components/SelectSearch/SelectSearch.d.ts +0 -15
- package/dist/components/SelectSearch/SelectSearch.js +0 -3876
- package/dist/components/SelectSearch/constants.d.ts +0 -4
- package/dist/components/SelectSearch/constants.js +0 -8
- package/dist/components/SelectSearch/index.d.ts +0 -2
- package/dist/components/SelectSearch/index.js +0 -6
- package/dist/components/Switch/Switch.d.ts +0 -294
- package/dist/components/Switch/Switch.js +0 -59
- package/dist/components/Switch/index.d.ts +0 -2
- package/dist/components/Switch/index.js +0 -4
- package/dist/components/TabTrail/TabButtons/TabButtons.d.ts +0 -8
- package/dist/components/TabTrail/TabButtons/TabButtons.js +0 -29
- package/dist/components/TabTrail/TabButtons/constants.d.ts +0 -8
- package/dist/components/TabTrail/TabButtons/constants.js +0 -14
- package/dist/components/TabTrail/TabButtons/index.d.ts +0 -1
- package/dist/components/TabTrail/TabButtons/index.js +0 -4
- package/dist/components/TabTrail/TabTrail.d.ts +0 -11
- package/dist/components/TabTrail/TabTrail.js +0 -282
- package/dist/components/TabTrail/constants.d.ts +0 -4
- package/dist/components/TabTrail/constants.js +0 -8
- package/dist/components/TabTrail/index.d.ts +0 -2
- package/dist/components/TabTrail/index.js +0 -6
- package/dist/components/Timer/Timer.d.ts +0 -24
- package/dist/components/Timer/Timer.js +0 -29
- package/dist/components/Timer/index.d.ts +0 -1
- package/dist/components/Timer/index.js +0 -4
- package/dist/components/Uploader/Uploader.d.ts +0 -30
- package/dist/components/Uploader/Uploader.js +0 -90
- package/dist/components/Uploader/constants.d.ts +0 -5
- package/dist/components/Uploader/constants.js +0 -16
- package/dist/components/Uploader/index.d.ts +0 -2
- package/dist/components/Uploader/index.js +0 -4
- package/dist/components/UploaderPhotos/UploaderPhotos.d.ts +0 -29
- package/dist/components/UploaderPhotos/UploaderPhotos.js +0 -46
- package/dist/components/UploaderPhotos/index.d.ts +0 -2
- package/dist/components/UploaderPhotos/index.js +0 -4
- package/dist/focus-management-1rQPII7Z.js +0 -77
- package/dist/hidden-BuVoeHNy.js +0 -13
- package/dist/hooks/useClickOutside/index.d.ts +0 -1
- package/dist/hooks/useClickOutside/index.js +0 -4
- package/dist/hooks/useClickOutside/useClickOutside.d.ts +0 -7
- package/dist/hooks/useClickOutside/useClickOutside.js +0 -25
- package/dist/hooks/useInterval/index.d.ts +0 -1
- package/dist/hooks/useInterval/index.js +0 -4
- package/dist/hooks/useInterval/useInterval.d.ts +0 -1
- package/dist/hooks/useInterval/useInterval.js +0 -17
- package/dist/hooks/useLockBodyScroll/index.d.ts +0 -1
- package/dist/hooks/useLockBodyScroll/index.js +0 -4
- package/dist/hooks/useLockBodyScroll/useLockBodyScroll.d.ts +0 -6
- package/dist/hooks/useLockBodyScroll/useLockBodyScroll.js +0 -20
- package/dist/hooks/useTimer/index.d.ts +0 -18
- package/dist/hooks/useTimer/index.js +0 -83
- package/dist/hooks/useTimer/useTimer.d.ts +0 -18
- package/dist/hooks/useTimer/useTimer.js +0 -87
- package/dist/hooks/useTimer/utils.d.ts +0 -24
- package/dist/hooks/useTimer/utils.js +0 -88
- package/dist/icons/components/12px/Close12px.d.ts +0 -4
- package/dist/icons/components/12px/Close12px.js +0 -18
- package/dist/keyboard-B256ZoM-.js +0 -745
- package/dist/label-C_5Syaoj.js +0 -159
- package/dist/open-closed-CbXq00et.js +0 -93
- package/dist/use-active-press-B6yeSopF.js +0 -31
- package/dist/use-by-comparator-BUO78DGe.js +0 -16
- package/dist/use-resolve-button-type-B6LE6gU3.js +0 -19
- package/dist/utils/UUID4.d.ts +0 -1
- package/dist/utils/UUID4.js +0 -9
- package/dist/utils/formating/Date.d.ts +0 -1
- package/dist/utils/formating/Date.js +0 -26
- package/dist/utils/formating/Month.d.ts +0 -8
- package/dist/utils/formating/Month.js +0 -80
- package/dist/utils/formating/Numbers.d.ts +0 -6
- package/dist/utils/formating/Numbers.js +0 -8
- package/dist/utils/index.d.ts +0 -11
- package/dist/utils/index.js +0 -13
@@ -1,77 +0,0 @@
|
|
1
|
-
import { u, a as u$1 } from "./keyboard-B256ZoM-.js";
|
2
|
-
let f = ["[contentEditable=true]", "[tabindex]", "a[href]", "area[href]", "button:not([disabled])", "iframe", "input:not([disabled])", "select:not([disabled])", "textarea:not([disabled])"].map((e) => `${e}:not([tabindex='-1'])`).join(","), p = ["[data-autofocus]"].map((e) => `${e}:not([tabindex='-1'])`).join(",");
|
3
|
-
var F = ((n) => (n[n.First = 1] = "First", n[n.Previous = 2] = "Previous", n[n.Next = 4] = "Next", n[n.Last = 8] = "Last", n[n.WrapAround = 16] = "WrapAround", n[n.NoScroll = 32] = "NoScroll", n[n.AutoFocus = 64] = "AutoFocus", n))(F || {}), T = ((o) => (o[o.Error = 0] = "Error", o[o.Overflow = 1] = "Overflow", o[o.Success = 2] = "Success", o[o.Underflow = 3] = "Underflow", o))(T || {}), y = ((t) => (t[t.Previous = -1] = "Previous", t[t.Next = 1] = "Next", t))(y || {});
|
4
|
-
function b(e = document.body) {
|
5
|
-
return e == null ? [] : Array.from(e.querySelectorAll(f)).sort((r, t) => Math.sign((r.tabIndex || Number.MAX_SAFE_INTEGER) - (t.tabIndex || Number.MAX_SAFE_INTEGER)));
|
6
|
-
}
|
7
|
-
function S(e = document.body) {
|
8
|
-
return e == null ? [] : Array.from(e.querySelectorAll(p)).sort((r, t) => Math.sign((r.tabIndex || Number.MAX_SAFE_INTEGER) - (t.tabIndex || Number.MAX_SAFE_INTEGER)));
|
9
|
-
}
|
10
|
-
var h = ((t) => (t[t.Strict = 0] = "Strict", t[t.Loose = 1] = "Loose", t))(h || {});
|
11
|
-
function A(e, r = 0) {
|
12
|
-
var t;
|
13
|
-
return e === ((t = u(e)) == null ? void 0 : t.body) ? false : u$1(r, { [0]() {
|
14
|
-
return e.matches(f);
|
15
|
-
}, [1]() {
|
16
|
-
let u2 = e;
|
17
|
-
for (; u2 !== null; ) {
|
18
|
-
if (u2.matches(f)) return true;
|
19
|
-
u2 = u2.parentElement;
|
20
|
-
}
|
21
|
-
return false;
|
22
|
-
} });
|
23
|
-
}
|
24
|
-
var H = ((t) => (t[t.Keyboard = 0] = "Keyboard", t[t.Mouse = 1] = "Mouse", t))(H || {});
|
25
|
-
typeof window != "undefined" && typeof document != "undefined" && (document.addEventListener("keydown", (e) => {
|
26
|
-
e.metaKey || e.altKey || e.ctrlKey || (document.documentElement.dataset.headlessuiFocusVisible = "");
|
27
|
-
}, true), document.addEventListener("click", (e) => {
|
28
|
-
e.detail === 1 ? delete document.documentElement.dataset.headlessuiFocusVisible : e.detail === 0 && (document.documentElement.dataset.headlessuiFocusVisible = "");
|
29
|
-
}, true));
|
30
|
-
let w = ["textarea", "input"].join(",");
|
31
|
-
function O(e) {
|
32
|
-
var r, t;
|
33
|
-
return (t = (r = e == null ? void 0 : e.matches) == null ? void 0 : r.call(e, w)) != null ? t : false;
|
34
|
-
}
|
35
|
-
function _(e, r = (t) => t) {
|
36
|
-
return e.slice().sort((t, u2) => {
|
37
|
-
let o = r(t), c = r(u2);
|
38
|
-
if (o === null || c === null) return 0;
|
39
|
-
let l = o.compareDocumentPosition(c);
|
40
|
-
return l & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : l & Node.DOCUMENT_POSITION_PRECEDING ? 1 : 0;
|
41
|
-
});
|
42
|
-
}
|
43
|
-
function P(e, r, { sorted: t = true, relativeTo: u2 = null, skipElements: o = [] } = {}) {
|
44
|
-
let c = Array.isArray(e) ? e.length > 0 ? e[0].ownerDocument : document : e.ownerDocument, l = Array.isArray(e) ? t ? _(e) : e : r & 64 ? S(e) : b(e);
|
45
|
-
o.length > 0 && l.length > 1 && (l = l.filter((s) => !o.some((a) => a != null && "current" in a ? (a == null ? void 0 : a.current) === s : a === s))), u2 = u2 != null ? u2 : c.activeElement;
|
46
|
-
let n = (() => {
|
47
|
-
if (r & 5) return 1;
|
48
|
-
if (r & 10) return -1;
|
49
|
-
throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last");
|
50
|
-
})(), x = (() => {
|
51
|
-
if (r & 1) return 0;
|
52
|
-
if (r & 2) return Math.max(0, l.indexOf(u2)) - 1;
|
53
|
-
if (r & 4) return Math.max(0, l.indexOf(u2)) + 1;
|
54
|
-
if (r & 8) return l.length - 1;
|
55
|
-
throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last");
|
56
|
-
})(), M = r & 32 ? { preventScroll: true } : {}, m = 0, d = l.length, i;
|
57
|
-
do {
|
58
|
-
if (m >= d || m + d <= 0) return 0;
|
59
|
-
let s = x + m;
|
60
|
-
if (r & 16) s = (s + d) % d;
|
61
|
-
else {
|
62
|
-
if (s < 0) return 3;
|
63
|
-
if (s >= d) return 1;
|
64
|
-
}
|
65
|
-
i = l[s], i == null || i.focus(M), m += n;
|
66
|
-
} while (i !== c.activeElement);
|
67
|
-
return r & 6 && O(i) && i.select(), 2;
|
68
|
-
}
|
69
|
-
export {
|
70
|
-
A,
|
71
|
-
F,
|
72
|
-
P,
|
73
|
-
T,
|
74
|
-
_,
|
75
|
-
f,
|
76
|
-
h
|
77
|
-
};
|
package/dist/hidden-BuVoeHNy.js
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
import { W, H } from "./keyboard-B256ZoM-.js";
|
2
|
-
let a = "span";
|
3
|
-
var s = ((e) => (e[e.None = 1] = "None", e[e.Focusable = 2] = "Focusable", e[e.Hidden = 4] = "Hidden", e))(s || {});
|
4
|
-
function l(t, r) {
|
5
|
-
var n;
|
6
|
-
let { features: d = 1, ...e } = t, o = { ref: r, "aria-hidden": (d & 2) === 2 ? true : (n = e["aria-hidden"]) != null ? n : void 0, hidden: (d & 4) === 4 ? true : void 0, style: { position: "fixed", top: 1, left: 1, width: 1, height: 0, padding: 0, margin: -1, overflow: "hidden", clip: "rect(0, 0, 0, 0)", whiteSpace: "nowrap", borderWidth: "0", ...(d & 4) === 4 && (d & 2) !== 2 && { display: "none" } } };
|
7
|
-
return H({ ourProps: o, theirProps: e, slot: {}, defaultTag: a, name: "Hidden" });
|
8
|
-
}
|
9
|
-
let T = W(l);
|
10
|
-
export {
|
11
|
-
T,
|
12
|
-
s
|
13
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export { useClickOutside } from './useClickOutside';
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import { useEffect } from "react";
|
2
|
-
function useClickOutside({
|
3
|
-
isActive,
|
4
|
-
setActive,
|
5
|
-
className
|
6
|
-
}) {
|
7
|
-
useEffect(() => {
|
8
|
-
const handleClickOtside = (e) => {
|
9
|
-
if (e.target) {
|
10
|
-
if (!e.target.closest("." + className)) {
|
11
|
-
setActive(false);
|
12
|
-
window.removeEventListener("click", handleClickOtside, true);
|
13
|
-
}
|
14
|
-
}
|
15
|
-
};
|
16
|
-
if (isActive) {
|
17
|
-
window.addEventListener("click", handleClickOtside, true);
|
18
|
-
} else {
|
19
|
-
window.removeEventListener("click", handleClickOtside, true);
|
20
|
-
}
|
21
|
-
}, [isActive]);
|
22
|
-
}
|
23
|
-
export {
|
24
|
-
useClickOutside
|
25
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export { useInterval } from './useInterval';
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare function useInterval(callback: VoidFunction, delay: number | null): void;
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import { useRef, useEffect } from "react";
|
2
|
-
function useInterval(callback, delay) {
|
3
|
-
const callbackRef = useRef();
|
4
|
-
callbackRef.current = callback;
|
5
|
-
useEffect(() => {
|
6
|
-
if (!delay) {
|
7
|
-
return;
|
8
|
-
}
|
9
|
-
const interval = setInterval(() => {
|
10
|
-
callbackRef.current && callbackRef.current();
|
11
|
-
}, delay);
|
12
|
-
return () => clearInterval(interval);
|
13
|
-
}, [delay]);
|
14
|
-
}
|
15
|
-
export {
|
16
|
-
useInterval
|
17
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export { useLockBodyScroll } from './useLockBodyScroll';
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { useLayoutEffect } from "react";
|
2
|
-
function useLockBodyScroll({ on, paddingRight }) {
|
3
|
-
useLayoutEffect(() => {
|
4
|
-
const hasVerticalScrollbar = document.documentElement.scrollHeight > document.documentElement.clientHeight;
|
5
|
-
if (!on || !hasVerticalScrollbar) return;
|
6
|
-
const originalStyle = window.getComputedStyle(document.body).overflow;
|
7
|
-
const originalPaddingStyle = window.getComputedStyle(
|
8
|
-
document.body
|
9
|
-
).paddingRight;
|
10
|
-
document.body.style.overflow = "hidden";
|
11
|
-
document.body.style.paddingRight = `${paddingRight}px`;
|
12
|
-
return () => {
|
13
|
-
document.body.style.overflow = originalStyle;
|
14
|
-
document.body.style.paddingRight = originalPaddingStyle;
|
15
|
-
};
|
16
|
-
}, [on, paddingRight]);
|
17
|
-
}
|
18
|
-
export {
|
19
|
-
useLockBodyScroll
|
20
|
-
};
|
@@ -1,18 +0,0 @@
|
|
1
|
-
export type TUserTimer = ReturnType<typeof useTimer>;
|
2
|
-
export type TUseTimerProps = {
|
3
|
-
expiryTimestamp?: number;
|
4
|
-
onExpire?: VoidFunction;
|
5
|
-
autoStart?: boolean;
|
6
|
-
};
|
7
|
-
export declare function useTimer({ expiryTimestamp: expiry, onExpire, autoStart }: TUseTimerProps): {
|
8
|
-
start: () => void;
|
9
|
-
pause: () => void;
|
10
|
-
resume: () => void;
|
11
|
-
restart: (newExpiryTimestamp: number, newAutoStart?: boolean) => void;
|
12
|
-
isRunning: boolean;
|
13
|
-
totalSeconds: number;
|
14
|
-
days: number;
|
15
|
-
hours: number;
|
16
|
-
minutes: number;
|
17
|
-
seconds: number;
|
18
|
-
};
|
@@ -1,83 +0,0 @@
|
|
1
|
-
import { useState, useCallback } from "react";
|
2
|
-
import { Time, Validate } from "./utils.js";
|
3
|
-
import { useInterval } from "../useInterval/useInterval.js";
|
4
|
-
const DEFAULT_DELAY = 1e3;
|
5
|
-
function getDelayFromExpiryTimestamp(expiryTimestamp) {
|
6
|
-
if (!Validate.expiryTimestamp(expiryTimestamp)) {
|
7
|
-
return null;
|
8
|
-
}
|
9
|
-
const seconds = Time.getSecondsFromExpiry(expiryTimestamp);
|
10
|
-
const extraMilliSeconds = Math.floor((seconds - Math.floor(seconds)) * 1e3);
|
11
|
-
return extraMilliSeconds > 0 ? extraMilliSeconds : DEFAULT_DELAY;
|
12
|
-
}
|
13
|
-
function useTimer({
|
14
|
-
expiryTimestamp: expiry,
|
15
|
-
onExpire,
|
16
|
-
autoStart = false
|
17
|
-
}) {
|
18
|
-
const [expiryTimestamp, setExpiryTimestamp] = useState(expiry);
|
19
|
-
const [seconds, setSeconds] = useState(
|
20
|
-
Time.getSecondsFromExpiry(expiry ?? 0)
|
21
|
-
);
|
22
|
-
const [isRunning, setIsRunning] = useState(autoStart);
|
23
|
-
const [didStart, setDidStart] = useState(autoStart);
|
24
|
-
const [delay, setDelay] = useState(getDelayFromExpiryTimestamp(expiry ?? 0));
|
25
|
-
const handleExpire = useCallback(() => {
|
26
|
-
Validate.onExpire(onExpire) && (onExpire == null ? void 0 : onExpire());
|
27
|
-
setIsRunning(false);
|
28
|
-
setDelay(null);
|
29
|
-
}, [onExpire]);
|
30
|
-
const pause = useCallback(() => {
|
31
|
-
setIsRunning(false);
|
32
|
-
}, []);
|
33
|
-
const restart = useCallback(
|
34
|
-
(newExpiryTimestamp, newAutoStart = true) => {
|
35
|
-
setDelay(getDelayFromExpiryTimestamp(newExpiryTimestamp));
|
36
|
-
setDidStart(newAutoStart);
|
37
|
-
setIsRunning(newAutoStart);
|
38
|
-
setExpiryTimestamp(newExpiryTimestamp);
|
39
|
-
setSeconds(Time.getSecondsFromExpiry(newExpiryTimestamp));
|
40
|
-
},
|
41
|
-
[]
|
42
|
-
);
|
43
|
-
const resume = useCallback(() => {
|
44
|
-
const time = /* @__PURE__ */ new Date();
|
45
|
-
time.setMilliseconds(time.getMilliseconds() + seconds * 1e3);
|
46
|
-
restart(time.getTime(), true);
|
47
|
-
}, [seconds, restart]);
|
48
|
-
const start = useCallback(() => {
|
49
|
-
if (didStart) {
|
50
|
-
setSeconds(Time.getSecondsFromExpiry(expiryTimestamp ?? 0, false));
|
51
|
-
setIsRunning(true);
|
52
|
-
} else {
|
53
|
-
resume();
|
54
|
-
}
|
55
|
-
}, [expiryTimestamp, didStart, resume]);
|
56
|
-
useInterval(
|
57
|
-
() => {
|
58
|
-
if (delay !== DEFAULT_DELAY) {
|
59
|
-
setDelay(DEFAULT_DELAY);
|
60
|
-
}
|
61
|
-
const secondsValue = Time.getSecondsFromExpiry(
|
62
|
-
expiryTimestamp ?? 0,
|
63
|
-
false
|
64
|
-
);
|
65
|
-
setSeconds(secondsValue);
|
66
|
-
if (secondsValue <= 0) {
|
67
|
-
handleExpire();
|
68
|
-
}
|
69
|
-
},
|
70
|
-
isRunning ? delay : null
|
71
|
-
);
|
72
|
-
return {
|
73
|
-
...Time.getTimeFromSeconds(seconds),
|
74
|
-
start,
|
75
|
-
pause,
|
76
|
-
resume,
|
77
|
-
restart,
|
78
|
-
isRunning
|
79
|
-
};
|
80
|
-
}
|
81
|
-
export {
|
82
|
-
useTimer
|
83
|
-
};
|
@@ -1,18 +0,0 @@
|
|
1
|
-
export type TUserTimer = ReturnType<typeof useTimer>;
|
2
|
-
export type TUseTimerProps = {
|
3
|
-
expiryTimestamp?: number;
|
4
|
-
onExpire?: VoidFunction;
|
5
|
-
autoStart?: boolean;
|
6
|
-
};
|
7
|
-
export declare function useTimer({ expiryTimestamp: expiry, onExpire, autoStart }: TUseTimerProps): {
|
8
|
-
start: () => void;
|
9
|
-
pause: () => void;
|
10
|
-
resume: () => void;
|
11
|
-
restart: (newExpiryTimestamp: number, newAutoStart?: boolean) => void;
|
12
|
-
isRunning: boolean;
|
13
|
-
totalSeconds: number;
|
14
|
-
days: number;
|
15
|
-
hours: number;
|
16
|
-
minutes: number;
|
17
|
-
seconds: number;
|
18
|
-
};
|
@@ -1,87 +0,0 @@
|
|
1
|
-
import { useState, useCallback } from "react";
|
2
|
-
import { Time, Validate, SECONDS_IN_MILLISECONDS } from "./utils.js";
|
3
|
-
import { useInterval } from "../useInterval/useInterval.js";
|
4
|
-
const DEFAULT_DELAY = 1e3;
|
5
|
-
function getDelayFromExpiryTimestamp(expiryTimestamp) {
|
6
|
-
if (!Validate.expiryTimestamp(expiryTimestamp)) {
|
7
|
-
return null;
|
8
|
-
}
|
9
|
-
const seconds = Time.getSecondsFromExpiry(expiryTimestamp);
|
10
|
-
const extraMilliSeconds = Math.floor(
|
11
|
-
(seconds - Math.floor(seconds)) * SECONDS_IN_MILLISECONDS
|
12
|
-
);
|
13
|
-
return extraMilliSeconds > 0 ? extraMilliSeconds : DEFAULT_DELAY;
|
14
|
-
}
|
15
|
-
function useTimer({
|
16
|
-
expiryTimestamp: expiry,
|
17
|
-
onExpire,
|
18
|
-
autoStart = true
|
19
|
-
}) {
|
20
|
-
const [expiryTimestamp, setExpiryTimestamp] = useState(expiry);
|
21
|
-
const [seconds, setSeconds] = useState(
|
22
|
-
Time.getSecondsFromExpiry(expiry ?? 0)
|
23
|
-
);
|
24
|
-
const [isRunning, setIsRunning] = useState(autoStart);
|
25
|
-
const [didStart, setDidStart] = useState(autoStart);
|
26
|
-
const [delay, setDelay] = useState(getDelayFromExpiryTimestamp(expiry ?? 0));
|
27
|
-
const handleExpire = useCallback(() => {
|
28
|
-
Validate.onExpire(onExpire) && (onExpire == null ? void 0 : onExpire());
|
29
|
-
setIsRunning(false);
|
30
|
-
setDelay(null);
|
31
|
-
}, [onExpire]);
|
32
|
-
const pause = useCallback(() => {
|
33
|
-
setIsRunning(false);
|
34
|
-
}, []);
|
35
|
-
const restart = useCallback(
|
36
|
-
(newExpiryTimestamp, newAutoStart = true) => {
|
37
|
-
setDelay(getDelayFromExpiryTimestamp(newExpiryTimestamp));
|
38
|
-
setDidStart(newAutoStart);
|
39
|
-
setIsRunning(newAutoStart);
|
40
|
-
setExpiryTimestamp(newExpiryTimestamp);
|
41
|
-
setSeconds(Time.getSecondsFromExpiry(newExpiryTimestamp));
|
42
|
-
},
|
43
|
-
[]
|
44
|
-
);
|
45
|
-
const resume = useCallback(() => {
|
46
|
-
const time = /* @__PURE__ */ new Date();
|
47
|
-
time.setMilliseconds(
|
48
|
-
time.getMilliseconds() + seconds * SECONDS_IN_MILLISECONDS
|
49
|
-
);
|
50
|
-
restart(time.getTime(), true);
|
51
|
-
}, [seconds, restart]);
|
52
|
-
const start = useCallback(() => {
|
53
|
-
if (didStart) {
|
54
|
-
setSeconds(Time.getSecondsFromExpiry(expiryTimestamp ?? 0, false));
|
55
|
-
setIsRunning(true);
|
56
|
-
} else {
|
57
|
-
resume();
|
58
|
-
}
|
59
|
-
}, [expiryTimestamp, didStart, resume]);
|
60
|
-
useInterval(
|
61
|
-
() => {
|
62
|
-
if (delay !== DEFAULT_DELAY) {
|
63
|
-
setDelay(DEFAULT_DELAY);
|
64
|
-
}
|
65
|
-
const secondsValue = Time.getSecondsFromExpiry(
|
66
|
-
expiryTimestamp ?? 0,
|
67
|
-
false
|
68
|
-
);
|
69
|
-
setSeconds(secondsValue);
|
70
|
-
if (secondsValue <= 0) {
|
71
|
-
handleExpire();
|
72
|
-
}
|
73
|
-
},
|
74
|
-
isRunning ? delay : null
|
75
|
-
);
|
76
|
-
return {
|
77
|
-
...Time.getTimeFromSeconds(seconds),
|
78
|
-
start,
|
79
|
-
pause,
|
80
|
-
resume,
|
81
|
-
restart,
|
82
|
-
isRunning
|
83
|
-
};
|
84
|
-
}
|
85
|
-
export {
|
86
|
-
useTimer
|
87
|
-
};
|
@@ -1,24 +0,0 @@
|
|
1
|
-
type TTimeObject = {
|
2
|
-
totalSeconds: number;
|
3
|
-
days: number;
|
4
|
-
hours: number;
|
5
|
-
minutes: number;
|
6
|
-
seconds: number;
|
7
|
-
};
|
8
|
-
type TFormattedTime = Omit<TTimeObject, 'totalSeconds' | 'days'>;
|
9
|
-
export declare const SECONDS_IN_MINUTE = 60;
|
10
|
-
export declare const SECONDS_IN_HOUR: number;
|
11
|
-
export declare const SECONDS_IN_DAY: number;
|
12
|
-
export declare const SECONDS_IN_MILLISECONDS = 1000;
|
13
|
-
export declare class Time {
|
14
|
-
static getTimeFromSeconds(secs: number): TTimeObject;
|
15
|
-
static getSecondsFromExpiry(expiry: number, shouldRound?: boolean): number;
|
16
|
-
static getSecondsFromPrevTime(prevTime: number, shouldRound: boolean): number;
|
17
|
-
static getSecondsFromTimeNow(): number;
|
18
|
-
static getFormattedTimeFromSeconds(totalSeconds: number): TFormattedTime;
|
19
|
-
}
|
20
|
-
export declare class Validate {
|
21
|
-
static expiryTimestamp(expiryTimestamp: number): boolean;
|
22
|
-
static onExpire(onExpire?: VoidFunction | null): boolean | null | undefined;
|
23
|
-
}
|
24
|
-
export {};
|
@@ -1,88 +0,0 @@
|
|
1
|
-
const SECONDS_IN_MINUTE = 60;
|
2
|
-
const SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE;
|
3
|
-
const SECONDS_IN_DAY = SECONDS_IN_HOUR * 24;
|
4
|
-
const SECONDS_IN_MILLISECONDS = 1e3;
|
5
|
-
class Time {
|
6
|
-
static getTimeFromSeconds(secs) {
|
7
|
-
const totalSeconds = Math.ceil(secs);
|
8
|
-
const days = Math.floor(totalSeconds / SECONDS_IN_DAY);
|
9
|
-
const hours = Math.floor(totalSeconds % SECONDS_IN_DAY / SECONDS_IN_HOUR);
|
10
|
-
const minutes = Math.floor(
|
11
|
-
totalSeconds % SECONDS_IN_HOUR / SECONDS_IN_MINUTE
|
12
|
-
);
|
13
|
-
const seconds = Math.floor(totalSeconds % SECONDS_IN_MINUTE);
|
14
|
-
return {
|
15
|
-
totalSeconds,
|
16
|
-
seconds,
|
17
|
-
minutes,
|
18
|
-
hours,
|
19
|
-
days
|
20
|
-
};
|
21
|
-
}
|
22
|
-
static getSecondsFromExpiry(expiry, shouldRound) {
|
23
|
-
const now = (/* @__PURE__ */ new Date()).getTime();
|
24
|
-
const milliSecondsDistance = expiry - now;
|
25
|
-
if (milliSecondsDistance > 0) {
|
26
|
-
const val = milliSecondsDistance / SECONDS_IN_MILLISECONDS;
|
27
|
-
return shouldRound ? Math.round(val) : val;
|
28
|
-
}
|
29
|
-
return 0;
|
30
|
-
}
|
31
|
-
static getSecondsFromPrevTime(prevTime, shouldRound) {
|
32
|
-
const now = (/* @__PURE__ */ new Date()).getTime();
|
33
|
-
const milliSecondsDistance = now - prevTime;
|
34
|
-
if (milliSecondsDistance > 0) {
|
35
|
-
const val = milliSecondsDistance / SECONDS_IN_MILLISECONDS;
|
36
|
-
return shouldRound ? Math.round(val) : val;
|
37
|
-
}
|
38
|
-
return 0;
|
39
|
-
}
|
40
|
-
static getSecondsFromTimeNow() {
|
41
|
-
const now = /* @__PURE__ */ new Date();
|
42
|
-
const currentTimestamp = now.getTime();
|
43
|
-
const offset = now.getTimezoneOffset() * SECONDS_IN_MINUTE;
|
44
|
-
return currentTimestamp / SECONDS_IN_MILLISECONDS - offset;
|
45
|
-
}
|
46
|
-
static getFormattedTimeFromSeconds(totalSeconds) {
|
47
|
-
const {
|
48
|
-
seconds: secondsValue,
|
49
|
-
minutes,
|
50
|
-
hours
|
51
|
-
} = Time.getTimeFromSeconds(totalSeconds);
|
52
|
-
return {
|
53
|
-
seconds: secondsValue,
|
54
|
-
minutes,
|
55
|
-
hours
|
56
|
-
};
|
57
|
-
}
|
58
|
-
}
|
59
|
-
class Validate {
|
60
|
-
static expiryTimestamp(expiryTimestamp) {
|
61
|
-
const isValid = new Date(expiryTimestamp).getTime() > 0;
|
62
|
-
if (!isValid) {
|
63
|
-
console.warn(
|
64
|
-
"{ useTimer } Invalid expiryTimestamp settings",
|
65
|
-
expiryTimestamp
|
66
|
-
);
|
67
|
-
}
|
68
|
-
return isValid;
|
69
|
-
}
|
70
|
-
static onExpire(onExpire) {
|
71
|
-
const isValid = onExpire && typeof onExpire === "function";
|
72
|
-
if (onExpire && !isValid) {
|
73
|
-
console.warn(
|
74
|
-
" { useTimer } Invalid onExpire settings function",
|
75
|
-
onExpire
|
76
|
-
);
|
77
|
-
}
|
78
|
-
return isValid;
|
79
|
-
}
|
80
|
-
}
|
81
|
-
export {
|
82
|
-
SECONDS_IN_DAY,
|
83
|
-
SECONDS_IN_HOUR,
|
84
|
-
SECONDS_IN_MILLISECONDS,
|
85
|
-
SECONDS_IN_MINUTE,
|
86
|
-
Time,
|
87
|
-
Validate
|
88
|
-
};
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
2
|
-
const Close12px = (props) => {
|
3
|
-
return /* @__PURE__ */ jsx(
|
4
|
-
"svg",
|
5
|
-
{
|
6
|
-
width: "12",
|
7
|
-
height: "12",
|
8
|
-
viewBox: "0 0 12 12",
|
9
|
-
fill: "none",
|
10
|
-
xmlns: "http://www.w3.org/2000/svg",
|
11
|
-
...props,
|
12
|
-
children: /* @__PURE__ */ jsx("path", { d: "M3 9L8.99991 3M9 9L3 3", stroke: "#333333", "stroke-width": "1.5" })
|
13
|
-
}
|
14
|
-
);
|
15
|
-
};
|
16
|
-
export {
|
17
|
-
Close12px as default
|
18
|
-
};
|