Skip to content

Commit d1ff043

Browse files
authoredDec 20, 2022
Merge pull request #8525 from marmelab/Add-TabbedForm.Tab-and-TabbedShowLayout.Tab-shortcuts
Add TabbedForm.Tab and TabbedShowLayout.Tab shortcuts
2 parents 4e186f6 + c7cf02b commit d1ff043

22 files changed

+280
-287
lines changed
 

‎docs/AuthRBAC.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ const ProductShow = () => (
630630

631631
### `<Tab>`
632632

633-
Replacement for the show `<Tab>` that only renders a tab if the user has the right permissions.
633+
Replacement for the `<TabbedShowLayout.Tab>` that only renders a tab if the user has the right permissions.
634634

635635
Add a `name` prop to the Tab to define the resource on which the user needs to have the 'read' permissions for.
636636

‎docs/Permissions.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ export const UserEdit = () => {
178178
return (
179179
<Edit title={<UserTitle />}>
180180
<TabbedForm defaultValue={{ role: 'user' }}>
181-
<FormTab label="user.form.summary">
181+
<TabbedForm.Tab label="user.form.summary">
182182
{permissions === 'admin' && <TextInput disabled source="id" />}
183183
<TextInput source="name" validate={required()} />
184-
</FormTab>
184+
</TabbedForm.Tab>
185185
{permissions === 'admin' &&
186-
<FormTab label="user.form.security">
186+
<TabbedForm.Tab label="user.form.security">
187187
<TextInput source="role" validate={required()} />
188-
</FormTab>}
188+
</TabbedForm.Tab>}
189189
</TabbedForm>
190190
</Edit>
191191
);

‎docs/Show.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ export const PostShow = () => (
8080
<Show>
8181
- <SimpleShowLayout>
8282
+ <TabbedShowLayout>
83-
+ <Tab label="Main>
83+
+ <TabbedShowLayout.Tab label="Main>
8484
<TextField source="title" />
8585
<TextField source="teaser" />
8686
<RichTextField source="body" />
8787
<DateField label="Publication date" source="created_at" />
88-
+ </Tab>
88+
+ </TabbedShowLayout.Tab>
8989
- </SimpleShowLayout>
9090
+ </TabbedShowLayout>
9191
</Show>
@@ -362,25 +362,25 @@ export const PostShow = () => {
362362
```
363363
{% endraw %}
364364

365-
This also works inside a `TabbedShowLayout`, and you can hide a `Tab` completely:
365+
This also works inside a `<TabbedShowLayout>`, and you can hide a `TabbedShowLayout.Tab` completely:
366366

367367
{% raw %}
368368
```jsx
369-
import { Show, TabbedShowLayout, Tab, TextField } from 'react-admin';
369+
import { Show, TabbedShowLayout, TextField } from 'react-admin';
370370

371371
export const UserShow = () => {
372372
const { permissions } = usePermissions();
373373
return (
374374
<Show>
375375
<TabbedShowLayout>
376-
<Tab label="user.form.summary">
376+
<TabbedShowLayout.Tab label="user.form.summary">
377377
{permissions === 'admin' && <TextField source="id" />}
378378
<TextField source="name" />
379-
</Tab>
379+
</TabbedShowLayout.Tab>
380380
{permissions === 'admin' &&
381-
<Tab label="user.form.security">
381+
<TabbedShowLayout.Tab label="user.form.security">
382382
<TextField source="role" />
383-
</Tab>}
383+
</TabbedShowLayout.Tab>}
384384
</TabbedShowLayout>
385385
</Show>
386386
);

‎docs/ShowTutorial.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -358,27 +358,27 @@ const BookShow = () => (
358358
When a Show view has to display a lot of fields, the `<SimpleShowLayout>` component ends up in very long page that is not user-friendly. You can use [the `<TabbedShowLayout>` component](./TabbedShowLayout.md) instead, which is a variant of the `<SimpleShowLayout>` component that displays the fields in tabs.
359359

360360
```jsx
361-
import { Show, TabbedShowLayout, Tab, TextField, DateField, WithRecord } from 'react-admin';
361+
import { Show, TabbedShowLayout, TextField, DateField, WithRecord } from 'react-admin';
362362
import StarIcon from '@mui/icons-material/Star';
363363
import FavoriteIcon from '@mui/icons-material/Favorite';
364364
import PersonPinIcon from '@mui/icons-material/PersonPin';
365365

366366
const BookShow = () => (
367367
<Show>
368368
<TabbedShowLayout>
369-
<Tab label="Description" icon={<FavoriteIcon />}>
369+
<TabbedShowLayout.Tab label="Description" icon={<FavoriteIcon />}>
370370
<TextField label="Title" source="title" />
371371
<ReferenceField label="Author" source="author_id">
372372
<TextField source="name" />
373373
</ReferenceField>
374374
<DateField label="Publication Date" source="published_at" />
375-
</Tab>
376-
<Tab label="User ratings" icon={<PersonPinIcon />}>
375+
</TabbedShowLayout.Tab>
376+
<TabbedShowLayout.Tab label="User ratings" icon={<PersonPinIcon />}>
377377
<WithRecord label="Rating" render={record => <>
378378
{[...Array(record.rating)].map((_, index) => <StarIcon key={index} />)}
379379
</>} />
380380
<DateField label="Last rating" source="last_rated_at" />
381-
</Tab>
381+
</TabbedShowLayout.Tab>
382382
</TabbedShowLayout>
383383
</Show>
384384
);

0 commit comments

Comments
 (0)