@itwin/itwinui-react 3.17.0-dev.0 → 3.17.0-dev.2

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 (86) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/DEV-cjs/core/Dialog/Dialog.js +35 -42
  3. package/DEV-cjs/core/Dialog/DialogBackdrop.js +6 -1
  4. package/DEV-cjs/core/Dialog/DialogMain.js +42 -34
  5. package/DEV-cjs/core/Dialog/DialogMainContext.js +23 -0
  6. package/DEV-cjs/core/Dialog/DialogTitleBar.js +10 -1
  7. package/DEV-cjs/core/Panels/Panels.js +1 -1
  8. package/DEV-cjs/core/SideNavigation/SideNavigation.js +1 -11
  9. package/DEV-cjs/core/Table/actionHandlers/selectHandler.js +7 -8
  10. package/DEV-cjs/core/Tabs/Tabs.js +9 -1
  11. package/DEV-cjs/core/ThemeProvider/ThemeProvider.js +12 -9
  12. package/DEV-cjs/core/Toast/Toast.js +132 -77
  13. package/DEV-cjs/core/Toast/Toaster.js +11 -3
  14. package/DEV-cjs/styles.js +1 -1
  15. package/DEV-cjs/utils/components/index.js +0 -1
  16. package/DEV-esm/core/Dialog/Dialog.js +32 -42
  17. package/DEV-esm/core/Dialog/DialogBackdrop.js +6 -1
  18. package/DEV-esm/core/Dialog/DialogMain.js +42 -34
  19. package/DEV-esm/core/Dialog/DialogMainContext.js +3 -0
  20. package/DEV-esm/core/Dialog/DialogTitleBar.js +10 -1
  21. package/DEV-esm/core/Panels/Panels.js +2 -1
  22. package/DEV-esm/core/SideNavigation/SideNavigation.js +2 -17
  23. package/DEV-esm/core/Table/actionHandlers/selectHandler.js +7 -8
  24. package/DEV-esm/core/Tabs/Tabs.js +9 -1
  25. package/DEV-esm/core/ThemeProvider/ThemeProvider.js +12 -9
  26. package/DEV-esm/core/Toast/Toast.js +131 -75
  27. package/DEV-esm/core/Toast/Toaster.js +11 -3
  28. package/DEV-esm/styles.js +1 -1
  29. package/DEV-esm/utils/components/index.js +0 -1
  30. package/LICENSE.md +1 -1
  31. package/cjs/core/Dialog/Dialog.d.ts +1 -1
  32. package/cjs/core/Dialog/Dialog.js +35 -42
  33. package/cjs/core/Dialog/DialogBackdrop.d.ts +1 -1
  34. package/cjs/core/Dialog/DialogBackdrop.js +6 -1
  35. package/cjs/core/Dialog/DialogMain.js +42 -34
  36. package/cjs/core/Dialog/DialogMainContext.d.ts +7 -0
  37. package/cjs/core/Dialog/DialogMainContext.js +23 -0
  38. package/cjs/core/Dialog/DialogTitleBar.js +10 -1
  39. package/cjs/core/Panels/Panels.js +1 -1
  40. package/cjs/core/SideNavigation/SideNavigation.d.ts +2 -2
  41. package/cjs/core/SideNavigation/SideNavigation.js +1 -11
  42. package/cjs/core/Table/actionHandlers/selectHandler.js +7 -8
  43. package/cjs/core/Tabs/Tabs.js +9 -1
  44. package/cjs/core/ThemeProvider/ThemeContext.d.ts +2 -1
  45. package/cjs/core/ThemeProvider/ThemeProvider.d.ts +13 -5
  46. package/cjs/core/ThemeProvider/ThemeProvider.js +12 -9
  47. package/cjs/core/Toast/Toast.d.ts +1 -1
  48. package/cjs/core/Toast/Toast.js +132 -77
  49. package/cjs/core/Toast/Toaster.d.ts +1 -1
  50. package/cjs/core/Toast/Toaster.js +11 -3
  51. package/cjs/styles.js +1 -1
  52. package/cjs/utils/components/index.d.ts +0 -1
  53. package/cjs/utils/components/index.js +0 -1
  54. package/cjs/utils/hooks/useGlobals.d.ts +1 -0
  55. package/esm/core/Dialog/Dialog.d.ts +1 -1
  56. package/esm/core/Dialog/Dialog.js +32 -42
  57. package/esm/core/Dialog/DialogBackdrop.d.ts +1 -1
  58. package/esm/core/Dialog/DialogBackdrop.js +6 -1
  59. package/esm/core/Dialog/DialogMain.js +42 -34
  60. package/esm/core/Dialog/DialogMainContext.d.ts +7 -0
  61. package/esm/core/Dialog/DialogMainContext.js +3 -0
  62. package/esm/core/Dialog/DialogTitleBar.js +10 -1
  63. package/esm/core/Panels/Panels.js +2 -1
  64. package/esm/core/SideNavigation/SideNavigation.d.ts +2 -2
  65. package/esm/core/SideNavigation/SideNavigation.js +2 -17
  66. package/esm/core/Table/actionHandlers/selectHandler.js +7 -8
  67. package/esm/core/Tabs/Tabs.js +9 -1
  68. package/esm/core/ThemeProvider/ThemeContext.d.ts +2 -1
  69. package/esm/core/ThemeProvider/ThemeProvider.d.ts +13 -5
  70. package/esm/core/ThemeProvider/ThemeProvider.js +12 -9
  71. package/esm/core/Toast/Toast.d.ts +1 -1
  72. package/esm/core/Toast/Toast.js +131 -75
  73. package/esm/core/Toast/Toaster.d.ts +1 -1
  74. package/esm/core/Toast/Toaster.js +11 -3
  75. package/esm/styles.js +1 -1
  76. package/esm/utils/components/index.d.ts +0 -1
  77. package/esm/utils/components/index.js +0 -1
  78. package/esm/utils/hooks/useGlobals.d.ts +1 -0
  79. package/package.json +5 -7
  80. package/styles.css +10 -10
  81. package/DEV-cjs/utils/components/WithCSSTransition.js +0 -60
  82. package/DEV-esm/utils/components/WithCSSTransition.js +0 -49
  83. package/cjs/utils/components/WithCSSTransition.d.ts +0 -6
  84. package/cjs/utils/components/WithCSSTransition.js +0 -60
  85. package/esm/utils/components/WithCSSTransition.d.ts +0 -6
  86. package/esm/utils/components/WithCSSTransition.js +0 -49
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', {
3
+ value: true,
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name],
10
+ });
11
+ }
12
+ _export(exports, {
13
+ DialogMainContext: function () {
14
+ return DialogMainContext;
15
+ },
16
+ useDialogMainContext: function () {
17
+ return useDialogMainContext;
18
+ },
19
+ });
20
+ const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
21
+ const _react = _interop_require_wildcard._(require('react'));
22
+ const DialogMainContext = _react.createContext(null);
23
+ const useDialogMainContext = () => _react.useContext(DialogMainContext);
@@ -15,11 +15,13 @@ const _classnames = _interop_require_default._(require('classnames'));
15
15
  const _index = require('../../utils/index.js');
16
16
  const _IconButton = require('../Buttons/IconButton.js');
17
17
  const _DialogContext = require('./DialogContext.js');
18
+ const _DialogMainContext = require('./DialogMainContext.js');
18
19
  const _DialogTitleBarTitle = require('./DialogTitleBarTitle.js');
19
20
  const _DialogDragContext = require('./DialogDragContext.js');
20
21
  const DialogTitleBar = Object.assign(
21
22
  _react.forwardRef((props, ref) => {
22
23
  let dialogContext = (0, _DialogContext.useDialogContext)();
24
+ let dialogMainContext = (0, _DialogMainContext.useDialogMainContext)();
23
25
  let {
24
26
  children,
25
27
  titleText,
@@ -31,6 +33,13 @@ const DialogTitleBar = Object.assign(
31
33
  ...rest
32
34
  } = props;
33
35
  let { onPointerDown } = (0, _DialogDragContext.useDialogDragContext)();
36
+ let onClick = _react.useCallback(
37
+ (e) => {
38
+ dialogMainContext?.beforeClose();
39
+ onClose?.(e);
40
+ },
41
+ [dialogMainContext, onClose],
42
+ );
34
43
  return _react.createElement(
35
44
  _index.Box,
36
45
  {
@@ -60,7 +69,7 @@ const DialogTitleBar = Object.assign(
60
69
  {
61
70
  size: 'small',
62
71
  styleType: 'borderless',
63
- onClick: onClose,
72
+ onClick: onClick,
64
73
  'aria-label': 'Close',
65
74
  'data-iui-shift': 'right',
66
75
  },
@@ -166,7 +166,7 @@ const PanelTrigger = (props) => {
166
166
  panels,
167
167
  } = (0, _index.useSafeContext)(PanelsWrapperContext);
168
168
  let { id: panelId } = (0, _index.useSafeContext)(PanelContext);
169
- let fallbackId = _react.useId();
169
+ let fallbackId = (0, _index.useId)();
170
170
  let triggerId = children.props.id || fallbackId;
171
171
  let onClick = _react.useCallback(() => {
172
172
  if (null == activePanel) return;
@@ -25,12 +25,12 @@ type SideNavigationProps = {
25
25
  */
26
26
  onExpanderClick?: () => void;
27
27
  /**
28
- * Submenu to show supplemental info assicated to the main item.
28
+ * Submenu to show supplemental info associated to the main item.
29
29
  *
30
30
  * Should be used with the `isSubmenuOpen` props from both `SideNavigation` and `SidenavButton`.
31
31
  * @example
32
32
  * <SideNavigation
33
- * // ...
33
+ * //
34
34
  * submenu={(
35
35
  * <SidenavSubmenu>
36
36
  * <SidenavSubmenuHeader>Documents</SidenavSubmenuHeader>
@@ -125,17 +125,7 @@ const SideNavigation = _react.forwardRef((props, forwardedRef) => {
125
125
  ),
126
126
  'bottom' === expanderPlacement && ExpandButton,
127
127
  ),
128
- submenu &&
129
- _react.createElement(
130
- _index.WithCSSTransition,
131
- {
132
- in: isSubmenuOpen,
133
- dimension: 'width',
134
- timeout: 200,
135
- classNames: 'iui',
136
- },
137
- submenu,
138
- ),
128
+ submenu && isSubmenuOpen ? submenu : null,
139
129
  ),
140
130
  );
141
131
  });
@@ -29,19 +29,18 @@ const onSelectHandler = (newState, instance, onSelect, isRowDisabled) => {
29
29
  let newSelectedRowIds = {};
30
30
  let handleRow = (row) => {
31
31
  if (isRowDisabled?.(row.original)) return false;
32
+ let hasSubComponents = !!row.initialSubRows[0]?.original[_Table.iuiId];
33
+ let hasSubRows = row.subRows.length > 0 && !hasSubComponents;
32
34
  let isAllSubSelected = true;
33
- if (row.initialSubRows[0]?.original[_Table.iuiId] === void 0)
35
+ if (hasSubRows)
34
36
  row.initialSubRows.forEach((subRow) => {
35
37
  let result = handleRow(subRow);
36
38
  if (!result) isAllSubSelected = false;
37
39
  });
38
- if (
39
- newState.selectedRowIds[row.id] &&
40
- (!instance.selectSubRows ||
41
- !row.initialSubRows.length ||
42
- isAllSubSelected)
43
- )
44
- newSelectedRowIds[row.id] = true;
40
+ let isRowSelected = newState.selectedRowIds[row.id];
41
+ let case1 = isRowSelected && (!instance.selectSubRows || !hasSubRows);
42
+ let case2 = hasSubRows && isAllSubSelected;
43
+ if (case1 || case2) newSelectedRowIds[row.id] = true;
45
44
  return !!newSelectedRowIds[row.id];
46
45
  };
47
46
  instance.initialRows.forEach((row) => handleRow(row));
@@ -174,7 +174,15 @@ const Tab = _react.forwardRef((props, forwardedRef) => {
174
174
  });
175
175
  };
176
176
  if ('default' !== type && isActive) updateStripe();
177
- }, [type, orientation, isActive, tabsWidth, setStripeProperties, tablistRef]);
177
+ }, [
178
+ type,
179
+ orientation,
180
+ isActive,
181
+ tabsWidth,
182
+ setStripeProperties,
183
+ tablistRef,
184
+ value,
185
+ ]);
178
186
  let onKeyDown = (event) => {
179
187
  if (event.altKey) return;
180
188
  let allTabs = Array.from(event.currentTarget.parentElement?.children ?? []);
@@ -1,7 +1,8 @@
1
1
  import * as React from 'react';
2
- import type { ThemeOptions, ThemeType } from './ThemeProvider.js';
2
+ import type { FutureOptions, ThemeOptions, ThemeType } from './ThemeProvider.js';
3
3
  export declare const ThemeContext: React.Context<{
4
4
  theme?: ThemeType;
5
5
  themeOptions?: ThemeOptions;
6
6
  portalContainer?: HTMLElement | null;
7
+ future?: FutureOptions;
7
8
  } | undefined>;
@@ -6,14 +6,18 @@ export type ThemeOptions = {
6
6
  * Will default to user preference if browser supports it.
7
7
  */
8
8
  highContrast?: boolean;
9
+ };
10
+ export type FutureOptions = {
9
11
  /**
12
+ * @alpha
13
+ *
10
14
  * If enabled, the theme resembles the future iTwinUI version's theme (including alphas) *whenever possible*.
11
15
  *
12
16
  * This is useful in making apps looks like future versions of iTwinUI to help with incremental adoption.
13
17
  *
14
18
  * **NOTE**: Since this is a theme bridge to *future* versions, the theme could have breaking changes.
15
19
  */
16
- bridgeToFutureVersions?: boolean;
20
+ themeBridge?: boolean;
17
21
  };
18
22
  export type ThemeType = 'light' | 'dark' | 'os';
19
23
  type RootProps = {
@@ -26,13 +30,13 @@ type RootProps = {
26
30
  *
27
31
  * The 'inherit' option is intended to be used by packages, to enable incremental adoption
28
32
  * of iTwinUI while respecting the theme set by the consuming app. It will fall back to 'light'
29
- * if no parent theme is found. Additionally, it will attempt to inherit `themeOptions.highContrast`
30
- * and `portalContainer` (if possible).
33
+ * if no parent theme is found. Additionally, it will attempt to inherit `themeOptions.highContrast`,
34
+ * `portalContainer`, and `future.themeBridge` (if possible).
31
35
  *
32
36
  * @default 'inherit'
33
37
  */
34
38
  theme?: ThemeType | 'inherit';
35
- themeOptions?: Pick<ThemeOptions, 'highContrast' | 'bridgeToFutureVersions'> & {
39
+ themeOptions?: Pick<ThemeOptions, 'highContrast'> & {
36
40
  /**
37
41
  * Whether or not the element should apply the recommended `background-color` on itself.
38
42
  *
@@ -46,8 +50,12 @@ type RootProps = {
46
50
  */
47
51
  applyBackground?: boolean;
48
52
  };
53
+ /**
54
+ * Options to help with early adoption of features from future versions.
55
+ */
56
+ future?: FutureOptions;
49
57
  };
50
- type ThemeProviderOwnProps = Pick<RootProps, 'theme'> & {
58
+ type ThemeProviderOwnProps = Pick<RootProps, 'theme' | 'future'> & {
51
59
  themeOptions?: RootProps['themeOptions'];
52
60
  children: Required<React.ReactNode>;
53
61
  /**
@@ -21,13 +21,14 @@ const _meta = require('../../utils/meta.js');
21
21
  const versionWithoutDots = _meta.meta.version.replace(/\./g, '');
22
22
  const ownerDocumentAtom = (0, _jotai.atom)(void 0);
23
23
  const ThemeProvider = _react.forwardRef((props, forwardedRef) => {
24
- var _themeOptions, _themeOptions1, _themeOptions2;
24
+ var _themeOptions, _themeOptions1, _future;
25
25
  let {
26
26
  theme: themeProp = 'inherit',
27
27
  children,
28
28
  themeOptions = {},
29
29
  portalContainer: portalContainerProp,
30
30
  includeCss = 'inherit' === themeProp,
31
+ future = {},
31
32
  ...rest
32
33
  } = props;
33
34
  useInertPolyfill();
@@ -39,11 +40,8 @@ const ThemeProvider = _react.forwardRef((props, forwardedRef) => {
39
40
  (_themeOptions1 = themeOptions).highContrast ??
40
41
  (_themeOptions1.highContrast =
41
42
  'inherit' === themeProp ? parent.highContrast : void 0);
42
- (_themeOptions2 = themeOptions).bridgeToFutureVersions ??
43
- (_themeOptions2.bridgeToFutureVersions =
44
- 'inherit' === themeProp
45
- ? parent.context?.themeOptions?.bridgeToFutureVersions
46
- : void 0);
43
+ (_future = future).themeBridge ??
44
+ (_future.themeBridge = parent.context?.future?.themeBridge);
47
45
  let [portalContainerFromParent] = (0, _index.useScopedAtom)(
48
46
  _index.portalContainerAtom,
49
47
  );
@@ -51,8 +49,9 @@ const ThemeProvider = _react.forwardRef((props, forwardedRef) => {
51
49
  () => ({
52
50
  theme,
53
51
  themeOptions,
52
+ future,
54
53
  }),
55
- [theme, JSON.stringify(themeOptions)],
54
+ [theme, JSON.stringify(themeOptions), JSON.stringify(future)],
56
55
  );
57
56
  return _react.createElement(
58
57
  _index.ScopeProvider,
@@ -80,6 +79,7 @@ const ThemeProvider = _react.forwardRef((props, forwardedRef) => {
80
79
  {
81
80
  theme: theme,
82
81
  themeOptions: themeOptions,
82
+ future: future,
83
83
  ref: (0, _index.useMergedRefs)(
84
84
  forwardedRef,
85
85
  setRootElement,
@@ -91,6 +91,7 @@ const ThemeProvider = _react.forwardRef((props, forwardedRef) => {
91
91
  _react.createElement(PortalContainer, {
92
92
  theme: theme,
93
93
  themeOptions: themeOptions,
94
+ future: future,
94
95
  portalContainerProp: portalContainerProp,
95
96
  portalContainerFromParent: portalContainerFromParent,
96
97
  isInheritingTheme: 'inherit' === themeProp,
@@ -118,7 +119,7 @@ const MainRoot = _react.forwardRef((props, forwardedRef) => {
118
119
  });
119
120
  });
120
121
  const Root = _react.forwardRef((props, forwardedRef) => {
121
- let { theme, children, themeOptions, className, ...rest } = props;
122
+ let { theme, children, themeOptions, className, future, ...rest } = props;
122
123
  let prefersDark = (0, _index.useMediaQuery)('(prefers-color-scheme: dark)');
123
124
  let prefersHighContrast = (0, _index.useMediaQuery)(
124
125
  '(prefers-contrast: more)',
@@ -138,7 +139,7 @@ const Root = _react.forwardRef((props, forwardedRef) => {
138
139
  ),
139
140
  'data-iui-theme': shouldApplyDark ? 'dark' : 'light',
140
141
  'data-iui-contrast': shouldApplyHC ? 'high' : 'default',
141
- 'data-iui-bridge': !!themeOptions?.bridgeToFutureVersions || void 0,
142
+ 'data-iui-bridge': !!future?.themeBridge || void 0,
142
143
  ref: forwardedRef,
143
144
  ...rest,
144
145
  },
@@ -188,6 +189,7 @@ const PortalContainer = _react.memo(
188
189
  isInheritingTheme,
189
190
  theme,
190
191
  themeOptions,
192
+ future,
191
193
  }) => {
192
194
  let [ownerDocument] = (0, _index.useScopedAtom)(ownerDocumentAtom);
193
195
  let [portalContainer, setPortalContainer] = (0, _index.useScopedAtom)(
@@ -218,6 +220,7 @@ const PortalContainer = _react.memo(
218
220
  ...themeOptions,
219
221
  applyBackground: false,
220
222
  },
223
+ future: future,
221
224
  'data-iui-portal': true,
222
225
  style: {
223
226
  display: 'contents',
@@ -66,7 +66,7 @@ export type ToastProps = {
66
66
  * <Toast type='temporary' content='26 files are available for synchronization.' category='informational' />
67
67
  * <Toast type='persisting' content='Job processing error.' category='negative' />
68
68
  */
69
- export declare const Toast: (props: ToastProps) => React.JSX.Element;
69
+ export declare const Toast: (props: ToastProps) => React.JSX.Element | null;
70
70
  export type ToastPresentationProps = Omit<ToastProps, 'duration' | 'id' | 'isVisible' | 'onRemove' | 'domProps'> & {
71
71
  onClose?: () => void;
72
72
  contentProps?: React.ComponentProps<'div'>;
@@ -20,7 +20,6 @@ _export(exports, {
20
20
  const _interop_require_default = require('@swc/helpers/_/_interop_require_default');
21
21
  const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
22
22
  const _react = _interop_require_wildcard._(require('react'));
23
- const _reacttransitiongroup = require('react-transition-group');
24
23
  const _classnames = _interop_require_default._(require('classnames'));
25
24
  const _index = require('../../utils/index.js');
26
25
  const _IconButton = require('../Buttons/IconButton.js');
@@ -48,9 +47,6 @@ const Toast = (props) => {
48
47
  let [height, setHeight] = _react.useState(0);
49
48
  let thisElement = _react.useRef(null);
50
49
  let [margin, setMargin] = _react.useState(0);
51
- let motionOk = (0, _index.useMediaQuery)(
52
- '(prefers-reduced-motion: no-preference)',
53
- );
54
50
  let marginStyle = () => {
55
51
  if ('top' === placementPosition)
56
52
  return {
@@ -90,81 +86,41 @@ const Toast = (props) => {
90
86
  setHeight(height);
91
87
  }
92
88
  };
93
- let calculateOutAnimation = (node) => {
94
- let translateX = 0;
95
- let translateY = 0;
96
- if (animateOutTo && node) {
97
- let { x: startX, y: startY } = node.getBoundingClientRect();
98
- let { x: endX, y: endY } = animateOutTo.getBoundingClientRect();
99
- translateX = endX - startX;
100
- translateY = endY - startY;
101
- }
102
- return {
103
- translateX,
104
- translateY,
105
- };
106
- };
107
- return _react.createElement(
108
- _reacttransitiongroup.Transition,
109
- {
110
- timeout: {
111
- enter: 240,
112
- exit: animateOutTo ? 400 : 120,
113
- },
114
- in: isVisible,
115
- appear: true,
116
- unmountOnExit: true,
117
- onEnter: (node) => {
118
- if (motionOk) {
119
- node.style.transform = 'translateY(15%)';
120
- node.style.transitionTimingFunction = 'ease';
121
- }
122
- },
123
- onEntered: (node) => {
124
- if (motionOk) node.style.transform = 'translateY(0)';
125
- },
126
- onExiting: (node) => {
127
- if (motionOk) {
128
- let { translateX, translateY } = calculateOutAnimation(node);
129
- node.style.transform = animateOutTo
130
- ? `scale(0.9) translate(${translateX}px,${translateY}px)`
131
- : 'scale(0.9)';
132
- node.style.opacity = '0';
133
- node.style.transitionDuration = animateOutTo ? '400ms' : '120ms';
134
- node.style.transitionTimingFunction = 'cubic-bezier(0.4, 0, 1, 1)';
135
- }
136
- },
137
- onExited: onRemove,
138
- },
139
- _react.createElement(
140
- _index.Box,
141
- {
142
- ref: thisElement,
143
- className: 'iui-toast-all',
144
- style: {
145
- height,
146
- ...marginStyle(),
147
- },
148
- },
149
- _react.createElement(
150
- 'div',
89
+ let shouldBeMounted = useAnimateToastBasedOnVisibility(isVisible, {
90
+ thisElement,
91
+ animateOutTo,
92
+ onRemove,
93
+ });
94
+ return shouldBeMounted
95
+ ? _react.createElement(
96
+ _index.Box,
151
97
  {
152
- ref: onRef,
98
+ ref: thisElement,
99
+ className: 'iui-toast-all',
100
+ style: {
101
+ height,
102
+ ...marginStyle(),
103
+ },
153
104
  },
154
- _react.createElement(ToastPresentation, {
155
- as: 'div',
156
- category: category,
157
- content: content,
158
- link: link,
159
- type: type,
160
- hasCloseButton: hasCloseButton,
161
- onClose: close,
162
- ...domProps?.toastProps,
163
- contentProps: domProps?.contentProps,
164
- }),
165
- ),
166
- ),
167
- );
105
+ _react.createElement(
106
+ 'div',
107
+ {
108
+ ref: onRef,
109
+ },
110
+ _react.createElement(ToastPresentation, {
111
+ as: 'div',
112
+ category: category,
113
+ content: content,
114
+ link: link,
115
+ type: type,
116
+ hasCloseButton: hasCloseButton,
117
+ onClose: close,
118
+ ...domProps?.toastProps,
119
+ contentProps: domProps?.contentProps,
120
+ }),
121
+ ),
122
+ )
123
+ : null;
168
124
  };
169
125
  const ToastPresentation = _react.forwardRef((props, forwardedRef) => {
170
126
  let {
@@ -239,3 +195,102 @@ const ToastPresentation = _react.forwardRef((props, forwardedRef) => {
239
195
  ),
240
196
  );
241
197
  });
198
+ const useAnimateToastBasedOnVisibility = (isVisible, args) => {
199
+ let { thisElement, animateOutTo, onRemove } = args;
200
+ let [shouldBeMounted, setShouldBeMounted] = _react.useState(isVisible);
201
+ let motionOk = (0, _index.useMediaQuery)(
202
+ '(prefers-reduced-motion: no-preference)',
203
+ );
204
+ let onRemoveRef = (0, _index.useLatestRef)(onRemove);
205
+ let [prevIsVisible, setPrevIsVisible] = _react.useState(void 0);
206
+ _react.useEffect(() => {
207
+ if (prevIsVisible !== isVisible) {
208
+ setPrevIsVisible(isVisible);
209
+ if (isVisible) safeAnimateIn();
210
+ else safeAnimateOut();
211
+ }
212
+ function calculateOutAnimation(node) {
213
+ let translateX = 0;
214
+ let translateY = 0;
215
+ if (animateOutTo && node) {
216
+ let { x: startX, y: startY } = node.getBoundingClientRect();
217
+ let { x: endX, y: endY } = animateOutTo.getBoundingClientRect();
218
+ translateX = endX - startX;
219
+ translateY = endY - startY;
220
+ }
221
+ return {
222
+ translateX,
223
+ translateY,
224
+ };
225
+ }
226
+ function safeAnimateIn() {
227
+ setShouldBeMounted(true);
228
+ queueMicrotask(() => {
229
+ animateIn();
230
+ });
231
+ }
232
+ function safeAnimateOut() {
233
+ if (motionOk) {
234
+ let animation = animateOut();
235
+ animation?.addEventListener('finish', () => {
236
+ setShouldBeMounted(false);
237
+ onRemoveRef.current?.();
238
+ });
239
+ } else {
240
+ setShouldBeMounted(false);
241
+ onRemoveRef.current?.();
242
+ }
243
+ }
244
+ function animateIn() {
245
+ if (!motionOk) return;
246
+ thisElement.current?.animate?.(
247
+ [
248
+ {
249
+ transform: 'translateY(15%)',
250
+ },
251
+ {
252
+ transform: 'translateY(0)',
253
+ },
254
+ ],
255
+ {
256
+ duration: 240,
257
+ fill: 'forwards',
258
+ },
259
+ );
260
+ }
261
+ function animateOut() {
262
+ if (null == thisElement.current || !motionOk) return;
263
+ let { translateX, translateY } = calculateOutAnimation(
264
+ thisElement.current,
265
+ );
266
+ let animationDuration = animateOutTo ? 400 : 120;
267
+ let animation = thisElement.current?.animate?.(
268
+ [
269
+ {
270
+ transform: animateOutTo
271
+ ? `scale(0.9) translate(${translateX}px,${translateY}px)`
272
+ : 'scale(0.9)',
273
+ opacity: 0,
274
+ transitionDuration: `${animationDuration}ms`,
275
+ transitionTimingFunction: 'cubic-bezier(0.4, 0, 1, 1)',
276
+ },
277
+ ],
278
+ {
279
+ duration: animationDuration,
280
+ iterations: 1,
281
+ fill: 'forwards',
282
+ },
283
+ );
284
+ return animation;
285
+ }
286
+ }, [
287
+ isVisible,
288
+ prevIsVisible,
289
+ animateOutTo,
290
+ motionOk,
291
+ thisElement,
292
+ setShouldBeMounted,
293
+ onRemoveRef,
294
+ ]);
295
+ return shouldBeMounted;
296
+ };
@@ -38,7 +38,7 @@ export declare const Toaster: () => React.JSX.Element;
38
38
  export declare const ToastProvider: ({ children, inherit, }: {
39
39
  children: React.ReactNode;
40
40
  inherit?: boolean;
41
- }) => string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
41
+ }) => React.JSX.Element;
42
42
  export declare const ToasterStateContext: React.Context<ToasterState | undefined>;
43
43
  type ToasterState = {
44
44
  toasts: ToastProps[];
@@ -96,16 +96,24 @@ const ToastProvider = ({ children, inherit = false }) => {
96
96
  placement: 'top',
97
97
  },
98
98
  });
99
- if (_react.useContext(ToasterStateContext) && inherit) return children;
99
+ let toasterDispatchContext = _react.useContext(ToasterDispatchContext);
100
+ let toasterStateContext = _react.useContext(ToasterStateContext);
101
+ let shouldReuse = toasterStateContext && inherit;
102
+ let toasterDispatchContextValue = shouldReuse
103
+ ? toasterDispatchContext
104
+ : dispatch;
105
+ let toasterStateContextValue = shouldReuse
106
+ ? toasterStateContext
107
+ : toasterState;
100
108
  return _react.createElement(
101
109
  ToasterDispatchContext.Provider,
102
110
  {
103
- value: dispatch,
111
+ value: toasterDispatchContextValue,
104
112
  },
105
113
  _react.createElement(
106
114
  ToasterStateContext.Provider,
107
115
  {
108
- value: toasterState,
116
+ value: toasterStateContextValue,
109
117
  },
110
118
  children,
111
119
  ),
package/cjs/styles.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
- const e = '3.17.0-dev.0';
3
+ const e = '3.17.0-dev.2';
4
4
  const u = new Proxy(
5
5
  {},
6
6
  {
@@ -3,7 +3,6 @@ export * from './FocusTrap.js';
3
3
  export * from './InputContainer.js';
4
4
  export * from './InputFlexContainer.js';
5
5
  export * from './InputWithIcon.js';
6
- export * from './WithCSSTransition.js';
7
6
  export * from './MiddleTextTruncation.js';
8
7
  export * from './AutoclearingHiddenLiveRegion.js';
9
8
  export * from './Box.js';
@@ -8,7 +8,6 @@ _export_star._(require('./FocusTrap.js'), exports);
8
8
  _export_star._(require('./InputContainer.js'), exports);
9
9
  _export_star._(require('./InputFlexContainer.js'), exports);
10
10
  _export_star._(require('./InputWithIcon.js'), exports);
11
- _export_star._(require('./WithCSSTransition.js'), exports);
12
11
  _export_star._(require('./MiddleTextTruncation.js'), exports);
13
12
  _export_star._(require('./AutoclearingHiddenLiveRegion.js'), exports);
14
13
  _export_star._(require('./Box.js'), exports);
@@ -10,6 +10,7 @@ export declare const useGlobals: () => {
10
10
  theme?: import("../../index.js").ThemeType;
11
11
  themeOptions?: import("../../core/ThemeProvider/ThemeProvider.js").ThemeOptions;
12
12
  portalContainer?: HTMLElement | null;
13
+ future?: import("../../core/ThemeProvider/ThemeProvider.js").FutureOptions;
13
14
  } | undefined;
14
15
  /** Shows console error if ThemeProvider is not used */
15
16
  export declare const useThemeProviderWarning: (themeContext: React.ContextType<typeof ThemeContext>) => void;
@@ -6,7 +6,7 @@ type DialogProps = {
6
6
  * Dialog content.
7
7
  */
8
8
  children: React.ReactNode;
9
- } & Omit<DialogContextProps, 'dialogRootRef'>;
9
+ } & DialogContextProps;
10
10
  /**
11
11
  * Dialog component.
12
12
  * @example