-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[Doc] Add ContainerLayout and HorizontalMenu documentation #8342
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
--- | ||
layout: default | ||
title: "ContainerLayout" | ||
--- | ||
|
||
# ContainerLayout | ||
|
||
This [Enterprise Edition](https://marmelab.com/ra-enterprise)<img class="icon" src="./img/premium.svg" /> component offers an alternative to react-admin's `<Layout>` for applications with a limited number of resources. It replaces the sidebar menu by an AppBar menu, and displays the content in a centered container. | ||
|
||
![Container layout](https://marmelab.com/ra-enterprise/modules/assets/ra-navigation/latest/container-layout.png) | ||
|
||
## Usage | ||
|
||
Set `<ContainerLayout>` as the `<Admin layout>` value: | ||
|
||
```jsx | ||
import { Admin, Resource } from 'react-admin'; | ||
import { ContainerLayout } from '@react-admin/ra-navigation'; | ||
|
||
export const App = () => ( | ||
<Admin dataProvider={dataProvider} layout={ContainerLayout}> | ||
<Resource name="songs" list={SongList} /> | ||
<Resource name="artists" list={ArtistList} /> | ||
</Admin> | ||
); | ||
``` | ||
|
||
See more details in the [ra-navigation documentation](https://marmelab.com/ra-enterprise/modules/ra-navigation#containerlayout). | ||
|
||
## Props | ||
|
||
`<ContainerLayout>` accepts the following props: | ||
|
||
- `menu`: The menu component to use. Defaults to `<HorizontalMenu>`. | ||
- `appBar`: The component to use to render the top AppBar. Defaults to `<Header>` | ||
- `toolbar`: The buttons to render on the top right of the toolbar. | ||
- `maxWidth`: The maximum width of the content `<Container>`. Defaults to `md`. | ||
- `fixed`: Whether the content `<Container>` should be fixed. Defaults to false. | ||
|
||
## `menu` | ||
|
||
By default, `<ContainerLayout>` renders one menu item per resource in the admin. To reorder the menu, omit resources, or add custom pages, pass a custom menu element to the `menu` prop. This element should be [a `<HorizontalMenu>` component](./HorizontalMenu.md) with `<HorizontalMenu.Item>` children. Each child should have a `value` corresponding to the [application location](https://marmelab.com/ra-enterprise/modules/ra-navigation#concepts) of the target, and can have a `to` prop corresponding to the target location if different from the app location. | ||
|
||
```jsx | ||
import { | ||
Admin, | ||
Resource, | ||
CustomRoutes, | ||
ListGuesser, | ||
EditGuesser, | ||
} from 'react-admin'; | ||
import { Route } from 'react-router-dom'; | ||
import { | ||
ContainerLayout, | ||
HorizontalMenu, | ||
useDefineAppLocation, | ||
} from '@react-admin/ra-navigation'; | ||
|
||
const Menu = () => ( | ||
<HorizontalMenu> | ||
<HorizontalMenu.Item label="Dashboard" to="/" value="" /> | ||
<HorizontalMenu.Item label="Songs" to="/songs" value="songs" /> | ||
<HorizontalMenu.Item label="Artists" to="/artists" value="artists" /> | ||
<HorizontalMenu.Item label="Custom" to="/custom" value="custom" /> | ||
</HorizontalMenu> | ||
); | ||
|
||
const MyLayout = props => <ContainerLayout {...props} menu={<Menu />} />; | ||
|
||
const CustomPage = () => { | ||
useDefineAppLocation('custom'); | ||
return <h1>Custom page</h1>; | ||
}; | ||
|
||
const Dashboard = () => <h1>Dashboard</h1>; | ||
const CustomPage = () => <h1>Custom page</h1>; | ||
|
||
export const App = () => ( | ||
<Admin dataProvider={dataProvider} layout={MyLayout} dashboard={Dashboard}> | ||
<Resource name="songs" list={ListGuesser} edit={EditGuesser} /> | ||
<Resource name="artists" list={ListGuesser} edit={EditGuesser} /> | ||
<CustomRoutes> | ||
<Route path="custom" element={<CustomPage />} /> | ||
</CustomRoutes> | ||
</Admin> | ||
); | ||
``` | ||
|
||
## `appBar` | ||
|
||
If you want to use a different color for the AppBar, or to make it sticky, pass a custom `appBar` element based on `<Header>`, which is a simple wrapper around [MUI's `<AppBar>` component](https://mui.com/material-ui/react-app-bar/#main-content). | ||
|
||
```jsx | ||
import { ContainerLayout, Header } from '@react-admin/ra-navigation'; | ||
|
||
const myAppBar = <Header color="primary" position="sticky" />; | ||
const MyLayout = props => <ContainerLayout {...props} appBar={myAppBar} />; | ||
``` | ||
|
||
## `toolbar` | ||
|
||
The `toolbar` prop allows to add buttons to the top right of the toolbar. It accepts an element. | ||
|
||
```jsx | ||
import { LocalesMenuButton, LoadingIndicator } from 'react-admin'; | ||
import { ContainerLayout } from '@react-admin/ra-navigation'; | ||
|
||
const toolbar = ( | ||
<> | ||
<LocalesMenuButton /> | ||
<LoadingIndicator /> | ||
</> | ||
); | ||
const MyLayout = props => <ContainerLayout {...props} toolbar={toolbar} />; | ||
``` | ||
|
||
## `maxWidth` | ||
|
||
This prop allows to set the maximum width of the content [`<Container>`](https://mui.com/material-ui/react-container/#main-content). It accepts a string, one of `xs`, `sm`, `md`, `lg`, `xl`, or `false` to remove side margins and occupy the full width of the screen. | ||
|
||
```jsx | ||
import { ContainerLayout } from '@react-admin/ra-navigation'; | ||
|
||
const MyLayout = props => <ContainerLayout {...props} maxWidth="md" />; | ||
``` | ||
|
||
## `fixed` | ||
|
||
If you prefer to design for a fixed set of sizes instead of trying to accommodate a fully fluid viewport, you can set the `fixed` prop. The max-width matches the min-width of the current breakpoint. | ||
|
||
```jsx | ||
import { ContainerLayout } from '@react-admin/ra-navigation'; | ||
|
||
const MyLayout = props => <ContainerLayout {...props} fixed />; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
layout: default | ||
title: "The HorizontalMenu Component" | ||
--- | ||
|
||
# `<HorizontalMenu>` | ||
|
||
|
||
This [Enterprise Edition](https://marmelab.com/ra-enterprise)<img class="icon" src="./img/premium.svg" /> component renders a horizontal menu, alternative to react-admin's [`<Menu>`](./Menu.md), to be used in the AppBar of the [`<ContainerLayout>`](./ContainerLayout.md). | ||
|
||
![Container layout](https://marmelab.com/ra-enterprise/modules/assets/ra-navigation/latest/container-layout.png) | ||
|
||
## Usage | ||
|
||
Create a menu component based on `<HorizontalMenu>` and `<HorizontalMenu.Item>` children. Each child should have a `value` corresponding to the [application location](https://marmelab.com/ra-enterprise/modules/ra-navigation#concepts) of the target, and can have a `to` prop corresponding to the target location if different from the app location. | ||
|
||
```jsx | ||
import { HorizontalMenu } from '@react-admin/ra-navigation'; | ||
|
||
export const Menu = () => ( | ||
<HorizontalMenu> | ||
<HorizontalMenu.Item label="Dashboard" to="/" value="" /> | ||
<HorizontalMenu.Item label="Songs" to="/songs" value="songs" /> | ||
<HorizontalMenu.Item label="Artists" to="/artists" value="artists" /> | ||
</HorizontalMenu> | ||
); | ||
``` | ||
|
||
Then pass it to the `<ContainerLayout>`: | ||
|
||
```jsx | ||
import { Admin, Resource } from 'react-admin'; | ||
import { ContainerLayout } from '@react-admin/ra-navigation'; | ||
|
||
import { Menu } from './Menu'; | ||
|
||
const MyLayout = props => <ContainerLayout {...props} menu={<Menu />} />; | ||
|
||
const App = () => ( | ||
<Admin dataProvider={dataProvider} layout={MyLayout}> | ||
... | ||
</Admin> | ||
); | ||
``` | ||
|
||
See more details in the [ra-navigation documentation](https://marmelab.com/ra-enterprise/modules/ra-navigation#containerlayout). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! 😅