Tally UI

ScaleProvider

ScaleProvider picks the UI scale step from the stored ui.scale setting and the window size, and hands its size tokens to the components below it; useScale reads them and usePointer reports a coarse or fine pointer.

Import

import {
  ScaleProvider, useScale, usePointer,
  type ScaleProviderProps, type ScaleScopeProps, type ScaleState,
} from '@tallyui/components';

Usage

import { ScaleProvider } from '@tallyui/components';
import { useAppSettings } from '@tallyui/pos';

const { settings } = useAppSettings(appSettingsCollection);

<ScaleProvider scale={settings['ui.scale']}>
  <App />
</ScaleProvider>

ScaleProvider reads the window size and the pointer, resolves a step (compact, regular or spacious) and puts the step, the pointer and the step's nine size tokens in context. Components such as ListRow and Skeleton read the tokens with useScale() as style numbers.

The step is the scale prop when it is compact, regular or spacious. For auto, a missing value or any other value, the window decides: under 640 is compact, 1600 and over is spacious, anything between is regular. On the web the window width is measured; on native, the shorter of width and height.

On the web the provider also writes the nine tokens onto document.documentElement as px custom properties, because portalled content leaves the provider's subtree. It rewrites them when the step or pointer changes and removes them when it unmounts. On native nothing is written to a root; pass scope to apply the tokens to the subtree.

The custom properties only move class-based styling if the app imports the opt-in @tallyui/theme/scale.css after tokens.css: it defines the ctl, row, tile and amt utilities and the derived text and radius ramp. Without it only the useScale() style numbers change.

Mount one ScaleProvider at the app root. On the web every provider writes the same root properties: the last to commit wins, and unmounting any of them removes all nine. The ScaleOverride, ScaleStep, Pointer and ScaleVariables types come from @tallyui/theme.

Props

PropTypeDefaultDescription
scaleScaleOverride | null---The stored ui.scale setting: 'auto' | 'compact' | 'regular' | 'spacious'; missing or unknown means Auto
scopeComponentType<ScaleScopeProps>---Wraps the children and receives the variables, to scope them on native (for example Uniwind's ScopedVariables); without it the children render directly
childrenReactNode---The app

Size tokens

Each step sets nine numbers. --spacing-ctl and --spacing-row are then raised to the pointer floor: 44 for a coarse pointer, 24 for a fine one.

Tokencompactregularspacious
--spacing3.545
--text-base131416
--spacing-ctl404452
--spacing-row364452
--spacing-tile566480
--radius6810
--text-amt344048
--text-xs121214
--text-2xs111113

useScale

function useScale(): ScaleState;

Returns the nearest provider's state. It never throws: with no provider above it, it returns step regular, pointer coarse and the regular tokens with the coarse floor, whatever the window size or the real pointer.

usePointer

function usePointer(): Pointer; // 'coarse' | 'fine'

Returns 'fine' only on the web when both (pointer: fine) and (hover: hover) match, and follows changes to either query. On native, where matchMedia is missing, or during server rendering it returns 'coarse'. It reads the media queries itself, so it works with or without a provider.

Types

ScaleState

interface ScaleState {
  step: ScaleStep;           // 'compact' | 'regular' | 'spacious'
  pointer: Pointer;          // 'coarse' | 'fine'
  variables: ScaleVariables; // the nine tokens above, as numbers
}

ScaleProviderProps

The props in the table above.

ScaleScopeProps

interface ScaleScopeProps {
  variables: ScaleVariables;
  children?: ReactNode;
}

The props the scope component receives. Tally UI exports only this type, not a scope component: the app supplies its own.