|
1 | 1 | import * as React from 'react'; |
2 | 2 | import { ReactElement } from 'react'; |
3 | 3 | import { ShowBase, RaRecord, ShowBaseProps } from 'ra-core'; |
| 4 | +import { useThemeProps } from '@mui/material/styles'; |
| 5 | + |
4 | 6 | import { ShowView, ShowViewProps } from './ShowView'; |
5 | 7 | import { Loading } from '../layout'; |
6 | 8 |
|
@@ -43,40 +45,53 @@ import { Loading } from '../layout'; |
43 | 45 | * ); |
44 | 46 | * export default App; |
45 | 47 | * |
46 | | - * @param {ShowProps} props |
47 | | - * @param {ReactElement|false} props.actions An element to display above the page content, or false to disable actions. |
48 | | - * @param {string} props.className A className to apply to the page content. |
49 | | - * @param {ElementType} props.component The component to use as root component (div by default). |
50 | | - * @param {boolean} props.emptyWhileLoading Do not display the page content while loading the initial data. |
51 | | - * @param {string} props.id The id of the resource to display (grabbed from the route params if not defined). |
52 | | - * @param {Object} props.queryClient Options to pass to the react-query useQuery hook. |
53 | | - * @param {string} props.resource The resource to fetch from the data provider (grabbed from the ResourceContext if not defined). |
54 | | - * @param {Object} props.sx Custom style object. |
55 | | - * @param {ElementType|string} props.title The title of the page. Defaults to `#{resource} #${id}`. |
| 48 | + * @param {ShowProps} inProps |
| 49 | + * @param {ReactElement|false} inProps.actions An element to display above the page content, or false to disable actions. |
| 50 | + * @param {string} inProps.className A className to apply to the page content. |
| 51 | + * @param {ElementType} inProps.component The component to use as root component (div by default). |
| 52 | + * @param {boolean} inProps.emptyWhileLoading Do not display the page content while loading the initial data. |
| 53 | + * @param {string} inProps.id The id of the resource to display (grabbed from the route params if not defined). |
| 54 | + * @param {Object} inProps.queryClient Options to pass to the react-query useQuery hook. |
| 55 | + * @param {string} inProps.resource The resource to fetch from the data provider (grabbed from the ResourceContext if not defined). |
| 56 | + * @param {Object} inProps.sx Custom style object. |
| 57 | + * @param {ElementType|string} inProps.title The title of the page. Defaults to `#{resource} #${id}`. |
56 | 58 | * |
57 | 59 | * @see ShowView for the actual rendering |
58 | 60 | */ |
59 | | -export const Show = <RecordType extends RaRecord = any>({ |
60 | | - id, |
61 | | - resource, |
62 | | - queryOptions, |
63 | | - disableAuthentication, |
64 | | - loading = defaultLoading, |
65 | | - ...rest |
66 | | -}: ShowProps<RecordType>): ReactElement => ( |
67 | | - <ShowBase<RecordType> |
68 | | - id={id} |
69 | | - disableAuthentication={disableAuthentication} |
70 | | - queryOptions={queryOptions} |
71 | | - resource={resource} |
72 | | - loading={loading} |
73 | | - > |
74 | | - <ShowView {...rest} /> |
75 | | - </ShowBase> |
76 | | -); |
| 61 | +export const Show = <RecordType extends RaRecord = any>( |
| 62 | + inProps: ShowProps<RecordType> |
| 63 | +): ReactElement => { |
| 64 | + const props = useThemeProps({ |
| 65 | + props: inProps, |
| 66 | + name: PREFIX, |
| 67 | + }); |
| 68 | + |
| 69 | + const { |
| 70 | + id, |
| 71 | + resource, |
| 72 | + queryOptions, |
| 73 | + disableAuthentication, |
| 74 | + loading = defaultLoading, |
| 75 | + ...rest |
| 76 | + } = props; |
| 77 | + |
| 78 | + return ( |
| 79 | + <ShowBase<RecordType> |
| 80 | + id={id} |
| 81 | + disableAuthentication={disableAuthentication} |
| 82 | + queryOptions={queryOptions} |
| 83 | + resource={resource} |
| 84 | + loading={loading} |
| 85 | + > |
| 86 | + <ShowView {...rest} /> |
| 87 | + </ShowBase> |
| 88 | + ); |
| 89 | +}; |
77 | 90 |
|
78 | 91 | export interface ShowProps<RecordType extends RaRecord = any> |
79 | 92 | extends ShowBaseProps<RecordType>, |
80 | 93 | Omit<ShowViewProps, 'children'> {} |
81 | 94 |
|
82 | 95 | const defaultLoading = <Loading />; |
| 96 | + |
| 97 | +const PREFIX = 'RaShow'; // Types declared in ShowView. |
0 commit comments