import type { PropsWithChildren } from 'react'; import React, { forwardRef, memo } from 'react'; import { classes, noop } from '../../utils'; import type { ButtonProps, ImportProps } from './models'; import { buttonVariants } from './variants'; import { useThemableElementRef } from '../../theming/hooks'; import { useMergeRefs } from '@floating-ui/react'; import { Spinner } from '../loading/Spinner'; export type IButtonSubcomponents = { Primary: typeof Primary; Secondary: typeof Secondary; Tertiary: typeof Tertiary; Ghost: typeof Ghost; Import: typeof Import; }; type ButtonWithRef = React.ForwardRefExoticComponent< React.PropsWithoutRef & React.RefAttributes >; const Button: ButtonWithRef & Partial = memo( forwardRef( ( { className, Icon, iconPosition = 'left', innerAlignment = 'center', size = 'md', isLoading = false, children, disabled = false, ...props }, propRef ) => { const themableRef = useThemableElementRef(); const ref = useMergeRefs([themableRef, propRef]); const isIconOnly = Icon && !children; const variants = buttonVariants({ size, iconPosition, innerAlignment, isIconOnly, }); return ( ); } ) ); const Primary = forwardRef( ({ className, coloring = 'default', active = false, ...props }, ref) => { const variants = buttonVariants({ type: 'primary', coloring, active, }); return (