2022-01-10 19:22:21 +08:00
|
|
|
import { observer, RecursionField, useField, useFieldSchema } from '@formily/react';
|
2022-02-05 17:06:33 +08:00
|
|
|
import { Button } from 'antd';
|
|
|
|
import React, { useState } from 'react';
|
2022-02-10 12:06:48 +08:00
|
|
|
import ActionContainer from './Action.Container';
|
2022-02-05 17:06:33 +08:00
|
|
|
import { ActionDrawer } from './Action.Drawer';
|
2022-02-10 12:06:48 +08:00
|
|
|
import { ActionModal } from './Action.Modal';
|
|
|
|
import { ActionPage } from './Action.Page';
|
|
|
|
import { ActionContext } from './context';
|
2022-02-05 17:06:33 +08:00
|
|
|
import { useA } from './hooks';
|
2022-01-10 19:22:21 +08:00
|
|
|
import { ComposedAction } from './types';
|
|
|
|
|
2022-02-10 12:06:48 +08:00
|
|
|
export const Action: ComposedAction = observer((props: any) => {
|
|
|
|
const { openMode, containerRefKey, useAction = useA, onClick, ...others } = props;
|
2022-01-10 19:22:21 +08:00
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
const schema = useFieldSchema();
|
|
|
|
const field = useField();
|
|
|
|
const { run } = useAction();
|
|
|
|
return (
|
2022-02-10 12:06:48 +08:00
|
|
|
<ActionContext.Provider value={{ visible, setVisible, openMode, containerRefKey }}>
|
2022-01-10 19:22:21 +08:00
|
|
|
<Button
|
|
|
|
{...others}
|
|
|
|
onClick={(e) => {
|
|
|
|
onClick && onClick(e);
|
|
|
|
setVisible(true);
|
|
|
|
run();
|
|
|
|
}}
|
|
|
|
>
|
2022-02-05 17:06:33 +08:00
|
|
|
{field.title}
|
2022-01-10 19:22:21 +08:00
|
|
|
</Button>
|
|
|
|
<RecursionField basePath={field.address} schema={schema} onlyRenderProperties />
|
2022-02-10 12:06:48 +08:00
|
|
|
</ActionContext.Provider>
|
2022-01-10 19:22:21 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Action.Drawer = ActionDrawer;
|
2022-02-10 12:06:48 +08:00
|
|
|
Action.Modal = ActionModal;
|
|
|
|
Action.Container = ActionContainer;
|
|
|
|
Action.Page = ActionPage;
|
2022-01-10 19:22:21 +08:00
|
|
|
|
|
|
|
export default Action;
|