Component
Solid Button
The primary, high-emphasis action. A filled neutral surface built on color.primary and color.primary-foreground — the canonical confirmation control in the DevSnips React system.
- Component
- React
- TSX
- Tailwind CSS
- MIT
What it does
Capabilities
- Semantic HTML
- ARIA
Preview
Live component
9:41 100%
devsnips.site/library/react/components/buttons/solid-button/ fluid · no fixed width 100%
Install
Add to your project
npx devsnips add React/Components/Buttons/solid-button React/Components/Buttons/solid-button import type { ButtonHTMLAttributes, ReactNode } from "react";
/* DevSnips React — SolidButton
* Filled primary action. High-emphasis: one per surface. Built on the
* semantic tokens color.primary / color.primary-foreground from
* React/DESIGN_TOKENS.md. Tailwind utilities consume the tokens via
* arbitrary values (var(--ds-...)) so the button themes with the surface.
*/
export type ButtonSize = "xs" | "sm" | "md" | "lg" | "xl";
export interface SolidButtonProps
extends ButtonHTMLAttributes<HTMLButtonElement> {
/** Control height. `md` (36px) is the default. */
size?: ButtonSize;
/** Fill the available width (`w-full`). */
block?: boolean;
/** Show a spinner and disable interaction while an action is pending. */
loading?: boolean;
/** Leading icon node. */
iconLeft?: ReactNode;
/** Trailing icon node. */
iconRight?: ReactNode;
}
function cx(...parts: Array<string | false | null | undefined>): string {
return parts.filter(Boolean).join(" ");
}
function Spinner() {
return (
<svg className="h-[1em] w-[1em] shrink-0 animate-spin motion-reduce:animate-none" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="3" className="opacity-25" />
<path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" strokeWidth="3" strokeLinecap="round" />
</svg>
);
}
const SIZES: Record<ButtonSize, string> = {
xs: "h-7 gap-1 px-2 text-xs [&_svg]:size-[14px]",
sm: "h-8 gap-1.5 px-3 text-xs [&_svg]:size-[14px]",
md: "h-9 gap-2 px-3.5 text-[13px] [&_svg]:size-4",
lg: "h-10 gap-2 px-4 text-[13px] [&_svg]:size-[18px]",
xl: "h-11 gap-2 px-5 text-sm [&_svg]:size-5",
};
export function SolidButton({
children,
size = "md",
block = false,
loading = false,
disabled,
iconLeft,
iconRight,
className,
type = "button",
...rest
}: SolidButtonProps) {
const isDisabled = disabled || loading;
return (
<button
type={type}
className={cx(
"inline-flex select-none items-center justify-center whitespace-nowrap rounded-[var(--ds-radius-sm)] border font-medium leading-none transition-colors duration-150 ease-out motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ds-color-focus-ring)] disabled:pointer-events-none disabled:opacity-50",
"border-transparent bg-[var(--ds-color-primary)] text-[var(--ds-color-primary-foreground)] hover:bg-[color-mix(in_srgb,var(--ds-color-primary)_88%,#000)] active:bg-[color-mix(in_srgb,var(--ds-color-primary)_80%,#000)]",
SIZES[size],
block && "w-full",
className,
)}
disabled={isDisabled}
aria-busy={loading || undefined}
{...rest}
>
{loading ? <Spinner /> : iconLeft}
<span>{children}</span>
{!loading && iconRight}
</button>
);
}
export default SolidButton; /* DevSnips React — JavaScript parity build.
* Same API, behavior, and classes as code.tsx; TypeScript types removed.
* Regenerated from code.tsx — edit code.tsx and re-run the generator.
*/
function cx(...parts) {
return parts.filter(Boolean).join(" ");
}
function Spinner() {
return <svg className="h-[1em] w-[1em] shrink-0 animate-spin motion-reduce:animate-none" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="3" className="opacity-25" />
<path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" strokeWidth="3" strokeLinecap="round" />
</svg>;
}
const SIZES = {
xs: "h-7 gap-1 px-2 text-xs [&_svg]:size-[14px]",
sm: "h-8 gap-1.5 px-3 text-xs [&_svg]:size-[14px]",
md: "h-9 gap-2 px-3.5 text-[13px] [&_svg]:size-4",
lg: "h-10 gap-2 px-4 text-[13px] [&_svg]:size-[18px]",
xl: "h-11 gap-2 px-5 text-sm [&_svg]:size-5"
};
export function SolidButton({
children,
size = "md",
block = false,
loading = false,
disabled,
iconLeft,
iconRight,
className,
type = "button",
...rest
}) {
const isDisabled = disabled || loading;
return <button
type={type}
className={cx(
"inline-flex select-none items-center justify-center whitespace-nowrap rounded-[var(--ds-radius-sm)] border font-medium leading-none transition-colors duration-150 ease-out motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ds-color-focus-ring)] disabled:pointer-events-none disabled:opacity-50",
"border-transparent bg-[var(--ds-color-primary)] text-[var(--ds-color-primary-foreground)] hover:bg-[color-mix(in_srgb,var(--ds-color-primary)_88%,#000)] active:bg-[color-mix(in_srgb,var(--ds-color-primary)_80%,#000)]",
SIZES[size],
block && "w-full",
className
)}
disabled={isDisabled}
aria-busy={loading || undefined}
{...rest}
>
{loading ? <Spinner /> : iconLeft}
<span>{children}</span>
{!loading && iconRight}
</button>;
}
export default SolidButton; # Solid Button
The primary, high-emphasis action. A filled neutral surface built on color.primary and color.primary-foreground — the canonical confirmation control in the DevSnips React system.
## Installation
This component requires **React** and **Tailwind CSS**. Drop `code.tsx` (or `code.jsx` for JavaScript projects) into your project. Tailwind utility classes are included directly in the component, so no separate CSS file is required.
The component consumes the DevSnips semantic design tokens through Tailwind arbitrary values (for example `bg-[var(--ds-color-primary)]`). Define the `--ds-*` tokens once in your theme — see [React/DESIGN_TOKENS.md](../../../DESIGN_TOKENS.md) for the full token spec.
## Usage
```tsx
<SolidButton size="md" onClick={save}>Save changes</SolidButton>
```
## JavaScript
A `code.jsx` build is provided for projects that ship plain JSX. It exposes the same API and behavior as `code.tsx` — only the TypeScript types are removed.
## Props
| Prop | Type | Default |
|---|---|---|
| `children` | `ReactNode` | — |
| `size` | `xs \| sm \| md \| lg \| xl` | `md` |
| `block` | `boolean` | `false` |
| `loading` | `boolean` | `false` |
| `disabled` | `boolean` | `false` |
| `iconLeft` / `iconRight` | `ReactNode` | — |
| `type` | `button \| submit \| reset` | `button` |
Plus all native `ButtonHTMLAttributes<HTMLButtonElement>` (onClick, aria-*, etc.).
## Variants
Single filled variant built on `color.primary` / `color.primary-foreground`. See OutlineButton / SecondaryButton / GhostButton for other emphasis levels.
## Sizes
xs (28px) · sm (32px) · **md (36px, default)** · lg (40px) · xl (44px). Horizontal padding scales 8 → 20px; icons scale 14 → 20px.
## States
default · hover · active · focus-visible · loading (spinner + `aria-busy`, layout preserved) · disabled (reduced opacity).
## Accessibility
Renders a native `<button>`. Focus-visible ring uses `color.focus-ring`. Loading sets `aria-busy` and disables to prevent double-submit. Disabled never removes the affordance (reduced opacity, not hidden). Meets the 44px touch target at lg/xl.
## Styling
Tailwind classes are included directly in the component and consume the DevSnips semantic design tokens (`--ds-*`) via arbitrary values. The button themes with the surface automatically in light and dark mode. No component-specific CSS file is needed.
## Design Tokens
See [React/DESIGN_TOKENS.md](../../../DESIGN_TOKENS.md) for the authoritative token specification. This button uses the semantic color, radius, and motion tokens; define them once in your project theme and every button in the family stays in sync.
## Notes
Keep exactly one solid button per prominent surface to preserve hierarchy. Pair with an OutlineButton for the cancel/secondary action. 81 lines UTF-8 · LF · Spaces: 2
DevSnips AI ready Claude · Cursor · Windsurf
Agent skill & Model Context Protocol
Pass this component straight into your AI workflow. DevSnips exposes each resource as a structured, addressable registry entry, so your agent installs the real files instead of approximating them.
devsnips://components/buttons/solid-button I want to use this DevSnips resource in production: Page: https://devsnips.site/library/react/components/buttons/solid-button/ Install: npx devsnips add React/Components/Buttons/solid-button This is the Solid Button — The primary, high-emphasis action. A filled neutral surface built on color.primary and color.primary-foreground — the canonical confirmation control in the DevSnips React system. Use this DevSnips resource as the starting point for my project. Adapt it to my project's stack and conventions, fix any issues, and make it production-ready while preserving its intended design and behavior.
Paste into ChatGPT, Claude or your agent — it already carries the page URL and the exact install path.
Resource URI
devsnips://components/buttons/solid-button