import type { PropsWithChildren, JSX } from 'react'; import { useCallback } from 'react'; import classNames from 'classnames'; import { LoadingIndicator } from 'mastodon/components/loading_indicator'; interface BaseProps extends Omit, 'children'> { block?: boolean; secondary?: boolean; compact?: boolean; dangerous?: boolean; loading?: boolean; } interface PropsChildren extends PropsWithChildren { text?: undefined; } interface PropsWithText extends BaseProps { text: JSX.Element | string; children?: undefined; } type Props = PropsWithText | PropsChildren; /** * Primary UI component for user interaction that doesn't result in navigation. */ export const Button: React.FC = ({ type = 'button', onClick, disabled, block, secondary, compact, dangerous, loading, className, title, text, children, ...props }) => { const handleClick = useCallback>( (e) => { if (disabled || loading) { e.stopPropagation(); e.preventDefault(); } else if (onClick) { onClick(e); } }, [disabled, loading, onClick], ); const label = text ?? children; return ( ); };