GuideTokensUpdated in v15

Density

Make every control tighter or roomier with one setting.

Set it up

Add the stylesheet and the feature; without the @use, density changes nothing.

@use 'ngwr/theme';
@use 'ngwr/density';
import { provideWr } from 'ngwr';
import { withDensity } from 'ngwr/density';

bootstrapApplication(AppComponent, {
  providers: [
    provideWr(
      withDensity({
        defaultDensity: 'sm',          // default 'md'
        storageKey: 'wr-density',      // null to not persist
      }),
    ),
  ],
});

The scale

sm, md (default), lg and touch. Each sets four multipliers.

smButton
mdButton
lgButton
touchButton
Tokensm / md / lg / touchScales
--wr-density-y0.55 / 1 / 1.35 / 1.7Vertical padding, so control height
--wr-density-x0.85 / 1 / 1.15 / 1.25Horizontal padding
--wr-density-gap0.8 / 1 / 1.15 / 1.5Gaps in layout components
--wr-density-text0.95 / 1 / 1.05 / 1Yours to read; no component uses it

Change it at runtime

WrDensity switches the whole app and remembers the choice.

current(): md

const density = inject(WrDensity);

density.set('lg');   // 'sm' | 'md' | 'lg' | 'touch'
density.cycle();     // sm, md, lg, touch, sm, …
density.current();   // 'sm' | 'md' | 'lg' | 'touch'

One subtree

wrDensity on any element sets the density for that subtree only.

<aside wrDensity="sm">
  <wr-list>…</wr-list>
</aside>

In your own styles

Multiply your padding by the multipliers.

.my-control {
  padding: calc(var(--wr-control-padding-y-md) * var(--wr-density-y, 1))
    calc(var(--wr-control-padding-x-md) * var(--wr-density-x, 1));
  gap: calc(0.5rem * var(--wr-density-gap, 1));
}

See also