// import { type JSX, createMemo, createSignal, splitProps, type ParentComponent, type Signal, Show, type ValidComponent, type Ref, type ComponentProps } from "solid-js"; // import { Ripple} from "../ripple"; // import { buttonControlStyle, buttonOutlineStyle, buttonStyle } from "./button.css"; // import clsx from "clsx/lite"; // import { Dynamic, type DynamicProps, type ElementOf, type OverrideProps } from "../dynamic"; // import { Focus } from "../focus"; // import { mergeRefs } from "@solid-primitives/refs"; // type ButtonVariant = "elevated" | "filled" | "tonal" | "outlined" | "text"; // // export type ButtonProps = { // // disabled?: boolean; // // variant: ButtonVariant; // // leading?: JSX.Element; // // trailing?: JSX.Element; // // } & ( // // | JSX.ButtonHTMLAttributes // // | JSX.AnchorHTMLAttributes // // ); // // export type ButtonProps< // // T extends keyof JSX.HTMLElementTags = "button", // // > = OverrideProps< // // ComponentProps, // // { // // as?: T; // // ref?: Ref>; // // variant: ButtonVariant; // // disabled?: boolean; // // leading?: JSX.Element; // // trailing?: JSX.Element; // // children: JSX.Element; // // } // // >; // export type ButtonProps< // T extends keyof JSX.HTMLElementTags, // P = ComponentProps, // > = OverrideProps< // P, // { // variant: ButtonVariant; // } // >; // export const Button = < // T extends keyof HTMLElementTagNameMap // >(props: ButtonProps) => { // const [local, others] = splitProps( // props, // [ // // "as", // "ref", // "class", // // "variant", // // "leading", // // "trailing", // // "children", // ], // ); // const [ref, setRef] = createSignal() as Signal; // return ( // // // // //
{local.leading}
//
// {local.children} // //
{local.trailing}
//
// //
// // // ); // } import { createMemo, createSignal, mergeProps, Show, splitProps, type Component, type ComponentProps, type JSX, type Signal } from "solid-js"; import { useButtonTheme, type ButtonVariants } from "./theme"; import { Dynamic } from "solid-js/web"; import { clsx } from "clsx/lite"; import { Ripple } from "../ripple"; import { mergeRefs } from "@solid-primitives/refs"; import { Focus } from "../focus"; import { buttonIconStyle, buttonOutlineStyle, buttonStyle } from "./button.css"; import { MaterialSymbolController } from "../icon"; const BUTTON_VARIANTS = [ "elevated", "filled", "filledTonal", "outlined", "text", ] as const; type ButtonVariant = typeof BUTTON_VARIANTS[number]; type ButtonBaseProps = { as?: T; disabled?: boolean; icon?: JSX.Element; iconAffinity?: "leading" | "trailing"; label: JSX.Element; } type ButtonVariantProps< T extends keyof JSX.HTMLElementTags, P = Omit, > = P & ButtonBaseProps; const BUTTON_INPUT_TYPES = ["button", "color", "file", "image", "reset", "submit"] type ButtonFullProps = ButtonVariantProps & { variant: ButtonVariant; } const Button = < T extends keyof JSX.HTMLElementTags = "button", >(props: ButtonFullProps): JSX.Element => { const mergedProps = mergeProps( { iconAffinity: "leading" as const }, props, ); const [local, others] = splitProps( mergedProps as any, [ "variant", "as", "class", "ref", "disabled", "icon", "iconAffinity", "label" ] ); const [ref, setRef] = createSignal() as Signal; const tag = () => local.as ?? "button"; const isButton = createMemo(() => { if(tag() === "button") return true; if (tag() === "input") { const type: string | undefined = others.type; if(!type) return false; return BUTTON_INPUT_TYPES.indexOf(type) !== -1; } return false; }); return ( // @ts-ignore {local.label}
); } /** * @category Component */ const proxy = new Proxy( Button, { get: (target, variant, receiver) => { if(!BUTTON_VARIANTS.includes(variant as any)) return; const component: ButtonVariantComponent = < T extends keyof JSX.HTMLElementTags >(props: ButtonVariantProps) => { return (