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

Opened.

Presses: 0

React

React row

Saves: 0, presses: 0

Sent: 0

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

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; }
TokenDefault
--sf-color-focus#2563eb
--sf-color-danger#b91c1c
--sf-button-bgvar(--sf-color-surface)
--sf-button-colorvar(--sf-color-text)
--sf-button-border-colorvar(--sf-field-border-color)
--sf-button-primary-bgvar(--sf-color-text)
--sf-button-primary-colorvar(--sf-color-surface)
--sf-button-weight600
--sf-button-paddingvar(--sf-space-4)
--sf-button-gapvar(--sf-space-2)
--sf-button-spinner-size1rem
--sf-button-spin-duration800ms
--sf-radius-buttonvar(--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.