opencode/packages/ui/src/components/button.tsx

34 lines
1002 B
TypeScript
Raw Normal View History

2025-10-14 20:14:26 +08:00
import { Button as Kobalte } from "@kobalte/core/button"
2025-10-23 19:33:52 +08:00
import { type ComponentProps, Show, splitProps } from "solid-js"
import { Icon, IconProps } from "./icon"
2025-10-14 20:14:26 +08:00
2025-10-23 06:31:44 +08:00
export interface ButtonProps
extends ComponentProps<typeof Kobalte>,
Pick<ComponentProps<"button">, "class" | "classList" | "children"> {
2025-12-13 03:24:11 +08:00
size?: "small" | "normal" | "large"
2025-10-14 20:14:26 +08:00
variant?: "primary" | "secondary" | "ghost"
2025-10-23 19:33:52 +08:00
icon?: IconProps["name"]
2025-10-14 20:14:26 +08:00
}
2025-10-23 06:31:44 +08:00
export function Button(props: ButtonProps) {
2025-10-23 19:33:52 +08:00
const [split, rest] = splitProps(props, ["variant", "size", "icon", "class", "classList"])
2025-10-14 20:14:26 +08:00
return (
<Kobalte
{...rest}
data-component="button"
data-size={split.size || "normal"}
data-variant={split.variant || "secondary"}
2025-10-23 19:33:52 +08:00
data-icon={split.icon}
2025-10-14 20:14:26 +08:00
classList={{
...(split.classList ?? {}),
[split.class ?? ""]: !!split.class,
}}
>
2025-10-23 19:33:52 +08:00
<Show when={split.icon}>
2025-12-02 06:26:06 +08:00
<Icon name={split.icon!} size="small" />
2025-10-23 19:33:52 +08:00
</Show>
2025-10-14 20:14:26 +08:00
{props.children}
</Kobalte>
)
}