Skip to content
Sapphire UIv4.1.0

Button

Trigger an action such as saving, submitting or opening a dialog. Use the primary variant for the main action, outline for alternatives and destructive for irreversible changes.

Examples

Variants

JSX usage

Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.

bun add @kongmy-dev/sapphire-ui react react-dom
"use client";
import { Button } from "@kongmy-dev/sapphire-ui/button";

function ButtonVariants() {
  return (
    <div className="sp-cluster">
      <Button>Primary</Button>
      <Button variant="outline">Outline</Button>
      <Button variant="ghost">Ghost</Button>
      <Button variant="brand">Brand</Button>
      <Button variant="link">Link</Button>

      <Button variant="destructive">Delete</Button>
      <Button variant="destructive-outline">Delete outline</Button>
      <Button variant="destructive-ghost">Delete ghost</Button>
    </div>
  );
}

export default ButtonVariants;
Example CSS

Load these demo styles alongside the package stylesheet for the same layout and surfaces.

.docs-button-stacked {
  margin-top: var(--space-3);
}

.docs-button-full-width {
  max-width: calc(var(--space-1) * 90);
}

.docs-button-hint {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--muted-foreground);
}

.sp-button-demo-dark {
  padding: var(--space-6);
  background: var(--brand-navy);
}
HTML markup

Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.

States

JSX usage

Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.

bun add @kongmy-dev/sapphire-ui react react-dom
"use client";
import { Button } from "@kongmy-dev/sapphire-ui/button";

function ButtonStates() {
  return (
    <div className="sp-cluster">
      <Button disabled>Disabled</Button>
      <Button loading>Saving</Button>
      <Button asChild disabled>
        <a href="#disabled">Disabled link</a>
      </Button>
      <Button asChild loading>
        <a href="#loading">Loading link</a>
      </Button>
    </div>
  );
}

export default ButtonStates;
Example CSS

Load these demo styles alongside the package stylesheet for the same layout and surfaces.

.docs-button-stacked {
  margin-top: var(--space-3);
}

.docs-button-full-width {
  max-width: calc(var(--space-1) * 90);
}

.docs-button-hint {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--muted-foreground);
}

.sp-button-demo-dark {
  padding: var(--space-6);
  background: var(--brand-navy);
}
HTML markup

Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.

Dynamic Disabled

JSX usage

Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.

bun add @kongmy-dev/sapphire-ui react react-dom
"use client";
import { useState } from "react";
import { Button } from "@kongmy-dev/sapphire-ui/button";

function ButtonDynamicDisabled() {
  const [disabled, setDisabled] = useState(false);
  return (
    <div className="sp-cluster">
      <Button
        asChild
        disabled={disabled}
        onKeyDown={(event) => {
          if (event.key.toLowerCase() === 'd') setDisabled(true);
        }}
      >
        <a href="#dynamic-destination">Disable this link with D</a>
      </Button>
      <Button
        onClick={() => setDisabled((current) => !current)}
        aria-pressed={disabled}
      >
        Toggle link disabled
      </Button>
      <a href="#next-destination">Next destination</a>
      <output>{disabled ? 'Disabled' : 'Enabled'}</output>
    </div>
  );
}

export default ButtonDynamicDisabled;
Example CSS

Load these demo styles alongside the package stylesheet for the same layout and surfaces.

.docs-button-stacked {
  margin-top: var(--space-3);
}

.docs-button-full-width {
  max-width: calc(var(--space-1) * 90);
}

.docs-button-hint {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--muted-foreground);
}

.sp-button-demo-dark {
  padding: var(--space-6);
  background: var(--brand-navy);
}
HTML markup

Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.

Icons

JSX usage

Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.

bun add @kongmy-dev/sapphire-ui react react-dom lucide-react
"use client";
import { ArrowRight, Plus } from "lucide-react";
import { Button } from "@kongmy-dev/sapphire-ui/button";

function ButtonIcons() {
  return (
    <div className="sp-cluster">
      <Button icon={<Plus className="sp-icon" aria-hidden="true" size={20} />}>
        Add item
      </Button>
      <Button
        icon={<ArrowRight className="sp-icon" aria-hidden="true" size={20} />}
        iconPosition="end"
      >
        Continue
      </Button>
      <Button size="icon-sm" aria-label="Add small">
        <Plus className="sp-icon" aria-hidden="true" size={16} />
      </Button>
      <Button size="icon" aria-label="Add">
        <Plus className="sp-icon" aria-hidden="true" size={20} />
      </Button>
      <Button size="icon-lg" aria-label="Add large">
        <Plus className="sp-icon" aria-hidden="true" size={24} />
      </Button>
    </div>
  );
}

export default ButtonIcons;
Example CSS

Load these demo styles alongside the package stylesheet for the same layout and surfaces.

.docs-button-stacked {
  margin-top: var(--space-3);
}

.docs-button-full-width {
  max-width: calc(var(--space-1) * 90);
}

.docs-button-hint {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--muted-foreground);
}

.sp-button-demo-dark {
  padding: var(--space-6);
  background: var(--brand-navy);
}
HTML markup

Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.

On Dark

JSX usage

Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.

bun add @kongmy-dev/sapphire-ui react react-dom
"use client";
import { Button } from "@kongmy-dev/sapphire-ui/button";

function ButtonOnDark() {
  return (
    <div className="sp-button-demo-dark sp-cluster" data-theme="dark">
      <Button variant="brand">Get started</Button>
      <Button variant="outline">Learn more</Button>
    </div>
  );
}

export default ButtonOnDark;
Example CSS

Load these demo styles alongside the package stylesheet for the same layout and surfaces.

.docs-button-stacked {
  margin-top: var(--space-3);
}

.docs-button-full-width {
  max-width: calc(var(--space-1) * 90);
}

.docs-button-hint {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--muted-foreground);
}

.sp-button-demo-dark {
  padding: var(--space-6);
  background: var(--brand-navy);
}
HTML markup

Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.

Sizes

JSX usage

Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.

bun add @kongmy-dev/sapphire-ui react react-dom
"use client";
import { Button } from "@kongmy-dev/sapphire-ui/button";

function ButtonSizes() {
  return (
    <div className="sp-cluster">
      <Button size="xs">Extra small</Button>
      <Button size="sm">Small</Button>
      <Button>Default</Button>
      <Button size="lg">Large</Button>
      <Button size="xl">Extra large</Button>
    </div>
  );
}

export default ButtonSizes;
Example CSS

Load these demo styles alongside the package stylesheet for the same layout and surfaces.

.docs-button-stacked {
  margin-top: var(--space-3);
}

.docs-button-full-width {
  max-width: calc(var(--space-1) * 90);
}

.docs-button-hint {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--muted-foreground);
}

.sp-button-demo-dark {
  padding: var(--space-6);
  background: var(--brand-navy);
}
HTML markup

Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.

Props

Generated from the current public TypeScript signatures, including composed behaviour props. “—” means no default is declared in the local signature; forwarded behaviour defaults are not inferred.

Button

Button component props
PropTypeRequiredLocal default
variant"link" | "brand" | "primary" | "outline" | "ghost" | "destructive" | "destructive-outline" | "destructive-ghost" | null | undefinedNo'primary'
size"xs" | "sm" | "lg" | "default" | "xl" | "icon-sm" | "icon" | "icon-lg" | null | undefinedNo'default'
fullWidthboolean | null | undefinedNo—
asChildboolean | undefinedNofalse
iconReactElement<unknown, string | import("react").JSXElementConstructor<any>> | undefinedNo—
iconPosition"start" | "end" | undefinedNo'start'
loadingboolean | undefinedNo—
Inherited HTML / React props (290)
Button common platform props
PropTypeRequiredLocal default
refimport("react").Ref<HTMLButtonElement> | undefinedNo—
disabledboolean | undefinedNo—
namestring | undefinedNo—
type"button" | "submit" | "reset" | undefinedNo—
valuestring | number | readonly string[] | undefinedNo—
defaultValuestring | number | readonly string[] | undefinedNo—
classNamestring | undefinedNo—
idstring | undefinedNo—
styleimport("react").CSSProperties | undefinedNo—
tabIndexnumber | undefinedNo—
roleimport("react").AriaRole | undefinedNo—
aria-labelstring | undefinedNo—
childrenReactNodeNo—
onChangeimport("react").ChangeEventHandler<HTMLButtonElement, Element> | undefinedNo—

All inherited prop names:

ref key disabled form formAction formEncType formMethod formNoValidate formTarget name type value defaultChecked defaultValue suppressContentEditableWarning suppressHydrationWarning accessKey autoCapitalize autoFocus className contentEditable contextMenu dir draggable enterKeyHint hidden id lang nonce slot spellCheck style tabIndex title translate radioGroup role about content datatype inlist prefix property rel resource rev typeof vocab autoCorrect autoSave color itemProp itemScope itemType itemID itemRef results security unselectable popover popoverTargetAction popoverTarget inert inputMode is exportparts part aria-activedescendant aria-atomic aria-autocomplete aria-braillelabel aria-brailleroledescription aria-busy aria-checked aria-colcount aria-colindex aria-colindextext aria-colspan aria-controls aria-current aria-describedby aria-description aria-details aria-disabled aria-dropeffect aria-errormessage aria-expanded aria-flowto aria-grabbed aria-haspopup aria-hidden aria-invalid aria-keyshortcuts aria-label aria-labelledby aria-level aria-live aria-modal aria-multiline aria-multiselectable aria-orientation aria-owns aria-placeholder aria-posinset aria-pressed aria-readonly aria-relevant aria-required aria-roledescription aria-rowcount aria-rowindex aria-rowindextext aria-rowspan aria-selected aria-setsize aria-sort aria-valuemax aria-valuemin aria-valuenow aria-valuetext children dangerouslySetInnerHTML onCopy onCopyCapture onCut onCutCapture onPaste onPasteCapture onCompositionEnd onCompositionEndCapture onCompositionStart onCompositionStartCapture onCompositionUpdate onCompositionUpdateCapture onFocus onFocusCapture onBlur onBlurCapture onChange onChangeCapture onBeforeInput onBeforeInputCapture onInput onInputCapture onReset onResetCapture onSubmit onSubmitCapture onInvalid onInvalidCapture onLoad onLoadCapture onError onErrorCapture onKeyDown onKeyDownCapture onKeyPress onKeyPressCapture onKeyUp onKeyUpCapture onAbort onAbortCapture onCanPlay onCanPlayCapture onCanPlayThrough onCanPlayThroughCapture onDurationChange onDurationChangeCapture onEmptied onEmptiedCapture onEncrypted onEncryptedCapture onEnded onEndedCapture onLoadedData onLoadedDataCapture onLoadedMetadata onLoadedMetadataCapture onLoadStart onLoadStartCapture onPause onPauseCapture onPlay onPlayCapture onPlaying onPlayingCapture onProgress onProgressCapture onRateChange onRateChangeCapture onSeeked onSeekedCapture onSeeking onSeekingCapture onStalled onStalledCapture onSuspend onSuspendCapture onTimeUpdate onTimeUpdateCapture onVolumeChange onVolumeChangeCapture onWaiting onWaitingCapture onAuxClick onAuxClickCapture onClick onClickCapture onContextMenu onContextMenuCapture onDoubleClick onDoubleClickCapture onDrag onDragCapture onDragEnd onDragEndCapture onDragEnter onDragEnterCapture onDragExit onDragExitCapture onDragLeave onDragLeaveCapture onDragOver onDragOverCapture onDragStart onDragStartCapture onDrop onDropCapture onMouseDown onMouseDownCapture onMouseEnter onMouseLeave onMouseMove onMouseMoveCapture onMouseOut onMouseOutCapture onMouseOver onMouseOverCapture onMouseUp onMouseUpCapture onSelect onSelectCapture onTouchCancel onTouchCancelCapture onTouchEnd onTouchEndCapture onTouchMove onTouchMoveCapture onTouchStart onTouchStartCapture onPointerDown onPointerDownCapture onPointerMove onPointerMoveCapture onPointerUp onPointerUpCapture onPointerCancel onPointerCancelCapture onPointerEnter onPointerLeave onPointerOver onPointerOverCapture onPointerOut onPointerOutCapture onGotPointerCapture onGotPointerCaptureCapture onLostPointerCapture onLostPointerCaptureCapture onScroll onScrollCapture onScrollEnd onScrollEndCapture onWheel onWheelCapture onAnimationStart onAnimationStartCapture onAnimationEnd onAnimationEndCapture onAnimationIteration onAnimationIterationCapture onToggle onBeforeToggle onTransitionCancel onTransitionCancelCapture onTransitionEnd onTransitionEndCapture onTransitionRun onTransitionRunCapture onTransitionStart onTransitionStartCapture

ARIA attributes and native event handlers keep their React types. data-* attributes are also accepted by React.

Setup

bun add @kongmy-dev/sapphire-ui react react-dom

For an app using package components throughout, load the full stylesheet once. Add this component import where you use it.

import "@kongmy-dev/sapphire-ui/sapphire.css";
import { Button } from "@kongmy-dev/sapphire-ui/button";

Mixing package and vendored components? Follow application setup.

Search documentation