From bce0aea782bd7a9490c8b2fbee0a4a8b5ec9c8f6 Mon Sep 17 00:00:00 2001 From: Kevin Date: Sat, 19 Feb 2022 14:00:37 +0800 Subject: [PATCH] refactor(react-components): [button] improve props --- .../react-components/src/button/button.tsx | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/react-components/src/button/button.tsx b/packages/react-components/src/button/button.tsx index 7958cea..94cf6e7 100644 --- a/packages/react-components/src/button/button.tsx +++ b/packages/react-components/src/button/button.tsx @@ -14,27 +14,37 @@ export const buttonTypes = [ ] as const export type ButtonTypes = typeof buttonTypes[number] -export interface ButtonProps { - children?: any +export type ButtonProps = { + children?: React.ReactNode size?: ComponentSizes type?: ButtonTypes plain?: boolean round?: boolean circle?: boolean - onClick?: () => void -} + onClick?: React.MouseEventHandler +} & Omit, 'type' | 'onClick'> export function Button(props: ButtonProps) { - const classNames = ['el-button'] - // eslint-disable-next-line unicorn/explicit-length-check - if (props.size) classNames.push(`el-button--${props.size}`) - if (props.type) classNames.push(`el-button--${props.type}`) - if (props.plain) classNames.push('is-plain') - if (props.round) classNames.push('is-round') - if (props.circle) classNames.push('is-circle') + const { + children, + className, + size, + type, + plain, + round, + circle, + onClick, + ...rest + } = props + const classNames = ['el-button', className] + if (size) classNames.push(`el-button--${size}`) + if (type) classNames.push(`el-button--${type}`) + if (plain) classNames.push('is-plain') + if (round) classNames.push('is-round') + if (circle) classNames.push('is-circle') return ( - ) } -- knotmirror 0.0.1