@sentry/scraps 0.3.0 → 0.4.0

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.
Files changed (43) hide show
  1. package/dist/layout/styles.d.ts +1 -1
  2. package/dist/menu/controlContext.d.ts +32 -0
  3. package/dist/menu/controlContext.js +7 -0
  4. package/dist/menu/dropdownButton.d.ts +18 -0
  5. package/dist/menu/dropdownButton.js +66 -0
  6. package/dist/menu/index.d.ts +7 -0
  7. package/dist/menu/index.js +3 -0
  8. package/dist/menu/menu.d.ts +159 -0
  9. package/dist/menu/menu.js +464 -0
  10. package/dist/menu/selectTypes.d.ts +96 -0
  11. package/dist/menu/selectTypes.js +0 -0
  12. package/dist/menu/selectValue.d.ts +13 -0
  13. package/dist/menu/selectValue.js +0 -0
  14. package/dist/overlayTrigger.d.ts +22 -0
  15. package/dist/overlayTrigger.js +30 -0
  16. package/dist/slot/knownContexts.d.ts +1 -1
  17. package/dist/spinner/index.d.ts +1 -0
  18. package/dist/spinner/index.js +1 -0
  19. package/dist/spinner/spinner.d.ts +14 -0
  20. package/dist/spinner/spinner.js +126 -0
  21. package/dist/splitPanel/index.d.ts +1 -0
  22. package/dist/splitPanel/index.js +1 -0
  23. package/dist/splitPanel/splitPanel.d.ts +36 -0
  24. package/dist/splitPanel/splitPanel.js +144 -0
  25. package/dist/toast/index.d.ts +5 -0
  26. package/dist/toast/index.js +4 -0
  27. package/dist/toast/toast.d.ts +10 -0
  28. package/dist/toast/toast.js +182 -0
  29. package/dist/toast/toastApi.d.ts +10 -0
  30. package/dist/toast/toastApi.js +53 -0
  31. package/dist/toast/toaster.d.ts +4 -0
  32. package/dist/toast/toaster.js +42 -0
  33. package/dist/toast/types.d.ts +17 -0
  34. package/dist/toast/types.js +2 -0
  35. package/dist/toggleCard/index.d.ts +1 -0
  36. package/dist/toggleCard/index.js +1 -0
  37. package/dist/toggleCard/toggleCard.d.ts +32 -0
  38. package/dist/toggleCard/toggleCard.js +301 -0
  39. package/dist/useDimensions.d.ts +12 -0
  40. package/dist/useDimensions.js +31 -0
  41. package/dist/useResizableDrawer.d.ts +72 -0
  42. package/dist/useResizableDrawer.js +136 -0
  43. package/package.json +34 -1
@@ -0,0 +1,126 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { keyframes } from "@emotion/react";
3
+ import styled from "@emotion/styled";
4
+ import classnames from "classnames";
5
+ function Spinner(props) {
6
+ return /*#__PURE__*/ jsxs(Container, {
7
+ className: classnames('scraps-spinner', props.className, {
8
+ 'scraps-spinner-mini': props.mini
9
+ }),
10
+ style: props.style,
11
+ "data-test-id": props['data-test-id'] ?? 'loading-indicator',
12
+ children: [
13
+ /*#__PURE__*/ jsx("div", {
14
+ className: classnames('scraps-spinner-container', {
15
+ 'scraps-spinner-relative': props.relative
16
+ }),
17
+ style: {
18
+ width: props.size,
19
+ height: props.size
20
+ },
21
+ children: /*#__PURE__*/ jsx("div", {
22
+ className: "scraps-spinner-ring",
23
+ style: props.size ? {
24
+ width: props.size - 1,
25
+ height: props.size - 1,
26
+ borderWidth: getSpinnerBorderWidth(props.size)
27
+ } : void 0
28
+ })
29
+ }),
30
+ props.children && /*#__PURE__*/ jsx("div", {
31
+ className: "scraps-spinner-message",
32
+ children: props.children
33
+ })
34
+ ]
35
+ });
36
+ }
37
+ function getSpinnerBorderWidth(size) {
38
+ if (!size) return;
39
+ if (size > 64) return 6;
40
+ return 2 + (size - 24) / 40 * 4;
41
+ }
42
+ const loading = keyframes`
43
+ from { transform: rotate(0deg); }
44
+ to { transform: rotate(360deg); }
45
+ `;
46
+ const Container = styled('div')`
47
+ margin: 6em auto;
48
+ position: relative;
49
+
50
+ .scraps-spinner-container {
51
+ box-sizing: border-box;
52
+ position: relative;
53
+ width: fit-content;
54
+ margin: 0 auto;
55
+ padding: 0.5px;
56
+ overflow: hidden;
57
+ }
58
+
59
+ .scraps-spinner-ring {
60
+ box-sizing: border-box;
61
+ position: relative;
62
+ background: transparent;
63
+ /* oxlint-disable-next-line @sentry/scraps/use-semantic-token -- Preserve the existing light-theme loader colors. */
64
+ border: 6px solid
65
+ ${(p)=>'dark' === p.theme.type ? p.theme.tokens.border.transparent.neutral.muted : '#e6e9ec'};
66
+ /* oxlint-disable-next-line @sentry/scraps/use-semantic-token -- Preserve the existing light-theme loader colors. */
67
+ border-left-color: ${(p)=>'dark' === p.theme.type ? p.theme.tokens.border.accent.vibrant : '#6c5fc7'};
68
+ animation: ${loading} 0.55s infinite linear;
69
+ margin: 0 auto;
70
+ }
71
+
72
+ .scraps-spinner-ring,
73
+ .scraps-spinner-ring::after {
74
+ border-radius: 50%;
75
+ width: 63px;
76
+ height: 63px;
77
+ }
78
+
79
+ .scraps-spinner-message {
80
+ margin-top: 20px;
81
+ text-align: center;
82
+ }
83
+
84
+ &.scraps-spinner-mini {
85
+ margin: 4px 0;
86
+ font-size: 13px;
87
+ height: 24px;
88
+ width: 24px;
89
+
90
+ .scraps-spinner-container {
91
+ position: absolute;
92
+ left: 0;
93
+ top: 0;
94
+ width: 24px;
95
+ height: 24px;
96
+
97
+ &.scraps-spinner-relative {
98
+ position: relative;
99
+ left: auto;
100
+ top: auto;
101
+ }
102
+ }
103
+
104
+ .scraps-spinner-ring {
105
+ margin: 0;
106
+ width: 23px;
107
+ height: 23px;
108
+ border-width: 2px;
109
+ }
110
+
111
+ .scraps-spinner-message {
112
+ padding-left: 30px;
113
+ margin-top: 1px;
114
+ display: inline-block;
115
+ }
116
+ }
117
+
118
+ @media (prefers-reduced-motion) {
119
+ .scraps-spinner-ring {
120
+ animation-delay: -1ms !important;
121
+ animation-duration: 0ms !important;
122
+ animation-iteration-count: 1 !important;
123
+ }
124
+ }
125
+ `;
126
+ export { Spinner };
@@ -0,0 +1 @@
1
+ export { SplitPanel, type SplitPanelHandle } from './splitPanel.js';
@@ -0,0 +1 @@
1
+ export { SplitPanel } from "./splitPanel.js";
@@ -0,0 +1,36 @@
1
+ import type * as React from 'react';
2
+ import { type Responsive } from '../layout/index.js';
3
+ export interface SplitPanelHandle {
4
+ /**
5
+ * Imperatively set the `sized` pane's size (px). Useful to seed the size from
6
+ * a measurement the parent takes after mount, without remounting (and thus
7
+ * without the parent gating the whole panel on its own measurement).
8
+ */
9
+ setSize: (size: number, userEvent?: boolean) => void;
10
+ }
11
+ interface SplitPanelProps {
12
+ /** Initial size of the `sized` pane in pixels; restored on double-click. */
13
+ defaultSize: number;
14
+ /** The pane with a draggable size. */
15
+ sized: React.ReactNode;
16
+ /** The pane that fills the remaining space. Omit to render a single pane. */
17
+ fill?: React.ReactNode;
18
+ /** Minimum size of the `fill` pane in pixels. */
19
+ fillMinSize?: number;
20
+ /** Starting size, e.g. restored from persistence. Defaults to `defaultSize`. */
21
+ initialSize?: number;
22
+ maxSize?: number;
23
+ minSize?: number;
24
+ /** Fires once when a drag ends. */
25
+ onResizeEnd?: (payload: {
26
+ direction: 'increase' | 'decrease';
27
+ endSize: number;
28
+ startSize: number;
29
+ }) => void;
30
+ /** Layout direction. Accepts a responsive value. */
31
+ orientation?: Responsive<'horizontal' | 'vertical'>;
32
+ /** Imperative handle exposing `setSize`. */
33
+ ref?: React.Ref<SplitPanelHandle>;
34
+ }
35
+ export declare function SplitPanel({ sized, fill, ref, orientation: orientationProp, defaultSize, initialSize, minSize, maxSize, fillMinSize, onResizeEnd, }: SplitPanelProps): import("@emotion/react/jsx-runtime").JSX.Element;
36
+ export {};
@@ -0,0 +1,144 @@
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { useCallback, useImperativeHandle, useRef, useState } from "react";
3
+ import styled from "@emotion/styled";
4
+ import { DRAG_HANDLE_SIZE, DragHandle } from "../dragHandle/index.js";
5
+ import { Flex, Stack } from "../layout/index.js";
6
+ import { useResponsivePropValue } from "../layout/styles.js";
7
+ import { useTranslation } from "../translation/useTranslation.js";
8
+ import { useDimensions } from "../useDimensions.js";
9
+ import { useResizableDrawer } from "../useResizableDrawer.js";
10
+ function Pane({ size, children }) {
11
+ const isFilling = null === size;
12
+ return /*#__PURE__*/ jsx(Stack, {
13
+ minHeight: "0",
14
+ minWidth: "0",
15
+ flexGrow: isFilling ? 1 : 0,
16
+ flexShrink: isFilling ? 1 : 0,
17
+ flexBasis: isFilling ? 0 : `${size}px`,
18
+ children: children
19
+ });
20
+ }
21
+ function SplitPanel({ sized, fill, ref, orientation: orientationProp = 'horizontal', defaultSize, initialSize = defaultSize, minSize = 0, maxSize, fillMinSize = 0, onResizeEnd }) {
22
+ const { t } = useTranslation();
23
+ const orientation = 'vertical' === useResponsivePropValue(orientationProp) ? 'vertical' : 'horizontal';
24
+ const hasFill = null != fill;
25
+ const containerRef = useRef(null);
26
+ const dims = useDimensions({
27
+ elementRef: containerRef
28
+ });
29
+ const availableSize = 'horizontal' === orientation ? dims.width : dims.height;
30
+ const min = minSize;
31
+ const explicitMax = maxSize ?? 1 / 0;
32
+ const max = availableSize > 0 ? Math.max(min, Math.min(explicitMax, availableSize - fillMinSize - DRAG_HANDLE_SIZE)) : explicitMax;
33
+ const handleResizeEnd = useCallback((startSize, endSize)=>{
34
+ if (startSize === endSize) return;
35
+ onResizeEnd?.({
36
+ startSize,
37
+ endSize,
38
+ direction: endSize > startSize ? 'increase' : 'decrease'
39
+ });
40
+ }, [
41
+ onResizeEnd
42
+ ]);
43
+ const [isHeld, setIsHeld] = useState(false);
44
+ const dragStateRef = useRef(null);
45
+ const { setSize, size: containerSize } = useResizableDrawer({
46
+ direction: 'horizontal' === orientation ? 'left' : 'down',
47
+ initialSize,
48
+ min,
49
+ max
50
+ });
51
+ useImperativeHandle(ref, ()=>({
52
+ setSize
53
+ }), [
54
+ setSize
55
+ ]);
56
+ const visibleSize = Math.max(min, Math.min(containerSize, max));
57
+ const handleDoubleClick = ()=>{
58
+ const target = Math.max(min, Math.min(defaultSize, max));
59
+ setSize(target, true);
60
+ handleResizeEnd(visibleSize, target);
61
+ };
62
+ const handleMoveStart = ()=>{
63
+ dragStateRef.current = {
64
+ size: visibleSize,
65
+ startSize: visibleSize
66
+ };
67
+ setIsHeld(true);
68
+ };
69
+ const handleMove = (delta)=>{
70
+ const state = dragStateRef.current;
71
+ if (!state) return;
72
+ state.size = Math.max(min, Math.min(max, state.size + delta));
73
+ setSize(Math.round(state.size), true);
74
+ };
75
+ const handleMoveEnd = ()=>{
76
+ const state = dragStateRef.current;
77
+ dragStateRef.current = null;
78
+ setIsHeld(false);
79
+ if (state) handleResizeEnd(state.startSize, Math.round(state.size));
80
+ };
81
+ const handleKeyDown = (event)=>{
82
+ let newSize = null;
83
+ if ('Home' === event.key) newSize = min;
84
+ else if ('End' === event.key) newSize = max;
85
+ if (null !== newSize && Number.isFinite(newSize)) {
86
+ event.preventDefault();
87
+ setSize(newSize, true);
88
+ handleResizeEnd(visibleSize, newSize);
89
+ }
90
+ };
91
+ const panes = [
92
+ /*#__PURE__*/ jsx(Pane, {
93
+ size: hasFill ? visibleSize : null,
94
+ children: sized
95
+ }, "sized")
96
+ ];
97
+ if (hasFill) panes.push(/*#__PURE__*/ jsx(DragHandle, {
98
+ "aria-label": t('Resize panels'),
99
+ isSizedFirst: true,
100
+ max: max,
101
+ min: min,
102
+ orientation: orientation,
103
+ value: visibleSize,
104
+ onDoubleClick: handleDoubleClick,
105
+ onKeyDown: handleKeyDown,
106
+ onMove: handleMove,
107
+ onMoveEnd: handleMoveEnd,
108
+ onMoveStart: handleMoveStart
109
+ }, "divider"), /*#__PURE__*/ jsx(Pane, {
110
+ size: null,
111
+ children: fill
112
+ }, "fill"));
113
+ return /*#__PURE__*/ jsx(Flex, {
114
+ direction: 'horizontal' === orientation ? 'row' : 'column',
115
+ position: "relative",
116
+ width: "100%",
117
+ height: "100%",
118
+ minHeight: "0",
119
+ minWidth: "0",
120
+ flex: "1",
121
+ children: (props)=>/*#__PURE__*/ jsx(RootElement, {
122
+ ...props,
123
+ ref: containerRef,
124
+ "data-is-held": isHeld,
125
+ style: hasFill && 0 === availableSize ? {
126
+ visibility: 'hidden'
127
+ } : void 0,
128
+ children: panes
129
+ })
130
+ });
131
+ }
132
+ const RootElement = styled('div')`
133
+ /*
134
+ * Disable iframe pointer events while dragging so the divider doesn't lose the
135
+ * cursor when crossing an embedded iframe (e.g. the Replay player). The
136
+ * triple-& raises specificity so this beats the player's own
137
+ * [data-inspectable] .replayer-wrapper > iframe !important rule, which would
138
+ * otherwise tie and make the drag intermittently stick over the video.
139
+ */
140
+ &&&[data-is-held='true'] iframe {
141
+ pointer-events: none !important;
142
+ }
143
+ `;
144
+ export { SplitPanel };
@@ -0,0 +1,5 @@
1
+ export { toast } from './toastApi.js';
2
+ export { ToastProvider } from './toaster.js';
3
+ export { DEFAULT_TOAST_DURATION } from './types.js';
4
+ export type { ToastAction, ToastOptions, ToastVariant } from './types.js';
5
+ export { Toast } from './toast.js';
@@ -0,0 +1,4 @@
1
+ export { toast } from "./toastApi.js";
2
+ export { ToastProvider } from "./toaster.js";
3
+ export { DEFAULT_TOAST_DURATION } from "./types.js";
4
+ export { Toast } from "./toast.js";
@@ -0,0 +1,10 @@
1
+ import type * as React from 'react';
2
+ import type { ToastAction, ToastVariant } from './types.js';
3
+ interface ToastProps {
4
+ message: React.ReactNode;
5
+ onDismiss: () => void;
6
+ variant: ToastVariant;
7
+ action?: ToastAction;
8
+ }
9
+ export declare function Toast({ message, variant, action, onDismiss }: ToastProps): import("@emotion/react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,182 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import styled from "@emotion/styled";
3
+ import { IconCheckmark } from "@sentry/icons/checkmark";
4
+ import { IconClose } from "@sentry/icons/close";
5
+ import { IconWarning } from "@sentry/icons/warning";
6
+ import { Button } from "../button/index.js";
7
+ import { Container, Flex } from "../layout/index.js";
8
+ import { Spinner } from "../spinner/index.js";
9
+ import { Text } from "../text/index.js";
10
+ import { useTranslation } from "../translation/useTranslation.js";
11
+ function Toast({ message, variant, action, onDismiss }) {
12
+ const { t } = useTranslation();
13
+ return /*#__PURE__*/ jsxs(ToastContainer, {
14
+ role: 'error' === variant ? 'alert' : 'status',
15
+ variant: variant,
16
+ children: [
17
+ /*#__PURE__*/ jsx(ToastIcon, {
18
+ variant: variant
19
+ }),
20
+ /*#__PURE__*/ jsx(Container, {
21
+ padding: "lg",
22
+ flex: "1",
23
+ minWidth: 0,
24
+ children: /*#__PURE__*/ jsx(Text, {
25
+ as: "div",
26
+ wrap: "normal",
27
+ wordBreak: "break-word",
28
+ children: message
29
+ })
30
+ }),
31
+ action ? /*#__PURE__*/ jsx(Flex, {
32
+ align: "center",
33
+ justify: "center",
34
+ padding: "0 lg",
35
+ children: /*#__PURE__*/ jsx(Button, {
36
+ variant: "secondary",
37
+ size: "xs",
38
+ onClick: (event)=>{
39
+ event.stopPropagation();
40
+ action.onClick();
41
+ onDismiss();
42
+ },
43
+ icon: action.icon,
44
+ children: action.label
45
+ })
46
+ }) : null,
47
+ /*#__PURE__*/ jsx(Flex, {
48
+ align: "center",
49
+ justify: "center",
50
+ padding: "0 lg",
51
+ children: /*#__PURE__*/ jsx(Button, {
52
+ "aria-label": t('Dismiss'),
53
+ variant: "transparent",
54
+ size: "xs",
55
+ icon: /*#__PURE__*/ jsx(IconClose, {
56
+ size: "xs"
57
+ }),
58
+ onClick: onDismiss
59
+ })
60
+ })
61
+ ]
62
+ });
63
+ }
64
+ function ToastIcon({ variant }) {
65
+ switch(variant){
66
+ case 'loading':
67
+ return /*#__PURE__*/ jsx(ToastIconContainer, {
68
+ variant: variant,
69
+ "aria-hidden": true,
70
+ children: /*#__PURE__*/ jsx(ToastSpinner, {
71
+ size: 16
72
+ })
73
+ });
74
+ case 'success':
75
+ return /*#__PURE__*/ jsx(ToastIconContainer, {
76
+ variant: variant,
77
+ "aria-hidden": true,
78
+ children: /*#__PURE__*/ jsx(IconCheckmark, {})
79
+ });
80
+ case 'error':
81
+ return /*#__PURE__*/ jsx(ToastIconContainer, {
82
+ variant: variant,
83
+ "aria-hidden": true,
84
+ children: /*#__PURE__*/ jsx(IconWarning, {})
85
+ });
86
+ case 'default':
87
+ return null;
88
+ default:
89
+ return variant;
90
+ }
91
+ }
92
+ function getContainerTheme(theme, variant) {
93
+ switch(variant){
94
+ case 'success':
95
+ return {
96
+ background: theme.tokens.background.transparent.success.muted,
97
+ borderBottom: `2px solid ${theme.tokens.border.success.moderate}`,
98
+ border: `1px solid ${theme.tokens.border.success.moderate}`,
99
+ boxShadow: theme.shadow.medium
100
+ };
101
+ case 'error':
102
+ return {
103
+ background: theme.tokens.background.transparent.danger.muted,
104
+ borderBottom: `2px solid ${theme.tokens.border.danger.moderate}`,
105
+ border: `1px solid ${theme.tokens.border.danger.moderate}`,
106
+ boxShadow: theme.shadow.medium
107
+ };
108
+ default:
109
+ return {
110
+ background: theme.tokens.background.overlay,
111
+ borderBottom: `2px solid ${theme.tokens.border.primary}`,
112
+ border: `1px solid ${theme.tokens.border.primary}`,
113
+ boxShadow: theme.shadow.medium
114
+ };
115
+ }
116
+ }
117
+ const ToastContainer = styled((props)=>{
118
+ const { variant, children, ...rest } = props;
119
+ return /*#__PURE__*/ jsx(ToastOuterContainer, {
120
+ variant: variant,
121
+ ...rest,
122
+ children: /*#__PURE__*/ jsx(ToastInnerContainer, {
123
+ variant: variant,
124
+ children: children
125
+ })
126
+ });
127
+ })``;
128
+ const ToastOuterContainer = styled('div')`
129
+ overflow: hidden;
130
+ /* The outer container is a separate element because the colors are not opaque,
131
+ * so we set the background color here to the background color so that the
132
+ * toast is not see-through.
133
+ */
134
+ background: ${(p)=>p.theme.tokens.background.primary};
135
+ border-radius: ${(p)=>p.theme.radius.lg};
136
+ border: ${(p)=>getContainerTheme(p.theme, p.variant).border};
137
+ box-shadow: ${(p)=>getContainerTheme(p.theme, p.variant).boxShadow};
138
+ `;
139
+ const ToastInnerContainer = styled('div')`
140
+ display: flex;
141
+ align-items: stretch;
142
+ background: ${(p)=>getContainerTheme(p.theme, p.variant).background};
143
+ `;
144
+ function getToastIconContainerTheme(theme, variant) {
145
+ switch(variant){
146
+ case 'success':
147
+ return {
148
+ background: theme.tokens.background.success.vibrant,
149
+ borderRight: `1px solid ${theme.tokens.border.success.moderate}`
150
+ };
151
+ case 'error':
152
+ return {
153
+ background: theme.tokens.background.danger.vibrant,
154
+ borderRight: `1px solid ${theme.tokens.border.danger.moderate}`
155
+ };
156
+ default:
157
+ return {
158
+ background: theme.tokens.background.overlay,
159
+ borderRight: `1px solid ${theme.tokens.border.primary}`
160
+ };
161
+ }
162
+ }
163
+ const ToastIconContainer = styled('div')`
164
+ display: flex;
165
+ align-items: center;
166
+ justify-content: center;
167
+ padding: ${(p)=>p.theme.space.lg} ${(p)=>p.theme.space.xl};
168
+ position: relative;
169
+ ${(p)=>({
170
+ ...getToastIconContainerTheme(p.theme, p.variant)
171
+ })};
172
+
173
+ svg {
174
+ width: 16px;
175
+ height: 16px;
176
+ color: ${(p)=>'success' === p.variant ? p.theme.tokens.content.onVibrant.dark : 'error' === p.variant ? p.theme.tokens.content.onVibrant.light : void 0} !important;
177
+ }
178
+ `;
179
+ const ToastSpinner = styled(Spinner)`
180
+ margin: 0;
181
+ `;
182
+ export { Toast };
@@ -0,0 +1,10 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ToastOptions } from './types.js';
3
+ export declare const toast: {
4
+ success: (message: ReactNode, options?: ToastOptions) => string | number;
5
+ error: (message: ReactNode, options?: ToastOptions) => string | number;
6
+ loading: (message: ReactNode, options?: ToastOptions) => string | number;
7
+ message: (message: ReactNode, options?: ToastOptions) => string | number;
8
+ /** Dismisses every toast. */
9
+ dismiss: () => string | number;
10
+ };
@@ -0,0 +1,53 @@
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { toast } from "sonner";
3
+ import { Toast } from "./toast.js";
4
+ const activeToastIds = new Map();
5
+ function removeActiveToast(variant, toastId) {
6
+ const ids = activeToastIds.get(variant);
7
+ ids?.delete(toastId);
8
+ if (ids?.size === 0) activeToastIds.delete(variant);
9
+ }
10
+ function dismissOtherVariants(variant, toastIdToUpdate) {
11
+ for (const [activeVariant, ids] of activeToastIds)if (activeVariant !== variant) {
12
+ for (const toastId of ids)if (toastId !== toastIdToUpdate) toast.dismiss(toastId);
13
+ activeToastIds.delete(activeVariant);
14
+ }
15
+ }
16
+ function show(variant, message, options = {}) {
17
+ const { action, duration, id, onDismiss } = options;
18
+ dismissOtherVariants(variant, id);
19
+ const toastId = toast.custom((renderedToastId)=>/*#__PURE__*/ jsx(Toast, {
20
+ variant: variant,
21
+ message: message,
22
+ action: action,
23
+ onDismiss: ()=>toast.dismiss(renderedToastId)
24
+ }), {
25
+ duration,
26
+ onDismiss: (dismissedToast)=>{
27
+ removeActiveToast(variant, dismissedToast.id);
28
+ onDismiss?.();
29
+ },
30
+ onAutoClose: (dismissedToast)=>{
31
+ removeActiveToast(variant, dismissedToast.id);
32
+ onDismiss?.();
33
+ },
34
+ ...void 0 === id ? {} : {
35
+ id
36
+ }
37
+ });
38
+ const ids = activeToastIds.get(variant) ?? new Set();
39
+ ids.add(toastId);
40
+ activeToastIds.set(variant, ids);
41
+ return toastId;
42
+ }
43
+ const toastApi_toast = {
44
+ success: (message, options)=>show('success', message, options),
45
+ error: (message, options)=>show('error', message, options),
46
+ loading: (message, options)=>show('loading', message, options),
47
+ message: (message, options)=>show('default', message, options),
48
+ dismiss: ()=>{
49
+ activeToastIds.clear();
50
+ return toast.dismiss();
51
+ }
52
+ };
53
+ export { toastApi_toast as toast };
@@ -0,0 +1,4 @@
1
+ import type { ReactNode } from 'react';
2
+ export declare function ToastProvider({ children }: {
3
+ children?: ReactNode;
4
+ }): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,42 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { Fragment } from "react";
3
+ import styled from "@emotion/styled";
4
+ import { Toaster } from "sonner";
5
+ import { useTranslation } from "../translation/useTranslation.js";
6
+ import { DEFAULT_TOAST_DURATION } from "./types.js";
7
+ const StyledToaster = styled(Toaster)`
8
+ &[data-sonner-toaster] {
9
+ z-index: ${(p)=>p.theme.zIndex.toast};
10
+ width: auto;
11
+ }
12
+
13
+ &[data-sonner-toaster] [data-sonner-toast] {
14
+ width: min(400px, calc(100vw - 60px));
15
+ }
16
+
17
+ /* Sonner hides overflow toasts with opacity and pointer-events, which leaves
18
+ * them in the accessibility tree and tab order. */
19
+ &[data-sonner-toaster] [data-sonner-toast][data-visible='false'] {
20
+ visibility: hidden;
21
+ }
22
+ `;
23
+ function ToastProvider({ children }) {
24
+ const { t } = useTranslation();
25
+ return /*#__PURE__*/ jsxs(Fragment, {
26
+ children: [
27
+ children,
28
+ /*#__PURE__*/ jsx(StyledToaster, {
29
+ position: "bottom-right",
30
+ offset: {
31
+ bottom: '30px',
32
+ right: 'calc(30px + var(--scrollbar-size, 0px))'
33
+ },
34
+ duration: DEFAULT_TOAST_DURATION,
35
+ gap: 12,
36
+ visibleToasts: 3,
37
+ containerAriaLabel: t('Notifications')
38
+ })
39
+ ]
40
+ });
41
+ }
42
+ export { ToastProvider };
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from 'react';
2
+ export declare const DEFAULT_TOAST_DURATION = 6000;
3
+ export type ToastVariant = 'success' | 'error' | 'loading' | 'default';
4
+ export interface ToastAction {
5
+ label: ReactNode;
6
+ onClick: () => void;
7
+ icon?: ReactNode;
8
+ }
9
+ export interface ToastOptions {
10
+ /** Renders a button next to the message. The toast dismisses after onClick. */
11
+ action?: ToastAction;
12
+ /** ms. Use `Infinity` to keep the toast until it is dismissed. */
13
+ duration?: number;
14
+ /** Pass an existing id to replace that toast instead of adding one. */
15
+ id?: string | number;
16
+ onDismiss?: () => void;
17
+ }
@@ -0,0 +1,2 @@
1
+ const DEFAULT_TOAST_DURATION = 6000;
2
+ export { DEFAULT_TOAST_DURATION };
@@ -0,0 +1 @@
1
+ export { ToggleCard, type ToggleCardProps } from './toggleCard.js';
@@ -0,0 +1 @@
1
+ export { ToggleCard } from "./toggleCard.js";