@stokr/components-library 4.2.1 → 4.2.3
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/components/Button/Button.styles.d.ts +5 -1
- package/dist/components/CardTabs/CardTabs.styles.d.ts +34 -9
- package/dist/components/Checkbox/Checkbox.d.ts +3 -1
- package/dist/components/Checkbox/Checkbox.styles.d.ts +17 -4
- package/dist/components/Collapsible/Collapsible.styles.d.ts +18 -6
- package/dist/components/CopyToClipboardTooltip/CopyToClipboardTooltip.styles.d.ts +3 -1
- package/dist/components/InfoIcon/InfoIcon.styles.d.ts +8 -2
- package/dist/components/Input/Input.styles.d.ts +9 -3
- package/dist/components/Lottie/LottieAnimation.d.ts +43 -0
- package/dist/components/Lottie/LottieAnimation.js +0 -12
- package/dist/components/Lottie/LottieAnimation.styles.d.ts +5 -0
- package/dist/components/Lottie/LottieAnimation.styles.js +3 -2
- package/dist/components/MaterialIcon/MaterialIcon.styles.d.ts +25 -5
- package/dist/components/Modal/Modal.js +19 -24
- package/dist/components/Modal/Modal.styles.d.ts +49 -15
- package/dist/components/Modal/Modal.styles.js +4 -3
- package/dist/components/Modal/SideModal.js +7 -71
- package/dist/components/Modal/SideModal.styles.d.ts +12 -4
- package/dist/components/Modal/SideModalParts.d.ts +6 -2
- package/dist/components/Modal/SuccessModal/SuccessModal.d.ts +42 -0
- package/dist/components/Modal/SuccessModal/SuccessModal.js +50 -38
- package/dist/components/Modal/bodyScrollLock.d.ts +6 -0
- package/dist/components/Modal/bodyScrollLock.js +80 -0
- package/dist/components/Modal/lockPageScroll.d.ts +8 -0
- package/dist/components/Modal/lockPageScroll.js +62 -0
- package/dist/components/Section/Section.styles.d.ts +35 -7
- package/dist/components/Skeleton/Skeleton.styles.d.ts +9 -3
- package/dist/components/StokrLoader/StokrLoader.d.ts +3 -1
- package/dist/components/Text/Text.styles.d.ts +6 -2
- package/dist/components/Tooltip/Tooltip.styles.d.ts +6 -2
- package/dist/index.d.ts +14 -5
- package/dist/styles/rwd.d.ts +3 -1
- package/dist/utils/customHooks.d.ts +11 -4
- package/dist/utils/customHooks.js +14 -22
- package/package.json +13 -3
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { AnchorHTMLAttributes, ButtonHTMLAttributes, ComponentType, ElementType } from 'react';
|
|
2
1
|
import { LinkProps } from 'react-router-dom';
|
|
3
|
-
|
|
2
|
+
import { AnchorHTMLAttributes, ButtonHTMLAttributes, ComponentType, ElementType } from 'react';
|
|
3
|
+
export declare const ModalRoot: import('styled-components/dist/types').IStyledComponentBase<"web", Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
4
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
5
|
+
}> & string;
|
|
4
6
|
export interface ModalDimmerProps {
|
|
5
7
|
/** CSS background of the backdrop. Default `rgba(0, 0, 0, 0.7)`. */
|
|
6
8
|
background?: string;
|
|
7
9
|
kyc?: boolean;
|
|
8
10
|
}
|
|
9
|
-
export declare const Dimmer: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').
|
|
11
|
+
export declare const Dimmer: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
12
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
13
|
+
}, ModalDimmerProps>> & string;
|
|
10
14
|
export interface ModalBoxProps {
|
|
11
15
|
maxHeight?: string;
|
|
12
16
|
maxWidth?: string;
|
|
@@ -15,8 +19,12 @@ export interface ModalBoxProps {
|
|
|
15
19
|
thin?: boolean;
|
|
16
20
|
isRegisterEntity?: boolean;
|
|
17
21
|
}
|
|
18
|
-
export declare const Box: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').
|
|
19
|
-
|
|
22
|
+
export declare const Box: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
23
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
24
|
+
}, ModalBoxProps>> & string;
|
|
25
|
+
export declare const ModalInnerSmartContractAddress: import('styled-components/dist/types').IStyledComponentBase<"web", Omit<import('react').DetailedHTMLProps<import('react').InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "style"> & {
|
|
26
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
27
|
+
}> & string;
|
|
20
28
|
export interface ModalInnerWithBorderProps {
|
|
21
29
|
bottomRadius0?: boolean;
|
|
22
30
|
topRadius0?: boolean;
|
|
@@ -25,7 +33,9 @@ export interface ModalInnerWithBorderProps {
|
|
|
25
33
|
textAlignRight?: boolean;
|
|
26
34
|
paddingSmall?: boolean;
|
|
27
35
|
}
|
|
28
|
-
export declare const ModalInnerWithBorder: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').
|
|
36
|
+
export declare const ModalInnerWithBorder: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
37
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
38
|
+
}, ModalInnerWithBorderProps>> & string;
|
|
29
39
|
export interface ModalInnerProps {
|
|
30
40
|
/** Full viewport height on phones. */
|
|
31
41
|
isMobile?: boolean;
|
|
@@ -41,19 +51,43 @@ export interface ModalInnerProps {
|
|
|
41
51
|
noPadding?: boolean;
|
|
42
52
|
noPaddingHorizontal?: boolean;
|
|
43
53
|
}
|
|
44
|
-
export declare const ModalInner: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
export declare const ModalInner: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
55
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
56
|
+
}, ModalInnerProps>> & string;
|
|
57
|
+
export declare const ModalClose: import('styled-components/dist/types').IStyledComponentBase<"web", Omit<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "style"> & {
|
|
58
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
59
|
+
}, "tabIndex" | "role" | "aria-label" | "children"> & Partial<Pick<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "style"> & {
|
|
60
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
61
|
+
}, "tabIndex" | "role" | "aria-label" | "children">>> & string;
|
|
62
|
+
export declare const ModalBack: import('styled-components/dist/types').IStyledComponentBase<"web", Omit<import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "style"> & {
|
|
63
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
64
|
+
}, {
|
|
65
|
+
hide?: boolean;
|
|
66
|
+
}>, "tabIndex" | "role" | "aria-label" | "children"> & Partial<Pick<import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "style"> & {
|
|
67
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
68
|
+
}, {
|
|
47
69
|
hide?: boolean;
|
|
48
|
-
}
|
|
49
|
-
export declare const ModalLinkWrap: import('styled-components/dist/types').IStyledComponentBase<"web",
|
|
70
|
+
}>, "tabIndex" | "role" | "aria-label" | "children">>> & string;
|
|
71
|
+
export declare const ModalLinkWrap: import('styled-components/dist/types').IStyledComponentBase<"web", Omit<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
72
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
73
|
+
}, "children"> & Partial<Pick<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
74
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
75
|
+
}, "children">>> & string;
|
|
50
76
|
/** Props of `ModalLink`: a router link (`to`), or any element via `as` (e.g. `as="button"`, then `to` isn't needed). */
|
|
51
77
|
export type ModalLinkProps = Partial<LinkProps> & AnchorHTMLAttributes<HTMLAnchorElement> & ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
52
78
|
as?: ElementType;
|
|
53
79
|
};
|
|
54
80
|
/** Underlined link for modal footers ("Forgot password?", "Back to login"). */
|
|
55
81
|
export declare const ModalLink: ComponentType<ModalLinkProps>;
|
|
56
|
-
export declare const ModalWrapper: import('styled-components/dist/types').IStyledComponentBase<"web",
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export declare const
|
|
82
|
+
export declare const ModalWrapper: import('styled-components/dist/types').IStyledComponentBase<"web", Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
83
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
84
|
+
}> & string;
|
|
85
|
+
export declare const ModalTitle: import('styled-components/dist/types').IStyledComponentBase<"web", Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
86
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
87
|
+
}> & string;
|
|
88
|
+
export declare const ModalScroll: import('styled-components/dist/types').IStyledComponentBase<"web", Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
89
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
90
|
+
}> & string;
|
|
91
|
+
export declare const ModalSection: import('styled-components/dist/types').IStyledComponentBase<"web", Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
92
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
93
|
+
}> & string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import styled, { css } from "styled-components";
|
|
2
|
-
import { Link } from "react-router-dom";
|
|
3
|
-
import grid from "../../styles/grid.js";
|
|
4
1
|
import rwd from "../../styles/rwd.js";
|
|
2
|
+
import grid from "../../styles/grid.js";
|
|
5
3
|
import { colors } from "../../styles/colors.js";
|
|
4
|
+
import styled, { css } from "styled-components";
|
|
5
|
+
import { Link } from "react-router-dom";
|
|
6
6
|
import { glyph, withGlyph } from "../MaterialIcon/glyph.js";
|
|
7
7
|
const ModalRoot = styled.div`
|
|
8
8
|
z-index: 1000;
|
|
@@ -19,6 +19,7 @@ const Dimmer = styled.div.withConfig({
|
|
|
19
19
|
top: 0;
|
|
20
20
|
left: 0;
|
|
21
21
|
display: block;
|
|
22
|
+
box-sizing: border-box;
|
|
22
23
|
width: 100%;
|
|
23
24
|
height: 100%;
|
|
24
25
|
background: ${(props) => props.background ? props.background : "rgba(0, 0, 0, 0.7)"};
|
|
@@ -1,70 +1,12 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import styled from "styled-components";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
|
-
import {
|
|
4
|
+
import { ModalClose } from "./Modal.styles.js";
|
|
5
5
|
import { OutlinedClose } from "./OutlinedClose.js";
|
|
6
|
+
import { lockBodyScroll } from "./bodyScrollLock.js";
|
|
6
7
|
import { SideModalContext } from "./SideModalContext.js";
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
function findScrolledElement() {
|
|
10
|
-
let best = null;
|
|
11
|
-
function walk(el) {
|
|
12
|
-
const s = getComputedStyle(el);
|
|
13
|
-
const scrollable = (s.overflowY === "auto" || s.overflowY === "scroll" || s.overflow === "auto" || s.overflow === "scroll") && el.scrollHeight > el.clientHeight && el.scrollTop > 0;
|
|
14
|
-
if (scrollable && (!best || el.scrollTop > best.scrollTop)) best = { el, scrollTop: el.scrollTop };
|
|
15
|
-
for (let i = 0; i < el.children.length; i++) walk(el.children[i]);
|
|
16
|
-
}
|
|
17
|
-
walk(document.body);
|
|
18
|
-
return best ? { type: "element", ...best } : null;
|
|
19
|
-
}
|
|
20
|
-
function restoreScroll(saved) {
|
|
21
|
-
if (!saved) return;
|
|
22
|
-
if (saved.type === "window") {
|
|
23
|
-
window.scrollTo(0, saved.y);
|
|
24
|
-
} else if (document.contains(saved.el)) {
|
|
25
|
-
saved.el.scrollTop = saved.scrollTop;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function clearBodyLock() {
|
|
29
|
-
const { style } = document.body;
|
|
30
|
-
const docEl = document.documentElement;
|
|
31
|
-
style.position = "";
|
|
32
|
-
style.top = "";
|
|
33
|
-
style.left = "";
|
|
34
|
-
style.right = "";
|
|
35
|
-
style.width = "";
|
|
36
|
-
style.height = "";
|
|
37
|
-
style.overflow = "";
|
|
38
|
-
style.paddingRight = "";
|
|
39
|
-
docEl.style.overflow = "";
|
|
40
|
-
docEl.style.setProperty("--scrollbar-compensation", "0px");
|
|
41
|
-
}
|
|
42
|
-
function lockBodyScroll(saved) {
|
|
43
|
-
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
|
44
|
-
if (saved?.type === "window") {
|
|
45
|
-
const docHeight = document.documentElement.scrollHeight;
|
|
46
|
-
document.documentElement.style.overflow = "hidden";
|
|
47
|
-
document.documentElement.style.setProperty("--scrollbar-compensation", `${scrollbarWidth}px`);
|
|
48
|
-
document.body.style.position = "fixed";
|
|
49
|
-
document.body.style.top = `-${saved.y}px`;
|
|
50
|
-
document.body.style.left = "0";
|
|
51
|
-
document.body.style.right = "0";
|
|
52
|
-
document.body.style.width = "100%";
|
|
53
|
-
document.body.style.height = `${docHeight}px`;
|
|
54
|
-
document.body.style.paddingRight = `${scrollbarWidth}px`;
|
|
55
|
-
} else {
|
|
56
|
-
document.documentElement.style.overflow = "hidden";
|
|
57
|
-
document.body.style.overflow = "hidden";
|
|
58
|
-
document.body.style.paddingRight = `${scrollbarWidth}px`;
|
|
59
|
-
document.documentElement.style.setProperty("--scrollbar-compensation", `${scrollbarWidth}px`);
|
|
60
|
-
if (saved) {
|
|
61
|
-
requestAnimationFrame(() => {
|
|
62
|
-
restoreScroll(saved);
|
|
63
|
-
requestAnimationFrame(() => restoreScroll(saved));
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
8
|
+
import { useState, useRef, useId, useCallback, useEffect } from "react";
|
|
9
|
+
import { SideModalRoot, Dimmer, SideModalBox } from "./SideModal.styles.js";
|
|
68
10
|
const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
69
11
|
function trapFocus(e, box) {
|
|
70
12
|
const active = document.activeElement;
|
|
@@ -126,11 +68,7 @@ const SideModal = ({
|
|
|
126
68
|
setIsVisible(false);
|
|
127
69
|
return;
|
|
128
70
|
}
|
|
129
|
-
|
|
130
|
-
if (isModal) {
|
|
131
|
-
saved = findScrolledElement() ?? (window.scrollY > 0 ? { type: "window", y: window.scrollY } : null);
|
|
132
|
-
lockBodyScroll(saved);
|
|
133
|
-
}
|
|
71
|
+
const unlockBody = isModal ? lockBodyScroll() : void 0;
|
|
134
72
|
const previousFocus = document.activeElement;
|
|
135
73
|
const box = boxRef.current;
|
|
136
74
|
const timerId = setTimeout(() => {
|
|
@@ -142,9 +80,7 @@ const SideModal = ({
|
|
|
142
80
|
const focusInPanel = box?.contains(document.activeElement) || document.activeElement === document.body;
|
|
143
81
|
if (focusInPanel && previousFocus && document.contains(previousFocus))
|
|
144
82
|
previousFocus.focus({ preventScroll: true });
|
|
145
|
-
|
|
146
|
-
clearBodyLock();
|
|
147
|
-
if (saved) requestAnimationFrame(() => restoreScroll(saved));
|
|
83
|
+
unlockBody?.();
|
|
148
84
|
};
|
|
149
85
|
}, [isOpen, isModal]);
|
|
150
86
|
useEffect(() => {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
interface RootProps {
|
|
2
2
|
$interactiveBehind: boolean;
|
|
3
3
|
}
|
|
4
|
-
export declare const SideModalRoot: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').
|
|
4
|
+
export declare const SideModalRoot: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
5
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
6
|
+
}, RootProps & {
|
|
5
7
|
$zIndex: number;
|
|
6
8
|
}>> & string;
|
|
7
9
|
interface DimmerProps {
|
|
@@ -10,7 +12,9 @@ interface DimmerProps {
|
|
|
10
12
|
$color: string;
|
|
11
13
|
$interactiveBehind: boolean;
|
|
12
14
|
}
|
|
13
|
-
export declare const Dimmer: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').
|
|
15
|
+
export declare const Dimmer: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
16
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
17
|
+
}, DimmerProps>> & string;
|
|
14
18
|
type Padding = number | string | [number | string, number | string];
|
|
15
19
|
interface BoxProps {
|
|
16
20
|
$padding: Padding;
|
|
@@ -20,9 +24,13 @@ interface BoxProps {
|
|
|
20
24
|
$isVisible: boolean;
|
|
21
25
|
$fullWidthOnMobile: boolean;
|
|
22
26
|
}
|
|
23
|
-
export declare const SideModalBox: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').
|
|
27
|
+
export declare const SideModalBox: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
28
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
29
|
+
}, BoxProps>> & string;
|
|
24
30
|
/** Figma icon-only "Button Outlined", 40px: the close button of the new design. */
|
|
25
|
-
export declare const OutlinedCloseButton: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').
|
|
31
|
+
export declare const OutlinedCloseButton: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "style"> & {
|
|
32
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
33
|
+
}, {
|
|
26
34
|
$inHeader?: boolean;
|
|
27
35
|
}>> & string;
|
|
28
36
|
export {};
|
|
@@ -15,6 +15,10 @@ export interface SideModalHeaderProps {
|
|
|
15
15
|
*/
|
|
16
16
|
export declare const SideModalHeader: ({ title, subtitle, size, divided, children }: SideModalHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
17
17
|
/** Scrolls between the header and the footer; shadows show when there is more to scroll. */
|
|
18
|
-
export declare const SideModalBody: import('styled-components/dist/types').IStyledComponentBase<"web",
|
|
18
|
+
export declare const SideModalBody: import('styled-components/dist/types').IStyledComponentBase<"web", Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
19
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
20
|
+
}> & string;
|
|
19
21
|
/** Fixed footer of a `SideModal`, e.g. the action buttons. */
|
|
20
|
-
export declare const SideModalFooter: import('styled-components/dist/types').IStyledComponentBase<"web",
|
|
22
|
+
export declare const SideModalFooter: import('styled-components/dist/types').IStyledComponentBase<"web", Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
23
|
+
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
24
|
+
}> & string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ModalProps } from '../Modal';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { MobileBreakpoint } from '../../../utils/customHooks';
|
|
4
|
+
import { LottieSegment } from '../../Lottie/LottieAnimation';
|
|
5
|
+
export type SuccessModalVariant = 'success' | 'progress' | 'upload';
|
|
6
|
+
export interface SuccessModalProps {
|
|
7
|
+
isOpen: boolean;
|
|
8
|
+
/** Called by the close (X) button and the Escape key. */
|
|
9
|
+
onClose: () => void;
|
|
10
|
+
variant?: SuccessModalVariant;
|
|
11
|
+
title?: ReactNode;
|
|
12
|
+
subtitle?: ReactNode;
|
|
13
|
+
content?: ReactNode;
|
|
14
|
+
/** A custom Lottie animation, played instead of the `variant` one. */
|
|
15
|
+
animationSrc?: string;
|
|
16
|
+
loop?: boolean;
|
|
17
|
+
autoplay?: boolean;
|
|
18
|
+
/** Frames to play, `[start, end]`. */
|
|
19
|
+
segment?: LottieSegment;
|
|
20
|
+
speed?: number;
|
|
21
|
+
/** Passed to the underlying `Modal`. */
|
|
22
|
+
modalProps?: Partial<Omit<ModalProps, 'children'>>;
|
|
23
|
+
/** CSS max width of the box. */
|
|
24
|
+
maxWidth?: string;
|
|
25
|
+
/** Skips the animation container entirely (e.g. a plain form step with no success/progress state). */
|
|
26
|
+
hideAnimation?: boolean;
|
|
27
|
+
/** Below this width it is a `SideModal` (full width under 768px). Default `'Medium'` (768px). */
|
|
28
|
+
sideModalBreakpoint?: MobileBreakpoint;
|
|
29
|
+
/** Stays a centred modal at every width instead of becoming a `SideModal`. */
|
|
30
|
+
disableSideModal?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare const SuccessModalComponent: ({ isOpen, onClose, variant, title, subtitle, content, animationSrc, loop, autoplay, segment, speed, modalProps, maxWidth, hideAnimation, sideModalBreakpoint, disableSideModal, }: SuccessModalProps) => import("react/jsx-runtime").JSX.Element;
|
|
33
|
+
export interface ShowSuccessOptions extends Omit<SuccessModalProps, 'isOpen' | 'onClose' | 'hideAnimation'> {
|
|
34
|
+
/** Closes the modal after this many ms; 0 keeps it open until the user closes it. */
|
|
35
|
+
autoClose?: number;
|
|
36
|
+
}
|
|
37
|
+
/** Mounts a `SuccessModal` outside the React tree; resolves once it has closed. */
|
|
38
|
+
export declare const showSuccess: (options?: ShowSuccessOptions) => Promise<void>;
|
|
39
|
+
/** `showSuccess` with the progress animation. */
|
|
40
|
+
export declare const showProgress: (options?: ShowSuccessOptions) => Promise<void>;
|
|
41
|
+
export { SuccessModalComponent as SuccessModal };
|
|
42
|
+
export default showSuccess;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { SideModal } from "../SideModal.js";
|
|
3
|
+
import { Modal } from "../Modal.js";
|
|
2
4
|
import { useEffect } from "react";
|
|
3
5
|
import { createRoot } from "react-dom/client";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
+
import { SideModalHeader, SideModalBody } from "../SideModalParts.js";
|
|
7
|
+
import { useMobileView } from "../../../utils/customHooks.js";
|
|
6
8
|
import { LottieAnimation } from "../../Lottie/LottieAnimation.js";
|
|
7
|
-
import { SuccessModalContent,
|
|
9
|
+
import { SuccessModalContent, Title, Subtitle, ContentWrapper, AnimationContainer } from "./SuccessModal.styles.js";
|
|
8
10
|
const SuccessModalComponent = ({
|
|
9
11
|
isOpen,
|
|
10
12
|
onClose,
|
|
@@ -19,10 +21,13 @@ const SuccessModalComponent = ({
|
|
|
19
21
|
speed = 1,
|
|
20
22
|
modalProps = {},
|
|
21
23
|
maxWidth = "800px",
|
|
22
|
-
hideAnimation = false
|
|
24
|
+
hideAnimation = false,
|
|
25
|
+
sideModalBreakpoint = "Medium",
|
|
26
|
+
disableSideModal = false
|
|
23
27
|
}) => {
|
|
28
|
+
const isSideModal = useMobileView(sideModalBreakpoint) && !disableSideModal;
|
|
24
29
|
useEffect(() => {
|
|
25
|
-
if (!isOpen) return;
|
|
30
|
+
if (!isOpen || isSideModal) return;
|
|
26
31
|
const handleKeyDown = (e) => {
|
|
27
32
|
if (e.key === "Escape") {
|
|
28
33
|
onClose?.();
|
|
@@ -30,7 +35,38 @@ const SuccessModalComponent = ({
|
|
|
30
35
|
};
|
|
31
36
|
document.addEventListener("keydown", handleKeyDown);
|
|
32
37
|
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
33
|
-
}, [isOpen, onClose]);
|
|
38
|
+
}, [isOpen, isSideModal, onClose]);
|
|
39
|
+
const animation = !hideAnimation && /* @__PURE__ */ jsx(AnimationContainer, { children: /* @__PURE__ */ jsx(
|
|
40
|
+
LottieAnimation,
|
|
41
|
+
{
|
|
42
|
+
variant,
|
|
43
|
+
src: animationSrc,
|
|
44
|
+
loop,
|
|
45
|
+
autoplay,
|
|
46
|
+
segment,
|
|
47
|
+
speed,
|
|
48
|
+
size: "100%"
|
|
49
|
+
}
|
|
50
|
+
) });
|
|
51
|
+
if (isSideModal) {
|
|
52
|
+
return /* @__PURE__ */ jsxs(
|
|
53
|
+
SideModal,
|
|
54
|
+
{
|
|
55
|
+
isOpen,
|
|
56
|
+
onClose,
|
|
57
|
+
fullWidthOnMobile: true,
|
|
58
|
+
showCloseButton: !modalProps.hideCloseButton,
|
|
59
|
+
closeButtonVariant: modalProps.closeButtonVariant,
|
|
60
|
+
children: [
|
|
61
|
+
(title || subtitle) && /* @__PURE__ */ jsx(SideModalHeader, { title, subtitle, size: "lg" }),
|
|
62
|
+
/* @__PURE__ */ jsxs(SideModalBody, { children: [
|
|
63
|
+
animation,
|
|
64
|
+
content
|
|
65
|
+
] })
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
34
70
|
return /* @__PURE__ */ jsx(
|
|
35
71
|
Modal,
|
|
36
72
|
{
|
|
@@ -41,18 +77,7 @@ const SuccessModalComponent = ({
|
|
|
41
77
|
maxWidth,
|
|
42
78
|
...modalProps,
|
|
43
79
|
children: /* @__PURE__ */ jsxs(SuccessModalContent, { children: [
|
|
44
|
-
|
|
45
|
-
LottieAnimation,
|
|
46
|
-
{
|
|
47
|
-
variant,
|
|
48
|
-
src: animationSrc,
|
|
49
|
-
loop,
|
|
50
|
-
autoplay,
|
|
51
|
-
segment,
|
|
52
|
-
speed,
|
|
53
|
-
size: "100%"
|
|
54
|
-
}
|
|
55
|
-
) }),
|
|
80
|
+
animation,
|
|
56
81
|
title && /* @__PURE__ */ jsx(Title, { children: title }),
|
|
57
82
|
subtitle && /* @__PURE__ */ jsx(Subtitle, { children: subtitle }),
|
|
58
83
|
content && /* @__PURE__ */ jsx(ContentWrapper, { children: content })
|
|
@@ -60,23 +85,6 @@ const SuccessModalComponent = ({
|
|
|
60
85
|
}
|
|
61
86
|
);
|
|
62
87
|
};
|
|
63
|
-
SuccessModalComponent.propTypes = {
|
|
64
|
-
isOpen: PropTypes.bool.isRequired,
|
|
65
|
-
onClose: PropTypes.func.isRequired,
|
|
66
|
-
variant: PropTypes.oneOf(["success", "progress", "upload"]),
|
|
67
|
-
title: PropTypes.node,
|
|
68
|
-
subtitle: PropTypes.node,
|
|
69
|
-
content: PropTypes.node,
|
|
70
|
-
animationSrc: PropTypes.string,
|
|
71
|
-
loop: PropTypes.bool,
|
|
72
|
-
autoplay: PropTypes.bool,
|
|
73
|
-
segment: PropTypes.arrayOf(PropTypes.number),
|
|
74
|
-
speed: PropTypes.number,
|
|
75
|
-
modalProps: PropTypes.object,
|
|
76
|
-
maxWidth: PropTypes.string,
|
|
77
|
-
/** Skips the animation container entirely (e.g. a plain form step with no success/progress state). */
|
|
78
|
-
hideAnimation: PropTypes.bool
|
|
79
|
-
};
|
|
80
88
|
let successContainer = null;
|
|
81
89
|
let successRoot = null;
|
|
82
90
|
const showSuccess = (options = {}) => {
|
|
@@ -92,7 +100,9 @@ const showSuccess = (options = {}) => {
|
|
|
92
100
|
speed = 1,
|
|
93
101
|
autoClose = 0,
|
|
94
102
|
modalProps = {},
|
|
95
|
-
maxWidth = "800px"
|
|
103
|
+
maxWidth = "800px",
|
|
104
|
+
sideModalBreakpoint,
|
|
105
|
+
disableSideModal
|
|
96
106
|
} = options;
|
|
97
107
|
return new Promise((resolve) => {
|
|
98
108
|
if (!successContainer) {
|
|
@@ -132,7 +142,9 @@ const showSuccess = (options = {}) => {
|
|
|
132
142
|
segment,
|
|
133
143
|
speed,
|
|
134
144
|
modalProps,
|
|
135
|
-
maxWidth
|
|
145
|
+
maxWidth,
|
|
146
|
+
sideModalBreakpoint,
|
|
147
|
+
disableSideModal
|
|
136
148
|
}
|
|
137
149
|
)
|
|
138
150
|
);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hides the page scrollbar behind an overlay. The body takes its width as padding so the layout stays put, and
|
|
3
|
+
* `--scrollbar-compensation` holds it for fixed elements (a header) to do the same. Nested overlays share one lock,
|
|
4
|
+
* released with the last one, which also restores the page scroll position. Returns the unlock function.
|
|
5
|
+
*/
|
|
6
|
+
export declare function lockBodyScroll(): () => void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
function findScrolledElement() {
|
|
2
|
+
let best = null;
|
|
3
|
+
function walk(el) {
|
|
4
|
+
const s = getComputedStyle(el);
|
|
5
|
+
const scrollable = (s.overflowY === "auto" || s.overflowY === "scroll" || s.overflow === "auto" || s.overflow === "scroll") && el.scrollHeight > el.clientHeight && el.scrollTop > 0;
|
|
6
|
+
if (scrollable && (!best || el.scrollTop > best.scrollTop)) best = { el, scrollTop: el.scrollTop };
|
|
7
|
+
for (let i = 0; i < el.children.length; i++) walk(el.children[i]);
|
|
8
|
+
}
|
|
9
|
+
walk(document.body);
|
|
10
|
+
return best ? { type: "element", ...best } : null;
|
|
11
|
+
}
|
|
12
|
+
function restoreScroll(saved) {
|
|
13
|
+
if (!saved) return;
|
|
14
|
+
if (saved.type === "window") {
|
|
15
|
+
window.scrollTo(0, saved.y);
|
|
16
|
+
} else if (document.contains(saved.el)) {
|
|
17
|
+
saved.el.scrollTop = saved.scrollTop;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function clearBodyLock() {
|
|
21
|
+
const { style } = document.body;
|
|
22
|
+
const docEl = document.documentElement;
|
|
23
|
+
style.position = "";
|
|
24
|
+
style.top = "";
|
|
25
|
+
style.left = "";
|
|
26
|
+
style.right = "";
|
|
27
|
+
style.width = "";
|
|
28
|
+
style.height = "";
|
|
29
|
+
style.overflow = "";
|
|
30
|
+
style.paddingRight = "";
|
|
31
|
+
docEl.style.overflow = "";
|
|
32
|
+
docEl.style.setProperty("--scrollbar-compensation", "0px");
|
|
33
|
+
}
|
|
34
|
+
function applyBodyLock(saved) {
|
|
35
|
+
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
|
36
|
+
if (saved?.type === "window") {
|
|
37
|
+
const docHeight = document.documentElement.scrollHeight;
|
|
38
|
+
document.documentElement.style.overflow = "hidden";
|
|
39
|
+
document.documentElement.style.setProperty("--scrollbar-compensation", `${scrollbarWidth}px`);
|
|
40
|
+
document.body.style.position = "fixed";
|
|
41
|
+
document.body.style.top = `-${saved.y}px`;
|
|
42
|
+
document.body.style.left = "0";
|
|
43
|
+
document.body.style.right = "0";
|
|
44
|
+
document.body.style.width = "100%";
|
|
45
|
+
document.body.style.height = `${docHeight}px`;
|
|
46
|
+
document.body.style.paddingRight = `${scrollbarWidth}px`;
|
|
47
|
+
} else {
|
|
48
|
+
document.documentElement.style.overflow = "hidden";
|
|
49
|
+
document.body.style.overflow = "hidden";
|
|
50
|
+
document.body.style.paddingRight = `${scrollbarWidth}px`;
|
|
51
|
+
document.documentElement.style.setProperty("--scrollbar-compensation", `${scrollbarWidth}px`);
|
|
52
|
+
if (saved) {
|
|
53
|
+
requestAnimationFrame(() => {
|
|
54
|
+
restoreScroll(saved);
|
|
55
|
+
requestAnimationFrame(() => restoreScroll(saved));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let lockCount = 0;
|
|
61
|
+
let savedScroll = null;
|
|
62
|
+
function lockBodyScroll() {
|
|
63
|
+
if (lockCount++ === 0) {
|
|
64
|
+
savedScroll = findScrolledElement() ?? (window.scrollY > 0 ? { type: "window", y: window.scrollY } : null);
|
|
65
|
+
applyBodyLock(savedScroll);
|
|
66
|
+
}
|
|
67
|
+
let released = false;
|
|
68
|
+
return () => {
|
|
69
|
+
if (released) return;
|
|
70
|
+
released = true;
|
|
71
|
+
if (--lockCount > 0) return;
|
|
72
|
+
clearBodyLock();
|
|
73
|
+
const saved = savedScroll;
|
|
74
|
+
savedScroll = null;
|
|
75
|
+
if (saved) requestAnimationFrame(() => restoreScroll(saved));
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
lockBodyScroll
|
|
80
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Whether an element between `target` and the page itself can still scroll by `deltaY`. */
|
|
2
|
+
export declare function canScrollInside(target: EventTarget | null, deltaY: number): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Stops the page behind an overlay from scrolling by blocking wheel, touch and keyboard scrolling
|
|
5
|
+
* that would reach it. Unlike hiding overflow or fixing the body, the page scrollbar stays exactly
|
|
6
|
+
* as it is, so nothing shifts or flashes while the overlay fades in. Returns the unlock function.
|
|
7
|
+
*/
|
|
8
|
+
export declare function lockPageScroll(): () => void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const SCROLL_KEY_DIRECTION = {
|
|
2
|
+
ArrowUp: -1,
|
|
3
|
+
PageUp: -1,
|
|
4
|
+
Home: -1,
|
|
5
|
+
ArrowDown: 1,
|
|
6
|
+
PageDown: 1,
|
|
7
|
+
End: 1,
|
|
8
|
+
" ": 1
|
|
9
|
+
};
|
|
10
|
+
const EDITABLE = 'input, textarea, select, [contenteditable]:not([contenteditable="false"])';
|
|
11
|
+
const SPACE_ACTIVATED = `${EDITABLE}, button, a[href], summary, [role="button"], [role="checkbox"], [role="switch"]`;
|
|
12
|
+
function canScrollInside(target, deltaY) {
|
|
13
|
+
let node = target instanceof Element ? target : null;
|
|
14
|
+
while (node && node !== document.body && node !== document.documentElement) {
|
|
15
|
+
const { overflowY } = getComputedStyle(node);
|
|
16
|
+
if (overflowY === "auto" || overflowY === "scroll") {
|
|
17
|
+
const maxScrollTop = node.scrollHeight - node.clientHeight;
|
|
18
|
+
if (maxScrollTop > 0 && (deltaY < 0 ? node.scrollTop > 0 : node.scrollTop < maxScrollTop - 1)) return true;
|
|
19
|
+
}
|
|
20
|
+
node = node.parentElement;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
function lockPageScroll() {
|
|
25
|
+
let lastTouchY = 0;
|
|
26
|
+
const onWheel = (event) => {
|
|
27
|
+
if (event.ctrlKey || event.deltaY === 0) return;
|
|
28
|
+
if (!canScrollInside(event.target, event.deltaY)) event.preventDefault();
|
|
29
|
+
};
|
|
30
|
+
const onTouchStart = (event) => {
|
|
31
|
+
lastTouchY = event.touches[0]?.clientY ?? 0;
|
|
32
|
+
};
|
|
33
|
+
const onTouchMove = (event) => {
|
|
34
|
+
if (event.touches.length !== 1) return;
|
|
35
|
+
const touchY = event.touches[0].clientY;
|
|
36
|
+
const deltaY = lastTouchY - touchY;
|
|
37
|
+
lastTouchY = touchY;
|
|
38
|
+
if (deltaY !== 0 && !canScrollInside(event.target, deltaY)) event.preventDefault();
|
|
39
|
+
};
|
|
40
|
+
const onKeyDown = (event) => {
|
|
41
|
+
const direction = SCROLL_KEY_DIRECTION[event.key];
|
|
42
|
+
if (!direction || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
43
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
44
|
+
if (target?.closest(event.key === " " ? SPACE_ACTIVATED : EDITABLE)) return;
|
|
45
|
+
if (!canScrollInside(target, event.shiftKey && event.key === " " ? -1 : direction)) event.preventDefault();
|
|
46
|
+
};
|
|
47
|
+
const options = { capture: true, passive: false };
|
|
48
|
+
document.addEventListener("wheel", onWheel, options);
|
|
49
|
+
document.addEventListener("touchstart", onTouchStart, { capture: true, passive: true });
|
|
50
|
+
document.addEventListener("touchmove", onTouchMove, options);
|
|
51
|
+
document.addEventListener("keydown", onKeyDown, options);
|
|
52
|
+
return () => {
|
|
53
|
+
document.removeEventListener("wheel", onWheel, options);
|
|
54
|
+
document.removeEventListener("touchstart", onTouchStart, { capture: true });
|
|
55
|
+
document.removeEventListener("touchmove", onTouchMove, options);
|
|
56
|
+
document.removeEventListener("keydown", onKeyDown, options);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
canScrollInside,
|
|
61
|
+
lockPageScroll
|
|
62
|
+
};
|