import cx from 'clsx'; import * as React from 'react'; import s0 from './Button.module.scss'; import { LoadingDot } from './shared/Basic'; const { forwardRef, useCallback } = React; type ButtonInternalProps = { children?: React.ReactNode; label?: string; text?: string; start?: React.ReactNode | (() => React.ReactNode); }; type ButtonProps = { isLoading?: boolean; onClick?: (e: React.MouseEvent) => unknown; disabled?: boolean; kind?: 'primary' | 'minimal'; className?: string; title?: string; } & ButtonInternalProps; function Button(props: ButtonProps, ref: React.Ref) { const { onClick, disabled = false, isLoading, kind = 'primary', className, children, label, text, start, ...restProps } = props; const internalProps = { children, label, text, start }; const internalOnClick = useCallback( (e) => { if (isLoading) return; onClick && onClick(e); }, [isLoading, onClick] ); const btnClassName = cx(s0.btn, { [s0.minimal]: kind === 'minimal' }, className); return ( ); } function ButtonInternal({ children, label, text, start }: ButtonInternalProps) { return (
{start && ( {typeof start === 'function' ? start() : start} )} {children || label || text}
); } export default forwardRef(Button);