当前位置 : 主页 > 手机开发 > harmonyos >

前端项目实战壹佰玖拾玖react-admin+material ui-react-admin之toolbar工具栏

来源:互联网 收集:自由互联 发布时间:2023-08-26
import * as React from 'react';import {Button,Typography,Box} from '@mui/material';import { Create,useNotify,useRedirect,Toolbar,SaveButton, SimpleForm, TextInput, DateInput, required,TopToolbar} from 'react-admin';import { useFormContext }


import * as React from 'react';
import {Button,Typography,Box} from '@mui/material';
import { Create,useNotify,useRedirect,Toolbar,SaveButton, SimpleForm, TextInput, DateInput, required,TopToolbar} from 'react-admin';
import { useFormContext } from 'react-hook-form';
const PostCreateActions = () => (
    <TopToolbar>
        {/* Add your custom actions */}
        <Button color="primary">geyao</Button>
    </TopToolbar>
);
const Aside = () => (
    <Box sx={{ width: '200px', margin: '1em' }}>
        <Typography variant="h6">Instructions</Typography>
        <Typography variant="body2">
            Posts will only be published once an editor approves them
        </Typography>
    </Box>
);
const MyWrapper=()=>{
    return(
        <div>我是歌谣</div>
    )
}
export const SimpleFormCreate = () => {
    const notify = useNotify();
    const onSuccess = (data) => {
        notify(`Changes saved`);
       
    };
    const transform = data => ({
        ...data,
        name: `${data.name} ${data.sex}`
    });
    const postSave = (data) => {
       
    };
    const PostCreateToolbar = () => {
        const notify = useNotify();
        const { reset } = useFormContext();
    
        return (
            <Toolbar>
                <SaveButton
                    type="button"
                    label="post.action.save_and_add"
                    variant="text"
                    mutationOptions={{
                        onSuccess: () => {
                            reset();
                            window.scrollTo(0, 0);
                            notify('ra.notification.created', {
                                type: 'info',
                                messageArgs: { smart_count: 1 },
                            });
                        },
                    }}
                />
            </Toolbar>
        );
    };
    const PostCreateToolbarData = () => {
        const redirect = useRedirect();
        const notify = useNotify();
        return (
            <Toolbar>
                <SaveButton
                    label="post.action.save_and_show"
                />
                <SaveButton
                    label="post.action.save_and_add"
                    mutationOptions={{
                        onSuccess: data => {
                            notify('ra.notification.created', {
                                type: 'info',
                                messageArgs: { smart_count: 1 },
                            });
                            redirect(false);
                        }}
                    }
                    type="button"
                    variant="text"
                />
            </Toolbar>
        );
    };
    return(
        <Create onSubmit={postSave}>
        <SimpleForm toolbar={PostCreateToolbar }>
            <TextInput source="name" validate={[required()]} fullWidth />
            <TextInput source="sex" multiline={true} label="Short description" />
            <TextInput source="salary" multiline={true} label="Short description" />
        </SimpleForm>
    </Create>
)
   
    }

运行结果

 

前端项目实战壹佰玖拾玖react-admin+material ui-react-admin之toolbar工具栏_ui

【本文来源:韩国服务器 http://www.558idc.com/kt.html欢迎留下您的宝贵建议】
网友评论