Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Improve Toolpad Core docs #43796

Merged
merged 20 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/data/material/components/app-bar/app-bar.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ You can override this behavior by setting the `enableColorOnDark` prop to `true`

{{"demo": "EnableColorOnDarkAppBar.js", "bg": true}}

## Experimental APIs
## Toolpad
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

### DashboardLayout
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 2 additions & 2 deletions docs/data/material/components/breadcrumbs/breadcrumbs.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ The accessibility of this component relies on:
- To prevent screen reader announcement of the visual separators between links, they are hidden with `aria-hidden`.
- A nav element labeled with `aria-label` identifies the structure as a breadcrumb trail and makes it a navigation landmark so that it is easy to locate.

## Experimental APIs
## Toolpad

### Page Container

The [PageContainer](https://mui.com/toolpad/core/react-page-container/) component in `@toolpad/core` is the ideal wrapper for the content of your dashboard. It makes the Material UI Container navigation aware and extends it with page title, breadcrumbs, actions, and more.
The [PageContainer](https://mui.com/toolpad/core/react-page-container/) component in `@toolpad/core` is the ideal wrapper for the content of your dashboard. It makes the Material UI Container navigation-aware and extends it with page title, breadcrumbs, actions, and more.

{{"demo": "./PageContainerBasic.js", "height": 400, "hideToolbar": true}}
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions docs/data/material/components/container/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ The max-width matches the min-width of the current breakpoint.
<Container fixed>
```

## Experimental APIs
## Toolpad

### Page Container

The [PageContainer](https://mui.com/toolpad/core/react-page-container/) component in `@toolpad/core` is the ideal wrapper for the content of your dashboard. It makes the Material UI Container navigation aware and extends it with page title, breadcrumbs, actions, and more.
The [PageContainer](https://mui.com/toolpad/core/react-page-container/) component in `@toolpad/core` is the ideal wrapper for the content of your dashboard. It makes the Material UI Container navigation-aware and extends it with page title, breadcrumbs, actions, and more.

{{"demo": "../breadcrumbs/PageContainerBasic.js", "height": 400, "hideToolbar": true}}
Copy link
Member

@oliviertassinari oliviertassinari Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dark/light mode is broken on all those demos.

As far as I understand things, theme={demoTheme} shouldn't be provided, not be the AppProvider responsibility to have this. Imagine I already have an application configured with a theme, I want some of my pages to have a Toolpad container, this shouldn't break. I mean, https://marmelab.com/react-admin/Theming.html feels wrong, no?

At minimum, MUI System should support theme nesting where you can inherit the light/dark mode and use different values for the other values.

Copy link
Member

@oliviertassinari oliviertassinari Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const demoWindow = window !== undefined ? window() : undefined; feels confusing, I think it should copy

* Injected by the documentation to work in an iframe.

to be clear.

99 changes: 99 additions & 0 deletions docs/data/material/components/dialogs/ToolpadDialogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { DialogsProvider, useDialogs } from '@toolpad/core/useDialogs';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import DialogContent from '@mui/material/DialogContent';
import DialogActions from '@mui/material/DialogActions';

function MyCustomDialog({ open, onClose }) {
return (
<Dialog
fullWidth
open={open}
onClose={(event) => onClose?.(event, 'escapeKeyDown')}
>
<DialogTitle>Custom dialog</DialogTitle>
<DialogContent>I am a custom dialog</DialogContent>
<DialogActions>
<Button onClick={(event) => onClose?.(event, 'escapeKeyDown')}>
Close me
</Button>
</DialogActions>
</Dialog>
);
}

MyCustomDialog.propTypes = {
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback.
* @param {string} reason Can be: `"escapeKeyDown"`, `"backdropClick"`.
*/
onClose: PropTypes.func,
/**
* If `true`, the component is shown.
*/
open: PropTypes.bool.isRequired,
};

function DemoContent() {
const dialogs = useDialogs();
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
<Button
onClick={async () => {
await dialogs.open(MyCustomDialog);
}}
>
Open a custom dialog!
</Button>
<div style={{ display: 'flex', gap: 16 }}>
<Button
onClick={async () => {
await dialogs.alert('This is an alert dialog');
}}
>
Alert
</Button>
<Button
onClick={async () => {
const confirmed = await dialogs.confirm(
'Are you sure you want to delete this?',
{
okText: 'Confirm',
cancelText: 'Cancel',
},
);
if (confirmed) {
dialogs.alert('Deleted!');
}
}}
>
Confirm
</Button>
<Button
onClick={async () => {
const name = await dialogs.prompt('Enter your name', {
okText: 'Confirm',
cancelText: 'Cancel',
});
dialogs.alert(`Hello, ${name}!`);
}}
>
Prompt
</Button>
</div>
</div>
);
}

export default function ToolpadDialogs() {
return (
<DialogsProvider>
<DemoContent />
</DialogsProvider>
);
}
88 changes: 88 additions & 0 deletions docs/data/material/components/dialogs/ToolpadDialogs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import * as React from 'react';
import { DialogsProvider, useDialogs } from '@toolpad/core/useDialogs';
import Button from '@mui/material/Button';
import Dialog, { DialogProps } from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import DialogContent from '@mui/material/DialogContent';
import DialogActions from '@mui/material/DialogActions';

function MyCustomDialog({ open, onClose }: Pick<DialogProps, 'open' | 'onClose'>) {
return (
<Dialog
fullWidth
open={open}
onClose={(event: React.SyntheticEvent) => onClose?.(event, 'escapeKeyDown')}
>
<DialogTitle>Custom dialog</DialogTitle>
<DialogContent>I am a custom dialog</DialogContent>
<DialogActions>
<Button
onClick={(event: React.SyntheticEvent) =>
onClose?.(event, 'escapeKeyDown')
}
>
Close me
</Button>
</DialogActions>
</Dialog>
);
}

function DemoContent() {
const dialogs = useDialogs();
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
<Button
onClick={async () => {
await dialogs.open(MyCustomDialog);
}}
>
Open a custom dialog!
</Button>
<div style={{ display: 'flex', gap: 16 }}>
<Button
onClick={async () => {
await dialogs.alert('This is an alert dialog');
}}
>
Alert
</Button>
<Button
onClick={async () => {
const confirmed = await dialogs.confirm(
'Are you sure you want to delete this?',
{
okText: 'Confirm',
cancelText: 'Cancel',
},
);
if (confirmed) {
dialogs.alert('Deleted!');
}
}}
>
Confirm
</Button>
<Button
onClick={async () => {
const name = await dialogs.prompt('Enter your name', {
okText: 'Confirm',
cancelText: 'Cancel',
});
dialogs.alert(`Hello, ${name}!`);
}}
>
Prompt
</Button>
</div>
</div>
);
}

export default function ToolpadDialogs() {
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
return (
<DialogsProvider>
<DemoContent />
</DialogsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<DialogsProvider>
<DemoContent />
</DialogsProvider>
8 changes: 5 additions & 3 deletions docs/data/material/components/dialogs/dialogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ The package [`material-ui-confirm`](https://github.com/jonatanklosko/material-ui

Follow the [Modal accessibility section](/material-ui/react-modal/#accessibility).

## Experimental APIs
## Toolpad

### Imperative API
### `useDialogs`
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

You can create and manipulate dialogs imperatively with the [`useDialog`](https://mui.com/toolpad/core/react-use-dialogs/) API in `@toolpad/core`. This API provides state management for opening and closing dialogs and for passing data to the dialog and back. It allows for stacking multiple dialogs. It also provides themed alternatives for `window.alert`, `window.confirm` and `window.prompt`.
You can create and manipulate dialogs imperatively with the [`useDialogs`](https://mui.com/toolpad/core/react-use-dialogs/) API in `@toolpad/core`. This API provides state management for opening and closing dialogs and for passing data to the dialog and back. It allows for stacking multiple dialogs. It also provides themed alternatives for `window.alert`, `window.confirm` and `window.prompt`.
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

{{"demo": "ToolpadDialogs.js", "defaultCodeOpen": false}}
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion docs/data/material/components/drawers/drawers.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Apps focused on productivity that require balance across the screen.

{{"demo": "ClippedDrawer.js", "iframe": true}}

## Experimental APIs
## Toolpad

### DashboardLayout
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
27 changes: 27 additions & 0 deletions docs/data/material/components/snackbars/ToolpadNotifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import {
useNotifications,
NotificationsProvider,
} from '@toolpad/core/useNotifications';
import Button from '@mui/material/Button';

export default function ToolpadNotifications() {
const notifications = useNotifications();
return (
<NotificationsProvider>
<div>
<Button
onClick={() => {
// preview-start
notifications.show('Consider yourself notified!', {
autoHideDuration: 3000,
});
// preview-end
}}
>
Notify me
</Button>
</div>
</NotificationsProvider>
);
}
29 changes: 29 additions & 0 deletions docs/data/material/components/snackbars/ToolpadNotifications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';
import {
useNotifications,
NotificationsProvider,
} from '@toolpad/core/useNotifications';
import Button from '@mui/material/Button';

function NotifyButton() {
const notifications = useNotifications();
return (
<Button
onClick={() => {
notifications.show('Consider yourself notified!', {
autoHideDuration: 3000,
});
}}
>
Notify me
</Button>
);
}

export default function ToolpadNotifications() {
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
return (
<NotificationsProvider>
<NotifyButton />
</NotificationsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<NotificationsProvider>
<div>
<Button
onClick={() => {
// preview-start
notifications.show('Consider yourself notified!', {
autoHideDuration: 3000,
});
// preview-end
}}
>
Notify me
</Button>
</div>
</NotificationsProvider>
6 changes: 4 additions & 2 deletions docs/data/material/components/snackbars/snackbars.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ The Snackbar component is composed of a root `<div>` that houses interior elemen
</div>
```

## Experimental APIs
## Toolpad
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

### Imperative API
### `useNotifications`

You can create and manipulate notifications imperatively with the [`useNotifications`](https://mui.com/toolpad/core/react-use-notifications/) API in `@toolpad/core`. This API provides state management for opening and closing snackbars. It also allows for queueing multiple notifications at once.
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

{{"demo": "ToolpadNotifications.js", "defaultCodeOpen": false}}
2 changes: 1 addition & 1 deletion docs/data/material/getting-started/templates/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ Looking for something more? You can find complete templates and themes in the <a

## Toolpad Core (beta)

[Toolpad Core](https://mui.com/toolpad/core/introduction/) is a framework designed to build dashboards and internal tools. It leverages the existing suite of components offered by Material UI and ties them together to help you create applications quickly.
[Toolpad Core](https://mui.com/toolpad/core/introduction/) is a set of components designed to build dashboards and internal tools. It leverages the existing suite of components offered by Material UI and ties them together to help you create applications quickly.

{{"demo": "../../components/app-bar/DashboardLayoutBasic.js", "height": 400, "iframe": true, "hideToolbar": true}}
Loading