import { type Component, type JSX, Show, splitProps } from 'solid-js'; /** * Props for the reusable Button component. * * - `primary` (default): indigo background, white text. * - `secondary`: white background, gray border, dark text. * - `danger`: red background, white text. * * When `loading` is true, the button is disabled and a spinner replaces the icon. */ interface ButtonProps extends JSX.ButtonHTMLAttributes { variant?: 'primary' | 'secondary' | 'danger'; loading?: boolean; icon?: Component<{ class?: string }>; } const variantClasses: Record = { primary: 'text-white bg-indigo-600 hover:bg-indigo-700 border-transparent focus:ring-indigo-500', secondary: 'text-gray-700 bg-white hover:bg-gray-50 border-gray-300 focus:ring-indigo-500', danger: 'text-white bg-red-600 hover:bg-red-700 border-transparent focus:ring-red-500', }; /** Styled button with variant theming, optional leading icon, and loading state. */ const Button: Component = (allProps) => { const [props, rest] = splitProps(allProps, [ 'variant', 'loading', 'icon', 'children', 'class', ]); const variant = () => props.variant ?? 'primary'; const renderIcon = () => { if (props.loading) { return (
); } if (props.icon) { const Icon = props.icon; return ; } return null; }; return ( ); }; export default Button;