import { createToken, resolveTokens, type JSXTokenizer, type TokenElement } from "@solid-primitives/jsx-tokenizer"; import { createSignal, type JSX, type Component, type ParentProps, For, splitProps, type Accessor, createMemo } from "solid-js"; import { ReactiveSet } from "@solid-primitives/set"; import { SegmentedButtonGroup, ButtonSegmentButton } from "./base"; export type ValidValue = string | number | symbol; export type BaseValueSegmentedButtonProps = & Omit, "children"> & { onSelectionChange?: (values: T) => void; selected: T; disabled?: boolean; children: JSX.Element; }; // export type SingleValueSegmentedButtonProps< // T extends ValidValue // > = BaseValueSegmentedButtonProps; // export type MultiValueSegmentedButtonProps< // T extends ValidValue, // V extends T[] | Set | Record, // > = BaseValueSegmentedButtonProps; export type ValueSegmentedButtonProps< T extends ValidValue, > = BaseValueSegmentedButtonProps; export const ValueSegmentedButton = < T extends ValidValue, >( props: ParentProps>, ) => { const [local, others] = splitProps( props, [ "onSelectionChange", "selected", "disabled", "children", ], ) const tokens = resolveTokens( ButtonSegment, () => props.children, ) as Accessor>[]>; return ( { ({ data: segment }, index) => { if(segment.value === undefined) { throw new Error(""); } return ( local.onSelectionChange?.(segment.value)} selected={local.selected === segment.value} icon={segment.icon} label={segment.label} /> ); } } ); } export type ButtonSegmentProps = { value: T; icon?: JSX.Element; label?: JSX.Element; } type ButtonSegmentComponent = & ((props: ButtonSegmentProps) => JSX.Element) & JSXTokenizer>; export const ButtonSegment = createToken>() as ButtonSegmentComponent;