Button

Triggers an action. Six variants, three sizes, icons, a loading state, and asChild for links.

Status: stable. Category: Actions.

import { Button, IconButton } from '@glyphui/ui'

Exports: Button, IconButton, buttonStyles.

Notes

  • Defaults to type="button", so it never submits a form by accident. Use FormSubmit inside forms.
  • IconButton requires aria-label because it has no visible text.

Button props

PropTypeDefaultDescription
asChildbooleanRender the child element (e.g. a router link) with button styles instead of a <button>.
fullWidthboolean
iconOnlyboolean
leftIconReactNode
loadingbooleanShows a spinner, disables the button and sets aria-busy.
rightIconReactNode
size"sm" | "md" | "lg"
variant"link" | "primary" | "danger" | "outline" | "secondary" | "ghost"

Example: Variants

import { Button } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="flex flex-wrap items-center gap-2">
      <Button>Primary</Button>
      <Button variant="secondary">Secondary</Button>
      <Button variant="outline">Outline</Button>
      <Button variant="ghost">Ghost</Button>
      <Button variant="danger">Delete</Button>
      <Button variant="link">Link</Button>
    </div>
  )
}

Example: Sizes and icons

import { Button, IconButton } from '@glyphui/ui'
import { Plus, Settings2 } from 'lucide-react'

export default function Example() {
  return (
    <div className="flex flex-wrap items-center gap-2">
      <Button size="sm" leftIcon={<Plus />}>
        Small
      </Button>
      <Button size="md" leftIcon={<Plus />}>
        Medium
      </Button>
      <Button size="lg" leftIcon={<Plus />}>
        Large
      </Button>
      <IconButton icon={<Settings2 />} aria-label="Settings" variant="outline" />
    </div>
  )
}

Example: Loading

Disables the button, shows a spinner and sets aria-busy.

import { Button } from '@glyphui/ui'
import { useState } from 'react'

export default function Example() {
  const [saving, setSaving] = useState(false)
  return (
    <Button
      loading={saving}
      onClick={() => {
        setSaving(true)
        setTimeout(() => setSaving(false), 1500)
      }}
    >
      {saving ? 'Saving…' : 'Save changes'}
    </Button>
  )
}

Example: As a link

asChild renders your router link with button styles.

import { Button } from '@glyphui/ui'
import { ArrowUpRight } from 'lucide-react'

export default function Example() {
  return (
    <Button variant="outline" rightIcon={<ArrowUpRight />} asChild>
      <a href="https://github.com/khalmohak/glyph">View on GitHub</a>
    </Button>
  )
}

Live page: https://glyphui.xyz/components/button