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] Add integration, base concepts #4080

Merged
merged 30 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
aa2b060
docs: Add integration, base concepts
bharatkashyap Sep 11, 2024
b3eab0b
fix: Why
bharatkashyap Sep 11, 2024
0707dcd
fix: Add `pages` router and images
bharatkashyap Sep 11, 2024
e69e9f8
fix: Add callout to base concepts on demo pages
bharatkashyap Sep 11, 2024
9fc9e35
Merge branch 'master' into docs/integration-base-concepts
bharatkashyap Sep 11, 2024
4e5bb30
Merge branch 'master' into docs/integration-base-concepts
bharatkashyap Sep 11, 2024
fd6e9c5
fix: `markdownlint`
bharatkashyap Sep 12, 2024
9242e60
Merge branch 'master' into docs/integration-base-concepts
bharatkashyap Sep 12, 2024
7390686
Update docs/data/toolpad/core/introduction/base-concepts.md
bharatkashyap Sep 12, 2024
04aae8a
Update docs/data/toolpad/core/introduction/base-concepts.md
bharatkashyap Sep 12, 2024
ebfd494
Merge branch 'master' into docs/integration-base-concepts
bharatkashyap Sep 12, 2024
44cb7ab
fix: Typo
bharatkashyap Sep 12, 2024
22623b9
fix: Make `AppProvider` props section leaner
bharatkashyap Sep 13, 2024
5c61022
Update docs/data/toolpad/core/introduction/base-concepts.md
bharatkashyap Sep 16, 2024
ec87f74
Update docs/data/toolpad/core/pages.ts
bharatkashyap Sep 16, 2024
0b586a2
Update docs/data/toolpad/core/introduction/base-concepts.md
bharatkashyap Sep 16, 2024
3c9e8e6
Update docs/data/toolpad/core/introduction/integration.md
bharatkashyap Sep 16, 2024
420cfdc
Update docs/data/toolpad/core/introduction/integration.md
bharatkashyap Sep 16, 2024
d95c67b
Merge branch 'master' of github.com:mui/mui-toolpad into docs/integra…
bharatkashyap Sep 17, 2024
d5f86a3
fix: Review
bharatkashyap Sep 17, 2024
4a2090e
Merge branch 'master' of github.com:mui/mui-toolpad into docs/integra…
bharatkashyap Sep 18, 2024
9b8ce2f
Update docs/data/toolpad/core/components/persistent-state/persistent-…
bharatkashyap Sep 20, 2024
8d523d6
Update docs/data/toolpad/core/components/account/account.md
bharatkashyap Sep 20, 2024
2f5ce91
fix: Jan review
bharatkashyap Sep 20, 2024
f1d721e
Merge branch 'master' of github.com:mui/mui-toolpad into docs/integra…
bharatkashyap Sep 20, 2024
bfe7258
fix: CI
bharatkashyap Sep 20, 2024
9e654e8
fix: Use `success` instead
bharatkashyap Sep 20, 2024
87931b1
Merge branch 'master' into docs/integration-base-concepts
bharatkashyap Sep 20, 2024
9b780e6
Merge branch 'master' into docs/integration-base-concepts
bharatkashyap Sep 20, 2024
d2e1106
Merge branch 'master' into docs/integration-base-concepts
bharatkashyap Sep 20, 2024
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
4 changes: 4 additions & 0 deletions docs/data/toolpad/core/components/account/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ components: Account

<p class="description">A component that renders an account management dropdown for your application.</p>

:::info
If this is your first time using Toolpad Core, you might want to start with the [base concepts](/docs/data/toolpad/core/introduction/base-concepts/) instead.
:::

The `Account` component is a quick and easy way to display an account management menu for authenticated users. It is deeply integrated with the `SignInPage` and `DashboardLayout` components, meaning that it automatically appears in the top navigation bar inside `DashboardLayout` once your users have signed in through the `SignInPage`.

## States
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ components: AppProvider

<p class="description">The app provider component provides the necessary context to easily set up a Toolpad application.</p>

:::info
If this is your first time using Toolpad Core, you might want to start with the [base concepts](/docs/data/toolpad/core/introduction/base-concepts/) instead.
:::

By wrapping an application at the root level with an `AppProvider` component, many of Toolpad's features (such as routing, navigation and theming) can be automatically enabled to their fullest extent, abstracting away complexity and helping you focus on the details that matter.

It is not mandatory that every application is wrapped in an `AppProvider`, but it is highly recommended for most apps that use Toolpad.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ components: AppProvider, DashboardLayout, Account

<p class="description">The dashboard layout component provides a customizable out-of-the-box layout for a typical dashboard page.</p>

:::info
If this is your first time using Toolpad Core, you might want to start with the [base concepts](/docs/data/toolpad/core/introduction/base-concepts/) instead.
:::

The `DashboardLayout` component is a quick, easy way to provide a standard full-screen layout with a header and sidebar to any dashboard page, as well as ready-to-use and easy to customize navigation and branding.

Many features of this component are configurable through the [AppProvider](https://mui.com/toolpad/core/react-app-provider/) component that should wrap it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ components: PageContainer, PageContainerToolbar

<p class="description">A component that wraps page content and provides a title, breadcrumbs, and page actions.</p>

:::info
If this is your first time using Toolpad Core, you might want to start with the [base concepts](/docs/data/toolpad/core/introduction/base-concepts/) instead.
:::

`PageContent` is the ideal wrapper for the content of your dashboard. It shows the current page title, and provides breadcrumbs to navigate back into the current hierarchy. It makes your page responsive through the use of the Material&nbsp;UI Container component under the hood.

Just like [`DashboardLayout`](/toolpad/core/react-dashboard-layout/), `PageContainer` uses the navigation structure that is defined in the [`AppProvider`](/toolpad/core/react-app-provider/) to build up its breadcrumbs and title.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

<p class="description">Hooks for synchronizing React state with browser storage.</p>

Toolpad provides a set of primitives that harmonize how you deal with persisting global state in the browser. Through our hooks you can synchronise React state with local storage or session storage, or in the url as a query parameter. These hooks all follow a similar philosophy: they identify their data with a unique key and support rich data types through the use of codecs.
:::info
If this is your first time using Toolpad Core, you might want to start with the [base concepts](/docs/data/toolpad/core/introduction/base-concepts/) instead.
:::

Toolpad Core provides a set of primitives that harmonize how you deal with persisting global state in the browser. Through our hooks you can synchronise React state with local storage or session storage, or in the url as a query parameter. These hooks all follow a similar philosophy: they identify their data with a unique key and support rich data types through the use of codecs.

Check warning on line 14 in docs/data/toolpad/core/components/persistent-state/persistent-state.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.We] Try to avoid using first-person plural like 'our'. Raw Output: {"message": "[Google.We] Try to avoid using first-person plural like 'our'.", "location": {"path": "docs/data/toolpad/core/components/persistent-state/persistent-state.md", "range": {"start": {"line": 14, "column": 124}}}, "severity": "WARNING"}
bharatkashyap marked this conversation as resolved.
Show resolved Hide resolved

The hook's signature intentionally resembles the `React.useState` hook. Where the first parameter represents the key under which to store the state in the browser, and the second parameter corresponds to the initial value. An optional third parameter can be used to configure the hook.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ components: SignInPage, Account, NotificationsProvider

<p class="description">A customizable sign-in UI component that abstracts away the pain needed to wire together a secure authentication page for your application.</p>

:::info
If this is your first time using Toolpad Core, you might want to start with the [base concepts](/docs/data/toolpad/core/introduction/base-concepts/) instead.
:::

The `SignInPage` component is a quick way to generate a ready-to-use authentication page with multiple OAuth providers, or a credentials form.

## OAuth
Expand Down
6 changes: 5 additions & 1 deletion docs/data/toolpad/core/components/use-dialogs/use-dialogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ components: DialogsProvider

<p class="description">Imperative APIs to open and interact with dialogs.</p>

Toolpad core offers a set of abstractions that makes interacting with dialogs simpler. It has an imperative API to open and close dialogs, and allows dialogs to be stacked on top of each other.
:::info
If this is your first time using Toolpad Core, you might want to start with the [base concepts](/docs/data/toolpad/core/introduction/base-concepts/) instead.
Copy link
Member

Choose a reason for hiding this comment

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

This link is taking me to a 404 in the preview.

:::

Toolpad Core offers a set of abstractions that makes interacting with dialogs simpler. It has an imperative API to open and close dialogs, and allows dialogs to be stacked on top of each other.

First thing you need to do is install the DialogsProvider at the root of your application.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ components: NotificationsProvider

<p class="description">Imperative APIs to show and interact with application notifications.</p>

Toolpad core offers a set of abstractions that make it easier to interact with notifications. Notifications are used to give short updates to the user about things that are happening during the application lifetime. They appear at the bottom of the screen. The Toolpad API allows for opening multiple notifications concurrenlty.
:::info
If this is your first time using Toolpad Core, you might want to start with the [base concepts](/docs/data/toolpad/core/introduction/base-concepts/) instead.
:::

Toolpad Core offers a set of abstractions that make it easier to interact with notifications. Notifications are used to give short updates to the user about things that are happening during the application lifetime. They appear at the bottom of the screen. The Toolpad API allows for opening multiple notifications concurrenlty.

First thing you need to do to get access to the notifications APIs is install the NotificationsProvider.

Expand Down
173 changes: 173 additions & 0 deletions docs/data/toolpad/core/introduction/base-concepts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
---
title: Toolpad Core - Base Concepts
---

# Base Concepts
bharatkashyap marked this conversation as resolved.
Show resolved Hide resolved

<p class="description">Understanding the fundamental concepts of Toolpad Core to effectively integrate and use it in your projects.</p>
bharatkashyap marked this conversation as resolved.
Show resolved Hide resolved

## Imports

Toolpad Core components can be imported directly from the `@toolpad/core` package. This allows you to use them alongside your existing Material UI or other components.

Check failure on line 11 in docs/data/toolpad/core/introduction/base-concepts.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [MUI.MuiBrandName] Use a non-breaking space (option+space on Mac, Alt+0160 on Windows or AltGr+Space on Linux, instead of space) for brand name ('Material UI' instead of 'Material UI') Raw Output: {"message": "[MUI.MuiBrandName] Use a non-breaking space (option+space on Mac, Alt+0160 on Windows or AltGr+Space on Linux, instead of space) for brand name ('Material UI' instead of 'Material UI')", "location": {"path": "docs/data/toolpad/core/introduction/base-concepts.md", "range": {"start": {"line": 11, "column": 136}}}, "severity": "ERROR"}
bharatkashyap marked this conversation as resolved.
Show resolved Hide resolved

```tsx
import { Button } from '@mui/material';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
```

## Component Hierarchy

The Toolpad Core library is designed to work within your existing React application structure. The key component in this hierarchy is the `AppProvider`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The Toolpad Core library is designed to work within your existing React application structure. The key component in this hierarchy is the `AppProvider`.
The Toolpad Core library is designed to work under different React runtimes such as Next.js, vite, or even your custom setup. Many of its components rely on specific functionality of the runtime it's used under. For example: routing. The key component in making the components runtime aware is the `AppProvider` component.


### App Provider

The `AppProvider` acts as a bridge between your application's runtime and Toolpad components. It should wrap your entire application or the part of your application where you want to use Toolpad components.

```tsx
import { AppProvider } from '@toolpad/core/AppProvider';

function MyApp({ Component, pageProps }) {
return (
<AppProvider>
<Component {...pageProps} />
</AppProvider>
);
}
```

By wrapping your application with `AppProvider`, you ensure that all other Toolpad components you use have access to the necessary context and functionality.

#### AppProvider Props
Copy link
Member

Choose a reason for hiding this comment

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

Aren't these already documented in the specific pages for the AppProvider?
If we're repeating it here it's also another part of documentation that we're going to keep up to date with any upcoming changes.

Copy link
Member

@apedroferreira apedroferreira Sep 12, 2024

Choose a reason for hiding this comment

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

Oh I see they're actually covered more in the DashboardLayout.
But maybe they could be described in the AppProvider documentation and we could link to there from here?
And keep this part in this page more generic and less specific to implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could do that to reduce maintenance load. The intention behind me doing this here is considering that this page could be something that a prospective user reads first before installing any components - so to make this document a "pitch", it should be the smoothest experience possible, which to me means fewer links, more inline demos. Let me know if that makes sense to you.

Copy link
Member

@apedroferreira apedroferreira Sep 12, 2024

Choose a reason for hiding this comment

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

I just think we can be a bit more generic here and not cover every AppProvider prop as extensively which is a bit too much information also... So just mentioning the most important things here: probably routing, theming, authentication... in a more general way. We can have code examples /demos too, just maybe condense and stick to the most important features as opposed to listing and describing every prop.

But it's also something we can discuss and do later if it's not super consensual.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree with covering it more generally and not overloading with information - you're right! I'll change this a bit

Copy link
Member

Choose a reason for hiding this comment

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

I agree with Pedro, I would even remove the one line explainers for each prop and directly show a code demo like below. It should give users the basic idea.

<AppProvider
              navigation={NAVIGATION}
              branding={BRANDING}
              session={session}
              theme={theme}
              authentication={AUTHENTICATION}
            >
              {props.children}
</AppProvider>


The `AppProvider` component accepts the following props:

- `theme`: The theme to be used by the app in light/dark mode. If you are using [Material UI with a custom theme](https://mui.com/material-ui/customization/theming/), you can directly pass it here.

Check failure on line 44 in docs/data/toolpad/core/introduction/base-concepts.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [MUI.MuiBrandName] Use a non-breaking space (option+space on Mac, Alt+0160 on Windows or AltGr+Space on Linux, instead of space) for brand name ('Material UI' instead of 'Material UI') Raw Output: {"message": "[MUI.MuiBrandName] Use a non-breaking space (option+space on Mac, Alt+0160 on Windows or AltGr+Space on Linux, instead of space) for brand name ('Material UI' instead of 'Material UI')", "location": {"path": "docs/data/toolpad/core/introduction/base-concepts.md", "range": {"start": {"line": 44, "column": 82}}}, "severity": "ERROR"}
bharatkashyap marked this conversation as resolved.
Show resolved Hide resolved

```tsx
import { createTheme } from '@mui/material';
import { AppProvider } from '@toolpad/core/AppProvider';

const customTheme = createTheme({
cssVariables: {
colorSchemeSelector: 'data-toolpad-color-scheme',
},
colorSchemes: {
light: {
// ...
},
dark: {
// ...
},
},
});

function MyApp({ Component, pageProps }) {
return <AppProvider theme={theme}>/* Your App */</AppProvider>;
}
```

- `branding`: Branding options for the app.

```tsx
import { AppProvider } from '@toolpad/core/AppProvider';

function MyApp({ Component, pageProps }) {
return <AppProvider branding={{ title: 'My Company Name' }}>..</AppProvider>;
}
```

- `navigation`: The navigation structure for the app.

```tsx
import { ShoppingCartIcon } from '@mui/icons-material';
import { AppProvider } from '@toolpad/core/AppProvider';

const NAVIGATION: Navigation = [
{
segment: 'orders',
title: 'Orders',
icon: <ShoppingCartIcon />,
},
];

function MyApp({ Component, pageProps }) {
return <AppProvider navigation={NAVIGATION}>..</AppProvider>;
}
```

- `router`: Router implementation used to navigate between pages. This is the same router that you use in your application.

:::info
Toolpad Core doesn't handle routing itself. Instead, it's designed to integrate seamlessly with your existing routing solution, whether you're using:

- Next.js App Router
- Next.js Pages Router
- React Router
- Or any other routing library which implements the same interface

You can pass the router implementation to the `AppProvider` component using the `router` prop. You do not need to pass this prop if you are using Next.js, since it has a file-system based router.

:::

- `authentication`: Authentication implementation used inside Toolpad components.

- `session`: Session implementation used inside Toolpad components.

```tsx
import { AppProvider } from '@toolpad/core/AppProvider';
import { SessionProvider, signIn, signOut } from 'next-auth/react';
import { auth } from '../auth';

function MyApp({ Component, pageProps }) {
const session = await auth();
return (
<SessionProvider session={session}>
<AppProvider authentication={{ signIn, signOut }} session={session}>
..
</AppProvider>
</SessionProvider>
);
}
```

It is important to note that the `AppProvider` component does not perform routing or authentication by itself. It integrates with any of your existing implementations for the same.

:::info
The [AppProvider](/toolpad/core/react-app-provider/) page contains more details and examples of the usage of these props.
:::

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add that for Next.js you don't need to set this up yourself. We have an AppProvider exported from @toolpad/core/nextjs that already sets it up correctly.

Copy link
Member Author

@bharatkashyap bharatkashyap Sep 20, 2024

Choose a reason for hiding this comment

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

I could add it as a separate callout from this info callout and draw specific attention to the @toolpad/core/nextjs export

## Slots

Toolpad Core uses slots for component customization. Slots allow you to override specific parts of a component, providing flexibility in styling and functionality. You can also pass additional props to specific slots using the `slotProps` prop.

Here's an example using the `SignInPage` component:

```tsx
import { SignInPage } from '@toolpad/core/SignInPage';
function MyComponent() {
return (
<SignInPage
slots={{
emailField: CustomEmailField,

}}
slotProps={{
passwordField: {
variant: 'outlined',
},
}}
>
Custom Button
</Button>
);
}
```

In this example:

- The `slots` prop allows you to replace entire parts of the component.
- The `slotProps` prop lets you pass additional props to specific slots.

## Next Steps

Now that you understand the basic concepts of Toolpad Core, you're ready to start integrating it into your project. Head over to the [integration docs](/toolpad/core/introduction/integration/) to learn more.
76 changes: 38 additions & 38 deletions docs/data/toolpad/core/introduction/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,44 @@ title: Toolpad Core - Installation

# Installation

## Manual Installation

Use your preferred package manager to install `@toolpad/core` in your project:

<codeblock storageKey="package-manager">

```bash npm
npm install -S @toolpad/core
```

```bash yarn
yarn add @toolpad/core
```

```bash pnpm
pnpm add @toolpad/core
```

</codeblock>

The Toolpad Core package has a peer dependency on `@mui/material` and `@mui/icons-material`. If you aren't using these already in your project, you can install them with:

<codeblock storageKey="package-manager">

```bash npm
npm install -S @mui/material @mui/icons-material @emotion/react @emotion/styled
```

```bash yarn
yarn add @mui/material @mui/icons-material @emotion/react @emotion/styled
```

```bash pnpm
pnpm add @mui/material @mui/icons-material @emotion/react @emotion/styled
```

</codeblock>

## Automatic Installation

<p class="description">Learn how to install Toolpad Core in your local environment.</p>
Expand Down Expand Up @@ -74,41 +112,3 @@ yarn dev
{{"component": "modules/components/DocsImage.tsx", "src": "/static/toolpad/docs/core/installation-1.png", "alt": "Toolpad Core entry point", "caption": "Starting with Toolpad Core", "zoom": true, "indent": 1 }}

5. Installation is complete! Begin building your project by making edits to `(dashboard/page/page.tsx`. To understand how to leverage Toolpad Core to build dashboards quickly, [see the detailed tutorial](/toolpad/core/introduction/tutorial/).

## Manual Installation

Use your preferred package manager to install `@toolpad/core` in your project:

<codeblock storageKey="package-manager">

```bash npm
npm install -S @toolpad/core
```

```bash yarn
yarn add @toolpad/core
```

```bash pnpm
pnpm add @toolpad/core
```

</codeblock>

The Toolpad Core package has a peer dependency on `@mui/material` and `@mui/icons-material`. If you aren't using these already in your project, you can install them with:

<codeblock storageKey="package-manager">

```bash npm
npm install -S @mui/material @mui/icons-material @emotion/react @emotion/styled
```

```bash yarn
yarn add @mui/material @mui/icons-material @emotion/react @emotion/styled
```

```bash pnpm
pnpm add @mui/material @mui/icons-material @emotion/react @emotion/styled
```

</codeblock>
Loading
Loading