Component · in flow
Button
A thin layer over the native button, prepared for work in progress, and a real link that looks the same.
Inside a bigger link
Where the whole row or bar is the link, a button cannot sit inside it. ButtonLook draws one without being one: no role, no focus, and its hover and pressed colours follow the link around it. Point anywhere on a row.
---
import ButtonLook from '@subfloor/astro/ButtonLook.astro'
---
<a class="cart-bar" href="/cart/">
<span>3 items · 412 Kč</span>
<!-- React: <ButtonLook variant="primary">; plain HTML: <span class="sf-button"
data-look data-variant="primary"><span class="sf-button__label">… -->
<ButtonLook variant="primary">Go to the cart <ArrowIcon /></ButtonLook>
</a>Busy
Presses:
React
Saves: , presses:
Sent:
Usage
Astro:
---
import Button from '@subfloor/astro/Button.astro'
import ButtonLink from '@subfloor/astro/ButtonLink.astro'
---
<form action="/export" method="post">
<!-- Busy while the browser sends the form; its name and value are sent too. -->
<Button variant="primary" busyOnSubmit busyLabel="Exporting…">Export</Button>
</form>
<ButtonLink href="/projects/">Projects</ButtonLink>React:
import { Button, ButtonLink } from '@subfloor/react'
const [state, action, pending] = useActionState(save, null)
<form action={action}>
<Button type="submit" variant="primary" busy={pending} busyLabel="Saving…">
Save
</Button>
</form>
<Button iconOnly aria-label="Close"><CloseIcon /></Button>Next.js, a link that shows its page is loading:
'use client'
import { ButtonLink } from '@subfloor/react'
import Link, { useLinkStatus } from 'next/link'
// Inside the link: shows that its page is loading. Clicks still work.
function Pending() {
return useLinkStatus().pending ? <span data-sf-pending="" hidden /> : null
}
<ButtonLink href="/report" renderLink={(props) => <Link {...props} />}>
Report <Pending />
</ButtonLink>Markup
<button class="sf-button" data-variant="primary" type="submit"
data-sf-busy-on-submit>
<span class="sf-button__label">Save</span>
<span class="sf-button__busy">
<span class="sf-button__spinner" aria-hidden="true"></span>
<span class="sf-button__busy-label">Saving…</span>
</span>
</button>
<script type="module">
import { initButtons, setButtonBusy } from '@subfloor/core'
initButtons()
setButtonBusy(button, true) // and false when the work is done
</script>Behaviour
- Button is always a
<button>, withtype="button"unless you say otherwise. ButtonLink is always a link. Use a link to go somewhere and a button to do something. - A busy button keeps focus. The script blocks its presses, so its own click listeners and
onClickdo not run, and submits that would use it: Enter in a field, orrequestSubmit(). Other buttons in the form still work.form.submit()skips the browser's submit event, so it cannot be blocked. - Say what is happening with
busyLabel. It does not change the button's width when it is shown, as its room is always there: a long one makes the button wider all the time. Without it, the name stays and only the spinner shows; a spinner alone is not enough. busyOnSubmit(Astro;data-sf-busy-on-submit) is for forms the browser sends. The button is usable again when the visitor comes back to the page, or after 10 seconds, because a download does not leave the page. Set another time in milliseconds. If your script handles the form, usesetButtonBusy(), orbusyin React. After you callsetButtonBusy(button, true), only you end the busy state. Ending it removesaria-disabled, also one you set yourself.- A loading link only shows that it is loading. Its clicks still work. In Next.js, pass
renderLinkfrom a client component: a Server Component cannot pass a function. - This cannot stop every duplicate, such as one from another tab. Make the server safe against repeated orders and payments.
Without JavaScript
Buttons, links and forms work, but nothing becomes busy or blocks a repeated press. Before React hydrates, its own onClick does not run.
Customisation
:root {
--sf-radius-button: 999px;
--sf-button-primary-bg: var(--brand);
--sf-button-primary-color: white;
}
/* Full width, or larger: your own CSS. */
.checkout .sf-button { width: 100%; min-height: 56px; }| Token | Default |
|---|---|
--sf-color-focus | #2563eb |
--sf-color-danger | #b91c1c |
--sf-button-bg | var(--sf-color-surface) |
--sf-button-color | var(--sf-color-text) |
--sf-button-border-color | var(--sf-field-border-color) |
--sf-button-primary-bg | var(--sf-color-text) |
--sf-button-primary-color | var(--sf-color-surface) |
--sf-button-weight | 600 |
--sf-button-padding | var(--sf-space-4) |
--sf-button-gap | var(--sf-space-2) |
--sf-button-spinner-size | 1rem |
--sf-button-spin-duration | 800ms |
--sf-radius-button | var(--sf-radius-control) |
Background
Content 1. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 2. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 3. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 4. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 5. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 6. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 7. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 8. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 9. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 10. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 11. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 12. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.