AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

button.tsx 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Slot } from "@radix-ui/react-slot"
  2. import { cva, type VariantProps } from "class-variance-authority"
  3. import * as React from "react"
  4. import { cn } from "@/lib/utils"
  5. const buttonVariants = cva(
  6. "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-[color,box-shadow] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
  7. {
  8. variants: {
  9. variant: {
  10. default:
  11. "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
  12. destructive:
  13. "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40",
  14. outline:
  15. "border border-input bg-background shadow-xs hover:bg-accent hover:text-accent-foreground",
  16. secondary:
  17. "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
  18. ghost: "hover:bg-accent hover:text-accent-foreground",
  19. link: "text-primary underline-offset-4 hover:underline",
  20. },
  21. size: {
  22. default: "h-9 px-4 py-2 has-[>svg]:px-3",
  23. sm: "h-8 rounded-md px-3 has-[>svg]:px-2.5",
  24. lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
  25. icon: "size-9",
  26. },
  27. },
  28. defaultVariants: {
  29. variant: "default",
  30. size: "default",
  31. },
  32. }
  33. )
  34. function Button({
  35. className,
  36. variant,
  37. size,
  38. asChild = false,
  39. ...props
  40. }: React.ComponentProps<"button"> &
  41. VariantProps<typeof buttonVariants> & {
  42. asChild?: boolean
  43. }) {
  44. const Comp = asChild ? Slot : "button"
  45. return (
  46. <Comp
  47. data-slot="button"
  48. className={cn(buttonVariants({ variant, size, className }))}
  49. {...props}
  50. />
  51. )
  52. }
  53. export { Button, buttonVariants }