Fancy button
The app button on Underlay's control language: basic, primary, neutral and destructive, with pending and done states.
One primary per view, basic beside it, neutral for a submit inside its context (Reply, Send), destructive for deletion. xsmall (30px, the default) is for toolbars and page chrome, small (36px) for dialog and sheet footers, medium (40px) for full-width actions on a phone. FancyButtonIcon takes the icon component in as, so its file is a client component; put the label in a <span> beside it and the button tightens the padding on the icon's side.
Variants
import { FancyButton } from "@/components/ui/fancy-button"
export default function FancyButtonVariants() {
return (
<div className="flex flex-wrap items-center justify-center gap-2">
<FancyButton>Cancel</FancyButton>
<FancyButton variant="primary">Save changes</FancyButton>
<FancyButton variant="neutral">Send reply</FancyButton>
<FancyButton variant="destructive">Delete project</FancyButton>
</div>
)
}
Sizes
import { FancyButton } from "@/components/ui/fancy-button"
export default function FancyButtonSizes() {
return (
<div className="flex flex-wrap items-center justify-center gap-2">
<FancyButton size="xsmall">Extra small</FancyButton>
<FancyButton size="small">Small</FancyButton>
<FancyButton size="medium">Medium</FancyButton>
</div>
)
}
With icon
"use client"
import { ArrowRightIcon, PlusIcon } from "@keyline-icons/react"
import { FancyButton, FancyButtonIcon } from "@/components/ui/fancy-button"
export default function FancyButtonWithIcon() {
return (
<div className="flex flex-wrap items-center justify-center gap-2">
<FancyButton variant="primary">
<FancyButtonIcon as={PlusIcon} />
<span>New invoice</span>
</FancyButton>
<FancyButton>
<span>Continue</span>
<FancyButtonIcon as={ArrowRightIcon} />
</FancyButton>
</div>
)
}
Icon only
"use client"
import { ArchiveIcon, DownloadIcon, PlusIcon } from "@keyline-icons/react"
import { FancyButton, FancyButtonIcon } from "@/components/ui/fancy-button"
export default function FancyButtonIconOnly() {
return (
<div className="flex flex-wrap items-center justify-center gap-2">
<FancyButton iconOnly aria-label="Add a task">
<FancyButtonIcon as={PlusIcon} />
</FancyButton>
<FancyButton iconOnly size="small" aria-label="Download the invoice">
<FancyButtonIcon as={DownloadIcon} />
</FancyButton>
<FancyButton iconOnly size="medium" variant="primary" aria-label="Archive the project">
<FancyButtonIcon as={ArchiveIcon} />
</FancyButton>
</div>
)
}
Disabled
import { FancyButton } from "@/components/ui/fancy-button"
export default function FancyButtonDisabled() {
return (
<div className="flex flex-wrap items-center justify-center gap-2">
<FancyButton disabled>Cancel</FancyButton>
<FancyButton variant="primary" disabled>
Save changes
</FancyButton>
<FancyButton variant="neutral" disabled>
Send reply
</FancyButton>
<FancyButton variant="destructive" disabled>
Delete project
</FancyButton>
</div>
)
}
Pending
"use client"
import { DownloadIcon } from "@keyline-icons/react"
import { FancyButton, FancyButtonIcon } from "@/components/ui/fancy-button"
export default function FancyButtonPending() {
return (
<div className="flex flex-wrap items-center justify-center gap-2">
<FancyButton variant="primary" pending>
Saving
</FancyButton>
<FancyButton pending>Exporting</FancyButton>
<FancyButton iconOnly pending aria-label="Downloading the invoice">
<FancyButtonIcon as={DownloadIcon} />
</FancyButton>
</div>
)
}
Pending then done
"use client"
import { FancyButton } from "@/components/ui/fancy-button"
import { useActionStatus } from "@/hooks/use-action-status"
// Stands in for a request.
const request = () => new Promise((resolve) => setTimeout(resolve, 1200))
export default function FancyButtonPendingThenDone() {
const save = useActionStatus()
const publish = useActionStatus()
return (
<div className="flex flex-wrap items-center justify-center gap-2">
<FancyButton variant="primary" status={save.status} onClick={() => save.run(request)}>
{save.status === "pending" ? "Saving" : "Save changes"}
</FancyButton>
<FancyButton status={publish.status} doneLabel="Published" onClick={() => publish.run(request)}>
{publish.status === "pending" ? "Publishing" : "Publish release"}
</FancyButton>
</div>
)
}
As a link
import { ArrowUpRightIcon } from "@keyline-icons/react"
import { FancyButton } from "@/components/ui/fancy-button"
export default function FancyButtonAsALink() {
return (
<FancyButton asChild>
<a href="https://ui.khaeli.com/r/fancy-button.json">
Open the Registry JSON
<ArrowUpRightIcon aria-hidden="true" />
</a>
</FancyButton>
)
}
Installation
npx shadcn@latest add @khaeli/fancy-buttonbunx --bun shadcn@latest add @khaeli/fancy-buttonInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- npm packages
- @keyline-icons/react ^2.2.0
- @radix-ui/react-slot ^1.1.0
Keyboard
EnterSpace- Activates the button. While it is
pendingor shows its done label, the press does nothing. Tab- Moves focus to the button. A
disabledbutton leaves the tab order. Apendingbutton stays in it asaria-disabled, so focus is not lost while the request runs.
Accessible name
- The name is the button's text. Keep it a verb that says what happens: Save changes, not OK.
- An
iconOnlybutton has no text, so give it anaria-label.FancyButtonIconhides its icon from assistive technology. - While
pending, the button keeps the label you give it and is exposed as disabled witharia-disabled. Change the label to say what is happening, such as Saving. The loader is hidden from assistive technology. - With
status, the done label (doneLabel, Saved unless you set it) replaces the text for a moment and is announced once by a polite live region inside the button. - With
asChildthe child is the element: a link stays a link and is announced as one. It shows no loader and no done label.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/fancy-button.json