From 403cc7e113cee085434f455aa4cbaebd5320d757 Mon Sep 17 00:00:00 2001 From: dark Date: Thu, 5 Sep 2024 21:23:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Action=E4=B8=BAA=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=97=B6=E4=B8=94disabled,=20onClick=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E8=BF=98=E8=83=BD=E7=82=B9=E5=87=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/action/Action.tsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/components/action/Action.tsx b/src/components/action/Action.tsx index 0bc3477..af949db 100644 --- a/src/components/action/Action.tsx +++ b/src/components/action/Action.tsx @@ -2,23 +2,27 @@ import { Button, ButtonProps } from 'antd' import { useStyle } from './style' export interface ActionProps extends ButtonProps { - as?: string + as?: string } const Action = ({ title, as, children, ...props }: ActionProps) => { - const { styles } = useStyle() + const { styles } = useStyle() - const isLink = as === 'a' || props.type === 'link' - //fixme 如果外部同时设置 as={'a'} disabled={true} ,这里a标签会置灰,但是仍可点击,为什么不直接用Button? - const Comp = isLink ? 'a' : Button - return ( - + const isLink = as === 'a' || props.type === 'link' + const Comp = isLink ? 'a' : Button + return ( + {title ?? children} + onClick={(e) => { + if (props.onClick && !props.disabled) { + props.onClick(e) + } + }} + type={isLink ? 'link' : props.type} + className={as === 'a' ? styles.actionA : ''}>{title ?? children} - ) + ) } export default Action \ No newline at end of file