import { children, createEffect, createMemo, createRenderEffect, createSignal, For, getOwner, mergeProps, runWithOwner, splitProps, type Accessor, 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"; import clsx from "clsx/lite"; import { createContextProvider } from "@solid-primitives/context"; import { asAccessor } from "@solid-primitives/utils"; type SegmentedButtonInternalsProps = { disabled: boolean; }; type SegmentedButtonInternals = { disabled: Accessor; }; const [SegmentedButtonInternalsProvider, useSegmentedButtonInternals] = createContextProvider< SegmentedButtonInternals, SegmentedButtonInternalsProps >((props) => ({ disabled: asAccessor(props.disabled), })); export type SegmentedButtonProps = Omit< JSX.HTMLAttributes, "role" | "children" > & { disabled?: boolean; children: JSX.Element; }; export const SegmentedButtonGroup: Component = ( props ) => { const mergedProps = mergeProps({ disabled: false }, props); const [local, others] = splitProps(mergedProps, [ "class", "disabled", "children", ]); return ( ); }; type ButtonSegmentAnimationState = "selecting" | "deselecting"; export type ButtonSegmentButtonProps = Omit< JSX.ButtonHTMLAttributes, "value" | "disabled" | "children" > & { selected: boolean; icon?: JSX.Element; label?: JSX.Element; }; export const ButtonSegmentButton: Component = ( props ) => { const [local, others] = splitProps(props, [ "ref", "selected", "icon", "label", ]); const { disabled } = useSegmentedButtonInternals()!; 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?: ButtonSegmentAnimationState; disabled: boolean; }; const ButtonSegmentCheckmark: Component = ( props ) => { return ( ); };