import { children, createEffect, createMemo, createRenderEffect, createSignal, For, getOwner, mergeProps, runWithOwner, splitProps, type ChildrenReturn, type Component, type FlowComponent, type JSX, type ParentComponent } from "solid-js"; import { isToken, resolveTokens } from "@solid-primitives/jsx-tokenizer"; import { ButtonSegmentToken, type ButtonSegmentData } from "./button-segment"; import { Ripple } from "../ripple"; import { Focus } from "../focus"; import { mergeRefs, resolveElements, resolveFirst } from "@solid-primitives/refs"; import { MaterialSymbolController } from "../icon"; import { Dynamic } from "solid-js/web"; import { buttonSegmentCheckmarkPathStyle, buttonSegmentCheckmarkStyle, buttonSegmentGraphicStyle, buttonSegmentIconStyle, buttonSegmentLeadingStyle, buttonSegmentMaterialSymbolStyle, buttonSegmentOutlineStyle, buttonSegmentStyle, buttonSegmentTouchStyle, segmentedButtonStyle, } from "./base.css"; export type SegmentedButtonProps = { disabled?: boolean; children: JSX.Element; } & JSX.HTMLAttributes; export const SegmentedButton = < T, >(props: SegmentedButtonProps) => { const mergedProps = mergeProps( { disabled: false, }, props, ); const [local, others] = splitProps( mergedProps, ["disabled", "children"] ); const tokens = resolveTokens( ButtonSegmentToken, () => local.children, // { includeJSXElements: true }, ); return ( isToken(ButtonSegmentToken, token))}>{ segment => ( ) } ); } type AnimationState = "selecting" | "deselecting"; type ButtonSegmentProps = ButtonSegmentData & { disabled: boolean; } const ButtonSegment: Component = (props) => { const mergedProps = mergeProps( { selected: false, disabled: false }, props, ); const [local, others] = splitProps( mergedProps, [ "ref", "value", "disabled", "selected", "icon", "label", ] ) let ref!: HTMLButtonElement; const label = children(() => local.label); const hasLabel = createMemo(() => label.toArray().length > 0); // const icon = children(() => local.icon); const hasIcon = () => !!local.icon; const [state, setState] = createSignal(); createEffect( (prevSelected) => { const nextSelected = local.selected; if(!prevSelected && nextSelected) { setState("selecting"); } else if(prevSelected && !nextSelected) { setState("deselecting"); } else setState(); return nextSelected; }, local.selected, ); return ( ); } type ButtonSegmentCheckmarkProps = { selected: boolean; state?: AnimationState; disabled: boolean; } const ButtonSegmentCheckmark: Component = (props) => { return ( ); }