feat(client): add Action.Link schema component

This commit is contained in:
chenos 2022-02-16 22:45:03 +08:00
parent 022c173f7e
commit f8863959b5
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,31 @@
import { observer, RecursionField, useField, useFieldSchema } from '@formily/react';
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import { ActionContext } from './context';
import { useA } from './hooks';
import { ComposedAction } from './types';
export const ActionLink: ComposedAction = observer((props: any) => {
const { openMode, containerRefKey, useAction = useA, onClick, ...others } = props;
const [visible, setVisible] = useState(false);
const schema = useFieldSchema();
const field = useField();
const { run } = useAction();
return (
<ActionContext.Provider value={{ visible, setVisible, openMode, containerRefKey }}>
<Link
{...others}
onClick={(e) => {
onClick && onClick(e);
setVisible(true);
run();
}}
>
{field.title}
</Link>
<RecursionField basePath={field.address} schema={schema} onlyRenderProperties />
</ActionContext.Provider>
);
});
export default ActionLink;

View File

@ -3,6 +3,7 @@ import { Button } from 'antd';
import React, { useState } from 'react';
import ActionContainer from './Action.Container';
import { ActionDrawer } from './Action.Drawer';
import { ActionLink } from './Action.Link';
import { ActionModal } from './Action.Modal';
import { ActionPage } from './Action.Page';
import { ActionContext } from './context';
@ -32,6 +33,7 @@ export const Action: ComposedAction = observer((props: any) => {
);
});
Action.Link = ActionLink;
Action.Drawer = ActionDrawer;
Action.Modal = ActionModal;
Action.Container = ActionContainer;