@itwin/itwinui-react 3.0.0-dev.2 → 3.0.0-dev.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/CHANGELOG.md +7 -0
- package/cjs/core/Alert/Alert.d.ts +2 -2
- package/cjs/core/FileUpload/FileUpload.d.ts +3 -4
- package/cjs/core/FileUpload/FileUpload.js +2 -2
- package/cjs/core/FileUpload/FileUploadTemplate.d.ts +1 -0
- package/cjs/core/FileUpload/FileUploadTemplate.js +1 -0
- package/cjs/core/ThemeProvider/ThemeProvider.js +5 -2
- package/cjs/core/Toast/Toast.d.ts +5 -10
- package/cjs/core/Toast/Toast.js +15 -13
- package/cjs/core/Toast/Toaster.d.ts +24 -26
- package/cjs/core/Toast/Toaster.js +91 -116
- package/cjs/core/Toast/index.d.ts +1 -4
- package/cjs/core/Toast/index.js +3 -6
- package/cjs/core/index.d.ts +1 -2
- package/cjs/core/index.js +2 -5
- package/cjs/core/utils/components/Popover.d.ts +1 -1
- package/cjs/core/utils/functions/dom.d.ts +0 -8
- package/cjs/core/utils/functions/dom.js +1 -24
- package/cjs/core/utils/functions/polymorphic.d.ts +1 -1
- package/esm/core/Alert/Alert.d.ts +2 -2
- package/esm/core/FileUpload/FileUpload.d.ts +3 -4
- package/esm/core/FileUpload/FileUpload.js +2 -2
- package/esm/core/FileUpload/FileUploadTemplate.d.ts +1 -0
- package/esm/core/FileUpload/FileUploadTemplate.js +1 -0
- package/esm/core/ThemeProvider/ThemeProvider.js +5 -2
- package/esm/core/Toast/Toast.d.ts +5 -10
- package/esm/core/Toast/Toast.js +16 -14
- package/esm/core/Toast/Toaster.d.ts +24 -26
- package/esm/core/Toast/Toaster.js +85 -116
- package/esm/core/Toast/index.d.ts +1 -4
- package/esm/core/Toast/index.js +1 -3
- package/esm/core/index.d.ts +1 -2
- package/esm/core/index.js +1 -1
- package/esm/core/utils/components/Popover.d.ts +1 -1
- package/esm/core/utils/functions/dom.d.ts +0 -8
- package/esm/core/utils/functions/dom.js +0 -19
- package/esm/core/utils/functions/polymorphic.d.ts +1 -1
- package/package.json +2 -2
- package/styles.css +1 -0
- package/cjs/core/Toast/ToastWrapper.d.ts +0 -10
- package/cjs/core/Toast/ToastWrapper.js +0 -49
- package/esm/core/Toast/ToastWrapper.d.ts +0 -10
- package/esm/core/Toast/ToastWrapper.js +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.0.0-dev.3
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#1330](https://github.com/iTwin/iTwinUI/pull/1330): Deprecated `FileUploadTemplate`. Removed all of its references.
|
|
8
|
+
- [#1351](https://github.com/iTwin/iTwinUI/pull/1351): `toaster` import has been removed and replaced with `useToaster` which returns a toaster object with the same API.
|
|
9
|
+
|
|
3
10
|
## 3.0.0-dev.2
|
|
4
11
|
|
|
5
12
|
### Major Changes
|
|
@@ -45,8 +45,8 @@ export declare const Alert: PolymorphicForwardRefComponent<"div", AlertOwnProps>
|
|
|
45
45
|
Icon: PolymorphicForwardRefComponent<"span", Omit<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & {
|
|
46
46
|
ref?: ((instance: HTMLSpanElement | null) => void) | React.RefObject<HTMLSpanElement> | null | undefined;
|
|
47
47
|
}, "as" | "fill" | "key" | "size" | keyof React.HTMLAttributes<HTMLSpanElement>> & {
|
|
48
|
-
size?: "small" | "auto" | "
|
|
49
|
-
fill?: "default" | "
|
|
48
|
+
size?: "small" | "auto" | "large" | "medium" | import("../utils/types.js").AnyString | undefined;
|
|
49
|
+
fill?: "default" | "informational" | "negative" | "positive" | "warning" | import("../utils/types.js").AnyString | undefined;
|
|
50
50
|
} & Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & {
|
|
51
51
|
as?: "span" | undefined;
|
|
52
52
|
}>;
|
|
@@ -4,7 +4,6 @@ declare type FileUploadProps = {
|
|
|
4
4
|
/**
|
|
5
5
|
* Content shown over `children` when file is being dragged onto the component.
|
|
6
6
|
* Should always be used when drag content differs from `children` being wrapped.
|
|
7
|
-
* Can be skipped if wrapping `FileUploadTemplate`.
|
|
8
7
|
*/
|
|
9
8
|
dragContent?: React.ReactNode;
|
|
10
9
|
/**
|
|
@@ -13,15 +12,15 @@ declare type FileUploadProps = {
|
|
|
13
12
|
onFileDropped: (files: FileList) => void;
|
|
14
13
|
/**
|
|
15
14
|
* Component to wrap `FileUpload` around.
|
|
16
|
-
* Either pass `
|
|
15
|
+
* Either pass `FileUploadCard` (for default state) or a different component to wrap.
|
|
17
16
|
*/
|
|
18
17
|
children: React.ReactNode;
|
|
19
18
|
};
|
|
20
19
|
/**
|
|
21
|
-
* File upload component to be wrapped around `
|
|
20
|
+
* File upload component to be wrapped around `FileUploadCard` or any arbitrary component.
|
|
22
21
|
* Provides support for dragging and dropping multiple files.
|
|
23
22
|
* @example
|
|
24
|
-
* <FileUpload onFileDropped={console.log}><
|
|
23
|
+
* <FileUpload onFileDropped={console.log}><FileUploadCard /></FileUpload>
|
|
25
24
|
* <FileUpload dragContent='Drop file here' onFileDropped={console.log}><Textarea /></FileUpload>
|
|
26
25
|
*/
|
|
27
26
|
export declare const FileUpload: PolymorphicForwardRefComponent<"div", FileUploadProps>;
|
|
@@ -35,10 +35,10 @@ const React = __importStar(require("react"));
|
|
|
35
35
|
const classnames_1 = __importDefault(require("classnames"));
|
|
36
36
|
const index_js_1 = require("../utils/index.js");
|
|
37
37
|
/**
|
|
38
|
-
* File upload component to be wrapped around `
|
|
38
|
+
* File upload component to be wrapped around `FileUploadCard` or any arbitrary component.
|
|
39
39
|
* Provides support for dragging and dropping multiple files.
|
|
40
40
|
* @example
|
|
41
|
-
* <FileUpload onFileDropped={console.log}><
|
|
41
|
+
* <FileUpload onFileDropped={console.log}><FileUploadCard /></FileUpload>
|
|
42
42
|
* <FileUpload dragContent='Drop file here' onFileDropped={console.log}><Textarea /></FileUpload>
|
|
43
43
|
*/
|
|
44
44
|
exports.FileUpload = React.forwardRef((props, ref) => {
|
|
@@ -32,6 +32,7 @@ declare type FileUploadTemplateProps = {
|
|
|
32
32
|
children?: React.ReactNode;
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
|
+
* @deprecated Use `FileUploadCard` instead.
|
|
35
36
|
* Default template to be used with the `FileUpload` wrapper component.
|
|
36
37
|
* Contains a hidden input with styled labels (customizable).
|
|
37
38
|
* @example
|
|
@@ -36,6 +36,7 @@ const classnames_1 = __importDefault(require("classnames"));
|
|
|
36
36
|
const index_js_1 = require("../utils/index.js");
|
|
37
37
|
const Anchor_js_1 = require("../Typography/Anchor/Anchor.js");
|
|
38
38
|
/**
|
|
39
|
+
* @deprecated Use `FileUploadCard` instead.
|
|
39
40
|
* Default template to be used with the `FileUpload` wrapper component.
|
|
40
41
|
* Contains a hidden input with styled labels (customizable).
|
|
41
42
|
* @example
|
|
@@ -35,6 +35,7 @@ const React = __importStar(require("react"));
|
|
|
35
35
|
const classnames_1 = __importDefault(require("classnames"));
|
|
36
36
|
const index_js_1 = require("../utils/index.js");
|
|
37
37
|
const ThemeContext_js_1 = require("./ThemeContext.js");
|
|
38
|
+
const Toaster_js_1 = require("../Toast/Toaster.js");
|
|
38
39
|
/**
|
|
39
40
|
* This component provides global styles and applies theme to the entire tree
|
|
40
41
|
* that it is wrapping around. The `theme` prop is optional and defaults to the
|
|
@@ -71,8 +72,10 @@ exports.ThemeProvider = React.forwardRef((props, ref) => {
|
|
|
71
72
|
const contextValue = React.useMemo(() => ({ theme, themeOptions, portalContainerRef }), [theme, themeOptions]);
|
|
72
73
|
return (React.createElement(ThemeContext_js_1.ThemeContext.Provider, { value: contextValue },
|
|
73
74
|
React.createElement(Root, { theme: theme, shouldApplyBackground: shouldApplyBackground, themeOptions: themeOptions, ref: ref, ...rest },
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
React.createElement(Toaster_js_1.ToastProvider, null,
|
|
76
|
+
children,
|
|
77
|
+
React.createElement("div", { ref: portalContainerRef },
|
|
78
|
+
React.createElement(Toaster_js_1.Toaster, null))))));
|
|
76
79
|
});
|
|
77
80
|
exports.default = exports.ThemeProvider;
|
|
78
81
|
const Root = React.forwardRef((props, forwardedRef) => {
|
|
@@ -22,10 +22,9 @@ export declare type ToastProps = {
|
|
|
22
22
|
*/
|
|
23
23
|
type?: 'persisting' | 'temporary';
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
* When false, will close the Toast and call onRemove when finished closing.
|
|
25
|
+
* Controlled boolean prop indicating whether the toast is visible.
|
|
27
26
|
*/
|
|
28
|
-
isVisible
|
|
27
|
+
isVisible?: boolean;
|
|
29
28
|
/**
|
|
30
29
|
* Duration of the toast in millisecond.
|
|
31
30
|
* @default 7000
|
|
@@ -37,12 +36,12 @@ export declare type ToastProps = {
|
|
|
37
36
|
*/
|
|
38
37
|
hasCloseButton?: boolean;
|
|
39
38
|
/**
|
|
40
|
-
*
|
|
39
|
+
* Props for a button/link that can be used to perform an action
|
|
40
|
+
* (e.g. to show additional information).
|
|
41
41
|
*/
|
|
42
42
|
link?: {
|
|
43
|
-
onClick: () => void;
|
|
44
43
|
title: string;
|
|
45
|
-
}
|
|
44
|
+
} & Omit<React.ComponentPropsWithoutRef<'button'>, 'children'>;
|
|
46
45
|
/**
|
|
47
46
|
* Function called when the toast is all the way closed.
|
|
48
47
|
*/
|
|
@@ -51,10 +50,6 @@ export declare type ToastProps = {
|
|
|
51
50
|
* Element to which the toast will animate out to.
|
|
52
51
|
*/
|
|
53
52
|
animateOutTo?: HTMLElement | null;
|
|
54
|
-
/**
|
|
55
|
-
* Parent toaster placement position for smoother animation.
|
|
56
|
-
*/
|
|
57
|
-
placementPosition?: 'top' | 'bottom';
|
|
58
53
|
};
|
|
59
54
|
/**
|
|
60
55
|
* Generic Toast Component
|
package/cjs/core/Toast/Toast.js
CHANGED
|
@@ -36,6 +36,7 @@ const react_transition_group_1 = require("react-transition-group");
|
|
|
36
36
|
const classnames_1 = __importDefault(require("classnames"));
|
|
37
37
|
const index_js_1 = require("../utils/index.js");
|
|
38
38
|
const index_js_2 = require("../Buttons/index.js");
|
|
39
|
+
const Toaster_js_1 = require("./Toaster.js");
|
|
39
40
|
const isMotionOk = () => (0, index_js_1.getWindow)()?.matchMedia?.('(prefers-reduced-motion: no-preference)')?.matches;
|
|
40
41
|
/**
|
|
41
42
|
* Generic Toast Component
|
|
@@ -46,9 +47,12 @@ const isMotionOk = () => (0, index_js_1.getWindow)()?.matchMedia?.('(prefers-red
|
|
|
46
47
|
* <Toast type='persisting' content='Job processing error.' category='negative' />
|
|
47
48
|
*/
|
|
48
49
|
const Toast = (props) => {
|
|
49
|
-
const { content, category, type = 'temporary', isVisible, link, duration = 7000, hasCloseButton, onRemove, animateOutTo,
|
|
50
|
+
const { content, category, type = 'temporary', isVisible: isVisibleProp, link, duration = 7000, hasCloseButton, onRemove, animateOutTo, } = props;
|
|
50
51
|
const closeTimeout = React.useRef(0);
|
|
51
|
-
const
|
|
52
|
+
const { placement } = (0, index_js_1.useSafeContext)(Toaster_js_1.ToasterStateContext).settings;
|
|
53
|
+
const placementPosition = placement.startsWith('top') ? 'top' : 'bottom';
|
|
54
|
+
const [visible, setVisible] = React.useState(isVisibleProp ?? true);
|
|
55
|
+
const isVisible = isVisibleProp ?? visible;
|
|
52
56
|
const [height, setHeight] = React.useState(0);
|
|
53
57
|
const thisElement = React.useRef(null);
|
|
54
58
|
const [margin, setMargin] = React.useState(0);
|
|
@@ -67,9 +71,6 @@ const Toast = (props) => {
|
|
|
67
71
|
};
|
|
68
72
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
73
|
}, [duration, type]);
|
|
70
|
-
React.useEffect(() => {
|
|
71
|
-
setVisible(isVisible);
|
|
72
|
-
}, [isVisible]);
|
|
73
74
|
React.useEffect(() => {
|
|
74
75
|
// if we don't have animateOutTo point and not isVisible, set negative margin to move other toasts up.
|
|
75
76
|
// Close all and close on toasts with no anchor.
|
|
@@ -113,7 +114,7 @@ const Toast = (props) => {
|
|
|
113
114
|
}
|
|
114
115
|
return { translateX, translateY };
|
|
115
116
|
};
|
|
116
|
-
return (React.createElement(react_transition_group_1.Transition, { timeout: { enter: 240, exit: animateOutTo ? 400 : 120 }, in:
|
|
117
|
+
return (React.createElement(react_transition_group_1.Transition, { timeout: { enter: 240, exit: animateOutTo ? 400 : 120 }, in: isVisible, appear: true, unmountOnExit: true, onEnter: (node) => {
|
|
117
118
|
if (isMotionOk()) {
|
|
118
119
|
node.style.transform = 'translateY(15%)';
|
|
119
120
|
node.style.transitionTimingFunction = 'ease';
|
|
@@ -132,12 +133,13 @@ const Toast = (props) => {
|
|
|
132
133
|
node.style.transitionDuration = animateOutTo ? '400ms' : '120ms';
|
|
133
134
|
node.style.transitionTimingFunction = 'cubic-bezier(0.4, 0, 1, 1)';
|
|
134
135
|
}
|
|
135
|
-
}, onExited: onRemove },
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
React.createElement(
|
|
136
|
+
}, onExited: onRemove },
|
|
137
|
+
React.createElement(index_js_1.Box, { ref: thisElement, className: 'iui-toast-all', style: {
|
|
138
|
+
height,
|
|
139
|
+
...marginStyle(),
|
|
140
|
+
} },
|
|
141
|
+
React.createElement("div", { ref: onRef },
|
|
142
|
+
React.createElement(exports.ToastPresentation, { category: category, content: content, link: link, type: type, hasCloseButton: hasCloseButton, onClose: close })))));
|
|
141
143
|
};
|
|
142
144
|
exports.Toast = Toast;
|
|
143
145
|
/**
|
|
@@ -150,7 +152,7 @@ const ToastPresentation = (props) => {
|
|
|
150
152
|
return (React.createElement(index_js_1.Box, { className: (0, classnames_1.default)(`iui-toast iui-${category}`, className), ...rest },
|
|
151
153
|
React.createElement(index_js_1.Box, { className: 'iui-status-area' }, React.createElement(StatusIcon, { className: 'iui-icon' })),
|
|
152
154
|
React.createElement(index_js_1.Box, { className: 'iui-message' }, content),
|
|
153
|
-
link && (React.createElement(index_js_1.Box, { as: '
|
|
155
|
+
link && (React.createElement(index_js_1.Box, { as: 'button', className: 'iui-toast-anchor', ...link, title: undefined }, link.title)),
|
|
154
156
|
(type === 'persisting' || hasCloseButton) && (React.createElement(index_js_2.IconButton, { size: 'small', styleType: 'borderless', onClick: onClose, "aria-label": 'Close' },
|
|
155
157
|
React.createElement(index_js_1.SvgCloseSmall, null)))));
|
|
156
158
|
};
|
|
@@ -4,45 +4,43 @@ export declare type ToasterSettings = {
|
|
|
4
4
|
/**
|
|
5
5
|
* Order of toasts.
|
|
6
6
|
* When set to 'descending', most recent toasts are on top. When set to 'ascending', most recent toasts are on bottom.
|
|
7
|
-
|
|
8
|
-
* When `placement` is set to a top value,
|
|
7
|
+
*
|
|
8
|
+
* When set to `auto`, it will behave like 'descending' when `placement` is set to a top value, otherwise 'ascending'.
|
|
9
|
+
*
|
|
10
|
+
* @default 'auto'
|
|
9
11
|
*/
|
|
10
|
-
order
|
|
12
|
+
order: 'descending' | 'ascending' | 'auto';
|
|
11
13
|
/**
|
|
12
14
|
* Placement of toasts.
|
|
13
15
|
* Changes placement of toasts. Start indicates left side of viewport. End - right side of viewport.
|
|
14
16
|
* @default 'top'
|
|
15
17
|
*/
|
|
16
|
-
placement
|
|
18
|
+
placement: 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end';
|
|
17
19
|
};
|
|
18
20
|
export declare type ToastOptions = Omit<ToastProps, 'category' | 'isVisible' | 'id' | 'content'>;
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
private lastId;
|
|
22
|
-
private settings;
|
|
23
|
-
private toastsRef;
|
|
24
|
-
private isInitialized;
|
|
25
|
-
private asyncInit;
|
|
26
|
-
/**
|
|
27
|
-
* Set global Toaster settings for toasts order and placement.
|
|
28
|
-
* Settings will be applied to new toasts on the page.
|
|
29
|
-
*/
|
|
30
|
-
setSettings(newSettings: ToasterSettings): void;
|
|
31
|
-
positive(content: React.ReactNode, options?: ToastOptions): {
|
|
21
|
+
export declare const useToaster: () => {
|
|
22
|
+
positive: (content: React.ReactNode, options?: ToastOptions) => {
|
|
32
23
|
close: () => void;
|
|
33
24
|
};
|
|
34
|
-
informational(content: React.ReactNode, options?: ToastOptions)
|
|
25
|
+
informational: (content: React.ReactNode, options?: ToastOptions) => {
|
|
35
26
|
close: () => void;
|
|
36
27
|
};
|
|
37
|
-
negative(content: React.ReactNode, options?: ToastOptions)
|
|
28
|
+
negative: (content: React.ReactNode, options?: ToastOptions) => {
|
|
38
29
|
close: () => void;
|
|
39
30
|
};
|
|
40
|
-
warning(content: React.ReactNode, options?: ToastOptions)
|
|
31
|
+
warning: (content: React.ReactNode, options?: ToastOptions) => {
|
|
41
32
|
close: () => void;
|
|
42
33
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
closeAll: () => void;
|
|
35
|
+
setSettings: (settings: Partial<ToasterSettings>) => void;
|
|
36
|
+
};
|
|
37
|
+
export declare const Toaster: () => JSX.Element;
|
|
38
|
+
export declare const ToastProvider: ({ children }: {
|
|
39
|
+
children: React.ReactNode;
|
|
40
|
+
}) => JSX.Element;
|
|
41
|
+
export declare const ToasterStateContext: React.Context<ToasterState | undefined>;
|
|
42
|
+
declare type ToasterState = {
|
|
43
|
+
toasts: ToastProps[];
|
|
44
|
+
settings: ToasterSettings;
|
|
45
|
+
};
|
|
46
|
+
export {};
|
|
@@ -22,132 +22,107 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.ToasterStateContext = exports.ToastProvider = exports.Toaster = exports.useToaster = void 0;
|
|
26
30
|
/*---------------------------------------------------------------------------------------------
|
|
27
31
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
28
32
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
29
33
|
*--------------------------------------------------------------------------------------------*/
|
|
30
34
|
const React = __importStar(require("react"));
|
|
31
|
-
const
|
|
35
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
32
36
|
const index_js_1 = require("../utils/index.js");
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const Toast_js_1 = require("./Toast.js");
|
|
38
|
+
// ----------------------------------------------------------------------------
|
|
39
|
+
const useToaster = () => {
|
|
40
|
+
const dispatch = (0, index_js_1.useSafeContext)(ToasterDispatchContext);
|
|
41
|
+
const showToast = React.useCallback((category) => (content, options) => {
|
|
42
|
+
const id = nextId();
|
|
43
|
+
dispatch({
|
|
44
|
+
type: 'add',
|
|
45
|
+
toast: { ...options, id, content, category },
|
|
46
|
+
});
|
|
47
|
+
return { close: () => dispatch({ type: 'remove', id }) };
|
|
48
|
+
}, [dispatch]);
|
|
49
|
+
return {
|
|
50
|
+
positive: showToast('positive'),
|
|
51
|
+
informational: showToast('informational'),
|
|
52
|
+
negative: showToast('negative'),
|
|
53
|
+
warning: showToast('warning'),
|
|
54
|
+
closeAll: () => {
|
|
55
|
+
dispatch({ type: 'close-all' });
|
|
56
|
+
},
|
|
57
|
+
setSettings: (settings) => {
|
|
58
|
+
dispatch({ type: 'settings', settings });
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
exports.useToaster = useToaster;
|
|
63
|
+
// ----------------------------------------------------------------------------
|
|
64
|
+
const Toaster = () => {
|
|
65
|
+
const { toasts, settings } = (0, index_js_1.useSafeContext)(exports.ToasterStateContext);
|
|
66
|
+
return (React.createElement(index_js_1.Box, { className: (0, classnames_1.default)(`iui-toast-wrapper`, `iui-placement-${settings.placement}`) }, toasts.map((toastProps) => {
|
|
67
|
+
return React.createElement(Toast_js_1.Toast, { key: toastProps.id, ...toastProps });
|
|
68
|
+
})));
|
|
69
|
+
};
|
|
70
|
+
exports.Toaster = Toaster;
|
|
71
|
+
// ----------------------------------------------------------------------------
|
|
72
|
+
const ToastProvider = ({ children }) => {
|
|
73
|
+
const [toasterState, dispatch] = React.useReducer(toastReducer, {
|
|
74
|
+
toasts: [],
|
|
75
|
+
settings: {
|
|
76
|
+
order: 'auto',
|
|
41
77
|
placement: 'top',
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
return (React.createElement(ToasterDispatchContext.Provider, { value: dispatch },
|
|
81
|
+
React.createElement(exports.ToasterStateContext.Provider, { value: toasterState }, children)));
|
|
82
|
+
};
|
|
83
|
+
exports.ToastProvider = ToastProvider;
|
|
84
|
+
const toastReducer = (state, action) => {
|
|
85
|
+
if (action.type === 'add') {
|
|
86
|
+
let order = state.settings.order;
|
|
87
|
+
if (order === 'auto') {
|
|
88
|
+
order = state.settings.placement.startsWith('top')
|
|
89
|
+
? 'descending'
|
|
90
|
+
: 'ascending';
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...state,
|
|
94
|
+
toasts: [
|
|
95
|
+
...(order === 'ascending' ? state.toasts : []),
|
|
96
|
+
action.toast,
|
|
97
|
+
...(order === 'descending' ? state.toasts : []),
|
|
98
|
+
],
|
|
42
99
|
};
|
|
43
|
-
this.toastsRef = React.createRef();
|
|
44
|
-
this.isInitialized = false;
|
|
45
|
-
// Create container on demand.
|
|
46
|
-
// Cannot do it in constructor, because SSG/SSR apps would fail.
|
|
47
|
-
this.asyncInit = async () => {
|
|
48
|
-
if (this.isInitialized) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const container = (0, index_js_1.getContainer)(TOASTS_CONTAINER_ID) ?? (0, index_js_1.getDocument)()?.body;
|
|
52
|
-
if (!container) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
this.isInitialized = true;
|
|
56
|
-
const toastWrapper = React.createElement(ToastWrapper_js_1.ToastWrapper, { ref: this.toastsRef });
|
|
57
|
-
const _ReactDOM = ReactDOM; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
58
|
-
// v18 mode
|
|
59
|
-
if (_ReactDOM.createRoot) {
|
|
60
|
-
const _ReactDOMInternals = _ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
61
|
-
// suppress warning about importing createRoot from react-dom/client
|
|
62
|
-
if (_ReactDOMInternals) {
|
|
63
|
-
_ReactDOMInternals.usingClientEntryPoint = true;
|
|
64
|
-
}
|
|
65
|
-
const root = _ReactDOM.createRoot(container);
|
|
66
|
-
root.render(toastWrapper);
|
|
67
|
-
// revert suppression, not to influence users app
|
|
68
|
-
if (_ReactDOMInternals) {
|
|
69
|
-
_ReactDOMInternals.usingClientEntryPoint = false;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
// v17 and before
|
|
74
|
-
ReactDOM.render(toastWrapper, container);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Set global Toaster settings for toasts order and placement.
|
|
80
|
-
* Settings will be applied to new toasts on the page.
|
|
81
|
-
*/
|
|
82
|
-
setSettings(newSettings) {
|
|
83
|
-
newSettings.placement ?? (newSettings.placement = this.settings.placement);
|
|
84
|
-
newSettings.order ?? (newSettings.order = newSettings.placement?.startsWith('bottom')
|
|
85
|
-
? 'ascending'
|
|
86
|
-
: 'descending');
|
|
87
|
-
this.settings = newSettings;
|
|
88
|
-
this.asyncInit().then(() => {
|
|
89
|
-
this.toastsRef.current?.setPlacement(this.settings.placement ?? 'top');
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
positive(content, options) {
|
|
93
|
-
return this.createToast(content, 'positive', options);
|
|
94
|
-
}
|
|
95
|
-
informational(content, options) {
|
|
96
|
-
return this.createToast(content, 'informational', options);
|
|
97
100
|
}
|
|
98
|
-
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
createToast(content, category, options) {
|
|
105
|
-
++this.lastId;
|
|
106
|
-
const currentId = this.lastId;
|
|
107
|
-
this.toasts = [
|
|
108
|
-
...(this.settings.order === 'ascending' ? this.toasts : []),
|
|
109
|
-
{
|
|
110
|
-
...options,
|
|
111
|
-
content,
|
|
112
|
-
category,
|
|
113
|
-
onRemove: () => {
|
|
114
|
-
this.removeToast(currentId);
|
|
115
|
-
options?.onRemove?.();
|
|
116
|
-
},
|
|
117
|
-
id: currentId,
|
|
118
|
-
isVisible: true,
|
|
119
|
-
},
|
|
120
|
-
...(this.settings.order === 'descending' ? this.toasts : []),
|
|
121
|
-
];
|
|
122
|
-
this.updateView();
|
|
123
|
-
return { close: () => this.closeToast(currentId) };
|
|
124
|
-
}
|
|
125
|
-
removeToast(id) {
|
|
126
|
-
this.toasts = this.toasts.filter((toast) => toast.id !== id);
|
|
127
|
-
this.updateView();
|
|
128
|
-
}
|
|
129
|
-
updateView() {
|
|
130
|
-
this.asyncInit().then(() => {
|
|
131
|
-
this.toastsRef.current?.setToasts(this.toasts);
|
|
132
|
-
});
|
|
101
|
+
if (action.type === 'remove') {
|
|
102
|
+
return {
|
|
103
|
+
...state,
|
|
104
|
+
toasts: state.toasts.filter((toast) => toast.id !== action.id),
|
|
105
|
+
};
|
|
133
106
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
this.updateView();
|
|
107
|
+
if (action.type === 'close-all') {
|
|
108
|
+
return {
|
|
109
|
+
...state,
|
|
110
|
+
toasts: state.toasts.map((toast) => ({ ...toast, isVisible: false })),
|
|
111
|
+
};
|
|
142
112
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
...toast,
|
|
147
|
-
isVisible: false,
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
this.updateView();
|
|
113
|
+
if (action.type === 'settings') {
|
|
114
|
+
return { ...state, settings: { ...state.settings, ...action.settings } };
|
|
151
115
|
}
|
|
152
|
-
|
|
153
|
-
|
|
116
|
+
return state;
|
|
117
|
+
};
|
|
118
|
+
// ----------------------------------------------------------------------------
|
|
119
|
+
exports.ToasterStateContext = React.createContext(undefined);
|
|
120
|
+
exports.ToasterStateContext.displayName = 'ToasterStateContext';
|
|
121
|
+
// ----------------------------------------------------------------------------
|
|
122
|
+
const ToasterDispatchContext = React.createContext(undefined);
|
|
123
|
+
ToasterDispatchContext.displayName = 'ToasterDispatchContext';
|
|
124
|
+
// ----------------------------------------------------------------------------
|
|
125
|
+
const nextId = (() => {
|
|
126
|
+
let count = 0;
|
|
127
|
+
return () => ++count;
|
|
128
|
+
})();
|
package/cjs/core/Toast/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useToaster = void 0;
|
|
6
4
|
/*---------------------------------------------------------------------------------------------
|
|
7
5
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
8
6
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
9
7
|
*--------------------------------------------------------------------------------------------*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.default = toaster;
|
|
8
|
+
var Toaster_js_1 = require("./Toaster.js");
|
|
9
|
+
Object.defineProperty(exports, "useToaster", { enumerable: true, get: function () { return Toaster_js_1.useToaster; } });
|
package/cjs/core/index.d.ts
CHANGED
|
@@ -51,8 +51,7 @@ export { Textarea } from './Textarea/index.js';
|
|
|
51
51
|
export { Tile } from './Tile/index.js';
|
|
52
52
|
export { TimePicker } from './TimePicker/index.js';
|
|
53
53
|
export type { MeridiemType } from './TimePicker/index.js';
|
|
54
|
-
export {
|
|
55
|
-
export type { ToastOptions } from './Toast/index.js';
|
|
54
|
+
export { useToaster } from './Toast/index.js';
|
|
56
55
|
export { ThemeProvider } from './ThemeProvider/index.js';
|
|
57
56
|
export type { ThemeType } from './ThemeProvider/index.js';
|
|
58
57
|
export { ToggleSwitch } from './ToggleSwitch/index.js';
|
package/cjs/core/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.InformationPanelHeader = exports.InformationPanelWrapper = exports.InformationPanel = exports.HorizontalTabs = exports.Tab = exports.Tabs = exports.VerticalTabs = exports.TransferList = exports.ListItem = exports.List = exports.HeaderLogo = exports.HeaderButton = exports.HeaderBreadcrumbs = exports.Header = exports.defaultFooterElements = exports.Footer = exports.FileEmptyCard = exports.FileUploadCard = exports.FileUploadTemplate = exports.FileUpload = exports.Fieldset = exports.ExpandableBlock = exports.NonIdealState = exports.ErrorPage = exports.DropdownMenu = exports.Dialog = exports.generateLocalizedStrings = exports.DatePicker = exports.ComboBox = exports.ColorPalette = exports.ColorInputPanel = exports.ColorBuilder = exports.ColorSwatch = exports.ColorPicker = exports.Checkbox = exports.Carousel = exports.ButtonGroup = exports.SplitButton = exports.IdeasButton = exports.IconButton = exports.DropdownButton = exports.Button = exports.Breadcrumbs = exports.Badge = exports.Backdrop = exports.UserIconGroup = exports.AvatarGroup = exports.UserIcon = exports.Avatar = exports.Alert = void 0;
|
|
7
|
-
exports.Tooltip = exports.ToggleSwitch = exports.ThemeProvider = exports.
|
|
4
|
+
exports.Tooltip = exports.ToggleSwitch = exports.ThemeProvider = exports.useToaster = exports.TimePicker = exports.Tile = exports.Textarea = exports.TagContainer = exports.Tag = exports.SelectionColumn = exports.ExpanderColumn = exports.ActionColumn = exports.TablePaginator = exports.EditableCell = exports.DefaultCell = exports.FilterButtonBar = exports.BaseFilter = exports.tableFilters = exports.Table = exports.Surface = exports.StatusMessage = exports.Slider = exports.SkipToContentLink = exports.SidenavSubmenuHeader = exports.SidenavSubmenu = exports.SidenavButton = exports.SideNavigation = exports.Select = exports.RadioTileGroup = exports.RadioTile = exports.Radio = exports.ProgressRadial = exports.ProgressLinear = exports.NotificationMarker = exports.ModalContent = exports.ModalButtonBar = exports.Modal = exports.MenuItemSkeleton = exports.MenuExtraContent = exports.MenuDivider = exports.MenuItem = exports.Menu = exports.LabeledTextarea = exports.LabeledSelect = exports.InputGroup = exports.LabeledInput = exports.Label = exports.Input = exports.InformationPanelContent = exports.InformationPanelBody = void 0;
|
|
8
5
|
exports.Divider = exports.VisuallyHidden = exports.Flex = exports.Icon = exports.LinkAction = exports.LinkBox = exports.MiddleTextTruncation = exports.ColorValue = exports.getUserColor = exports.SearchBox = exports.WorkflowDiagram = exports.Stepper = exports.Wizard = exports.Text = exports.KbdKeys = exports.Kbd = exports.Code = exports.Blockquote = exports.Anchor = exports.TreeNodeExpander = exports.TreeNode = exports.Tree = void 0;
|
|
9
6
|
/*---------------------------------------------------------------------------------------------
|
|
10
7
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
@@ -155,7 +152,7 @@ Object.defineProperty(exports, "Tile", { enumerable: true, get: function () { re
|
|
|
155
152
|
var index_js_48 = require("./TimePicker/index.js");
|
|
156
153
|
Object.defineProperty(exports, "TimePicker", { enumerable: true, get: function () { return index_js_48.TimePicker; } });
|
|
157
154
|
var index_js_49 = require("./Toast/index.js");
|
|
158
|
-
Object.defineProperty(exports, "
|
|
155
|
+
Object.defineProperty(exports, "useToaster", { enumerable: true, get: function () { return index_js_49.useToaster; } });
|
|
159
156
|
var index_js_50 = require("./ThemeProvider/index.js");
|
|
160
157
|
Object.defineProperty(exports, "ThemeProvider", { enumerable: true, get: function () { return index_js_50.ThemeProvider; } });
|
|
161
158
|
var index_js_51 = require("./ToggleSwitch/index.js");
|
|
@@ -25,7 +25,7 @@ export declare type PopoverProps = {
|
|
|
25
25
|
* with pre-configured props and plugins (e.g. lazy mounting, focus, etc).
|
|
26
26
|
* @private
|
|
27
27
|
*/
|
|
28
|
-
export declare const Popover: React.ForwardRefExoticComponent<Pick<PopoverProps, "disabled" | "className" | "role" | "offset" | "children" | "content" | "plugins" | "
|
|
28
|
+
export declare const Popover: React.ForwardRefExoticComponent<Pick<PopoverProps, "disabled" | "className" | "role" | "offset" | "children" | "content" | "plugins" | "placement" | "trigger" | "visible" | "render" | "animateFill" | "appendTo" | "aria" | "delay" | "duration" | "followCursor" | "getReferenceClientRect" | "hideOnClick" | "ignoreAttributes" | "inlinePositioning" | "interactive" | "interactiveBorder" | "interactiveDebounce" | "moveTransition" | "popperOptions" | "showOnCreate" | "sticky" | "touch" | "triggerTarget" | "onAfterUpdate" | "onBeforeUpdate" | "onCreate" | "onDestroy" | "onHidden" | "onHide" | "onMount" | "onShow" | "onShown" | "onTrigger" | "onUntrigger" | "onClickOutside" | "allowHTML" | "animation" | "arrow" | "inertia" | "maxWidth" | "theme" | "zIndex" | "singleton" | "reference"> & React.RefAttributes<unknown>>;
|
|
29
29
|
/**
|
|
30
30
|
* Plugin to hide Popover when either Esc key is pressed,
|
|
31
31
|
* or when the content inside is not tabbable and Tab key is pressed.
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
/**
|
|
3
|
-
* Get the container as a child of body, or create one if it doesn't exist.
|
|
4
|
-
* Mostly used for dynamic components like Modal or Toast.
|
|
5
|
-
*
|
|
6
|
-
* @param containerId id of the container to find or create
|
|
7
|
-
* @param ownerDocument Can be changed if the container should be in a different document (e.g. in popup).
|
|
8
|
-
*/
|
|
9
|
-
export declare const getContainer: (containerId: string, ownerDocument?: Document | undefined) => HTMLElement | undefined;
|
|
10
2
|
/**
|
|
11
3
|
* Get document if it is defined.
|
|
12
4
|
* Used to support SSR/SSG applications.
|
|
@@ -3,31 +3,8 @@
|
|
|
3
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.getTranslateValues = exports.mergeEventHandlers = exports.getWindow = exports.getDocument =
|
|
11
|
-
const styles_js_1 = __importDefault(require("../../../styles.js"));
|
|
12
|
-
/**
|
|
13
|
-
* Get the container as a child of body, or create one if it doesn't exist.
|
|
14
|
-
* Mostly used for dynamic components like Modal or Toast.
|
|
15
|
-
*
|
|
16
|
-
* @param containerId id of the container to find or create
|
|
17
|
-
* @param ownerDocument Can be changed if the container should be in a different document (e.g. in popup).
|
|
18
|
-
*/
|
|
19
|
-
const getContainer = (containerId, ownerDocument = (0, exports.getDocument)()) => {
|
|
20
|
-
let container = ownerDocument?.getElementById(containerId) ?? undefined;
|
|
21
|
-
if (container == null && !!ownerDocument) {
|
|
22
|
-
container = ownerDocument.createElement('div');
|
|
23
|
-
container.setAttribute('id', containerId);
|
|
24
|
-
const root = ownerDocument.querySelector(`.${styles_js_1.default['iui-root']}`) ??
|
|
25
|
-
ownerDocument.body;
|
|
26
|
-
root.appendChild(container);
|
|
27
|
-
}
|
|
28
|
-
return container;
|
|
29
|
-
};
|
|
30
|
-
exports.getContainer = getContainer;
|
|
7
|
+
exports.getTranslateValues = exports.mergeEventHandlers = exports.getWindow = exports.getDocument = void 0;
|
|
31
8
|
/**
|
|
32
9
|
* Get document if it is defined.
|
|
33
10
|
* Used to support SSR/SSG applications.
|