Actions

Button

Clear actions, useful variants, and stable loading states.

OSCL StudioComponents, in context.Live preview
FOUNDATION / ACTIONS

Button

Go on. Give it a click.
Interactive preview. Real components.View docs

Use it in your project

Install oscl-ui from npm and import oscl-ui/styles.css once. See installation.

button-example.tsx
import { Button } from "oscl-ui";

<Button variant="primary">Build something</Button>

Accessibility

Keep visible labels and keyboard focus. Supply an accessible name to icon-only actions. Try this preview with Tab, Enter, Space, and Escape where appropriate.

The source, in full

This is the actual source from the isolated OSCL package used by this website. Native props and TypeScript declarations are included in the npm package.

button.tsx
"use client";

import { forwardRef } from "react";
import type { ButtonHTMLAttributes, ReactNode } from "react";

export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
  variant?: "primary" | "secondary" | "outline" | "ghost" | "destructive";
  loading?: boolean;
  leadingIcon?: ReactNode;
  trailingIcon?: ReactNode;
} & ({ size: "icon"; "aria-label": string } | { size?: "sm" | "md" | "lg" });

export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
  { variant = "primary", size = "md", loading = false, disabled, leadingIcon, trailingIcon, className = "", children, type = "button", ...props }, ref,
) {
  return <button {...props} ref={ref} type={type} disabled={disabled || loading} aria-busy={loading || undefined}
    className={`oscl-button oscl-button--${variant} oscl-button--${size} ${className}`}>
    <span className="oscl-button-content" style={{ visibility: loading ? "hidden" : undefined }}>
      {leadingIcon}{children}{trailingIcon}
    </span>
    {loading && <span className="oscl-spinner" aria-hidden="true" />}
  </button>;
});