Component library for Astro and React
Accessible by default. Styled by you.
Subfloor gives a project components that already behave right, with keyboard, focus and screen readers covered, and almost no styling of their own. Put your own design on top and change as much or as little as you like.
- Keyboard, focus and screen readers handledbehaviour
- A plain default look to start fromminimal CSS
- Your CSS wins without !important@layer
- Restyle with tokens and part classes--sf-*
Components
top layer · 6in flow · 10
- See all fields
- See the docs
- See the docs
- See the docskg
- See the docs
To the address above.
- See the docs
- See the docs
- See the docs
- See the docsAllBreadCakesPastriesDrinksDesserts
- See the docs
- planned
Tabs
When a project needs them. Ask for it in the repo.
What every component passes
Subfloor's own tests check these for its components. If you compose something new on top, run through them again.
- It works with the keyboard, with the right roles and names.
- Keyboard focus is always visible, and never lost when something closes.
- It is sized for touch, and nothing is wider than a 320px screen.
- Light and dark follow your page; states never rely on colour alone.
- Reduced motion means no animation.
- With JavaScript off, it works as far as the browser allows.
- Tested in Chromium, WebKit and Firefox, at desktop and phone sizes.
What every modal adds
Modal, Sheet, Sidepanel and Mobile nav take over the page while open, so they also pass these.
- The page behind does not scroll, on wheel, keys or touch.
- Nothing moves sideways when it opens.
- Focus moves in, stays in, and returns, also in Safari.
- Escape and a backdrop click close it; a drag does not.
- The page behind is inert.
- Long content scrolls inside, never past the screen.
- It renders closed on the server.
Principles
- Native first.
<dialog>withshowModal(), Invoker Commands,:has(),dvh,overscroll-behavior. A little TypeScript only where the platform falls short: the iOS scroll lock, exit transitions,data-state. - One core, thin adapters. Behaviour and CSS live in
@subfloor/core;@subfloor/reactand@subfloor/astroonly render its markup. - Customise without forking. Every visual value is a token; all kit CSS is in
@layer subfloor, so your CSS and utility classes win without!important.
Install
pnpm add @subfloor/core @subfloor/astro # Astro
pnpm add @subfloor/core @subfloor/react # React / Next.jsReact islands in Astro, and Vitest, need one setting each, or the build fails with Unknown file extension ".css":
// astro.config.mjs, with React islands: bundle Subfloor, as Next.js does by itself
export default defineConfig({
integrations: [react()],
vite: { resolve: { noExternal: ['@subfloor/core', '@subfloor/react'] } },
})
// vitest.config.ts, for tests that import @subfloor/react
export default defineConfig({
test: { server: { deps: { inline: [/@subfloor\//] } } },
})/* Once, in the global stylesheet or layout. Each component brings its own styles. */
@import '@subfloor/core/base.css';
/* Plain script without the React or Astro components (showSnackbar, createDialog...):
import what you use, or everything at once */
@import '@subfloor/core/styles/snackbar.css';
@import '@subfloor/core/components.css';/* With Tailwind v4: the mapping first, so its layer order applies */
@import '@subfloor/core/tailwind.css';
@import 'tailwindcss';
@import '@subfloor/core/base.css';Tokens
Light defaults below. Override any of them on :root, a wrapper or one component.
Light and dark
The colours follow the page's color-scheme, so set it to match what the page shows. Without it they stay light, also on a dark device. Subfloor does not set it. A section can have its own. A browser without light-dark() follows the device instead.
:root { color-scheme: light dark; } /* follow the device */
/* The user's choice, if your project has one. */
:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }All tokens
| Token | Default |
|---|---|
--sf-color-surface | #fff |
--sf-color-text | #18181b |
--sf-color-muted | #52525b |
--sf-color-border | #e4e4e7 |
--sf-color-backdrop | rgb(9 9 11 / 50%) |
--sf-color-focus | #2563eb |
--sf-color-hover | rgb(9 9 11 / 6%) |
--sf-color-current | rgb(37 99 235 / 10%) |
--sf-radius-overlay | 12px |
--sf-radius-control | 8px |
--sf-border-width | 1px |
--sf-shadow-overlay | 0 20px 50px rgb(0 0 0 / 20%) |
--sf-space-1 | 0.25rem |
--sf-space-2 | 0.5rem |
--sf-space-3 | 0.75rem |
--sf-space-4 | 1rem |
--sf-space-6 | 1.5rem |
--sf-title-size | 1.125rem |
--sf-title-weight | 600 |
--sf-title-line-height | 1.4 |
--sf-touch-target | 44px |
--sf-overlay-gutter | var(--sf-space-4) |
--sf-dialog-width | 32rem |
--sf-sidepanel-width | 24rem |
--sf-sidepanel-inline-shadow | none |
--sf-sheet-max-height | 90dvh |
--sf-sheet-bar-width | 44px |
--sf-sheet-bar-height | 5px |
--sf-sheet-bar-offset | var(--sf-space-2) |
--sf-sheet-bar-color | var(--sf-field-border-color) |
--sf-mobile-nav-width | 20rem |
--sf-mobile-nav-top | var(--sf-fixed-top) |
--sf-mobile-nav-indent | var(--sf-space-4) |
--sf-popover-min-width | 12rem |
--sf-popover-max-width | min(22rem, 100vw - 2 * var(--sf-overlay-gutter)) |
--sf-popover-max-height | min(22rem, 70dvh) |
--sf-popover-offset | var(--sf-space-1) |
--sf-radius-popover | var(--sf-radius-control) |
--sf-shadow-popover | 0 8px 24px rgb(0 0 0 / 16%) |
--sf-menu-description-color | var(--sf-color-muted) |
--sf-menu-description-size | 0.875em |
--sf-color-danger | #b91c1c |
--sf-color-success | #15803d |
--sf-snackbar-max-width | min(28rem, 100vw - 2 * var(--sf-overlay-gutter)) |
--sf-snackbar-offset | var(--sf-space-4) |
--sf-snackbar-bg | #18181b |
--sf-snackbar-color | #fafafa |
--sf-radius-snackbar | var(--sf-radius-control) |
--sf-field-border-color | #71717a |
--sf-field-font-size | 1rem |
--sf-field-gap | var(--sf-space-1) |
--sf-field-padding | var(--sf-space-3) |
--sf-field-short-width | 6rem |
--sf-field-suffix-gap | var(--sf-space-2) |
--sf-caret-size | 1rem |
--sf-caret-gap | var(--sf-space-2) |
--sf-caret-color | currentcolor |
--sf-segmented-bg | var(--sf-color-hover) |
--sf-segmented-current-bg | var(--sf-color-surface) |
--sf-segmented-current-border | var(--sf-field-border-color) |
--sf-segmented-gap | 3px |
--sf-segmented-padding | var(--sf-space-3) |
--sf-segmented-fade | 2rem |
--sf-radius-segmented | var(--sf-radius-control) |
--sf-scroll-row-gap | var(--sf-space-2) |
--sf-scroll-row-fade | 2rem |
--sf-scroll-row-ring | 4px |
--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) |
--sf-choice-size | 24px |
--sf-choice-gap | var(--sf-space-3) |
--sf-choice-bg | var(--sf-color-surface) |
--sf-choice-border-color | var(--sf-field-border-color) |
--sf-choice-border-width | 1.5px |
--sf-choice-checked-bg | var(--sf-button-primary-bg) |
--sf-choice-checked-color | var(--sf-button-primary-color) |
--sf-radius-choice | 6px |
--sf-switch-width | 44px |
--sf-switch-height | 26px |
--sf-calendar-day-size | var(--sf-touch-target) |
--sf-calendar-padding | 6px |
--sf-calendar-selected-bg | var(--sf-button-primary-bg) |
--sf-calendar-selected-color | var(--sf-button-primary-color) |
--sf-time-lists-option-size | var(--sf-touch-target) |
--sf-time-lists-rows | 5.5 |
--sf-time-lists-padding | 6px |
--sf-time-lists-selected-bg | var(--sf-button-primary-bg) |
--sf-time-lists-selected-color | var(--sf-button-primary-color) |
--sf-fixed-top | 0px |
--sf-fixed-bottom | 0px |
--sf-duration-enter | 200ms |
--sf-duration-exit | 150ms |
--sf-ease-enter | cubic-bezier(0.2, 0.8, 0.2, 1) |
--sf-ease-exit | cubic-bezier(0.4, 0, 1, 1) |
--sf-dialog-enter-from | translate(0, 0.5rem) |