icon-button.tsx 948 B

12345678910111213141516171819202122232425262728
  1. import { Button as Kobalte } from "@kobalte/core/button"
  2. import { type ComponentProps, splitProps } from "solid-js"
  3. import { Icon, IconProps } from "./icon"
  4. export interface IconButtonProps extends ComponentProps<typeof Kobalte> {
  5. icon: IconProps["name"]
  6. size?: "normal" | "large"
  7. iconSize?: IconProps["size"]
  8. variant?: "primary" | "secondary" | "ghost"
  9. }
  10. export function IconButton(props: ComponentProps<"button"> & IconButtonProps) {
  11. const [split, rest] = splitProps(props, ["variant", "size", "iconSize", "class", "classList"])
  12. return (
  13. <Kobalte
  14. {...rest}
  15. data-component="icon-button"
  16. data-size={split.size || "normal"}
  17. data-variant={split.variant || "secondary"}
  18. classList={{
  19. ...(split.classList ?? {}),
  20. [split.class ?? ""]: !!split.class,
  21. }}
  22. >
  23. <Icon name={props.icon} size={split.iconSize ?? (split.size === "large" ? "normal" : "small")} />
  24. </Kobalte>
  25. )
  26. }