@itwin/itwinui-react 3.9.1 → 3.10.1

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 (65) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/cjs/core/Breadcrumbs/Breadcrumbs.js +2 -3
  3. package/cjs/core/Buttons/Button.js +1 -1
  4. package/cjs/core/Buttons/IconButton.js +1 -1
  5. package/cjs/core/Buttons/IdeasButton.js +6 -2
  6. package/cjs/core/ComboBox/ComboBox.js +1 -1
  7. package/cjs/core/DropdownMenu/DropdownMenu.js +36 -13
  8. package/cjs/core/Input/Input.js +1 -1
  9. package/cjs/core/LabeledSelect/LabeledSelect.d.ts +26 -4
  10. package/cjs/core/Menu/Menu.js +9 -0
  11. package/cjs/core/Menu/MenuItem.d.ts +12 -0
  12. package/cjs/core/Menu/MenuItem.js +114 -66
  13. package/cjs/core/NotificationMarker/NotificationMarker.d.ts +7 -6
  14. package/cjs/core/Popover/Popover.d.ts +32 -9
  15. package/cjs/core/Popover/Popover.js +68 -17
  16. package/cjs/core/Select/Select.js +2 -3
  17. package/cjs/core/SideNavigation/SideNavigation.d.ts +1 -0
  18. package/cjs/core/SideNavigation/SideNavigation.js +20 -21
  19. package/cjs/core/SideNavigation/SidenavButton.js +5 -1
  20. package/cjs/core/Table/TablePaginator.js +1 -3
  21. package/cjs/core/Table/columns/selectionColumn.js +10 -1
  22. package/cjs/core/Table/hooks/useSubRowSelection.js +1 -1
  23. package/cjs/core/ThemeProvider/ThemeProvider.js +53 -17
  24. package/cjs/core/TimePicker/TimePicker.js +12 -12
  25. package/cjs/core/ToggleSwitch/ToggleSwitch.d.ts +4 -0
  26. package/cjs/core/ToggleSwitch/ToggleSwitch.js +2 -2
  27. package/cjs/utils/components/Portal.d.ts +6 -2
  28. package/cjs/utils/components/Portal.js +11 -14
  29. package/cjs/utils/providers/ScopeProvider.d.ts +26 -0
  30. package/cjs/utils/providers/ScopeProvider.js +77 -0
  31. package/cjs/utils/providers/index.d.ts +1 -0
  32. package/cjs/utils/providers/index.js +1 -0
  33. package/esm/core/Breadcrumbs/Breadcrumbs.js +2 -3
  34. package/esm/core/Buttons/Button.js +1 -1
  35. package/esm/core/Buttons/IconButton.js +1 -1
  36. package/esm/core/Buttons/IdeasButton.js +3 -2
  37. package/esm/core/ComboBox/ComboBox.js +1 -1
  38. package/esm/core/DropdownMenu/DropdownMenu.js +36 -13
  39. package/esm/core/Input/Input.js +1 -1
  40. package/esm/core/LabeledSelect/LabeledSelect.d.ts +26 -4
  41. package/esm/core/Menu/Menu.js +9 -0
  42. package/esm/core/Menu/MenuItem.d.ts +12 -0
  43. package/esm/core/Menu/MenuItem.js +114 -66
  44. package/esm/core/NotificationMarker/NotificationMarker.d.ts +7 -6
  45. package/esm/core/Popover/Popover.d.ts +32 -9
  46. package/esm/core/Popover/Popover.js +71 -20
  47. package/esm/core/Select/Select.js +2 -3
  48. package/esm/core/SideNavigation/SideNavigation.d.ts +1 -0
  49. package/esm/core/SideNavigation/SideNavigation.js +20 -21
  50. package/esm/core/SideNavigation/SidenavButton.js +5 -1
  51. package/esm/core/Table/TablePaginator.js +2 -4
  52. package/esm/core/Table/columns/selectionColumn.js +10 -1
  53. package/esm/core/Table/hooks/useSubRowSelection.js +1 -1
  54. package/esm/core/ThemeProvider/ThemeProvider.js +54 -18
  55. package/esm/core/TimePicker/TimePicker.js +12 -12
  56. package/esm/core/ToggleSwitch/ToggleSwitch.d.ts +4 -0
  57. package/esm/core/ToggleSwitch/ToggleSwitch.js +2 -2
  58. package/esm/utils/components/Portal.d.ts +6 -2
  59. package/esm/utils/components/Portal.js +9 -8
  60. package/esm/utils/providers/ScopeProvider.d.ts +26 -0
  61. package/esm/utils/providers/ScopeProvider.js +48 -0
  62. package/esm/utils/providers/index.d.ts +1 -0
  63. package/esm/utils/providers/index.js +1 -0
  64. package/package.json +2 -1
  65. package/styles.css +1 -1
@@ -0,0 +1,48 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import * as React from 'react';
6
+ import { createStore, useAtomValue, useSetAtom } from 'jotai';
7
+ const ScopeContext = React.createContext({
8
+ store: createStore(),
9
+ parentStore: null,
10
+ });
11
+ /**
12
+ * Provider that creates a fresh, isolated jotai store for its children.
13
+ *
14
+ * Should be used with `useScopedAtom` and/or `useScopedSetAtom`.
15
+ *
16
+ * @private
17
+ */
18
+ export const ScopeProvider = ({ children }) => {
19
+ const store = React.useMemo(() => createStore(), []);
20
+ const parentStore = React.useContext(ScopeContext).store;
21
+ return (React.createElement(ScopeContext.Provider, { value: React.useMemo(() => ({ store, parentStore }), [store, parentStore]) }, children));
22
+ };
23
+ /**
24
+ * Wrapper over `useAtom` that uses the store from the nearest `ScopeProvider`.
25
+ *
26
+ * If the atom is not set in the current store, it will recursively look in the parent store(s).
27
+ * This is only useful for initial values. Future updates to the parent will not be reflected.
28
+ *
29
+ * @private
30
+ */
31
+ export const useScopedAtom = (atom) => {
32
+ const { store, parentStore } = React.useContext(ScopeContext);
33
+ const setAtom = useScopedSetAtom(atom);
34
+ const value = useAtomValue(atom, { store });
35
+ const inheritedValue = useAtomValue(atom, { store: parentStore || store });
36
+ if (value == undefined && inheritedValue != undefined) {
37
+ setAtom(inheritedValue);
38
+ }
39
+ return [value, setAtom];
40
+ };
41
+ /**
42
+ * Wrapper over `useSetAtom` that uses the store from the nearest `ScopeProvider`.
43
+ * @private
44
+ */
45
+ export const useScopedSetAtom = (atom) => {
46
+ const { store } = React.useContext(ScopeContext);
47
+ return useSetAtom(atom, { store });
48
+ };
@@ -1 +1,2 @@
1
1
  export * from './HydrationProvider.js';
2
+ export * from './ScopeProvider.js';
@@ -3,3 +3,4 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  export * from './HydrationProvider.js';
6
+ export * from './ScopeProvider.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/itwinui-react",
3
- "version": "3.9.1",
3
+ "version": "3.10.1",
4
4
  "author": "Bentley Systems",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -59,6 +59,7 @@
59
59
  "@floating-ui/react": "^0.26.10",
60
60
  "@itwin/itwinui-illustrations-react": "^2.1.0",
61
61
  "classnames": "^2.3.2",
62
+ "jotai": "^2.8.0",
62
63
  "react-table": "^7.8.0",
63
64
  "react-transition-group": "^4.4.5",
64
65
  "tslib": "^2.6.0"