@cas-smartdesign/styles
v4.0.6
Published
A shared package providing style variables and basic style sheets to create SmartDesign like components and apps.
Readme
@cas-smartdesign/styles
A shared package providing style variables and basic style sheets to create SmartDesign like components and apps.
This package must be used together with the design tokens of SmartDesign. For an independent application, make sure to include the @cas-smartdesign/design-tokens package. For a web app / web widget, refer to the official documentation about design token usage.
Entry points and bundles
The package has two main SCSS files and two corresponding CSS bundles.
- scss/styles.scss (compiled to dist/styles.css)
- scss/theme.scss (compiled to dist/theme.css)
Styles bundle
Contains prefixed class rules that can be added to your components to make them fit into SmartDesign.
In order to make use of the predefined variables (e.g. colors or spacings) in your components we recommend to use the styles.scss file or the module SCSS files and include it in your build process.
Theme bundle
The theme bundle contains every rule that is contained in the styles and also defines rules to some standard HTML tags that makes it easier to style a simple page.
Note that as it can modify the look and feel of other components we don't recommend this to be used on complex apps that also use third party elements.
SCSS structure
Beside the main files every SCSS file is declared as partial and they are organized in two folders:
Variables (scss/variables)
Files in this folder contain shared variables that are used for components or other modules.
Modules (scss/modules)
Files in this folder contain rules that are specific for a topic or component.
| Module | Description |
| :---------: | ------------------------------------------------------------------------------ |
| app | Defines the most basic styles |
| base_colors | Auto-generated color palette classes (see below); generated from palette.mts |
| button | Defines rules for button-like elements |
| colors | Semantic surface (sd-bg-*) and border (sd-border*) utilities |
| group | Defines the rounded content group surface with caption/content regions |
| link | Defines rules for hyperlink-like elements |
| misc | Separator plus helpers (sd-hidden, sd-visually-hidden, sd-truncate) |
| radius | Corner-radius utilities (sd-rounded, sd-rounded-*) |
| shadow | Elevation utilities (sd-shadow, sd-shadow-weak, sd-shadow-strong) |
| spacing | Defines classes for setting pre-defined margin and padding values |
| token | Defines classes for token/chip-like elements |
| typography | Text-style classes and sd-fg-* foreground-color utilities |
color palette
Every chromatic hue (red, orange, yellow, lightgreen, green, teal, lightblue, blue, pink,
purple, brown) is generated across an intensity range mapped onto the token --color-rainbow-* scale, plus the
neutrals (white, palegrey, lightgrey, silver, grey, darkgrey, black). Each entry emits a text-color
and a background utility:
.sd-<hue>/.sd-<hue>-background— the default shade.sd-<hue>-weak/-weaker— progressively lighter tints (great as surfaces).sd-<hue>-strong/-stronger— progressively darker shades
e.g. .sd-blue-weaker-background, .sd-red-strong, .sd-teal-background.
Token-aligned aliases are provided for the hues whose legacy name differs from the design-token hue:
.sd-cyan (= teal), .sd-dark-blue (= blue) and .sd-dark-green (= green). Note that the legacy
.sd-blue/.sd-green keep their existing (dark) meaning, so the token hues blue/green are .sd-lightblue/
.sd-lightgreen.
The palette is generated from build-tools/palette.mts — add a hue, level or alias there and re-run
pnpm generate-colors; never edit the generated _base_colors.scss files by hand.
Typography
Text styles follow the token scale, smallest to largest: .sd-caption-text, .sd-secondary-text,
.sd-primary-text, .sd-strong-text, .sd-subtitle-text, .sd-heading-small-text, .sd-heading-text,
.sd-heading-large-text.
Foreground and background color utilities set only the color, so they compose with any text style or surface:
.sd-fg-default,.sd-fg-weak,.sd-fg-weaker,.sd-fg-accent,.sd-fg-danger,.sd-fg-success,.sd-fg-warning.sd-bg-default,.sd-bg-weak,.sd-bg-weaker,.sd-bg-success,.sd-bg-danger,.sd-bg-warning.sd-border,.sd-border-weak,.sd-border-strong
Spacing, radius and elevation
- Spacing — padding/margin utilities for the named steps (
.sd-tiny-*,.sd-small-*,.sd-normal-*,.sd-large-*,.sd-huge-*). The full token-aligned scale ($sd-spacing-x1…$sd-spacing-x16) is available as SCSS variables for finer composition. - Radius —
.sd-rounded(default) and.sd-rounded-xs|s|m|l|xl|round. - Elevation —
.sd-shadow(default),.sd-shadow-weak,.sd-shadow-strong.
SCSS variable API
When consuming the SCSS partials directly you can reference the underlying variables, e.g.
@use "@cas-smartdesign/styles/scss/styles" as sd; then sd.$sd-interaction-color, sd.$sd-primary-font,
sd.$sd-spacing-x8, sd.$sd-radius-s, sd.$sd-shadow-default, sd.$sd-red, … Every variable resolves to a design
token with a light-theme fallback.
Dark mode
All values resolve through the design tokens, which ship both light and dark themes switched via the
[sd-color-scheme] attribute (see @cas-smartdesign/design-tokens). Load a token theme on your document and the
bundles follow it automatically. The built-in fallbacks only cover the light theme, so dark mode requires the token
stylesheet to be loaded.
Migrating from 3.x to 4.0
4.0 rebuilds the package on top of @cas-smartdesign/design-tokens. Most class names are unchanged, but a few
were renamed and several rendered values now come from the tokens.
Required
- Load a design-token theme. All values resolve through the token custom properties. Without the token
stylesheet you get the built-in light-theme fallbacks only, and dark mode will not work. Add
@cas-smartdesign/design-tokens(declared here as an optional peer dependency) and load one of its themes.
Renamed CSS classes
| 3.x | 4.0 |
| --------------------------------- | ------------------------------ |
| .field-validation-warn-color | .sd-field-validation-warn |
| .field-validation-suggest-color | .sd-field-validation-suggest |
| .field-validation-error-color | .sd-field-validation-error |
These are now sd--prefixed and color-only (the previous …-color / …-color-background pair is gone).
Renamed / removed SCSS variables
Typography moved from granular family/size/weight variables to font shorthands:
| 3.x | 4.0 |
| -------------------------------------------------------------------- | ------------------------------------------ |
| $sd-font-family, $sd-font-family-light, $sd-primary-font-size | $sd-primary-font (font: shorthand) |
| $sd-secondary-font-size | $sd-secondary-font |
| $sd-heading-font-size, $sd-heading-font-weight | $sd-heading-font |
| $field-validation-warn-color (etc.) | $sd-field-validation-warn (etc.) |
| $sd-button-focus-background, $sd-primary-button-focus-background | removed — focus now shares the hover state |
Text-color variables ($sd-primary-text-color, $sd-secondary-text-color, $sd-heading-text-color) are kept.
Changed rendered values
Even where class names are unchanged, adopting the tokens shifts some output:
- Typography — body text is now Inter 15px/20px (was Segoe UI 16px); headings use the token title scale.
- Palette —
red(#cc0017→#e2001a),purple,brownand the greys move to their token values; the other hues are unchanged. - Buttons —
.sd-buttonnow matches the button component (min-height 36px, 6/8px padding, rounded corners, ghost/primary variants, focus-visible ring) instead of the flat 3.x button. - Theme bundle —
<section>is now a rounded surface with 16px padding (was 24px, square);h1–h6render as a descending size hierarchy rather than all one size.
New in 4.0 (additive)
Per-hue intensity ranges (.sd-<hue>-weak/-weaker/-strong/-stronger) and token aliases (.sd-cyan,
.sd-dark-blue, .sd-dark-green); .sd-fg-* / .sd-bg-* / .sd-border* utilities; .sd-rounded*, .sd-shadow*
and the full $sd-spacing-x* scale (plus .sd-huge-*); helpers .sd-hidden, .sd-visually-hidden,
.sd-truncate; the .sd-group* classes; and an exports map with clean ./styles.css, ./theme.css and
./scss/* subpaths (the old ./dist/* paths still resolve).
Styling guidelines
- Every rule should behave the same in all the supported browsers
- Always use the "sd-" prefix for class names
- Beside the theme bundle, avoid changing default HTML styles
- Only use !important keyword for very specific rules (e.g. sd-hidden, sd-red)
- A variable file must not reference to files outside the variables folder (e.g. the modules folder)
- A module file can use other modules and variables, but dependencies should be imported explicitly
