@galaxy-io/dls 1.1.2 → 1.1.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/chips/Chip.js +2 -2
- package/dist/inputs/CheckboxInput.js +1 -1
- package/dist/inputs/Input.js +1 -1
- package/dist/inputs/RadioInput.js +1 -1
- package/dist/inputs/TextAreaInput.js +1 -1
- package/dist/spreadsheet/InfiniteSpreadsheet.js +1 -1
- package/dist/styles.css +2 -0
- package/dist/toast/Toast.d.ts +18 -0
- package/dist/toast/Toast.js +103 -0
- package/dist/toast/ToastContainer.d.ts +10 -0
- package/dist/toast/ToastContainer.js +31 -0
- package/dist/toast/ToastProvider.d.ts +16 -0
- package/dist/toast/ToastProvider.js +111 -0
- package/dist/toast/ToastWrapper.d.ts +6 -0
- package/dist/toast/ToastWrapper.js +27 -0
- package/dist/toast/useToast.d.ts +1 -0
- package/dist/toast/useToast.js +10 -0
- package/package.json +5 -1
package/dist/chips/Chip.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { withTheme } from "../theme/GalaxyTheme.js";
|
|
2
2
|
import Text, { TextSize, TextVariant } from "../text/Text.js";
|
|
3
|
-
import TextShimmer from "../text/TextShimmer.js";
|
|
4
|
-
import Ellipsis from "../text/Ellipsis.js";
|
|
5
3
|
import FlexWrapper from "../containers/FlexWrapper.js";
|
|
6
4
|
import FlexItem from "../containers/FlexItem.js";
|
|
7
5
|
import Icon, { IconVariant } from "../icons/Icon.js";
|
|
6
|
+
import TextShimmer from "../text/TextShimmer.js";
|
|
7
|
+
import Ellipsis from "../text/Ellipsis.js";
|
|
8
8
|
import AvatarShimmer from "../avatar/AvatarShimmer.js";
|
|
9
9
|
/* empty css */
|
|
10
10
|
import { styled } from "@linaria/react";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { withTheme } from "../theme/GalaxyTheme.js";
|
|
2
2
|
import Text, { TextVariant } from "../text/Text.js";
|
|
3
|
-
import RequiredMarker from "../text/RequiredMarker.js";
|
|
4
3
|
import FlexWrapper, { AlignItems } from "../containers/FlexWrapper.js";
|
|
5
4
|
import Icon, { IconVariant, IconWeight } from "../icons/Icon.js";
|
|
5
|
+
import RequiredMarker from "../text/RequiredMarker.js";
|
|
6
6
|
/* empty css */
|
|
7
7
|
import { styled } from "@linaria/react";
|
|
8
8
|
import { match } from "ts-pattern";
|
package/dist/inputs/Input.js
CHANGED
|
@@ -2,9 +2,9 @@ import { withTheme } from "../theme/GalaxyTheme.js";
|
|
|
2
2
|
import { getCssSizeValue } from "../utils/linaria.js";
|
|
3
3
|
import Text, { TextSize, TextVariant } from "../text/Text.js";
|
|
4
4
|
import Tooltip, { TooltipPosition } from "../tooltip/Tooltip.js";
|
|
5
|
-
import RequiredMarker from "../text/RequiredMarker.js";
|
|
6
5
|
import FlexWrapper, { AlignItems, FlexDirection } from "../containers/FlexWrapper.js";
|
|
7
6
|
import Icon, { IconVariant } from "../icons/Icon.js";
|
|
7
|
+
import RequiredMarker from "../text/RequiredMarker.js";
|
|
8
8
|
import Spacing from "../containers/Spacing.js";
|
|
9
9
|
import HelpIcon from "../icons/HelpIcon.js";
|
|
10
10
|
/* empty css */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { withTheme } from "../theme/GalaxyTheme.js";
|
|
2
2
|
import Text, { TextVariant } from "../text/Text.js";
|
|
3
3
|
import Tooltip, { TooltipPosition } from "../tooltip/Tooltip.js";
|
|
4
|
-
import RequiredMarker from "../text/RequiredMarker.js";
|
|
5
4
|
import FlexWrapper, { AlignItems } from "../containers/FlexWrapper.js";
|
|
5
|
+
import RequiredMarker from "../text/RequiredMarker.js";
|
|
6
6
|
import Spacing from "../containers/Spacing.js";
|
|
7
7
|
import HelpIcon from "../icons/HelpIcon.js";
|
|
8
8
|
/* empty css */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { withTheme } from "../theme/GalaxyTheme.js";
|
|
2
2
|
import { getCssSizeValue } from "../utils/linaria.js";
|
|
3
3
|
import Text, { TextSize, TextVariant } from "../text/Text.js";
|
|
4
|
-
import TextShimmer from "../text/TextShimmer.js";
|
|
5
4
|
import FlexWrapper, { FlexDirection } from "../containers/FlexWrapper.js";
|
|
5
|
+
import TextShimmer from "../text/TextShimmer.js";
|
|
6
6
|
import { InputLabel } from "./Input.js";
|
|
7
7
|
/* empty css */
|
|
8
8
|
import { styled } from "@linaria/react";
|
|
@@ -12,8 +12,8 @@ import { styled } from "@linaria/react";
|
|
|
12
12
|
import { match } from "ts-pattern";
|
|
13
13
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
14
14
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
-
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
16
15
|
import { PlusIcon } from "@phosphor-icons/react";
|
|
16
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
17
17
|
//#region src/spreadsheet/InfiniteSpreadsheet.tsx
|
|
18
18
|
var _exp = () => ({ $width, $fillWidth }) => {
|
|
19
19
|
if ($fillWidth) return "100%";
|
package/dist/styles.css
CHANGED
|
@@ -208,5 +208,7 @@
|
|
|
208
208
|
.s10h6trl{margin:10px 0 4px 0;}.s10h6trl:first-child{margin-top:0;}
|
|
209
209
|
.sts1mtj{color:var(--sts1mtj-0);font-family:var(--sts1mtj-1);font-size:var(--sts1mtj-2);font-weight:var(--sts1mtj-3);line-height:var(--sts1mtj-4);letter-spacing:var(--sts1mtj-5);text-align:var(--sts1mtj-6);cursor:var(--sts1mtj-7);-webkit-user-select:var(--sts1mtj-8);-moz-user-select:var(--sts1mtj-8);-ms-user-select:var(--sts1mtj-8);user-select:var(--sts1mtj-8);-webkit-user-select:var(--sts1mtj-8);-moz-user-select:var(--sts1mtj-8);-ms-user-select:var(--sts1mtj-8);display:var(--sts1mtj-9);-webkit-line-clamp:var(--sts1mtj-10);-webkit-box-orient:var(--sts1mtj-11);overflow:var(--sts1mtj-12);width:var(--sts1mtj-13);min-height:var(--sts1mtj-14);overscroll-behavior:auto;-webkit-transition:color 0.075s ease-in-out;transition:color 0.075s ease-in-out;}
|
|
210
210
|
.sfziwh{-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;user-select:text;-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;}
|
|
211
|
+
.sgmrm4{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;gap:8px;padding:var(--sgmrm4-0);min-width:360px;max-width:420px;background-color:var(--sgmrm4-1);border:0.5px solid var(--sgmrm4-2);border-radius:5px;}
|
|
212
|
+
.stlie57{position:fixed;z-index:11000;top:var(--stlie57-0);right:var(--stlie57-1);bottom:var(--stlie57-2);left:var(--stlie57-3);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column-reverse;-ms-flex-direction:column-reverse;flex-direction:column-reverse;gap:8px;pointer-events:none;}.stlie57 >*{pointer-events:auto;}
|
|
211
213
|
.sx1o0cd{background:var(--sx1o0cd-0);border:0.5px solid var(--sx1o0cd-1);border-radius:5px;padding:var(--sx1o0cd-2);box-shadow:0 1px 10px 0 var(--sx1o0cd-3),0 1px 1px 0 var(--sx1o0cd-4);width:var(--sx1o0cd-5);height:var(--sx1o0cd-6);min-width:var(--sx1o0cd-7);max-width:var(--sx1o0cd-8);min-height:var(--sx1o0cd-9);max-height:var(--sx1o0cd-10);cursor:var(--sx1o0cd-11);}.sx1o0cd:hover{border-color:var(--sx1o0cd-12);}
|
|
212
214
|
/*$vite$:1*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Icon as PhosphorIcon } from "@phosphor-icons/react";
|
|
2
|
+
import { ButtonProps } from "../buttons/Button";
|
|
3
|
+
export declare enum ToastVariant {
|
|
4
|
+
PRIMARY = "PRIMARY",
|
|
5
|
+
SUCCESS = "SUCCESS",
|
|
6
|
+
WARNING = "WARNING",
|
|
7
|
+
ERROR = "ERROR"
|
|
8
|
+
}
|
|
9
|
+
export interface ToastProps {
|
|
10
|
+
variant?: ToastVariant;
|
|
11
|
+
icon?: PhosphorIcon;
|
|
12
|
+
header: string | React.ReactNode;
|
|
13
|
+
subheader: string | React.ReactNode;
|
|
14
|
+
actions?: ButtonProps[];
|
|
15
|
+
onClose?: () => void;
|
|
16
|
+
}
|
|
17
|
+
declare const Toast: ({ variant, icon, header, subheader, actions, onClose, }: ToastProps) => import("react").JSX.Element;
|
|
18
|
+
export default Toast;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { withTheme } from "../theme/GalaxyTheme.js";
|
|
2
|
+
import Text, { TextVariant } from "../text/Text.js";
|
|
3
|
+
import FlexWrapper, { AlignItems, FlexDirection } from "../containers/FlexWrapper.js";
|
|
4
|
+
import FlexItem from "../containers/FlexItem.js";
|
|
5
|
+
import Icon, { IconVariant, IconWeight } from "../icons/Icon.js";
|
|
6
|
+
import Button, { ButtonSize, ButtonVariant } from "../buttons/Button.js";
|
|
7
|
+
/* empty css */
|
|
8
|
+
import { styled } from "@linaria/react";
|
|
9
|
+
import { match } from "ts-pattern";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { CheckCircleIcon, SpinnerGapIcon, WarningIcon, XIcon } from "@phosphor-icons/react";
|
|
12
|
+
//#region src/toast/Toast.tsx
|
|
13
|
+
var ToastVariant = /* @__PURE__ */ function(ToastVariant) {
|
|
14
|
+
ToastVariant["PRIMARY"] = "PRIMARY";
|
|
15
|
+
ToastVariant["SUCCESS"] = "SUCCESS";
|
|
16
|
+
ToastVariant["WARNING"] = "WARNING";
|
|
17
|
+
ToastVariant["ERROR"] = "ERROR";
|
|
18
|
+
return ToastVariant;
|
|
19
|
+
}({});
|
|
20
|
+
var _exp = () => ({ $hasActions }) => $hasActions ? "12px 12px 8px 12px" : "12px";
|
|
21
|
+
var _exp2 = () => ({ theme, $variant }) => match($variant).with("PRIMARY", () => theme.color.background.tertiary).with("SUCCESS", () => theme.color.background.tertiary).with("WARNING", () => theme.color.background.tertiary).with("ERROR", () => theme.color.background.tertiary).exhaustive();
|
|
22
|
+
var _exp3 = () => ({ theme, $variant }) => match($variant).with("PRIMARY", () => theme.color.border.primary).with("SUCCESS", () => theme.color.border.success).with("WARNING", () => theme.color.border.primary).with("ERROR", () => theme.color.border.error).exhaustive();
|
|
23
|
+
var StyledToast = withTheme(/*#__PURE__*/ styled("div")({
|
|
24
|
+
name: "StyledToast",
|
|
25
|
+
class: "sgmrm4",
|
|
26
|
+
propsAsIs: false,
|
|
27
|
+
vars: {
|
|
28
|
+
"sgmrm4-0": [_exp()],
|
|
29
|
+
"sgmrm4-1": [_exp2()],
|
|
30
|
+
"sgmrm4-2": [_exp3()]
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
var Toast = ({ variant = "PRIMARY", icon, header, subheader, actions, onClose }) => {
|
|
34
|
+
const renderIcon = () => {
|
|
35
|
+
if (icon) return /* @__PURE__ */ jsx(Icon, {
|
|
36
|
+
component: icon,
|
|
37
|
+
size: 16
|
|
38
|
+
});
|
|
39
|
+
return match(variant).with("PRIMARY", () => /* @__PURE__ */ jsx(Icon, {
|
|
40
|
+
component: SpinnerGapIcon,
|
|
41
|
+
size: 16
|
|
42
|
+
})).with("SUCCESS", () => /* @__PURE__ */ jsx(Icon, {
|
|
43
|
+
component: CheckCircleIcon,
|
|
44
|
+
variant: IconVariant.SUCCESS,
|
|
45
|
+
size: 16,
|
|
46
|
+
weight: IconWeight.FILL
|
|
47
|
+
})).with("WARNING", () => /* @__PURE__ */ jsx(Icon, {
|
|
48
|
+
component: WarningIcon,
|
|
49
|
+
variant: IconVariant.WARNING,
|
|
50
|
+
size: 16,
|
|
51
|
+
weight: IconWeight.FILL
|
|
52
|
+
})).with("ERROR", () => /* @__PURE__ */ jsx(Icon, {
|
|
53
|
+
component: WarningIcon,
|
|
54
|
+
variant: IconVariant.ERROR,
|
|
55
|
+
size: 16,
|
|
56
|
+
weight: IconWeight.FILL
|
|
57
|
+
})).exhaustive();
|
|
58
|
+
};
|
|
59
|
+
const hasActions = (actions && actions.length > 0) ?? false;
|
|
60
|
+
return /* @__PURE__ */ jsxs(StyledToast, {
|
|
61
|
+
$variant: variant,
|
|
62
|
+
$hasActions: hasActions,
|
|
63
|
+
children: [/* @__PURE__ */ jsxs(FlexWrapper, {
|
|
64
|
+
alignItems: AlignItems.START,
|
|
65
|
+
gap: 8,
|
|
66
|
+
children: [
|
|
67
|
+
/* @__PURE__ */ jsx(FlexWrapper, {
|
|
68
|
+
width: 20,
|
|
69
|
+
height: 20,
|
|
70
|
+
children: renderIcon()
|
|
71
|
+
}),
|
|
72
|
+
/* @__PURE__ */ jsx(FlexItem, {
|
|
73
|
+
grow: 1,
|
|
74
|
+
children: /* @__PURE__ */ jsxs(FlexWrapper, {
|
|
75
|
+
direction: FlexDirection.COLUMN,
|
|
76
|
+
gap: 4,
|
|
77
|
+
children: [typeof header === "string" ? /* @__PURE__ */ jsx(Text, { children: header }) : header, typeof subheader === "string" ? /* @__PURE__ */ jsx(Text, {
|
|
78
|
+
variant: TextVariant.TERTIARY,
|
|
79
|
+
children: subheader
|
|
80
|
+
}) : subheader]
|
|
81
|
+
})
|
|
82
|
+
}),
|
|
83
|
+
onClose && /* @__PURE__ */ jsx(Button, {
|
|
84
|
+
icon: XIcon,
|
|
85
|
+
variant: ButtonVariant.TERTIARY,
|
|
86
|
+
size: ButtonSize.SMALL,
|
|
87
|
+
onClick: onClose
|
|
88
|
+
})
|
|
89
|
+
]
|
|
90
|
+
}), hasActions && /* @__PURE__ */ jsx(FlexWrapper, {
|
|
91
|
+
alignItems: AlignItems.CENTER,
|
|
92
|
+
gap: 8,
|
|
93
|
+
children: actions?.map((action, index) => /* @__PURE__ */ jsx(Button, {
|
|
94
|
+
label: action.label,
|
|
95
|
+
variant: action.variant ?? ButtonVariant.TERTIARY,
|
|
96
|
+
size: ButtonSize.SMALL,
|
|
97
|
+
onClick: action.onClick
|
|
98
|
+
}, index))
|
|
99
|
+
})]
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
//#endregion
|
|
103
|
+
export { ToastVariant, Toast as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
interface ToastContainerProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
top?: number | string;
|
|
5
|
+
right?: number | string;
|
|
6
|
+
bottom?: number | string;
|
|
7
|
+
left?: number | string;
|
|
8
|
+
}
|
|
9
|
+
declare const ToastContainer: ({ children, top, right, bottom, left }: ToastContainerProps) => import("react").JSX.Element;
|
|
10
|
+
export default ToastContainer;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getCssSizeValue } from "../utils/linaria.js";
|
|
2
|
+
/* empty css */
|
|
3
|
+
import { styled } from "@linaria/react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region src/toast/ToastContainer.tsx
|
|
6
|
+
var _exp2 = () => ({ $top, $bottom }) => $top !== void 0 ? getCssSizeValue($top) : $bottom !== void 0 ? "auto" : "auto";
|
|
7
|
+
var _exp3 = () => ({ $right, $left }) => $right !== void 0 ? getCssSizeValue($right) : $left !== void 0 ? "auto" : getCssSizeValue(24);
|
|
8
|
+
var _exp4 = () => ({ $bottom, $top }) => $bottom !== void 0 ? getCssSizeValue($bottom) : $top !== void 0 ? "auto" : getCssSizeValue(24);
|
|
9
|
+
var _exp5 = () => ({ $left }) => $left !== void 0 ? getCssSizeValue($left) : "auto";
|
|
10
|
+
var StyledToastContainer = /*#__PURE__*/ styled("div")({
|
|
11
|
+
name: "StyledToastContainer",
|
|
12
|
+
class: "stlie57",
|
|
13
|
+
propsAsIs: false,
|
|
14
|
+
vars: {
|
|
15
|
+
"stlie57-0": [_exp2()],
|
|
16
|
+
"stlie57-1": [_exp3()],
|
|
17
|
+
"stlie57-2": [_exp4()],
|
|
18
|
+
"stlie57-3": [_exp5()]
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
var ToastContainer = ({ children, top, right, bottom, left }) => {
|
|
22
|
+
return /* @__PURE__ */ jsx(StyledToastContainer, {
|
|
23
|
+
$top: top,
|
|
24
|
+
$right: right,
|
|
25
|
+
$bottom: bottom,
|
|
26
|
+
$left: left,
|
|
27
|
+
children
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { ToastContainer as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
import { ToastVariant, type ToastProps } from "./Toast";
|
|
3
|
+
export type ShowToastProps = Omit<ToastProps, "onClose"> & {
|
|
4
|
+
timeout?: number;
|
|
5
|
+
top?: number | string;
|
|
6
|
+
left?: number | string;
|
|
7
|
+
right?: number | string;
|
|
8
|
+
bottom?: number | string;
|
|
9
|
+
};
|
|
10
|
+
export interface ToastContextProps {
|
|
11
|
+
showToast: (options: ShowToastProps) => string;
|
|
12
|
+
hideToast: (id?: string) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare const ToastContext: import("react").Context<ToastContextProps | undefined>;
|
|
15
|
+
export declare const ToastProvider: ({ children }: PropsWithChildren) => import("react").JSX.Element;
|
|
16
|
+
export { ToastVariant };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import Toast, { ToastVariant } from "./Toast.js";
|
|
2
|
+
import ToastContainer from "./ToastContainer.js";
|
|
3
|
+
import ToastWrapper from "./ToastWrapper.js";
|
|
4
|
+
import { createContext, useCallback, useEffect, useRef, useState } from "react";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { createPortal } from "react-dom";
|
|
7
|
+
import { AnimatePresence } from "framer-motion";
|
|
8
|
+
//#region src/toast/ToastProvider.tsx
|
|
9
|
+
var ToastContext = createContext(void 0);
|
|
10
|
+
var DEFAULT_TIMEOUT = 3e3;
|
|
11
|
+
var toastCounter = 0;
|
|
12
|
+
var nextToastId = () => `toast-${++toastCounter}`;
|
|
13
|
+
var positionKey = (toast) => JSON.stringify([
|
|
14
|
+
toast.top,
|
|
15
|
+
toast.right,
|
|
16
|
+
toast.bottom,
|
|
17
|
+
toast.left
|
|
18
|
+
]);
|
|
19
|
+
var ToastProvider = ({ children }) => {
|
|
20
|
+
const [toasts, setToasts] = useState([]);
|
|
21
|
+
const timeoutRefs = useRef(/* @__PURE__ */ new Map());
|
|
22
|
+
const showToast = useCallback((options) => {
|
|
23
|
+
const id = nextToastId();
|
|
24
|
+
const { timeout, top, right, bottom, left, ...props } = options;
|
|
25
|
+
const finalTimeout = timeout === void 0 ? DEFAULT_TIMEOUT : timeout;
|
|
26
|
+
setToasts((prev) => [...prev, {
|
|
27
|
+
id,
|
|
28
|
+
props,
|
|
29
|
+
timeout: finalTimeout,
|
|
30
|
+
top,
|
|
31
|
+
right,
|
|
32
|
+
bottom,
|
|
33
|
+
left
|
|
34
|
+
}]);
|
|
35
|
+
return id;
|
|
36
|
+
}, []);
|
|
37
|
+
const hideToast = useCallback((id) => {
|
|
38
|
+
if (id) {
|
|
39
|
+
const timeoutId = timeoutRefs.current.get(id);
|
|
40
|
+
if (timeoutId) {
|
|
41
|
+
clearTimeout(timeoutId);
|
|
42
|
+
timeoutRefs.current.delete(id);
|
|
43
|
+
}
|
|
44
|
+
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
45
|
+
} else setToasts((prev) => {
|
|
46
|
+
const firstToast = prev[0];
|
|
47
|
+
if (firstToast) {
|
|
48
|
+
const timeoutId = timeoutRefs.current.get(firstToast.id);
|
|
49
|
+
if (timeoutId) {
|
|
50
|
+
clearTimeout(timeoutId);
|
|
51
|
+
timeoutRefs.current.delete(firstToast.id);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return prev.slice(1);
|
|
55
|
+
});
|
|
56
|
+
}, []);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const currentToastIds = new Set(toasts.map((toast) => toast.id));
|
|
59
|
+
toasts.forEach((toast) => {
|
|
60
|
+
if (timeoutRefs.current.has(toast.id)) return;
|
|
61
|
+
if (toast.timeout > 0) {
|
|
62
|
+
const timeoutId = setTimeout(() => {
|
|
63
|
+
setToasts((prev) => prev.filter((t) => t.id !== toast.id));
|
|
64
|
+
timeoutRefs.current.delete(toast.id);
|
|
65
|
+
}, toast.timeout);
|
|
66
|
+
timeoutRefs.current.set(toast.id, timeoutId);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
timeoutRefs.current.forEach((timeoutId, toastId) => {
|
|
70
|
+
if (!currentToastIds.has(toastId)) {
|
|
71
|
+
clearTimeout(timeoutId);
|
|
72
|
+
timeoutRefs.current.delete(toastId);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}, [toasts]);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
const refs = timeoutRefs.current;
|
|
78
|
+
return () => {
|
|
79
|
+
refs.forEach((timeoutId) => {
|
|
80
|
+
clearTimeout(timeoutId);
|
|
81
|
+
});
|
|
82
|
+
refs.clear();
|
|
83
|
+
};
|
|
84
|
+
}, []);
|
|
85
|
+
const positionGroups = /* @__PURE__ */ new Map();
|
|
86
|
+
toasts.forEach((toast) => {
|
|
87
|
+
const key = positionKey(toast);
|
|
88
|
+
const group = positionGroups.get(key);
|
|
89
|
+
if (group) group.push(toast);
|
|
90
|
+
else positionGroups.set(key, [toast]);
|
|
91
|
+
});
|
|
92
|
+
const toastContent = /* @__PURE__ */ jsx(Fragment, { children: [...positionGroups.entries()].map(([key, group]) => /* @__PURE__ */ jsx(ToastContainer, {
|
|
93
|
+
top: group[0].top,
|
|
94
|
+
right: group[0].right,
|
|
95
|
+
bottom: group[0].bottom,
|
|
96
|
+
left: group[0].left,
|
|
97
|
+
children: /* @__PURE__ */ jsx(AnimatePresence, { children: group.map((toast) => /* @__PURE__ */ jsx(ToastWrapper, { children: /* @__PURE__ */ jsx(Toast, {
|
|
98
|
+
...toast.props,
|
|
99
|
+
onClose: () => hideToast(toast.id)
|
|
100
|
+
}) }, toast.id)) })
|
|
101
|
+
}, key)) });
|
|
102
|
+
return /* @__PURE__ */ jsxs(ToastContext.Provider, {
|
|
103
|
+
value: {
|
|
104
|
+
showToast,
|
|
105
|
+
hideToast
|
|
106
|
+
},
|
|
107
|
+
children: [children, typeof document !== "undefined" && createPortal(toastContent, document.body)]
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
//#endregion
|
|
111
|
+
export { ToastContext, ToastProvider, ToastVariant };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { motion } from "framer-motion";
|
|
3
|
+
//#region src/toast/ToastWrapper.tsx
|
|
4
|
+
var ToastWrapper = ({ children }) => {
|
|
5
|
+
return /* @__PURE__ */ jsx(motion.div, {
|
|
6
|
+
initial: {
|
|
7
|
+
opacity: 0,
|
|
8
|
+
x: 50
|
|
9
|
+
},
|
|
10
|
+
animate: {
|
|
11
|
+
opacity: 1,
|
|
12
|
+
x: 0
|
|
13
|
+
},
|
|
14
|
+
exit: {
|
|
15
|
+
opacity: 0,
|
|
16
|
+
x: 50
|
|
17
|
+
},
|
|
18
|
+
transition: {
|
|
19
|
+
type: "tween",
|
|
20
|
+
duration: .15,
|
|
21
|
+
ease: "easeOut"
|
|
22
|
+
},
|
|
23
|
+
children
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ToastWrapper as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useToast: () => import("./ToastProvider").ToastContextProps;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ToastContext } from "./ToastProvider.js";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
//#region src/toast/useToast.ts
|
|
4
|
+
var useToast = () => {
|
|
5
|
+
const context = useContext(ToastContext);
|
|
6
|
+
if (!context) throw new Error("useToast must be used within a ToastProvider");
|
|
7
|
+
return context;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { useToast };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@galaxy-io/dls",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Galaxy Design Language System",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -143,6 +143,10 @@
|
|
|
143
143
|
"types": "./dist/theme/*.d.ts",
|
|
144
144
|
"import": "./dist/theme/*.js"
|
|
145
145
|
},
|
|
146
|
+
"./toast/*": {
|
|
147
|
+
"types": "./dist/toast/*.d.ts",
|
|
148
|
+
"import": "./dist/toast/*.js"
|
|
149
|
+
},
|
|
146
150
|
"./tooltip/*": {
|
|
147
151
|
"types": "./dist/tooltip/*.d.ts",
|
|
148
152
|
"import": "./dist/tooltip/*.js"
|