@sentry/scraps 0.2.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.
- package/dist/button/buttonBar.js +7 -1
- package/dist/dragHandle/dragHandle.d.ts +34 -0
- package/dist/dragHandle/dragHandle.js +115 -0
- package/dist/dragHandle/index.d.ts +4 -0
- package/dist/dragHandle/index.js +4 -0
- package/dist/dragHandle/setDocumentDragging.d.ts +9 -0
- package/dist/dragHandle/setDocumentDragging.js +6 -0
- package/dist/dragHandle/useDragMove.d.ts +244 -0
- package/dist/dragHandle/useDragMove.js +66 -0
- package/dist/dragHandle/useDragSeparator.d.ts +256 -0
- package/dist/dragHandle/useDragSeparator.js +36 -0
- package/dist/formPresentation/autoSaveContext.d.ts +23 -0
- package/dist/formPresentation/autoSaveContext.js +13 -0
- package/dist/formPresentation/base.d.ts +11 -0
- package/dist/formPresentation/base.js +37 -0
- package/dist/formPresentation/displayField.d.ts +17 -0
- package/dist/formPresentation/displayField.js +69 -0
- package/dist/formPresentation/fieldIds.d.ts +3 -0
- package/dist/formPresentation/fieldIds.js +14 -0
- package/dist/formPresentation/fieldLayout.d.ts +23 -0
- package/dist/formPresentation/fieldLayout.js +76 -0
- package/dist/formPresentation/formContext.d.ts +4 -0
- package/dist/formPresentation/formContext.js +6 -0
- package/dist/formPresentation/groupContext.d.ts +24 -0
- package/dist/formPresentation/groupContext.js +22 -0
- package/dist/formPresentation/icons.d.ts +11 -0
- package/dist/formPresentation/icons.js +61 -0
- package/dist/formPresentation/index.d.ts +8 -0
- package/dist/formPresentation/index.js +8 -0
- package/dist/formPresentation/meta.d.ts +18 -0
- package/dist/formPresentation/meta.js +88 -0
- package/dist/formPresentation/useStackedLayout.d.ts +1 -0
- package/dist/formPresentation/useStackedLayout.js +9 -0
- package/dist/input/index.d.ts +8 -0
- package/dist/input/index.js +6 -0
- package/dist/input/input.d.ts +19 -0
- package/dist/input/input.js +14 -0
- package/dist/input/inputGroup.d.ts +29 -0
- package/dist/input/inputGroup.js +167 -0
- package/dist/input/inputStyles.d.ts +13 -0
- package/dist/input/inputStyles.js +52 -0
- package/dist/input/numberDragInput.d.ts +20 -0
- package/dist/input/numberDragInput.js +97 -0
- package/dist/input/numberInput.d.ts +10 -0
- package/dist/input/numberInput.js +94 -0
- package/dist/input/otpInput.d.ts +28 -0
- package/dist/input/otpInput.js +81 -0
- package/dist/input/useAutosizeInput.d.ts +17 -0
- package/dist/input/useAutosizeInput.js +56 -0
- package/dist/layout/styles.d.ts +1 -1
- package/dist/menu/controlContext.d.ts +32 -0
- package/dist/menu/controlContext.js +7 -0
- package/dist/menu/dropdownButton.d.ts +18 -0
- package/dist/menu/dropdownButton.js +66 -0
- package/dist/menu/index.d.ts +7 -0
- package/dist/menu/index.js +3 -0
- package/dist/menu/menu.d.ts +159 -0
- package/dist/menu/menu.js +464 -0
- package/dist/menu/selectTypes.d.ts +96 -0
- package/dist/menu/selectTypes.js +0 -0
- package/dist/menu/selectValue.d.ts +13 -0
- package/dist/menu/selectValue.js +0 -0
- package/dist/overlayPositioning.d.ts +10 -1
- package/dist/overlayPositioning.js +15 -2
- package/dist/overlayTrigger.d.ts +22 -0
- package/dist/overlayTrigger.js +30 -0
- package/dist/slot/knownContexts.d.ts +1 -1
- package/dist/spinner/index.d.ts +1 -0
- package/dist/spinner/index.js +1 -0
- package/dist/spinner/spinner.d.ts +14 -0
- package/dist/spinner/spinner.js +126 -0
- package/dist/splitPanel/index.d.ts +1 -0
- package/dist/splitPanel/index.js +1 -0
- package/dist/splitPanel/splitPanel.d.ts +36 -0
- package/dist/splitPanel/splitPanel.js +144 -0
- package/dist/table/index.d.ts +3 -0
- package/dist/table/index.js +3 -0
- package/dist/table/sortableHeaderCell.d.ts +36 -0
- package/dist/table/sortableHeaderCell.js +99 -0
- package/dist/table/styles.d.ts +46 -0
- package/dist/table/styles.js +93 -0
- package/dist/table/table.d.ts +64 -0
- package/dist/table/table.js +228 -0
- package/dist/table/useColumnResize.d.ts +27 -0
- package/dist/table/useColumnResize.js +62 -0
- package/dist/table/useObservedColumnSize.d.ts +12 -0
- package/dist/table/useObservedColumnSize.js +74 -0
- package/dist/text/heading.d.ts +1 -1
- package/dist/text/text.d.ts +7 -0
- package/dist/text/text.js +1 -1
- package/dist/textarea/index.d.ts +1 -0
- package/dist/textarea/index.js +1 -0
- package/dist/textarea/textarea.d.ts +22 -0
- package/dist/textarea/textarea.js +77 -0
- package/dist/toast/index.d.ts +5 -0
- package/dist/toast/index.js +4 -0
- package/dist/toast/toast.d.ts +10 -0
- package/dist/toast/toast.js +182 -0
- package/dist/toast/toastApi.d.ts +10 -0
- package/dist/toast/toastApi.js +53 -0
- package/dist/toast/toaster.d.ts +4 -0
- package/dist/toast/toaster.js +42 -0
- package/dist/toast/types.d.ts +17 -0
- package/dist/toast/types.js +2 -0
- package/dist/toggleCard/index.d.ts +1 -0
- package/dist/toggleCard/index.js +1 -0
- package/dist/toggleCard/toggleCard.d.ts +32 -0
- package/dist/toggleCard/toggleCard.js +301 -0
- package/dist/useDimensions.d.ts +12 -0
- package/dist/useDimensions.js +31 -0
- package/dist/useOverlay.js +2 -1
- package/dist/useResizableDrawer.d.ts +72 -0
- package/dist/useResizableDrawer.js +136 -0
- package/package.json +60 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useMemo, useState } from "react";
|
|
2
|
+
import { useResizeObserver } from "@react-aria/utils";
|
|
3
|
+
const NO_ANCESTORS = {
|
|
4
|
+
cell: null,
|
|
5
|
+
table: null
|
|
6
|
+
};
|
|
7
|
+
function setProperty(element, property, value) {
|
|
8
|
+
if (element.style.getPropertyValue(property) !== value) element.style.setProperty(property, value);
|
|
9
|
+
}
|
|
10
|
+
function measureColumn(element, cell, table) {
|
|
11
|
+
setProperty(element, '--column-resizer-height', `${table.clientHeight}px`);
|
|
12
|
+
setProperty(element, '--drag-separator-target-length', `${cell.offsetHeight}px`);
|
|
13
|
+
return {
|
|
14
|
+
max: Math.max(table.clientWidth, cell.offsetWidth),
|
|
15
|
+
width: cell.offsetWidth
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function useObservedColumnSize(elementRef) {
|
|
19
|
+
const [measurements, setMeasurements] = useState({
|
|
20
|
+
max: 0,
|
|
21
|
+
width: 0
|
|
22
|
+
});
|
|
23
|
+
const [{ cell, table }, setAncestors] = useState(NO_ANCESTORS);
|
|
24
|
+
const measure = useCallback((element, target, grid)=>{
|
|
25
|
+
const next = measureColumn(element, target, grid);
|
|
26
|
+
setMeasurements((current)=>current.max === next.max && current.width === next.width ? current : next);
|
|
27
|
+
}, []);
|
|
28
|
+
useLayoutEffect(()=>{
|
|
29
|
+
const element = elementRef.current;
|
|
30
|
+
const foundCell = element?.closest('th') ?? null;
|
|
31
|
+
const foundTable = foundCell?.closest('table') ?? null;
|
|
32
|
+
setAncestors({
|
|
33
|
+
cell: foundCell,
|
|
34
|
+
table: foundTable
|
|
35
|
+
});
|
|
36
|
+
if (element && foundCell && foundTable) measure(element, foundCell, foundTable);
|
|
37
|
+
}, [
|
|
38
|
+
elementRef,
|
|
39
|
+
measure
|
|
40
|
+
]);
|
|
41
|
+
const cellRef = useMemo(()=>({
|
|
42
|
+
current: cell
|
|
43
|
+
}), [
|
|
44
|
+
cell
|
|
45
|
+
]);
|
|
46
|
+
const tableRef = useMemo(()=>({
|
|
47
|
+
current: table
|
|
48
|
+
}), [
|
|
49
|
+
table
|
|
50
|
+
]);
|
|
51
|
+
const onResize = useCallback(()=>{
|
|
52
|
+
const element = elementRef.current;
|
|
53
|
+
if (!element || !cell || !table) return;
|
|
54
|
+
measure(element, cell, table);
|
|
55
|
+
}, [
|
|
56
|
+
cell,
|
|
57
|
+
elementRef,
|
|
58
|
+
measure,
|
|
59
|
+
table
|
|
60
|
+
]);
|
|
61
|
+
useResizeObserver({
|
|
62
|
+
ref: cellRef,
|
|
63
|
+
onResize
|
|
64
|
+
});
|
|
65
|
+
useResizeObserver({
|
|
66
|
+
ref: tableRef,
|
|
67
|
+
onResize
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
cell,
|
|
71
|
+
...measurements
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export { useObservedColumnSize };
|
package/dist/text/heading.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type * as React from 'react';
|
|
|
2
2
|
import { type Responsive } from '../layout/index.js';
|
|
3
3
|
import type { HeadingSize } from '../theme/index.js';
|
|
4
4
|
import { type BaseTextProps } from './text.js';
|
|
5
|
-
type BaseHeadingProps = Omit<BaseTextProps, 'bold' | 'uppercase'>;
|
|
5
|
+
type BaseHeadingProps = Omit<BaseTextProps, 'bold' | 'uppercase' | 'trim'>;
|
|
6
6
|
type ExclusiveHeadingEllipsisProps = {
|
|
7
7
|
ellipsis?: true;
|
|
8
8
|
wrap?: never;
|
package/dist/text/text.d.ts
CHANGED
|
@@ -56,6 +56,13 @@ export interface BaseTextProps {
|
|
|
56
56
|
* @default undefined
|
|
57
57
|
*/
|
|
58
58
|
textWrap?: 'wrap' | 'nowrap' | 'balance' | 'pretty' | 'stable';
|
|
59
|
+
/**
|
|
60
|
+
* Trims the text box to the glyph bounds with `text-box-trim`. Set to false when
|
|
61
|
+
* the content is taller than a line of text, such as a tag or pill, so it isn't
|
|
62
|
+
* clipped when combined with `ellipsis`.
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
trim?: boolean;
|
|
59
66
|
/**
|
|
60
67
|
* Determines how text should be underlined.
|
|
61
68
|
* @default undefined
|
package/dist/text/text.js
CHANGED
|
@@ -49,7 +49,7 @@ const getTextStyles = (p)=>css`
|
|
|
49
49
|
text-transform: ${p.uppercase ? 'uppercase' : void 0};
|
|
50
50
|
|
|
51
51
|
text-box-edge: text text;
|
|
52
|
-
text-box-trim: trim-both;
|
|
52
|
+
text-box-trim: ${false === p.trim ? 'none' : 'trim-both'};
|
|
53
53
|
`;
|
|
54
54
|
const Text = styled((props)=>{
|
|
55
55
|
if ('function' == typeof props.children) return props.children({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TextArea, type TextAreaProps } from './textarea.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TextArea } from "./textarea.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type TextareaAutosizeProps } from 'react-textarea-autosize';
|
|
3
|
+
import { type InputStylesProps } from '../input/inputStyles.js';
|
|
4
|
+
export interface TextAreaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'css' | 'onResize' | 'style'>, InputStylesProps {
|
|
5
|
+
/**
|
|
6
|
+
* Enable autosizing of the textarea.
|
|
7
|
+
*/
|
|
8
|
+
autosize?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Max number of rows to default to.
|
|
11
|
+
*/
|
|
12
|
+
maxRows?: number;
|
|
13
|
+
ref?: React.Ref<HTMLTextAreaElement>;
|
|
14
|
+
/**
|
|
15
|
+
* Number of rows to default to.
|
|
16
|
+
*/
|
|
17
|
+
rows?: number;
|
|
18
|
+
style?: TextareaAutosizeProps['style'];
|
|
19
|
+
}
|
|
20
|
+
export declare const TextArea: import("@emotion/styled").StyledComponent<TextAreaProps & {
|
|
21
|
+
theme?: import("@emotion/react").Theme;
|
|
22
|
+
}, {}, {}>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo, useState } from "react";
|
|
3
|
+
import react_textarea_autosize from "react-textarea-autosize";
|
|
4
|
+
import is_prop_valid from "@emotion/is-prop-valid";
|
|
5
|
+
import { css } from "@emotion/react";
|
|
6
|
+
import styled from "@emotion/styled";
|
|
7
|
+
import { mergeRefs } from "@react-aria/utils";
|
|
8
|
+
import { inputStyles } from "../input/inputStyles.js";
|
|
9
|
+
function TextAreaControl({ ref, autosize, rows = 3, maxRows, size: _size, ...p }) {
|
|
10
|
+
return autosize ? /*#__PURE__*/ jsx(AutosizeTextArea, {
|
|
11
|
+
...p,
|
|
12
|
+
ref: ref,
|
|
13
|
+
rows: rows,
|
|
14
|
+
maxRows: maxRows
|
|
15
|
+
}) : /*#__PURE__*/ jsx("textarea", {
|
|
16
|
+
ref: ref,
|
|
17
|
+
...p,
|
|
18
|
+
rows: rows
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
TextAreaControl.displayName = 'TextAreaControl';
|
|
22
|
+
function AutosizeTextArea({ ref, rows, maxRows, ...p }) {
|
|
23
|
+
'use no memo';
|
|
24
|
+
const [, setWidth] = useState();
|
|
25
|
+
const observerRef = useCallback((node)=>{
|
|
26
|
+
if (!node) return;
|
|
27
|
+
const observer = new ResizeObserver((entries)=>{
|
|
28
|
+
const entry = entries[0];
|
|
29
|
+
const width = entry?.borderBoxSize?.[0]?.inlineSize ?? entry?.contentRect.width;
|
|
30
|
+
setWidth(width);
|
|
31
|
+
});
|
|
32
|
+
observer.observe(node, {
|
|
33
|
+
box: 'border-box'
|
|
34
|
+
});
|
|
35
|
+
return ()=>observer.disconnect();
|
|
36
|
+
}, []);
|
|
37
|
+
const mergedRef = useMemo(()=>mergeRefs(ref, observerRef), [
|
|
38
|
+
ref,
|
|
39
|
+
observerRef
|
|
40
|
+
]);
|
|
41
|
+
return /*#__PURE__*/ jsx(react_textarea_autosize, {
|
|
42
|
+
...p,
|
|
43
|
+
ref: mergedRef,
|
|
44
|
+
minRows: rows,
|
|
45
|
+
maxRows: maxRows
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const StyledTextArea = styled(TextAreaControl, {
|
|
49
|
+
shouldForwardProp: (p)=>[
|
|
50
|
+
'autosize',
|
|
51
|
+
'maxRows'
|
|
52
|
+
].includes(p) || is_prop_valid(p)
|
|
53
|
+
})`
|
|
54
|
+
${inputStyles};
|
|
55
|
+
line-height: ${(p)=>p.theme.font.lineHeight.comfortable};
|
|
56
|
+
/** Allow react-textarea-autosize to freely control height based on props. */
|
|
57
|
+
${(p)=>p.autosize && css`
|
|
58
|
+
height: unset;
|
|
59
|
+
min-height: unset;
|
|
60
|
+
`}
|
|
61
|
+
`;
|
|
62
|
+
const TextArea = styled(StyledTextArea)`
|
|
63
|
+
/* re-set height to let it be determined by the rows prop */
|
|
64
|
+
height: unset;
|
|
65
|
+
/* this calculation reduces padding to account for the line-height, which ensures text is still correctly centered. */
|
|
66
|
+
${({ theme, size = 'md' })=>`padding-top: calc(
|
|
67
|
+
(${theme.form[size].height} -
|
|
68
|
+
(${theme.form[size].fontSize} * ${theme.font.lineHeight.comfortable})
|
|
69
|
+
) / 2
|
|
70
|
+
)`};
|
|
71
|
+
${({ theme, size = 'md' })=>`padding-bottom: calc(
|
|
72
|
+
(${theme.form[size].height} -
|
|
73
|
+
(${theme.form[size].fontSize} * ${theme.font.lineHeight.comfortable})
|
|
74
|
+
) / 2
|
|
75
|
+
)`};
|
|
76
|
+
`;
|
|
77
|
+
export { TextArea };
|
|
@@ -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,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 @@
|
|
|
1
|
+
export { ToggleCard, type ToggleCardProps } from './toggleCard.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ToggleCard } from "./toggleCard.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type ContainerProps } from '../layout/index.js';
|
|
3
|
+
interface CommonProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {
|
|
4
|
+
autoFocus?: boolean;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
padding?: ContainerProps['padding'];
|
|
7
|
+
ref?: React.Ref<HTMLElement>;
|
|
8
|
+
}
|
|
9
|
+
interface SelectionProps extends Omit<CommonProps, 'onClick'> {
|
|
10
|
+
checked: boolean;
|
|
11
|
+
onChange: React.ChangeEventHandler<HTMLInputElement>;
|
|
12
|
+
variant: 'radio' | 'checkbox';
|
|
13
|
+
details?: React.ReactNode;
|
|
14
|
+
name?: string;
|
|
15
|
+
onClick?: never;
|
|
16
|
+
required?: boolean;
|
|
17
|
+
value?: React.InputHTMLAttributes<HTMLInputElement>['value'];
|
|
18
|
+
}
|
|
19
|
+
interface ActionProps extends CommonProps, Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, keyof CommonProps | 'type'> {
|
|
20
|
+
variant: 'button';
|
|
21
|
+
checked?: never;
|
|
22
|
+
details?: never;
|
|
23
|
+
onChange?: never;
|
|
24
|
+
required?: never;
|
|
25
|
+
}
|
|
26
|
+
export type ToggleCardProps = SelectionProps | ActionProps;
|
|
27
|
+
declare function ToggleCardRoot(props: ToggleCardProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
28
|
+
declare function ToggleCardIndicator(): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
29
|
+
export declare const ToggleCard: typeof ToggleCardRoot & {
|
|
30
|
+
Indicator: typeof ToggleCardIndicator;
|
|
31
|
+
};
|
|
32
|
+
export {};
|