icon-button.tsx 979 B

1234567891011121314151617181920212223242526272829
  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?: "small" | "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-icon={props.icon}
  17. data-size={split.size || "normal"}
  18. data-variant={split.variant || "secondary"}
  19. classList={{
  20. ...split.classList,
  21. [split.class ?? ""]: !!split.class,
  22. }}
  23. >
  24. <Icon name={props.icon} size={split.iconSize ?? (split.size === "large" ? "normal" : "small")} />
  25. </Kobalte>
  26. )
  27. }