System Layers
The repository is built as a layered design-system stack:
packages/tokensRaw design tokens such as colors, spacing, radius, shadows, typography, and layers.packages/themeSemantic theme variables built on top of tokens. This is where.lightand.darkare defined.packages/uiReact components and component CSS modules that consume theme semantics.docs/and Storybook Human-facing documentation, examples, and integration guidance built on top of the published API.
Read this stack left to right:
tokens -> theme -> ui -> stories/tests/docs
Workspace Packages
packages/ui: main React package published as@vega-ui/reactpackages/theme: global semantic theme layer published as@vega-ui/theme-corepackages/tokens: raw design tokens published as@vega-ui/tokens-corepackages/icons: icon assets and icon exportspackages/hooks: shared hooks such as controlled state, selection, and resize helperspackages/utils: low-level utilities such as prop merging, refs, dates, and small data helperspackages/react-context: shared context helpers used by compound componentspackages/i18n: framework-agnostic calendar system adapters, locale and formatting helpers, and calendar-aware ISO date helpers, published as@vega-ui/i18n(see Dates and calendar systems)
Dependency Model
The important dependency direction is:
uidepends onhooks,i18n,icons,react-context, andutilsthemedepends ontokens- components in
uiare styled against semantic variables fromtheme
That means:
- token changes affect the whole styling system
- theme changes remap semantic meaning without rewriting every component
- component-local CSS variables should stay local and not replace the theme layer
UI Package Structure
Most components in packages/ui/src/<Component>/ follow a repeatable structure:
Component.tsx: public component implementationtypes.ts: exported types and unions when neededindex.ts: public exports for the package entrypointstyle.module.css: component-local stylingcomponents/: exported child parts for compound componentscontexts/: shared local context for compound state__tests__/*.browser.test.tsx: browser interaction tests*.stories.tsx: story-driven usage examples
Example:
- packages/ui/src/TextField/TextField.tsx
- packages/ui/src/TextField/components/TextFieldInput/TextFieldInput.tsx
- packages/ui/src/TextField/style.module.css
- packages/ui/src/TextField/tests/TextField.browser.test.tsx
Stories, Tests, And Docs
These three layers serve different purposes and should stay aligned:
- stories describe realistic supported usage and visual states
- tests describe behavior, interactions, and edge cases
- docs describe the consumer contract: when to use a component, how to compose it, and what commonly breaks
In this repository, stories mostly live next to components in packages/ui/src/**, while Storybook configuration lives in .storybook/.
Documentation Sources Of Truth
When documenting a component, use these priorities:
- source code for public exports and type shape
- stories for supported examples and variants
- tests for edge cases and behavioral guarantees
- CSS modules for styling hooks and component-local variables
This prevents docs from drifting into patterns the source does not actually support.
See Glossary for the shared definition of source of truth.