-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathShow.stories.tsx
189 lines (164 loc) · 4.89 KB
/
Show.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import * as React from 'react';
import { Admin } from 'react-admin';
import { Resource, useRecordContext } from 'ra-core';
import { createMemoryHistory } from 'history';
import { Box, Card, Stack } from '@mui/material';
import { TextField } from '../field';
import { Labeled } from '../Labeled';
import { SimpleShowLayout } from './SimpleShowLayout';
import { EditButton } from '../button';
import TopToolbar from '../layout/TopToolbar';
import { Show } from './Show';
export default { title: 'ra-ui-materialui/detail/Show' };
const dataProvider = {
getOne: () =>
Promise.resolve({
data: {
id: 1,
title: 'War and Peace',
author: 'Leo Tolstoy',
summary:
"War and Peace broadly focuses on Napoleon's invasion of Russia, and the impact it had on Tsarist society. The book explores themes such as revolution, revolution and empire, the growth and decline of various states and the impact it had on their economies, culture, and society.",
year: 1869,
},
}),
} as any;
const history = createMemoryHistory({ initialEntries: ['/books/1/show'] });
const BookTitle = () => {
const record = useRecordContext();
return record ? <span>{record.title}</span> : null;
};
const PostShowBasic = () => (
<Show>
<BookTitle />
</Show>
);
export const Basic = () => (
<Admin dataProvider={dataProvider} history={history}>
<Resource name="books" show={PostShowBasic} />
</Admin>
);
const PostShowWithFields = () => (
<Show>
<Stack spacing={2} sx={{ padding: 2 }}>
<Labeled label="Title">
<TextField source="title" />
</Labeled>
<Labeled label="Author">
<TextField source="author" />
</Labeled>
<Labeled label="Summary">
<TextField source="summary" />
</Labeled>
<Labeled label="Year">
<TextField source="year" />
</Labeled>
</Stack>
</Show>
);
export const WithFields = () => (
<Admin dataProvider={dataProvider} history={history}>
<Resource name="books" show={PostShowWithFields} />
</Admin>
);
const PostShowWithCustomActions = () => (
<Show
actions={
<TopToolbar>
<EditButton />
</TopToolbar>
}
>
<BookTitle />
</Show>
);
export const Actions = () => (
<Admin dataProvider={dataProvider} history={history}>
<Resource name="books" show={PostShowWithCustomActions} />
</Admin>
);
const PostShowWithTitle = () => (
<Show title="Hello">
<BookTitle />
</Show>
);
export const Title = () => (
<Admin dataProvider={dataProvider} history={history}>
<Resource name="books" show={PostShowWithTitle} />
</Admin>
);
const AsideComponent = () => <Card sx={{ padding: 2 }}>Aside</Card>;
const PostShowWithAside = () => (
<Show aside={<AsideComponent />}>
<BookTitle />
</Show>
);
export const Aside = () => (
<Admin dataProvider={dataProvider} history={history}>
<Resource name="books" show={PostShowWithAside} />
</Admin>
);
const CustomWrapper = ({ children }) => (
<Box
sx={{ padding: 2, width: 200, border: 'solid 1px black' }}
data-testid="custom-component"
>
{children}
</Box>
);
const PostShowWithComponent = () => (
<Show component={CustomWrapper}>
<BookTitle />
</Show>
);
export const Component = () => (
<Admin dataProvider={dataProvider} history={history}>
<Resource name="books" show={PostShowWithComponent} />
</Admin>
);
const PostShowWithStyles = () => (
<Show
sx={{
padding: 2,
border: '1px solid #333',
}}
>
<BookTitle />
</Show>
);
export const SX = () => (
<Admin dataProvider={dataProvider} history={history}>
<Resource name="books" show={PostShowWithStyles} />
</Admin>
);
const DefaultPostShow = () => (
<Show>
<SimpleShowLayout>
<TextField source="title" />
<TextField source="author" />
<TextField source="summary" />
<TextField source="year" />
</SimpleShowLayout>
</Show>
);
const dataProviderWithLog = {
getOne: (resource, params) => {
console.log('getOne', resource, params);
return dataProvider.getOne(resource, params);
},
} as any;
const PostShowWithMeta = () => (
<Show queryOptions={{ meta: { foo: 'bar ' } }}>
<BookTitle />
</Show>
);
export const Meta = () => (
<Admin dataProvider={dataProviderWithLog} history={history}>
<Resource name="books" show={PostShowWithMeta} />
</Admin>
);
export const Default = () => (
<Admin dataProvider={dataProvider} history={history}>
<Resource name="books" show={DefaultPostShow} edit={() => <span />} />
</Admin>
);