Skip to content
Sveltier
Mode
API

sharedClasses

Turns a component's shared props into classes that set the shared custom properties.

Signature

Signature
import { sharedClasses, type SharedClassProps } from 'sveltier';

function sharedClasses(props: SharedClassProps): string;

sharedClasses({ variant: 'tonal', size: 'sm', color: 'success', rounded: true });
// 'sv-variant-tonal sv-size-sm sv-color-success sv-rounded'

It returns classes only for the props you pass, in a fixed order, and imports the stylesheet that defines them. Use it in $derived or directly in the class attribute.

Props and classes

NameTypeDescription
variant'flat' | 'tonal' | 'outlined' | 'text' | 'plain'sv-variant-<variant>: sets --sv-variant-bg, --sv-variant-fg and --sv-variant-border from the colour. plain also sets --sv-state-hover and --sv-state-press to 0%.
colorColorsv-color-<name>: sets --sv-color and --sv-on-color. Intents and custom colours get their class from the theme stylesheet.
size'xs' | 'sm' | 'md' | 'lg' | 'xl'sv-size-<size>: sets --sv-size-height (a control height) and --sv-size-text.
density'compact' | 'default' | 'comfortable'sv-density-<density>: sets --sv-density, a multiplier for heights and paddings.
roundedboolean | 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full'sv-rounded (true) clears --sv-rounded so the component default applies; false and none give 0, sm–xl a theme radius, full a pill in every theme.

Types

NameTypeDescription
SharedPropsinterfacevariant, density, size, color, rounded, disabled and loading: the props every component that has them declares with these names and values.
SharedClassPropsPick<SharedProps, 'variant' | 'density' | 'size' | 'color' | 'rounded'>What sharedClasses takes.
ColorIntentColor | 'neutral' | keyof CustomColorsA theme colour. Anything else is a type error.
CustomColorsinterfaceRegister custom colours from defineTheme here by declaration merging.
VARIANTS / SIZES / DENSITIESreadonly tuplesThe allowed values, for building controls or validating input.

See Shared props for the meaning of each value and a live preview.