@etsoo/toolpad 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/.github/workflows/main.yml +49 -0
  2. package/.vscode/settings.json +3 -0
  3. package/LICENSE +21 -0
  4. package/README.md +11 -0
  5. package/build/src/Account/Account.d.ts +71 -0
  6. package/build/src/Account/Account.js +117 -0
  7. package/build/src/Account/Account.test.d.ts +1 -0
  8. package/build/src/Account/Account.test.js +35 -0
  9. package/build/src/Account/AccountPopoverFooter.d.ts +6 -0
  10. package/build/src/Account/AccountPopoverFooter.js +21 -0
  11. package/build/src/Account/AccountPopoverHeader.d.ts +6 -0
  12. package/build/src/Account/AccountPopoverHeader.js +15 -0
  13. package/build/src/Account/AccountPreview.d.ts +67 -0
  14. package/build/src/Account/AccountPreview.js +76 -0
  15. package/build/src/Account/AccountPreview.test.d.ts +1 -0
  16. package/build/src/Account/AccountPreview.test.js +47 -0
  17. package/build/src/Account/SignInButton.d.ts +2 -0
  18. package/build/src/Account/SignInButton.js +26 -0
  19. package/build/src/Account/SignOutButton.d.ts +3 -0
  20. package/build/src/Account/SignOutButton.js +28 -0
  21. package/build/src/Account/index.d.ts +6 -0
  22. package/build/src/Account/index.js +6 -0
  23. package/build/src/AppProvider/AppProvider.d.ts +98 -0
  24. package/build/src/AppProvider/AppProvider.js +4 -0
  25. package/build/src/AppProvider/AppProvider.test.d.ts +4 -0
  26. package/build/src/AppProvider/AppProvider.test.js +16 -0
  27. package/build/src/AppProvider/AppProviderComponent.d.ts +17 -0
  28. package/build/src/AppProvider/AppProviderComponent.js +120 -0
  29. package/build/src/AppProvider/AppThemeProvider.d.ts +12 -0
  30. package/build/src/AppProvider/AppThemeProvider.js +73 -0
  31. package/build/src/AppProvider/index.d.ts +1 -0
  32. package/build/src/AppProvider/index.js +1 -0
  33. package/build/src/DashboardLayout/DashboardLayout.d.ts +83 -0
  34. package/build/src/DashboardLayout/DashboardLayout.js +286 -0
  35. package/build/src/DashboardLayout/DashboardLayout.test.d.ts +1 -0
  36. package/build/src/DashboardLayout/DashboardLayout.test.js +291 -0
  37. package/build/src/DashboardLayout/DashboardSidebarSubNavigation.d.ts +16 -0
  38. package/build/src/DashboardLayout/DashboardSidebarSubNavigation.js +149 -0
  39. package/build/src/DashboardLayout/ThemeSwitcher.d.ts +5 -0
  40. package/build/src/DashboardLayout/ThemeSwitcher.js +40 -0
  41. package/build/src/DashboardLayout/ToolbarActions.d.ts +5 -0
  42. package/build/src/DashboardLayout/ToolbarActions.js +9 -0
  43. package/build/src/DashboardLayout/index.d.ts +2 -0
  44. package/build/src/DashboardLayout/index.js +3 -0
  45. package/build/src/DashboardLayout/utils.d.ts +8 -0
  46. package/build/src/DashboardLayout/utils.js +16 -0
  47. package/build/src/PageContainer/PageContainer.d.ts +66 -0
  48. package/build/src/PageContainer/PageContainer.js +97 -0
  49. package/build/src/PageContainer/PageContainer.test.d.ts +1 -0
  50. package/build/src/PageContainer/PageContainer.test.js +127 -0
  51. package/build/src/PageContainer/PageContainerToolbar.d.ts +16 -0
  52. package/build/src/PageContainer/PageContainerToolbar.js +24 -0
  53. package/build/src/PageContainer/PageContainerToolbar.test.d.ts +1 -0
  54. package/build/src/PageContainer/PageContainerToolbar.test.js +10 -0
  55. package/build/src/PageContainer/index.d.ts +2 -0
  56. package/build/src/PageContainer/index.js +2 -0
  57. package/build/src/index.d.ts +8 -0
  58. package/build/src/index.js +8 -0
  59. package/build/src/nextjs/AppProvider.d.ts +6 -0
  60. package/build/src/nextjs/AppProvider.js +16 -0
  61. package/build/src/nextjs/AppProvider.test.d.ts +1 -0
  62. package/build/src/nextjs/AppProvider.test.js +36 -0
  63. package/build/src/nextjs/AppProviderNextApp.d.ts +5 -0
  64. package/build/src/nextjs/AppProviderNextApp.js +27 -0
  65. package/build/src/nextjs/AppProviderNextPages.d.ts +5 -0
  66. package/build/src/nextjs/AppProviderNextPages.js +37 -0
  67. package/build/src/nextjs/index.d.ts +1 -0
  68. package/build/src/nextjs/index.js +1 -0
  69. package/build/src/persistence/codec.d.ts +47 -0
  70. package/build/src/persistence/codec.js +57 -0
  71. package/build/src/persistence/index.d.ts +1 -0
  72. package/build/src/persistence/index.js +1 -0
  73. package/build/src/persistence/useStorageState.d.ts +50 -0
  74. package/build/src/persistence/useStorageState.js +116 -0
  75. package/build/src/persistence/useStorageState.test.d.ts +1 -0
  76. package/build/src/persistence/useStorageState.test.js +61 -0
  77. package/build/src/react-router-dom/AppProvider.d.ts +6 -0
  78. package/build/src/react-router-dom/AppProvider.js +29 -0
  79. package/build/src/react-router-dom/AppProvider.test.d.ts +1 -0
  80. package/build/src/react-router-dom/AppProvider.test.js +12 -0
  81. package/build/src/react-router-dom/index.d.ts +1 -0
  82. package/build/src/react-router-dom/index.js +1 -0
  83. package/build/src/shared/Link.d.ts +8 -0
  84. package/build/src/shared/Link.js +19 -0
  85. package/build/src/shared/branding.d.ts +1 -0
  86. package/build/src/shared/branding.js +6 -0
  87. package/build/src/shared/components.d.ts +5 -0
  88. package/build/src/shared/components.js +23 -0
  89. package/build/src/shared/context.d.ts +12 -0
  90. package/build/src/shared/context.js +10 -0
  91. package/build/src/shared/locales/LocaleContext.d.ts +19 -0
  92. package/build/src/shared/locales/LocaleContext.js +18 -0
  93. package/build/src/shared/locales/en.d.ts +6 -0
  94. package/build/src/shared/locales/en.js +8 -0
  95. package/build/src/shared/navigation.d.ts +16 -0
  96. package/build/src/shared/navigation.js +129 -0
  97. package/build/src/useActivePage/index.d.ts +1 -0
  98. package/build/src/useActivePage/index.js +1 -0
  99. package/build/src/useActivePage/useActivePage.d.ts +11 -0
  100. package/build/src/useActivePage/useActivePage.js +48 -0
  101. package/build/src/useLocalStorageState/index.d.ts +1 -0
  102. package/build/src/useLocalStorageState/index.js +1 -0
  103. package/build/src/useLocalStorageState/useLocalStorageState.d.ts +2 -0
  104. package/build/src/useLocalStorageState/useLocalStorageState.js +14 -0
  105. package/build/src/useSessionStorageState/index.d.ts +1 -0
  106. package/build/src/useSessionStorageState/index.js +1 -0
  107. package/build/src/useSessionStorageState/useSessionStorageState.d.ts +2 -0
  108. package/build/src/useSessionStorageState/useSessionStorageState.js +14 -0
  109. package/build/src/utils/collections.d.ts +44 -0
  110. package/build/src/utils/collections.js +43 -0
  111. package/build/src/utils/describeConformance.d.ts +7 -0
  112. package/build/src/utils/describeConformance.js +3 -0
  113. package/build/src/utils/events.d.ts +27 -0
  114. package/build/src/utils/events.js +54 -0
  115. package/build/src/utils/hooks/index.d.ts +2 -0
  116. package/build/src/utils/hooks/index.js +2 -0
  117. package/build/src/utils/hooks/useBoolean.d.ts +11 -0
  118. package/build/src/utils/hooks/useBoolean.js +11 -0
  119. package/build/src/utils/hooks/useDebounced.d.ts +8 -0
  120. package/build/src/utils/hooks/useDebounced.js +28 -0
  121. package/build/src/utils/hooks/useDebouncedHandler.d.ts +12 -0
  122. package/build/src/utils/hooks/useDebouncedHandler.js +41 -0
  123. package/build/src/utils/hooks/useLatest.d.ts +6 -0
  124. package/build/src/utils/hooks/useLatest.js +9 -0
  125. package/build/src/utils/hooks/usePageTitle.d.ts +4 -0
  126. package/build/src/utils/hooks/usePageTitle.js +13 -0
  127. package/build/src/utils/hooks/useSsr.d.ts +4 -0
  128. package/build/src/utils/hooks/useSsr.js +16 -0
  129. package/build/src/utils/hooks/useStorageState.d.ts +10 -0
  130. package/build/src/utils/hooks/useStorageState.js +51 -0
  131. package/build/src/utils/warnOnce.d.ts +5 -0
  132. package/build/src/utils/warnOnce.js +11 -0
  133. package/build/vitest.setup.d.ts +1 -0
  134. package/build/vitest.setup.js +19 -0
  135. package/package.json +60 -0
  136. package/src/Account/Account.test.tsx +56 -0
  137. package/src/Account/Account.tsx +226 -0
  138. package/src/Account/AccountPopoverFooter.tsx +33 -0
  139. package/src/Account/AccountPopoverHeader.tsx +20 -0
  140. package/src/Account/AccountPreview.test.tsx +79 -0
  141. package/src/Account/AccountPreview.tsx +189 -0
  142. package/src/Account/SignInButton.tsx +38 -0
  143. package/src/Account/SignOutButton.tsx +44 -0
  144. package/src/Account/index.ts +6 -0
  145. package/src/AppProvider/AppProvider.test.tsx +25 -0
  146. package/src/AppProvider/AppProvider.tsx +116 -0
  147. package/src/AppProvider/AppProviderComponent.tsx +162 -0
  148. package/src/AppProvider/AppThemeProvider.tsx +177 -0
  149. package/src/AppProvider/index.ts +1 -0
  150. package/src/DashboardLayout/DashboardLayout.test.tsx +429 -0
  151. package/src/DashboardLayout/DashboardLayout.tsx +558 -0
  152. package/src/DashboardLayout/DashboardSidebarSubNavigation.tsx +301 -0
  153. package/src/DashboardLayout/ThemeSwitcher.tsx +81 -0
  154. package/src/DashboardLayout/ToolbarActions.tsx +11 -0
  155. package/src/DashboardLayout/index.ts +4 -0
  156. package/src/DashboardLayout/utils.ts +23 -0
  157. package/src/PageContainer/PageContainer.test.tsx +194 -0
  158. package/src/PageContainer/PageContainer.tsx +201 -0
  159. package/src/PageContainer/PageContainerToolbar.test.tsx +11 -0
  160. package/src/PageContainer/PageContainerToolbar.tsx +31 -0
  161. package/src/PageContainer/index.ts +2 -0
  162. package/src/index.ts +15 -0
  163. package/src/nextjs/AppProvider.test.tsx +48 -0
  164. package/src/nextjs/AppProvider.tsx +18 -0
  165. package/src/nextjs/AppProviderNextApp.tsx +37 -0
  166. package/src/nextjs/AppProviderNextPages.tsx +52 -0
  167. package/src/nextjs/index.tsx +1 -0
  168. package/src/persistence/codec.tsx +81 -0
  169. package/src/persistence/index.ts +1 -0
  170. package/src/persistence/useStorageState.test.tsx +101 -0
  171. package/src/persistence/useStorageState.tsx +244 -0
  172. package/src/react-router-dom/AppProvider.test.tsx +17 -0
  173. package/src/react-router-dom/AppProvider.tsx +40 -0
  174. package/src/react-router-dom/index.tsx +1 -0
  175. package/src/shared/Link.tsx +37 -0
  176. package/src/shared/branding.ts +7 -0
  177. package/src/shared/components.tsx +46 -0
  178. package/src/shared/context.ts +21 -0
  179. package/src/shared/locales/LocaleContext.tsx +44 -0
  180. package/src/shared/locales/en.tsx +9 -0
  181. package/src/shared/navigation.tsx +197 -0
  182. package/src/useActivePage/index.ts +1 -0
  183. package/src/useActivePage/useActivePage.ts +66 -0
  184. package/src/useLocalStorageState/index.ts +1 -0
  185. package/src/useLocalStorageState/useLocalStorageState.tsx +23 -0
  186. package/src/useSessionStorageState/index.tsx +1 -0
  187. package/src/useSessionStorageState/useSessionStorageState.tsx +23 -0
  188. package/src/utils/collections.ts +125 -0
  189. package/src/utils/describeConformance.ts +14 -0
  190. package/src/utils/events.ts +81 -0
  191. package/src/utils/hooks/index.ts +2 -0
  192. package/src/utils/hooks/useBoolean.ts +12 -0
  193. package/src/utils/hooks/useDebounced.ts +39 -0
  194. package/src/utils/hooks/useDebouncedHandler.ts +71 -0
  195. package/src/utils/hooks/useLatest.ts +16 -0
  196. package/src/utils/hooks/usePageTitle.ts +14 -0
  197. package/src/utils/hooks/useSsr.ts +24 -0
  198. package/src/utils/hooks/useStorageState.ts +130 -0
  199. package/src/utils/warnOnce.ts +12 -0
  200. package/tsconfig.json +19 -0
  201. package/vite.config.ts +27 -0
  202. package/vitest.setup.ts +22 -0
@@ -0,0 +1,98 @@
1
+ import * as React from "react";
2
+ import { Theme } from "@mui/material/styles";
3
+ export interface NavigateOptions {
4
+ history?: "auto" | "push" | "replace";
5
+ }
6
+ export interface Navigate {
7
+ (url: string | URL, options?: NavigateOptions): void;
8
+ }
9
+ /**
10
+ * Abstract router used by Toolpad components.
11
+ */
12
+ export interface Router {
13
+ pathname: string;
14
+ searchParams: URLSearchParams;
15
+ navigate: Navigate;
16
+ }
17
+ export interface Branding {
18
+ title?: string;
19
+ logo?: React.ReactNode;
20
+ }
21
+ export interface NavigationPageItem {
22
+ kind?: "page";
23
+ segment?: string;
24
+ title?: string;
25
+ icon?: React.ReactNode;
26
+ pattern?: string;
27
+ action?: React.ReactNode;
28
+ children?: Navigation;
29
+ }
30
+ export interface NavigationSubheaderItem {
31
+ kind: "header";
32
+ title: string;
33
+ }
34
+ export interface NavigationDividerItem {
35
+ kind: "divider";
36
+ }
37
+ export type NavigationItem = NavigationPageItem | NavigationSubheaderItem | NavigationDividerItem;
38
+ export type Navigation = NavigationItem[];
39
+ export interface Session {
40
+ user?: {
41
+ id?: string | null;
42
+ name?: string | null;
43
+ image?: string | null;
44
+ email?: string | null;
45
+ };
46
+ }
47
+ export interface Authentication {
48
+ signIn: () => void;
49
+ signOut: () => void;
50
+ }
51
+ export declare const AuthenticationContext: React.Context<Authentication | null>;
52
+ export declare const SessionContext: React.Context<Session | null>;
53
+ export type AppTheme = Theme | {
54
+ light: Theme;
55
+ dark: Theme;
56
+ };
57
+ export interface AppProviderProps {
58
+ /**
59
+ * The content of the app provider.
60
+ */
61
+ children: React.ReactNode;
62
+ /**
63
+ * [Theme or themes](https://mui.com/toolpad/core/react-app-provider/#theming) to be used by the app in light/dark mode. A [CSS variables theme](https://mui.com/material-ui/customization/css-theme-variables/overview/) is recommended.
64
+ * @default createTheme()
65
+ */
66
+ theme?: AppTheme;
67
+ /**
68
+ * Branding options for the app.
69
+ * @default null
70
+ */
71
+ branding?: Branding | null;
72
+ /**
73
+ * Navigation definition for the app.
74
+ * @default []
75
+ */
76
+ navigation?: Navigation;
77
+ /**
78
+ * Router implementation used inside Toolpad components.
79
+ * @default null
80
+ */
81
+ router?: Router;
82
+ /**
83
+ * Session info about the current user.
84
+ * @default null
85
+ */
86
+ session?: Session | null;
87
+ /**
88
+ * Authentication methods.
89
+ * @default null
90
+ */
91
+ authentication?: Authentication | null;
92
+ /**
93
+ * The window where the application is rendered.
94
+ * This is needed when rendering the app inside an iframe, for example.
95
+ * @default window
96
+ */
97
+ window?: Window;
98
+ }
@@ -0,0 +1,4 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ export const AuthenticationContext = React.createContext(null);
4
+ export const SessionContext = React.createContext(null);
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { describe, test, expect } from "vitest";
3
+ import { render, screen } from "@testing-library/react";
4
+ import { createTheme } from "@mui/material/styles";
5
+ import { AppProvider } from "./AppProviderComponent";
6
+ describe("AppProvider", () => {
7
+ test("renders content correctly", async () => {
8
+ render(_jsx(AppProvider, { children: "Hello world" }));
9
+ expect(screen.getByText("Hello world")).toBeTruthy();
10
+ });
11
+ test("renders content correctly when using legacy theme", async () => {
12
+ const legacyTheme = createTheme();
13
+ render(_jsx(AppProvider, { theme: legacyTheme, children: "Hello world" }));
14
+ expect(screen.getByText("Hello world")).toBeTruthy();
15
+ });
16
+ });
@@ -0,0 +1,17 @@
1
+ import { AppProviderProps } from "./AppProvider";
2
+ /**
3
+ *
4
+ * Demos:
5
+ *
6
+ * - [App Provider](https://mui.com/toolpad/core/react-app-provider/)
7
+ * - [Dashboard Layout](https://mui.com/toolpad/core/react-dashboard-layout/)
8
+ *
9
+ * API:
10
+ *
11
+ * - [AppProvider API](https://mui.com/toolpad/core/api/app-provider)
12
+ */
13
+ declare function AppProvider(props: AppProviderProps): import("react/jsx-runtime").JSX.Element;
14
+ declare namespace AppProvider {
15
+ var propTypes: any;
16
+ }
17
+ export { AppProvider };
@@ -0,0 +1,120 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import PropTypes from "prop-types";
4
+ import { BrandingContext, NavigationContext, RouterContext, WindowContext } from "../shared/context";
5
+ import { AppThemeProvider } from "./AppThemeProvider";
6
+ import { createTheme as createMuiTheme } from "@mui/material/styles";
7
+ import { AuthenticationContext, SessionContext } from "./AppProvider";
8
+ function createTheme() {
9
+ return createMuiTheme({
10
+ cssVariables: {
11
+ colorSchemeSelector: "data-toolpad-color-scheme"
12
+ },
13
+ colorSchemes: { dark: true }
14
+ });
15
+ }
16
+ /**
17
+ *
18
+ * Demos:
19
+ *
20
+ * - [App Provider](https://mui.com/toolpad/core/react-app-provider/)
21
+ * - [Dashboard Layout](https://mui.com/toolpad/core/react-dashboard-layout/)
22
+ *
23
+ * API:
24
+ *
25
+ * - [AppProvider API](https://mui.com/toolpad/core/api/app-provider)
26
+ */
27
+ function AppProvider(props) {
28
+ const { children, theme = createTheme(), branding = null, navigation = [], router = null, authentication = null, session = null, window: appWindow } = props;
29
+ return (_jsx(WindowContext.Provider, { value: appWindow, children: _jsx(AuthenticationContext.Provider, { value: authentication, children: _jsx(SessionContext.Provider, { value: session, children: _jsx(RouterContext.Provider, { value: router, children: _jsx(AppThemeProvider, { theme: theme, window: appWindow, children: _jsx(BrandingContext.Provider, { value: branding, children: _jsx(NavigationContext.Provider, { value: navigation, children: children }) }) }) }) }) }) }));
30
+ }
31
+ AppProvider.propTypes /* remove-proptypes */ = {
32
+ // ┌────────────────────────────── Warning ──────────────────────────────┐
33
+ // │ These PropTypes are generated from the TypeScript type definitions. │
34
+ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
35
+ // └─────────────────────────────────────────────────────────────────────┘
36
+ /**
37
+ * Authentication methods.
38
+ * @default null
39
+ */
40
+ authentication: PropTypes.shape({
41
+ signIn: PropTypes.func.isRequired,
42
+ signOut: PropTypes.func.isRequired
43
+ }),
44
+ /**
45
+ * Branding options for the app.
46
+ * @default null
47
+ */
48
+ branding: PropTypes.shape({
49
+ logo: PropTypes.node,
50
+ title: PropTypes.string
51
+ }),
52
+ /**
53
+ * The content of the app provider.
54
+ */
55
+ children: PropTypes.node,
56
+ /**
57
+ * Navigation definition for the app.
58
+ * @default []
59
+ */
60
+ navigation: PropTypes.arrayOf(PropTypes.oneOfType([
61
+ PropTypes.shape({
62
+ action: PropTypes.node,
63
+ children: PropTypes.arrayOf(PropTypes.oneOfType([
64
+ PropTypes.object,
65
+ PropTypes.shape({
66
+ kind: PropTypes.oneOf(["header"]).isRequired,
67
+ title: PropTypes.string.isRequired
68
+ }),
69
+ PropTypes.shape({
70
+ kind: PropTypes.oneOf(["divider"]).isRequired
71
+ })
72
+ ]).isRequired),
73
+ icon: PropTypes.node,
74
+ kind: PropTypes.oneOf(["page"]),
75
+ pattern: PropTypes.string,
76
+ segment: PropTypes.string,
77
+ title: PropTypes.string
78
+ }),
79
+ PropTypes.shape({
80
+ kind: PropTypes.oneOf(["header"]).isRequired,
81
+ title: PropTypes.string.isRequired
82
+ }),
83
+ PropTypes.shape({
84
+ kind: PropTypes.oneOf(["divider"]).isRequired
85
+ })
86
+ ]).isRequired),
87
+ /**
88
+ * Router implementation used inside Toolpad components.
89
+ * @default null
90
+ */
91
+ router: PropTypes.shape({
92
+ navigate: PropTypes.func.isRequired,
93
+ pathname: PropTypes.string.isRequired,
94
+ searchParams: PropTypes.instanceOf(URLSearchParams).isRequired
95
+ }),
96
+ /**
97
+ * Session info about the current user.
98
+ * @default null
99
+ */
100
+ session: PropTypes.shape({
101
+ user: PropTypes.shape({
102
+ email: PropTypes.string,
103
+ id: PropTypes.string,
104
+ image: PropTypes.string,
105
+ name: PropTypes.string
106
+ })
107
+ }),
108
+ /**
109
+ * [Theme or themes](https://mui.com/toolpad/core/react-app-provider/#theming) to be used by the app in light/dark mode. A [CSS variables theme](https://mui.com/material-ui/customization/css-theme-variables/overview/) is recommended.
110
+ * @default createTheme()
111
+ */
112
+ theme: PropTypes.object,
113
+ /**
114
+ * The window where the application is rendered.
115
+ * This is needed when rendering the app inside an iframe, for example.
116
+ * @default window
117
+ */
118
+ window: PropTypes.object
119
+ };
120
+ export { AppProvider };
@@ -0,0 +1,12 @@
1
+ import * as React from "react";
2
+ import type { AppTheme } from "./AppProvider";
3
+ interface AppThemeProviderProps {
4
+ children: React.ReactNode;
5
+ theme: AppTheme;
6
+ window?: Window;
7
+ }
8
+ /**
9
+ * @ignore - internal component.
10
+ */
11
+ declare function AppThemeProvider(props: AppThemeProviderProps): import("react/jsx-runtime").JSX.Element;
12
+ export { AppThemeProvider };
@@ -0,0 +1,73 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { useMediaQuery } from "@mui/material";
4
+ import { ThemeProvider, useColorScheme } from "@mui/material/styles";
5
+ import InitColorSchemeScript from "@mui/material/InitColorSchemeScript";
6
+ import CssBaseline from "@mui/material/CssBaseline";
7
+ import invariant from "invariant";
8
+ import { useLocalStorageState } from "../useLocalStorageState";
9
+ import { PaletteModeContext } from "../shared/context";
10
+ const COLOR_SCHEME_ATTRIBUTE = "data-toolpad-color-scheme";
11
+ const COLOR_SCHEME_STORAGE_KEY = "toolpad-color-scheme";
12
+ const MODE_STORAGE_KEY = "toolpad-mode";
13
+ function usePreferredMode(window) {
14
+ const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)", window && {
15
+ matchMedia: window.matchMedia
16
+ });
17
+ return prefersDarkMode ? "dark" : "light";
18
+ }
19
+ function isCssVarsTheme(theme) {
20
+ return "vars" in theme;
21
+ }
22
+ /**
23
+ * Compatibility layer for classic v5 themes. It will handle state management for the theme switcher.
24
+ * In the v6 theme, this state management is handled by `useColorScheme`. But this hook will crash if
25
+ * not run under context with a css vars theme.
26
+ */
27
+ function LegacyThemeProvider(props) {
28
+ const { children, theme, window: appWindow } = props;
29
+ invariant(!isCssVarsTheme(theme), "This provider only accepts legacy themes.");
30
+ const isDualTheme = "light" in theme || "dark" in theme;
31
+ const preferredMode = usePreferredMode(appWindow);
32
+ const [userMode, setUserMode] = useLocalStorageState(MODE_STORAGE_KEY, "system");
33
+ const paletteMode = !userMode || userMode === "system" ? preferredMode : userMode;
34
+ const dualAwareTheme = React.useMemo(() => isDualTheme
35
+ ? theme[paletteMode === "dark" ? "dark" : "light"] ??
36
+ theme[paletteMode === "dark" ? "light" : "dark"]
37
+ : theme, [isDualTheme, paletteMode, theme]);
38
+ // The v5 shim, based on local state
39
+ const paletteModeContextValue = React.useMemo(() => ({
40
+ paletteMode,
41
+ setPaletteMode: setUserMode,
42
+ isDualTheme
43
+ }), [isDualTheme, paletteMode, setUserMode]);
44
+ return (_jsx(ThemeProvider, { theme: dualAwareTheme, children: _jsxs(PaletteModeContext.Provider, { value: paletteModeContextValue, children: [_jsx(CssBaseline, { enableColorScheme: true }), children] }) }));
45
+ }
46
+ function CssVarsPaletteModeProvider(props) {
47
+ const { children, window: appWindow } = props;
48
+ const preferredMode = usePreferredMode(appWindow);
49
+ const { mode, setMode, allColorSchemes } = useColorScheme();
50
+ // The v6 API, based on `useColorScheme`
51
+ const paletteModeContextValue = React.useMemo(() => {
52
+ return {
53
+ paletteMode: !mode || mode === "system" ? preferredMode : mode,
54
+ setPaletteMode: setMode,
55
+ isDualTheme: allColorSchemes.length > 1
56
+ };
57
+ }, [allColorSchemes, mode, preferredMode, setMode]);
58
+ return (_jsx(PaletteModeContext.Provider, { value: paletteModeContextValue, children: children }));
59
+ }
60
+ function CssVarsThemeProvider(props) {
61
+ const { children, theme, window: appWindow } = props;
62
+ invariant(isCssVarsTheme(theme), "This provider only accepts CSS vars themes.");
63
+ return (_jsxs(ThemeProvider, { theme: theme, documentNode: appWindow?.document, colorSchemeNode: appWindow?.document.documentElement, disableNestedContext: true, colorSchemeStorageKey: COLOR_SCHEME_STORAGE_KEY, modeStorageKey: MODE_STORAGE_KEY, children: [_jsx(InitColorSchemeScript, { attribute: COLOR_SCHEME_ATTRIBUTE, colorSchemeStorageKey: COLOR_SCHEME_STORAGE_KEY, modeStorageKey: MODE_STORAGE_KEY }), _jsxs(CssVarsPaletteModeProvider, { window: appWindow, children: [_jsx(CssBaseline, { enableColorScheme: true }), children] })] }));
64
+ }
65
+ /**
66
+ * @ignore - internal component.
67
+ */
68
+ function AppThemeProvider(props) {
69
+ const { children, theme, ...rest } = props;
70
+ const useCssVarsProvider = isCssVarsTheme(theme);
71
+ return useCssVarsProvider ? (_jsx(CssVarsThemeProvider, { theme: theme, ...rest, children: children })) : (_jsx(LegacyThemeProvider, { theme: theme, ...rest, children: children }));
72
+ }
73
+ export { AppThemeProvider };
@@ -0,0 +1 @@
1
+ export * from "./AppProvider";
@@ -0,0 +1 @@
1
+ export * from "./AppProvider";
@@ -0,0 +1,83 @@
1
+ import * as React from "react";
2
+ import { type Theme, SxProps } from "@mui/material";
3
+ import { type AccountProps } from "../Account";
4
+ export interface SidebarFooterProps {
5
+ mini: boolean;
6
+ }
7
+ export interface DashboardLayoutSlotProps {
8
+ toolbarActions?: {};
9
+ toolbarAccount?: AccountProps;
10
+ sidebarFooter?: SidebarFooterProps;
11
+ }
12
+ export interface DashboardLayoutSlots {
13
+ /**
14
+ * The toolbar actions component used in the layout header.
15
+ * @default ToolbarActions
16
+ */
17
+ toolbarActions?: React.JSXElementConstructor<{}>;
18
+ /**
19
+ * The toolbar account component used in the layout header.
20
+ * @default Account
21
+ */
22
+ toolbarAccount?: React.JSXElementConstructor<AccountProps>;
23
+ /**
24
+ * Optional footer component used in the layout sidebar.
25
+ * @default null
26
+ */
27
+ sidebarFooter?: React.JSXElementConstructor<SidebarFooterProps>;
28
+ }
29
+ export interface DashboardLayoutProps {
30
+ /**
31
+ * The content of the dashboard.
32
+ */
33
+ children: React.ReactNode;
34
+ /**
35
+ * Whether the sidebar should not be collapsible to a mini variant in desktop and tablet viewports.
36
+ * @default false
37
+ */
38
+ disableCollapsibleSidebar?: boolean;
39
+ /**
40
+ * Whether the sidebar should start collapsed in desktop size screens.
41
+ * @default false
42
+ */
43
+ defaultSidebarCollapsed?: boolean;
44
+ /**
45
+ * Whether the navigation bar and menu icon should be hidden
46
+ * @default false
47
+ */
48
+ hideNavigation?: boolean;
49
+ /**
50
+ * Width of the sidebar when expanded.
51
+ * @default 320
52
+ */
53
+ sidebarExpandedWidth?: number | string;
54
+ /**
55
+ * The components used for each slot inside.
56
+ * @default {}
57
+ */
58
+ slots?: DashboardLayoutSlots;
59
+ /**
60
+ * The props used for each slot inside.
61
+ * @default {}
62
+ */
63
+ slotProps?: DashboardLayoutSlotProps;
64
+ /**
65
+ * The system prop that allows defining system overrides as well as additional CSS styles.
66
+ */
67
+ sx?: SxProps<Theme>;
68
+ }
69
+ /**
70
+ *
71
+ * Demos:
72
+ *
73
+ * - [Dashboard Layout](https://mui.com/toolpad/core/react-dashboard-layout/)
74
+ *
75
+ * API:
76
+ *
77
+ * - [DashboardLayout API](https://mui.com/toolpad/core/api/dashboard-layout)
78
+ */
79
+ declare function DashboardLayout(props: DashboardLayoutProps): import("react/jsx-runtime").JSX.Element;
80
+ declare namespace DashboardLayout {
81
+ var propTypes: any;
82
+ }
83
+ export { DashboardLayout };