Size Context

Alignment target:@astryxdesign/core v0.7.1 · SizeContext

Usage #

SizeProvider sets a default size (sm, md, or lg) for a whole subtree. Interactive components inside use it when they have no size of their own; a component with an explicit size is unaffected. It renders no extra element and passes its default slot through.

TypeScript
import { provideSize, SizeProvider, useSize } from '@astryx-vue/core/SizeContext'

Size resolves in this order, first match wins:

  1. The explicit size on the component.
  2. Button only: the size of the enclosing ButtonGroup.
  3. The context from an enclosing SizeProvider or container component.
  4. The component's own default.

Toolbar, ButtonGroup, and InputGroup provide their size automatically, so children need no per-item size. Button, MoreMenu, TextInput, TextArea, Selector, MultiSelector, NumberInput, the date inputs and TimeInput, SegmentedControl, TabList, PowerSearch, and Tokenizer consume it.

Like other layer-scoped context, it resets inside teleported overlay layers: menus, popovers, and similar content rendered through a Teleport do not inherit the outer size. Add another SizeProvider inside the layer if needed.

Best practices #

GuidancePractices
DoSet one size for a whole region with SizeProvider, or the size of Toolbar or InputGroup, instead of repeating it on every child.
DoFor a single exception, set size on that component; it always wins.
Don'tExpect SizeProvider to reach content inside overlay layers: teleported content falls back to defaults.

Examples #

Common configurations, variations, and states.

Size Context — SizeContext — SizeProvider

Open in Playground

The first row uses default sizes; the second is wrapped in SizeProvider value="sm", so the Button and TextInput both render small.