@viamrobotics/tailwind-config
v1.15.0
Published
Viam's shared Tailwind CSS v4 configuration.
Readme
Viam's Tailwind Config
This module contains Viam's shared Tailwind CSS v4 configuration.
Installation
pnpm add --save-dev tailwindcss @viamrobotics/tailwind-configThis package requires a Tailwind CSS v4 bundler integration (@tailwindcss/vite or @tailwindcss/postcss). See the Tailwind installation guides for setup instructions.
Usage
Add this package in your main CSS file:
/* app.css */
@import "@viamrobotics/tailwind-config";Fonts
The config references the following font families.
- Space Grotesk:
font-space-grotesk - Roboto Mono:
font-roboto-mono - Public Sans:
font-public-sans
Add them to your project with the following Typescript import:
import "@viamrobotics/tailwind-config/fonts";Typography
Tailwind v4's default sizes and line heights already match the design system's type tokens, so most names map to stock classes.
| Design-system name | Tailwind classes |
| ------------------------- | ----------------------- |
| --text-text-xs | text-xs |
| --text-text-xs-semibold | text-xs font-semibold |
| --text-text-sm | text-sm |
| --text-text-sm-semibold | text-sm font-semibold |
| --text-text-base | text-base |
| --text-text-lg-semibold | text-lg font-semibold |
| --text-display | text-display |
| --text-code | text-code |
text-displayis Space Grotesk, weight 500, 24px with a 26px line height. It is the only token stock classes cannot express.text-codeis Roboto Mono at thetext-xssize and line height, the same asfont-roboto-mono text-xs.
Z layers
Named layers order floating UI by who must clear whom. Wear a layer instead of a bare number.
| Class | Token | Value | What sits on it |
| ----------- | ------------- | ----- | ------------------------------------------------------------------------ |
| z-sticky | --z-sticky | 100 | Headers and docked bars. |
| z-overlay | --z-overlay | 1000 | A dialog's backdrop. |
| z-dialog | --z-dialog | 1100 | The dialog panel. |
| z-popover | --z-popover | 1200 | Popovers, select panels, and comboboxes. |
| z-menu | --z-menu | 1200 | Menus. Same value as z-popover, so a consumer never has to know which. |
| z-toast | --z-toast | 1300 | Notifications. |
| z-tooltip | --z-tooltip | 1400 | Above everything that can carry a hovered control. |
| z-max | --z-max | 9999 | Reserved. Nothing may cover it. |
Bare numbers such as z-50 and z-1150 still work through Tailwind's own utility. Steps of 100 leave room for a bare value between layers.
Chart colors
Ten tokens color data graphics, and each adapts in dark mode: --color-chart-series-1 through --color-chart-series-7 for data series, assigned in order, plus --color-chart-grid, --color-chart-axis, and --color-chart-axis-label. Every series color holds 3:1 against its theme's background, and the axis label holds 4.5:1.
Dark mode
Dark mode is opt-in. Import it after the base config.
@import "@viamrobotics/tailwind-config";
@import "@viamrobotics/tailwind-config/dark";- By default the theme follows
prefers-color-scheme. - A
.darkclass on any element forces dark for that subtree. A.lightclass on any element forces light for that subtree, including a.lightsubtree inside.dark. The class wins over the OS preference. dark:utilities follow the same rules as the tokens. They apply under a.darkancestor, or under the OS preference, and never inside a.lightsubtree.- One level of
.lightinside.darkis supported. A.darknested inside that.lightflips the tokens but notdark:utilities. - The dark palette is derived from the light tokens and the grayscale ramp is inverted, so
bg-whiteis not literally white in dark mode.bg-extralightadapts too, because it readsgray-0. - Every
--color-*token is reassigned except the four--color-pixel-*illustration colors, which keep their light values in dark mode.
Colors in script
A canvas, a WebGL scene, or a map marker needs a concrete color, where a class or var() cannot reach. themeColor reads a token's current value from the page.
import { themeColor } from "@viamrobotics/tailwind-config/theme-color";
const hovered = themeColor("--color-solar-power-bright");- Write the whole custom property name as a literal at the call site. Tailwind emits a theme variable only when a scanned source file names it in full. A name built from parts, such as
`--color-${tone}`, reads as unset. - Your Tailwind build has to scan the file that makes the call. A package that calls
themeColorneeds an@sourceentry in the app, as it does for its classes. - It returns the value as the stylesheet writes it, or
undefinedwhen the token is unset. - Pass the element the color is drawn on as the second argument to follow a
.darkor.lightsubtree. It defaults to the document root. - It reads
documentwhen called, so call it in the browser. The import is safe on a server. ThemeColorNameis the union of every color token.
Component classes
The config also ships the design system's components as @utility classes, so a native element, a bits-ui trigger, or a non-Svelte consumer can wear it. A bare class is the design-system default. A modifier class beside it recolors or changes the fill. A utility written after the class wins, so class="button px-4" keeps the wider padding.
| Class | Modifiers | Reads |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| button | color: button-dark, button-danger, button-warning, button-success, button-info, button-pending. Fill: button-outline, button-ghost. Size: button-compact, button-xs. Join a row inside a button-group | :disabled, aria-disabled="true", aria-busy="true" |
| icon-button | the same button-* color and fill modifiers | the same, and it needs aria-label or aria-labelledby |
| button-group | none. Its button children keep every color, fill, and size modifier | the children's :disabled, aria-disabled="true", :hover, :focus-visible, and :has(:focus-visible) |
| badge | badge-success, badge-warning, badge-danger, badge-pending, badge-neutral | none |
| pill | pill-outline | aria-readonly="true", aria-disabled="true" |
| kbd | none | none. Inside an enabled button with a solid fill, its text and border take the button's label color |
| underline-tabs | none | none. A row of tabs 16px apart over a 1px gray-4 bottom border |
| underline-tab | none | aria-selected="true", aria-disabled="true". The selected tab draws a 2px gray-9 line over the strip's border and sets its text semibold |
| file-tabs | none | none. A 35px row that scrolls sideways and never wraps, with its scrollbar hidden |
| file-tab | none | aria-selected="true", aria-disabled="true". The selected tab carries a line on top and joins the content below |
| file-tab-slot | none | none. A placeholder cell in a file-tabs strip that draws the separator a file-tab draws on its right |
| avatar | none | none, and it needs role="img" and aria-label |
| progress-dots | none | none, and it needs role="status" with a visually hidden label |
| status-dot | state: status-dot-info, status-dot-warning, status-dot-success, status-dot-danger, status-dot-disabled. Fill: status-dot-hollow. Bare is the neutral gray dot | none, and it needs role="img" and aria-label. A direct progress-dots child replaces the dot with the spinner |
| banner | banner-info (the default), banner-success, banner-warning, banner-danger, banner-pending, banner-block. Parts: banner-chip, banner-title, banner-description, banner-actions, banner-details, banner-close, banner-progress | none, and the root needs role="status" or role="alert" |
| progress | tone: progress-info, progress-success, progress-warning, progress-danger. Bare is info | aria-valuenow, and its absence means indeterminate. It needs role="progressbar" and aria-label |
| input | input-compact | aria-invalid="true", data-field-state="warn", readonly, :disabled, each also on a direct child <input>, and data-readonly, data-disabled on the frame itself |
| readout | parts: readout-value and readout-suffix, for a value with a unit | none |
| popover-panel | none | none. A light border, a white fill, and the popover shadow |
| listbox-option | none | data-highlighted, data-disabled |
| listbox-heading | none | none. Labels a group of options |
| input-button | none | :hover, :disabled. A square icon button inside an input frame |
| date-field | worn beside input. Part: date-segment | data-state="open" on the frame. A segment reads aria-valuetext="Empty", data-segment="literal", and :focus |
| calendar-nav | none | :hover, data-disabled |
| calendar-weekday | none | none |
| calendar-day | calendar-day-range for a range calendar | data-today, data-outside-month, data-selected, data-disabled, data-unavailable, :hover. A range day also reads data-selection-start, data-selection-end, data-highlighted |
| focus-ring | focus-ring-within for a frame whose focus lives on a child, focus-ring-inset for a control flush against a clipping edge | :focus-visible |
| control-label | none | none |
| field-grid | part: field-row, a label then its control. Alone a row is a flex row. Inside the grid the rows share a label column, up to 40% wide | none. The consumer sets the gap between rows |
| toast-stack-item | none | --z-index, --x, --y, --scale, and --opacity set on the item, and prefers-reduced-motion |
| scrollbar-* | scrollbar-thin for the thin standard width. WebKit parts: scrollbar-w-*, scrollbar-track-*, scrollbar-thumb-*, scrollbar-thumb-border-* | none. scrollbar-* itself sets scrollbar-color to a color token over a clear track |
| slider-track-* | slider-track-w-*, slider-track-h-*, slider-track-cursor-* | none. Worn on an <input type="range"> with appearance-none, and takes a color token |
| slider-thumb-* | slider-thumb-w-*, slider-thumb-h-*, slider-thumb-border-*, slider-thumb-cursor-*, and bare slider-thumb-border for a round gray-bordered thumb | none. Worn on an <input type="range"> with appearance-none, and takes a color token |
| table-container | parts: table-header, table-header-cell, table-data-cell, table-cell-link, table-cell-flex | none. Worn on the <table>, with its parts on the <thead>, each <th>, each <td>, and a cell's content |
table-data-cell goes on each <td>. table-cell is deprecated and does the same, but Tailwind core already owns the name for display: table-cell, so its rule merges into that class and a responsive hidden @2xl:table-cell gains the cell's padding and border. The next major removes it.
switch-info, switch-success, switch-warning, and switch-danger set --switch-on, the track color a prime-ui Switch paints while it is on.
A banner is the compact one-liner until a banner-title sits inside it, and then it lays out stacked. A status-dot is 8px. button-compact and input-compact tighten padding and set text-xs for dense panels. button-xs is the 24px size of a toggle button item. A button-group wrapper joins its direct children into one control, whether or not they wear button. Neighbors share one border, only the outer corners round, and a hovered or focused button draws above its neighbors. A readout is a read-only value box at the 26px field height, for a <span>. A progress holds a progress-fill child that the consumer sizes with an inline width. progress-warning and the banner-progress of a banner-warning fill with --color-warning-text, which holds 3:1 on the gray track where --color-warning-dark does not.
transition-hover-colors animates color, background-color, border-color, text-decoration-color, fill, and stroke. That is the set transition-colors animates, minus outline-color and the gradient stops, so a focus ring appears at once instead of fading in. button, icon-button, input, input-button, and calendar-nav wear it, and it comes from the --transition-property-hover-colors token.
Elevation tokens --shadow-popover and --shadow-dialog back the shadow-popover and shadow-dialog classes. Each shadow reads its color from --shadow-color-popover or --shadow-color-dialog, and the dark theme reassigns those colors.
Every state is a nested selector on an attribute the element already carries, with no !important, so a consumer class can still override anything. On a native single <select>, input replaces the browser's arrow with a chevron in the subtle text color and pads the right edge for it. Recipes for each class, including leading icons and the busy spinner, are on the docs site under the package's "Component classes" page.
