MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / Button

Function Button

packages/react/src/components/button.tsx:40–84  ·  view source on GitHub ↗
({
  className,
  variant = "default",
  size = "default",
  asChild = false,
  loading = false,
  disabled,
  children,
  ...props
}: React.ComponentProps<"button"> &
  VariantProps<typeof buttonVariants> & {
    asChild?: boolean;
    /** Show a centered spinner while keeping the label's footprint, so the
     *  button (and any row it sits in) does not change width on entering the
     *  loading state. Ignored with `asChild` (Slot requires a single child). */
    loading?: boolean;
  })

Source from the content-addressed store, hash-verified

38);
39
40function Button({
41 className,
42 variant = "default",
43 size = "default",
44 asChild = false,
45 loading = false,
46 disabled,
47 children,
48 ...props
49}: React.ComponentProps<"button"> &
50 VariantProps<typeof buttonVariants> & {
51 asChild?: boolean;
52 /** Show a centered spinner while keeping the label's footprint, so the
53 * button (and any row it sits in) does not change width on entering the
54 * loading state. Ignored with `asChild` (Slot requires a single child). */
55 loading?: boolean;
56 }) {
57 const Comp = asChild ? Slot.Root : "button";
58 const showLoading = loading && !asChild;
59
60 return (
61 <Comp
62 data-slot="button"
63 data-variant={variant}
64 data-size={size}
65 data-loading={showLoading ? "" : undefined}
66 className={cn(buttonVariants({ variant, size, className }), showLoading && "relative")}
67 disabled={disabled || loading}
68 {...props}
69 >
70 {showLoading ? (
71 <>
72 {/* Reserve the label's width so the box stays the same size; overlay
73 the spinner centered on top. */}
74 <span className="invisible">{children}</span>
75 <span className="absolute inset-0 flex items-center justify-center">
76 <Spinner className="size-3.5" />
77 </span>
78 </>
79 ) : (
80 children
81 )}
82 </Comp>
83 );
84}
85
86export { Button, buttonVariants };

Callers

nothing calls this directly

Calls 1

cnFunction · 0.90

Tested by

no test coverage detected