Skip to content

Repository files navigation

@swiss-ui/react

Headless React components for Swiss UI design system.

Installation

npm install @swiss-ui/react
yarn add @swiss-ui/react
pnpm add @swiss-ui/react

Usage

Headless import

All components are exported from the root entry with no default styles attached. You provide all styling yourself.

import{Button,Input,Modal}from'@swiss-ui/react'

You can also import individual components from their own sub-paths to enable more granular code splitting:

import{Button}from'@swiss-ui/react/button'import{Input}from'@swiss-ui/react/input'

Styled import

The @swiss-ui/react/styled entry re-exports every component with a swiss-* CSS class pre-applied. Apply the swiss-ui CSS token sheet and component stylesheet alongside this entry to get themed components out of the box.

import{Button,Input,Stack}from'@swiss-ui/react/styled'

Components

ComponentDescriptionKey props
BoxGeneric polymorphic containeras
TextInline or block textas, size, weight, align, truncate
ContainerCentered max-width wrappersize (sm / md / lg / xl / full)
StackVertical flex containergap, align, justify
GridCSS grid containercols, gap, align
GridItemGrid child with span supportcolSpan, rowSpan
HeadingSemantic heading h1-h6level, size, weight, align, as
ButtonPolymorphic action triggervariant, size, loading, leftIcon, rightIcon, as
InputText input with addonssize, invalid, leftAddon, rightAddon, describedBy
TextareaMulti-line text inputsize, invalid, resize, autoResize, describedBy
SelectNative select elementsize, invalid, placeholder, describedBy
CheckboxCheckbox with indeterminate stateindeterminate, invalid
RadioRadio buttoninvalid
RadioGroupRadio group context providername, value, onChange, orientation
SwitchToggle switchchecked, defaultChecked, onChange
BadgeInline status indicatorvariant, color
AlertContextual message blockvariant, icon, title, description, actions
SpinnerLoading indicatorsize, color, label
ModalAccessible dialogisOpen, onClose
ModalOverlayModal backdrop
ModalContentDialog container with focus trap
ModalHeaderHeader slot
ModalBodyBody slot, provides aria-describedby
ModalFooterFooter slot
ModalCloseButtonPre-wired close button
TooltipHover/focus tooltipcontent, placement, delay, disabled
DropdownMenu dropdown container
DropdownTriggerMenu trigger button
DropdownContentMenu panel
DropdownItemMenu action itemdisabled
DropdownSeparatorVisual separator
DropdownLabelNon-interactive group label

Accessibility

The following accessibility features are implemented out of the box:

  • All interactive elements use native HTML elements or appropriate ARIA roles.
  • Button supports polymorphic rendering; when rendered as a non-button element, aria-disabled is set instead of the disabled attribute.
  • Input, Textarea, and Select expose aria-invalid and aria-describedby props.
  • Checkbox supports the indeterminate state via the DOM property.
  • RadioGroup renders a radiogroup role; Radio buttons share a name from context.
  • Switch uses role="switch" with aria-checked.
  • Alert maps info and success variants to role="status" and warning / error to role="alert".
  • Spinner exposes role="status" with a configurable aria-label.
  • Modal locks body scroll, traps focus inside ModalContent, and closes on Escape.
  • Tooltip renders role="tooltip" inside a portal and links to the trigger via aria-describedby.
  • Dropdown follows the ARIA menu button pattern: aria-haspopup, aria-expanded, aria-controls, and full keyboard navigation (ArrowUp / ArrowDown / Home / End / Escape / Tab).

Customization

Components use CSS custom properties for all design tokens. Override them on :root or any ancestor element:

:root {
--swiss-font-size-md:1rem;
--swiss-spacing-4:1rem;
--swiss-color-primary:#0055cc;
}

The data-variant, data-size, data-color, and data-component attributes on every element give you CSS attribute selectors without any class naming convention:

[data-component="button"][data-variant="solid"] {
background:var(--swiss-color-primary);
}

SSR compatibility

All portal-based components (Modal, Tooltip, Dropdown) guard against document access with typeof document !== 'undefined' checks, making them safe to render in server environments. They hydrate correctly on the client without any additional configuration.

About

Headless React components for Swiss UI design system.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages