Button
solid-ui/buttonFreeComponent
A button component
Live preview
live · rendered by the registry
Rendered by solid-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.solid-ui.com/r/button.jsonSource
1import type { JSX, ValidComponent } from "solid-js"2import { splitProps } from "solid-js"34import * as ButtonPrimitive from "@kobalte/core/button"5import type { PolymorphicProps } from "@kobalte/core/polymorphic"6import type { VariantProps } from "class-variance-authority"7import { cva } from "class-variance-authority"89import { cn } from "~/lib/utils"1011const buttonVariants = cva(12 "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",13 {14 variants: {15 variant: {16 default: "bg-primary text-primary-foreground hover:bg-primary/90",17 destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",18 outline: "border border-input hover:bg-accent hover:text-accent-foreground",19 secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",20 ghost: "hover:bg-accent hover:text-accent-foreground",21 link: "text-primary underline-offset-4 hover:underline"22 },23 size: {24 default: "h-10 px-4 py-2",25 sm: "h-9 px-3 text-xs",26 lg: "h-11 px-8",27 icon: "size-10"28 }29 },30 defaultVariants: {31 variant: "default",32 size: "default"33 }34 }35)3637type ButtonProps<T extends ValidComponent = "button"> = ButtonPrimitive.ButtonRootProps<T> &38 VariantProps<typeof buttonVariants> & { class?: string | undefined; children?: JSX.Element }3940const Button = <T extends ValidComponent = "button">(41 props: PolymorphicProps<T, ButtonProps<T>>42) => {43 const [local, others] = splitProps(props as ButtonProps, ["variant", "size", "class"])44 return (45 <ButtonPrimitive.Root46 class={cn(buttonVariants({ variant: local.variant, size: local.size }), local.class)}47 {...others}48 />49 )50}5152export { Button, buttonVariants }53export type { ButtonProps }
What it pulls in
npm packages
Files it writes
More from solid-ui
All 55 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | solid-ui | Components | Free | 2 deps | |
| Alertalert | solid-ui | Components | Free | 3 deps | |
| Alert Dialogalert-dialog | solid-ui | Components | Free | 2 deps | |
| Aspect Ratioaspect-ratio | solid-ui | Components | Free | 1 dep | |
| Avataravatar | solid-ui | Components | Free | 2 deps | |
| Badgebadge | solid-ui | Components | Free | 2 deps | |
| Badge Deltabadge-delta | solid-ui | Components | Free | 2 deps | |
| Bar Listbar-list | solid-ui | Components | Free | 1 dep |
