import React, { FC, ButtonHTMLAttributes, AnchorHTMLAttributes } from 'react'; import classNames from 'classnames'; export type ButtonSize = 'lg' | 'sm'; export type ButtonType = 'primary' | 'default' | 'danger' | 'link'; interface BaseButtonProps { className?: string; disabled?: boolean; size?: ButtonSize; btnType?: ButtonType; children: React.ReactNode; href?: string; loading?: boolean; } type NativeButtonProps = BaseButtonProps & ButtonHTMLAttributes; type AnchorButtonProps = BaseButtonProps & AnchorHTMLAttributes; export type ButtonProps = Partial; export const Button: FC = (props) => { const { btnType, className, disabled, size, children, href, loading, ...restProps } = props; // btn, btn-lg, btn-primary const classes = classNames('btn', className, { [`btn-${btnType}`]: btnType, [`btn-${size}`]: size, disabled: btnType === 'link' && disabled, }); const loadingIndicator = () => { return (
); }; if (btnType === 'link' && href) { return ( {children} ); } else { return ( ); } }; Button.defaultProps = { disabled: false, btnType: 'default', loading: false, }; export default Button;