@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.
- package/.github/workflows/main.yml +49 -0
- package/.vscode/settings.json +3 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/build/src/Account/Account.d.ts +71 -0
- package/build/src/Account/Account.js +117 -0
- package/build/src/Account/Account.test.d.ts +1 -0
- package/build/src/Account/Account.test.js +35 -0
- package/build/src/Account/AccountPopoverFooter.d.ts +6 -0
- package/build/src/Account/AccountPopoverFooter.js +21 -0
- package/build/src/Account/AccountPopoverHeader.d.ts +6 -0
- package/build/src/Account/AccountPopoverHeader.js +15 -0
- package/build/src/Account/AccountPreview.d.ts +67 -0
- package/build/src/Account/AccountPreview.js +76 -0
- package/build/src/Account/AccountPreview.test.d.ts +1 -0
- package/build/src/Account/AccountPreview.test.js +47 -0
- package/build/src/Account/SignInButton.d.ts +2 -0
- package/build/src/Account/SignInButton.js +26 -0
- package/build/src/Account/SignOutButton.d.ts +3 -0
- package/build/src/Account/SignOutButton.js +28 -0
- package/build/src/Account/index.d.ts +6 -0
- package/build/src/Account/index.js +6 -0
- package/build/src/AppProvider/AppProvider.d.ts +98 -0
- package/build/src/AppProvider/AppProvider.js +4 -0
- package/build/src/AppProvider/AppProvider.test.d.ts +4 -0
- package/build/src/AppProvider/AppProvider.test.js +16 -0
- package/build/src/AppProvider/AppProviderComponent.d.ts +17 -0
- package/build/src/AppProvider/AppProviderComponent.js +120 -0
- package/build/src/AppProvider/AppThemeProvider.d.ts +12 -0
- package/build/src/AppProvider/AppThemeProvider.js +73 -0
- package/build/src/AppProvider/index.d.ts +1 -0
- package/build/src/AppProvider/index.js +1 -0
- package/build/src/DashboardLayout/DashboardLayout.d.ts +83 -0
- package/build/src/DashboardLayout/DashboardLayout.js +286 -0
- package/build/src/DashboardLayout/DashboardLayout.test.d.ts +1 -0
- package/build/src/DashboardLayout/DashboardLayout.test.js +291 -0
- package/build/src/DashboardLayout/DashboardSidebarSubNavigation.d.ts +16 -0
- package/build/src/DashboardLayout/DashboardSidebarSubNavigation.js +149 -0
- package/build/src/DashboardLayout/ThemeSwitcher.d.ts +5 -0
- package/build/src/DashboardLayout/ThemeSwitcher.js +40 -0
- package/build/src/DashboardLayout/ToolbarActions.d.ts +5 -0
- package/build/src/DashboardLayout/ToolbarActions.js +9 -0
- package/build/src/DashboardLayout/index.d.ts +2 -0
- package/build/src/DashboardLayout/index.js +3 -0
- package/build/src/DashboardLayout/utils.d.ts +8 -0
- package/build/src/DashboardLayout/utils.js +16 -0
- package/build/src/PageContainer/PageContainer.d.ts +66 -0
- package/build/src/PageContainer/PageContainer.js +97 -0
- package/build/src/PageContainer/PageContainer.test.d.ts +1 -0
- package/build/src/PageContainer/PageContainer.test.js +127 -0
- package/build/src/PageContainer/PageContainerToolbar.d.ts +16 -0
- package/build/src/PageContainer/PageContainerToolbar.js +24 -0
- package/build/src/PageContainer/PageContainerToolbar.test.d.ts +1 -0
- package/build/src/PageContainer/PageContainerToolbar.test.js +10 -0
- package/build/src/PageContainer/index.d.ts +2 -0
- package/build/src/PageContainer/index.js +2 -0
- package/build/src/index.d.ts +8 -0
- package/build/src/index.js +8 -0
- package/build/src/nextjs/AppProvider.d.ts +6 -0
- package/build/src/nextjs/AppProvider.js +16 -0
- package/build/src/nextjs/AppProvider.test.d.ts +1 -0
- package/build/src/nextjs/AppProvider.test.js +36 -0
- package/build/src/nextjs/AppProviderNextApp.d.ts +5 -0
- package/build/src/nextjs/AppProviderNextApp.js +27 -0
- package/build/src/nextjs/AppProviderNextPages.d.ts +5 -0
- package/build/src/nextjs/AppProviderNextPages.js +37 -0
- package/build/src/nextjs/index.d.ts +1 -0
- package/build/src/nextjs/index.js +1 -0
- package/build/src/persistence/codec.d.ts +47 -0
- package/build/src/persistence/codec.js +57 -0
- package/build/src/persistence/index.d.ts +1 -0
- package/build/src/persistence/index.js +1 -0
- package/build/src/persistence/useStorageState.d.ts +50 -0
- package/build/src/persistence/useStorageState.js +116 -0
- package/build/src/persistence/useStorageState.test.d.ts +1 -0
- package/build/src/persistence/useStorageState.test.js +61 -0
- package/build/src/react-router-dom/AppProvider.d.ts +6 -0
- package/build/src/react-router-dom/AppProvider.js +29 -0
- package/build/src/react-router-dom/AppProvider.test.d.ts +1 -0
- package/build/src/react-router-dom/AppProvider.test.js +12 -0
- package/build/src/react-router-dom/index.d.ts +1 -0
- package/build/src/react-router-dom/index.js +1 -0
- package/build/src/shared/Link.d.ts +8 -0
- package/build/src/shared/Link.js +19 -0
- package/build/src/shared/branding.d.ts +1 -0
- package/build/src/shared/branding.js +6 -0
- package/build/src/shared/components.d.ts +5 -0
- package/build/src/shared/components.js +23 -0
- package/build/src/shared/context.d.ts +12 -0
- package/build/src/shared/context.js +10 -0
- package/build/src/shared/locales/LocaleContext.d.ts +19 -0
- package/build/src/shared/locales/LocaleContext.js +18 -0
- package/build/src/shared/locales/en.d.ts +6 -0
- package/build/src/shared/locales/en.js +8 -0
- package/build/src/shared/navigation.d.ts +16 -0
- package/build/src/shared/navigation.js +129 -0
- package/build/src/useActivePage/index.d.ts +1 -0
- package/build/src/useActivePage/index.js +1 -0
- package/build/src/useActivePage/useActivePage.d.ts +11 -0
- package/build/src/useActivePage/useActivePage.js +48 -0
- package/build/src/useLocalStorageState/index.d.ts +1 -0
- package/build/src/useLocalStorageState/index.js +1 -0
- package/build/src/useLocalStorageState/useLocalStorageState.d.ts +2 -0
- package/build/src/useLocalStorageState/useLocalStorageState.js +14 -0
- package/build/src/useSessionStorageState/index.d.ts +1 -0
- package/build/src/useSessionStorageState/index.js +1 -0
- package/build/src/useSessionStorageState/useSessionStorageState.d.ts +2 -0
- package/build/src/useSessionStorageState/useSessionStorageState.js +14 -0
- package/build/src/utils/collections.d.ts +44 -0
- package/build/src/utils/collections.js +43 -0
- package/build/src/utils/describeConformance.d.ts +7 -0
- package/build/src/utils/describeConformance.js +3 -0
- package/build/src/utils/events.d.ts +27 -0
- package/build/src/utils/events.js +54 -0
- package/build/src/utils/hooks/index.d.ts +2 -0
- package/build/src/utils/hooks/index.js +2 -0
- package/build/src/utils/hooks/useBoolean.d.ts +11 -0
- package/build/src/utils/hooks/useBoolean.js +11 -0
- package/build/src/utils/hooks/useDebounced.d.ts +8 -0
- package/build/src/utils/hooks/useDebounced.js +28 -0
- package/build/src/utils/hooks/useDebouncedHandler.d.ts +12 -0
- package/build/src/utils/hooks/useDebouncedHandler.js +41 -0
- package/build/src/utils/hooks/useLatest.d.ts +6 -0
- package/build/src/utils/hooks/useLatest.js +9 -0
- package/build/src/utils/hooks/usePageTitle.d.ts +4 -0
- package/build/src/utils/hooks/usePageTitle.js +13 -0
- package/build/src/utils/hooks/useSsr.d.ts +4 -0
- package/build/src/utils/hooks/useSsr.js +16 -0
- package/build/src/utils/hooks/useStorageState.d.ts +10 -0
- package/build/src/utils/hooks/useStorageState.js +51 -0
- package/build/src/utils/warnOnce.d.ts +5 -0
- package/build/src/utils/warnOnce.js +11 -0
- package/build/vitest.setup.d.ts +1 -0
- package/build/vitest.setup.js +19 -0
- package/package.json +60 -0
- package/src/Account/Account.test.tsx +56 -0
- package/src/Account/Account.tsx +226 -0
- package/src/Account/AccountPopoverFooter.tsx +33 -0
- package/src/Account/AccountPopoverHeader.tsx +20 -0
- package/src/Account/AccountPreview.test.tsx +79 -0
- package/src/Account/AccountPreview.tsx +189 -0
- package/src/Account/SignInButton.tsx +38 -0
- package/src/Account/SignOutButton.tsx +44 -0
- package/src/Account/index.ts +6 -0
- package/src/AppProvider/AppProvider.test.tsx +25 -0
- package/src/AppProvider/AppProvider.tsx +116 -0
- package/src/AppProvider/AppProviderComponent.tsx +162 -0
- package/src/AppProvider/AppThemeProvider.tsx +177 -0
- package/src/AppProvider/index.ts +1 -0
- package/src/DashboardLayout/DashboardLayout.test.tsx +429 -0
- package/src/DashboardLayout/DashboardLayout.tsx +558 -0
- package/src/DashboardLayout/DashboardSidebarSubNavigation.tsx +301 -0
- package/src/DashboardLayout/ThemeSwitcher.tsx +81 -0
- package/src/DashboardLayout/ToolbarActions.tsx +11 -0
- package/src/DashboardLayout/index.ts +4 -0
- package/src/DashboardLayout/utils.ts +23 -0
- package/src/PageContainer/PageContainer.test.tsx +194 -0
- package/src/PageContainer/PageContainer.tsx +201 -0
- package/src/PageContainer/PageContainerToolbar.test.tsx +11 -0
- package/src/PageContainer/PageContainerToolbar.tsx +31 -0
- package/src/PageContainer/index.ts +2 -0
- package/src/index.ts +15 -0
- package/src/nextjs/AppProvider.test.tsx +48 -0
- package/src/nextjs/AppProvider.tsx +18 -0
- package/src/nextjs/AppProviderNextApp.tsx +37 -0
- package/src/nextjs/AppProviderNextPages.tsx +52 -0
- package/src/nextjs/index.tsx +1 -0
- package/src/persistence/codec.tsx +81 -0
- package/src/persistence/index.ts +1 -0
- package/src/persistence/useStorageState.test.tsx +101 -0
- package/src/persistence/useStorageState.tsx +244 -0
- package/src/react-router-dom/AppProvider.test.tsx +17 -0
- package/src/react-router-dom/AppProvider.tsx +40 -0
- package/src/react-router-dom/index.tsx +1 -0
- package/src/shared/Link.tsx +37 -0
- package/src/shared/branding.ts +7 -0
- package/src/shared/components.tsx +46 -0
- package/src/shared/context.ts +21 -0
- package/src/shared/locales/LocaleContext.tsx +44 -0
- package/src/shared/locales/en.tsx +9 -0
- package/src/shared/navigation.tsx +197 -0
- package/src/useActivePage/index.ts +1 -0
- package/src/useActivePage/useActivePage.ts +66 -0
- package/src/useLocalStorageState/index.ts +1 -0
- package/src/useLocalStorageState/useLocalStorageState.tsx +23 -0
- package/src/useSessionStorageState/index.tsx +1 -0
- package/src/useSessionStorageState/useSessionStorageState.tsx +23 -0
- package/src/utils/collections.ts +125 -0
- package/src/utils/describeConformance.ts +14 -0
- package/src/utils/events.ts +81 -0
- package/src/utils/hooks/index.ts +2 -0
- package/src/utils/hooks/useBoolean.ts +12 -0
- package/src/utils/hooks/useDebounced.ts +39 -0
- package/src/utils/hooks/useDebouncedHandler.ts +71 -0
- package/src/utils/hooks/useLatest.ts +16 -0
- package/src/utils/hooks/usePageTitle.ts +14 -0
- package/src/utils/hooks/useSsr.ts +24 -0
- package/src/utils/hooks/useStorageState.ts +130 -0
- package/src/utils/warnOnce.ts +12 -0
- package/tsconfig.json +19 -0
- package/vite.config.ts +27 -0
- 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,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 };
|