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.

The page behind does not scroll and cannot be focused. Escape, the backdrop or the close button close it.

The same dialog along the end edge, full height in dvh.

The same dialog from the bottom. Long content scrolls inside it.

What every component passes

Subfloor's own tests check these for its components. If you compose something new on top, run through them again.

  1. It works with the keyboard, with the right roles and names.
  2. Keyboard focus is always visible, and never lost when something closes.
  3. It is sized for touch, and nothing is wider than a 320px screen.
  4. Light and dark follow your page; states never rely on colour alone.
  5. Reduced motion means no animation.
  6. With JavaScript off, it works as far as the browser allows.
  7. Tested in Chromium, WebKit and Firefox, at desktop and phone sizes.

Principles

Install

pnpm add @subfloor/core @subfloor/astro   # Astro
pnpm add @subfloor/core @subfloor/react   # React / Next.js

React 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

TokenDefault
--sf-color-surface#fff
--sf-color-text#18181b
--sf-color-muted#52525b
--sf-color-border#e4e4e7
--sf-color-backdroprgb(9 9 11 / 50%)
--sf-color-focus#2563eb
--sf-color-hoverrgb(9 9 11 / 6%)
--sf-color-currentrgb(37 99 235 / 10%)
--sf-radius-overlay12px
--sf-radius-control8px
--sf-border-width1px
--sf-shadow-overlay0 20px 50px rgb(0 0 0 / 20%)
--sf-space-10.25rem
--sf-space-20.5rem
--sf-space-30.75rem
--sf-space-41rem
--sf-space-61.5rem
--sf-title-size1.125rem
--sf-title-weight600
--sf-title-line-height1.4
--sf-touch-target44px
--sf-overlay-guttervar(--sf-space-4)
--sf-dialog-width32rem
--sf-sidepanel-width24rem
--sf-sidepanel-inline-shadownone
--sf-sheet-max-height90dvh
--sf-sheet-bar-width44px
--sf-sheet-bar-height5px
--sf-sheet-bar-offsetvar(--sf-space-2)
--sf-sheet-bar-colorvar(--sf-field-border-color)
--sf-mobile-nav-width20rem
--sf-mobile-nav-topvar(--sf-fixed-top)
--sf-mobile-nav-indentvar(--sf-space-4)
--sf-popover-min-width12rem
--sf-popover-max-widthmin(22rem, 100vw - 2 * var(--sf-overlay-gutter))
--sf-popover-max-heightmin(22rem, 70dvh)
--sf-popover-offsetvar(--sf-space-1)
--sf-radius-popovervar(--sf-radius-control)
--sf-shadow-popover0 8px 24px rgb(0 0 0 / 16%)
--sf-menu-description-colorvar(--sf-color-muted)
--sf-menu-description-size0.875em
--sf-color-danger#b91c1c
--sf-color-success#15803d
--sf-snackbar-max-widthmin(28rem, 100vw - 2 * var(--sf-overlay-gutter))
--sf-snackbar-offsetvar(--sf-space-4)
--sf-snackbar-bg#18181b
--sf-snackbar-color#fafafa
--sf-radius-snackbarvar(--sf-radius-control)
--sf-field-border-color#71717a
--sf-field-font-size1rem
--sf-field-gapvar(--sf-space-1)
--sf-field-paddingvar(--sf-space-3)
--sf-field-short-width6rem
--sf-field-suffix-gapvar(--sf-space-2)
--sf-caret-size1rem
--sf-caret-gapvar(--sf-space-2)
--sf-caret-colorcurrentcolor
--sf-segmented-bgvar(--sf-color-hover)
--sf-segmented-current-bgvar(--sf-color-surface)
--sf-segmented-current-bordervar(--sf-field-border-color)
--sf-segmented-gap3px
--sf-segmented-paddingvar(--sf-space-3)
--sf-segmented-fade2rem
--sf-radius-segmentedvar(--sf-radius-control)
--sf-scroll-row-gapvar(--sf-space-2)
--sf-scroll-row-fade2rem
--sf-scroll-row-ring4px
--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)
--sf-choice-size24px
--sf-choice-gapvar(--sf-space-3)
--sf-choice-bgvar(--sf-color-surface)
--sf-choice-border-colorvar(--sf-field-border-color)
--sf-choice-border-width1.5px
--sf-choice-checked-bgvar(--sf-button-primary-bg)
--sf-choice-checked-colorvar(--sf-button-primary-color)
--sf-radius-choice6px
--sf-switch-width44px
--sf-switch-height26px
--sf-calendar-day-sizevar(--sf-touch-target)
--sf-calendar-padding6px
--sf-calendar-selected-bgvar(--sf-button-primary-bg)
--sf-calendar-selected-colorvar(--sf-button-primary-color)
--sf-time-lists-option-sizevar(--sf-touch-target)
--sf-time-lists-rows5.5
--sf-time-lists-padding6px
--sf-time-lists-selected-bgvar(--sf-button-primary-bg)
--sf-time-lists-selected-colorvar(--sf-button-primary-color)
--sf-fixed-top0px
--sf-fixed-bottom0px
--sf-duration-enter200ms
--sf-duration-exit150ms
--sf-ease-entercubic-bezier(0.2, 0.8, 0.2, 1)
--sf-ease-exitcubic-bezier(0.4, 0, 1, 1)
--sf-dialog-enter-fromtranslate(0, 0.5rem)