sterling-svelte  1.0.4
A modern, accessible, lightweight UI component library for Svelte.

Sterling Theme (Opt-In)

While sterling-svelte components do not apply any default style, a set of CSS styles is provided for you use if you like.

You can choose to import all the component styles or pick the individual component styles. Your Svelte application build will optimize and bundle the CSS.

import 'sterling.css' from '@sterling-svelte/css/sterling.css'

Component class names

Components render HTML structure and class names to support styling and themes. They can be considered an API contract for the CSS styles. Any changes are considered breaking changes.

  • Each component’s root element has a stering-<component> class name. For example, Button has sterling-button.
  • Components use the natural state pseudo-selectors whenever they exist for the HTML element being rendered. For example, Button styles use :hover, :active, and :disabled selectors.
  • When components have state that isn’t represented by built-in pseudo-selectors, they apply class names (e.g. 'checked, .open, .disabled, .vertical).
  • Components also apply class names to help identify child elements (e.g. .item, .container, .fill, .thumb).

CSS variables for light & dark mode

The sterling theme supports light and dark mode.

  • The sterling theme uses css variables starting with --stsv- to switch modes.
  • There are fewer than 100 CSS variables defined to handle common, button, input, and status colors. This also includes a set of variables defined to handle colorful variants.
  • The applyLightDarkMode action applies .light-mode or .dark-mode and the theme defines a set of CSS variables.

For example, --stsv-button__background-color, --stsv-button__border-color, and -stsv-button__color are defined for the Button style’s default state. When light/dark mode changes, the variables are updated to show the theme without re-rendering the button.

Variant styles

Each component has a variant string property. This string is merged after the component’s class name on the component’s root element.

This allows callers to vary the style of any component. The sterling theme comes with some variants. Multiple variants can be applied.

Components variant effect
(most *) colorful applies colorful accent colors
(some *) composed hides focus and disabled styles so a container can compose this component
Button capsule shows a border with rounded ends
Button circular shows a circular border with a 1:1 aspect ratio
Button secondary hides the background until hovered over
Button square shows a square border
Button tool hides the border entirely and hides the background until hovered over.
Label boxed adds a border and focus styles to contain another component
Link ghost removes the underline until hovered over
Link undecorated removes the underline entirely

* colorful is supported by Button, Callout, Checkbox, Dropdown, Input, Label, Link, Radio, Slider, Switch, Tab, and TextArea.

* composed is supported by Dropdown, Input, List, Select, Slider, and Tree.

Custom styles and themes

You can define CSS in your application using any CSS framework you like (e.g. LESS, SASS, Tailwind, Bootstrap).

  1. Inspect the CSS files in sterling-svelte to the class names you should use in your selectors.
  2. Inspect the HTML of the component either through the source code or inspecting the component in the browser.
  3. Author your own CSS and include it after the Sterling Theme CSS.
  4. Once it is how you like it, you can remove the Sterling Theme CSS.

For example, the base Button styles here demonstrate setting the default and state styles.

  • .sterling-button
  • .sterling-button:hover
  • .sterling-button:active
  • .sterling-button:focus-visible
  • .sterling-button:disabled

The .sterling-button:disabled::after style shows the disabled diagnonal stripe (i.e. no step) pattern over the button.

Sterling Theme CSS Vars

Common

The common variables are used for body text and containers (e.g. lists, trees).

T
--stsv-common__background-color
--stsv-common__border-color
--stsv-common__color

Common - Outline

Outline colors are used across components to indicate keyboard focus.

T
--stsv-common__outline-color

Common - Disabled

Components indicate disabled state as an overlay with a diagonal striped pattern.


Svelte

  • The pattern is taken from the diagonal “NO STEP” pattern on aircraft.
  • The stripes are white and black with low opacity and work well across light and dark themes.

Traditionally, disabled state is indicated using dimmed colors of the component often centering aroound a midline gray. This tends to damage contrast when the background, border, and foreground colors are near the disabled colors.


Common - Secondary, Subtle, and Faint

Secondary, subtle, and faint colors are used for less important text, placeholders, visually separate regions, and decorations.


T
--stsv-common__background-color--secondary
--stsv-common__color--secondary

T
--stsv-common__background-color--subtle
--stsv-common__color--subtle

T
--stsv-common__background-color--faint
--stsv-common__color--faint

Button

These are used for clickable buttons that take action.

T
--stsv-button__background-color
--stsv-button__border-color
--stsv-button__color

Button - Hover

T
--stsv-button__background-color--hover
--stsv-button__border-color--hover
--stsv-button__color--hover

Button - Focus

T
--stsv-button__background-color--focus
--stsv-button__border-color--focus
--stsv-button__color--focus

Button - Active

T
--stsv-button__background-color--active
--stsv-button__border-color--active
--stsv-button__color--active

Input

These are used with interactive form controls (e.g. checkbox, text input, radio)

T
--stsv-input__background-color
--stsv-input__border-color
--stsv-input__color

Input - Hover

T
--stsv-input__background-color--hover
--stsv-input__border-color--hover
--stsv-input__color--hover

Input - Focus

T
--stsv-input__background-color--focus
--stsv-input__border-color--focus
--stsv-input__color--focus

Input - Selected

T
--stsv-input__background-color--selected
--stsv-input__border-color--selected
--stsv-input__color--selected

Status Colors

Several colors are used to create an association with a status.

T
--stsv-status--info__background-color
--stsv-status--info__border-color
--stsv-status--info__color

T
--stsv-status--success__background-color
--stsv-status--success__border-color
--stsv-status--success__color

T
--stsv-status--warning__background-color
--stsv-status--warning__border-color
--stsv-status--warning__color

T
--stsv-status--danger__background-color
--stsv-status--danger__border-color
--stsv-status--danger__color

Sterling Theme Colorful CSS Vars

Many components support a colorful variant to apply accent colors.

Common

T
--stsv-common--colorful__background-color
--stsv-common--colorful__border-color
--stsv-common--colorful__color

Common - Secondary, Subtle, and Faint

T
--stsv-common--colorful__background-color--secondary
--stsv-common--colorful__color--secondary

T
--stsv-common--colorful__background-color--subtle
--stsv-common--colorful__color--subtle

T
--stsv-common--colorful__background-color--faint
--stsv-common--colorful__color--faint

Button

T
--stsv-button--colorful__background-color
--stsv-button--colorful__border-color
--stsv-button--colorful__color

Button - Hover

T
--stsv-button--colorful__background-color--hover
--stsv-button--colorful__border-color--hover
--stsv-button--colorful__color--hover

Button - Focus

T
--stsv-button--colorful__background-color--focus
--stsv-button--colorful__border-color--focus
--stsv-button--colorful__color--focus

Button - Active

T
--stsv-button--colorful__background-color--active
--stsv-button--colorful__border-color--active
--stsv-button--colorful__color--active

Input

T
--stsv-input--colorful__background-color
--stsv-input--colorful__border-color
--stsv-input--colorful__color

Input - Hover

T
--stsv-input--colorful__background-color--hover
--stsv-input--colorful__border-color--hover
--stsv-input--colorful__color--hover

Input - Focus

T
--stsv-input--colorful__background-color--focus
--stsv-input--colorful__border-color--focus
--stsv-input--colorful__color--focus

Input - Selected

T
--stsv-input--colorful__background-color--selected
--stsv-input--colorful__border-color--selected
--stsv-input--colorful__color--selected