summaryrefslogtreecommitdiffhomepage
path: root/packages/ui/src/components/icon-button.tsx
blob: f483f92a74271d3e2ea0fcd11b1c5854a76995f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Button as Kobalte } from "@kobalte/core/button"
import { type ComponentProps, splitProps } from "solid-js"
import { Icon, IconProps } from "./icon"

export interface IconButtonProps {
  icon: IconProps["name"]
  size?: "normal" | "large"
  variant?: "primary" | "secondary" | "ghost"
}

export function IconButton(props: ComponentProps<"button"> & IconButtonProps) {
  const [split, rest] = splitProps(props, ["variant", "size", "class", "classList"])
  return (
    <Kobalte
      {...rest}
      data-component="icon-button"
      data-size={split.size || "normal"}
      data-variant={split.variant || "secondary"}
      classList={{
        ...(split.classList ?? {}),
        [split.class ?? ""]: !!split.class,
      }}
    >
      <Icon data-slot="icon" name={props.icon} size={split.size === "large" ? "normal" : "small"} />
    </Kobalte>
  )
}