Utoljára aktív 1728989378

React-admin-readme-3.jsx Eredeti
1// in posts.js
2import * as React from "react";
3import { List, Datagrid, Edit, Create, SimpleForm, DateField, TextField, EditButton, TextInput, DateInput, useRecordContext } from 'react-admin';
4import BookIcon from '@mui/icons-material/Book';
5export const PostIcon = BookIcon;
6
7export const PostList = () => (
8 <List>
9 <Datagrid>
10 <TextField source="id" />
11 <TextField source="title" />
12 <DateField source="published_at" />
13 <TextField source="average_note" />
14 <TextField source="views" />
15 <EditButton />
16 </Datagrid>
17 </List>
18);
19
20const PostTitle = () => {
21 const record = useRecordContext();
22 return <span>Post {record ? `"${record.title}"` : ''}</span>;
23};
24
25export const PostEdit = () => (
26 <Edit title={<PostTitle />}>
27 <SimpleForm>
28 <TextInput disabled source="id" />
29 <TextInput source="title" />
30 <TextInput source="teaser" options={{ multiline: true }} />
31 <TextInput multiline source="body" />
32 <DateInput label="Publication date" source="published_at" />
33 <TextInput source="average_note" />
34 <TextInput disabled label="Nb views" source="views" />
35 </SimpleForm>
36 </Edit>
37);
38
39export const PostCreate = () => (
40 <Create title="Create a Post">
41 <SimpleForm>
42 <TextInput source="title" />
43 <TextInput source="teaser" options={{ multiline: true }} />
44 <TextInput multiline source="body" />
45 <TextInput label="Publication date" source="published_at" />
46 <TextInput source="average_note" />
47 </SimpleForm>
48 </Create>
49);