import { createEffect, createSignal, mergeProps, on, splitProps, untrack } from 'solid-js'; import type { Accessor, JSX, ParentProps } from 'solid-js'; import styles from './Button.module.scss'; type ButtonProps = JSX.ButtonHTMLAttributes & ParentProps & { iconLeft?: JSX.Element; iconRight?: JSX.Element; buttonStyle?: 'primary' | 'secondary' | 'danger' | 'icon' | 'iconPrimary' | 'iconSecondary' | 'iconDanger' | 'ghost'; large?: boolean; }; function Button(props: ButtonProps) { const [buttonProps, rest] = splitProps(props, ['iconLeft', 'iconRight', 'buttonStyle', 'class', 'large']); const merged = mergeProps({ buttonStyle: 'primary', large: false }, buttonProps); return ( ); } type ButtonToggleProps = ButtonProps & { checked?: Accessor; onChecked?: (checked: boolean) => any; }; Button.Toggle = (props: ButtonToggleProps) => { const [split, rest] = splitProps(props, ['checked', 'onChecked', 'onClick']); const [checked, setChecked] = createSignal(untrack(() => split.checked?.()) || false); createEffect(on(() => split.checked?.(), newValue => setChecked(newValue || false))); function toggle() { const newValue = !checked(); setChecked(newValue); props.onChecked?.(newValue); } return (