Button
Displays a button or a component that looks like a button.
/** @jsxImportSource @bext-stack/framework */
// src/components/ui/button.tsx
const BASE = "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50";
const VARIANT = {
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
};
const SIZE = { default: "h-9 px-4 py-2", sm: "h-8 rounded-md px-3 text-xs", lg: "h-10 rounded-md px-8", icon: "h-9 w-9" };
export function Button(o) {
const c = [BASE, VARIANT[o.variant || "default"], SIZE[o.size || "default"], o.class].filter(Boolean).join(" ");
if (o.href) return \`<a href="\${o.href}" class="\${c}">\${o.children}</a>\`;
return \`<button class="\${c}">\${o.children}</button>\`;
}
Installation
$ bext ui add button
Copy and paste the following into src/components/ui/button.tsx.
/** @jsxImportSource @bext-stack/framework */
// src/components/ui/button.tsx
const BASE = "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50";
const VARIANT = {
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
};
const SIZE = { default: "h-9 px-4 py-2", sm: "h-8 rounded-md px-3 text-xs", lg: "h-10 rounded-md px-8", icon: "h-9 w-9" };
export function Button(o) {
const c = [BASE, VARIANT[o.variant || "default"], SIZE[o.size || "default"], o.class].filter(Boolean).join(" ");
if (o.href) return \`<a href="\${o.href}" class="\${c}">\${o.children}</a>\`;
return \`<button class="\${c}">\${o.children}</button>\`;
}
Usage
import { Button } from "@/components/ui/button";
export default function Page() {
return Button({ variant: "outline", children: "Button" });
}
Examples
Default
Secondary
Destructive
Outline
Ghost
Link
Icon
With Icon
Loading
Sizes
On This Page