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';
|
|
|
|
import { ActionDrawer } from './Action.Drawer';
|
2022-01-10 19:22:21 +08:00
|
|
|
import { VisibleContext } 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';
|
|
|
|
|
|
|
|
export const Action: ComposedAction = observer((props) => {
|
|
|
|
const { useAction = useA, onClick, ...others } = props;
|
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
const schema = useFieldSchema();
|
|
|
|
const field = useField();
|
|
|
|
const { run } = useAction();
|
|
|
|
return (
|
|
|
|
<VisibleContext.Provider value={[visible, setVisible]}>
|
|
|
|
<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 />
|
|
|
|
</VisibleContext.Provider>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Action.Drawer = ActionDrawer;
|
|
|
|
|
|
|
|
export default Action;
|