Design system structure

From zakariaf/ReactNative-Skills · View interactive version

Design system structure is an AI agent skill from the GitHub repository zakariaf/ReactNative-Skills. Structures a design system: two-tier tokens, contrast-proven light/dark palettes, the theme provider, makeStyles, text roles, fonts. Use when touching colours, dark mode, fonts or theme files. Not for components (ui-component-library).

How to use this skill

Skill file

Design system structure

Makes every visual value in an Expo app come from one token file through one typed theme: semantic

colour roles in light and dark palettes that are proven readable pair by pair, makeStyles and one

AppText with type roles on the device pixel grid at every text size, the system font (bundled,

pinned fonts as an opt-in), motion tokens with complete springs, and one press surface whose look is

a token choice. Two checkers prove the theme equals the token file, the navigator and the root view

follow it, and that no raw colour, size, weight, radius, duration, spring, palette import, platform

shadow or second theme hides in the app's code.

Rules that must hold

  1. The token file is the only source; theme modules copy it. design/tokens.json holds primitives

(tier 1) and semantic roles (tier 2); tokens.ts, type-styles.ts, motion.ts and palette.ts

copy it, and every mapped export is compared value by value (theme-mismatch). A retyped value

drifts by one digit and nobody notices until a screen looks wrong.

  1. Components read semantic roles only, through the theme. Colours come from

theme.colors.<role> through makeStyles or useTheme; no colour literal (hex, rgb(), hsl(),

or a named colour such as color="white" on a colour prop) or raw radius lives outside src/theme

(no-color-literal, no-raw-radius), no palette module, token file or APP_THEMES is imported

there (no-palette-import), and no second theme (the create-expo-app constants/theme.ts, another

useTheme) sits beside it (second-theme-system). A colour read any other way is frozen to one

scheme: it breaks dark mode and every palette flavour at once.

  1. Every palette is generated and proven readable, pair by pair. write-palette.mjs writes

palette.ts only when every pair passes (text 4.5:1; edges, focus and icons 3:1; filled shapes

3:1 off their ground or edge), with translucent colours painted over their ground first. The

pairs are the app's contracts/contrast.json (accessibility-as-code owns that contract and the

rule to declare every pair there), or the default pairs until it exists; the core pairs are

checked whatever the contract says (no exception accepts one), and palette.test.ts keeps them

in Jest. Contrast belongs to pairs, so it is tested as pairs, from one table.

  1. Light and dark are two hand-tuned sets that follow the person on iOS and Android, everywhere.

AppThemeProvider resolves the saved preference against the phone, mirrors it to Appearance

and paints the root view (SystemUI.setBackgroundColorAsync); NavigationThemeProvider sits

inside it and hands the navigator colours mapped from the theme (navigation-theme-mapped: never

a bare DarkTheme/DefaultTheme); the app config says userInterfaceStyle: 'automatic' with no

ios or android override saying otherwise, and expo-system-ui is installed; a runtime file

(the routes layout, or App.tsx with React Navigation) renders the provider imported from

src/theme/theme-provider (color-scheme-config, theme-provider-behaviour,

theme-provider-mounted). Miss one and iOS reports light forever, Android ignores the setting,

or headers and screen backgrounds stay light in dark mode.

  1. A makeStyles factory builds with StyleSheet.create and returns it. Styles are cached per

theme object (make-styles-factory). That keeps tsc's excess-property check and the style lint

rules; a plain object loses both.

  1. Text renders only through AppText with a type role or style. No raw fontSize or

letterSpacing, inline or as a branch of a conditional (no-raw-font-size, no-letter-spacing);

the templates use the system font (null in SCRIPT_FONTS, weight by fontWeight); a bundled

family is one face per weight, so never fontWeight with it (no-font-weight: there is no face to

choose, Android fakes a bold and iOS swaps files); changing numbers use tabular figures

(tabular-digits); headings set the header role; font scaling caps at 200 % (MAX_FONT_SCALE).

  1. **Line heights sit on the device pixel grid at the current font scale, and glyphs are never

nudged.** lineHeight = snapToPixels(fontSize * ratio * fontScale) / fontScale, because React

Native multiplies line heights by the font scale and rounds every text box up to whole pixels

(line-height-grid, no-rounded-line-height); no per-size padding, margin or translate on text

(no-glyph-nudge): a nudge breaks every height built on exact boxes.

  1. Tall scripts get their own line heights and an overflow guard from font metrics. A tall ratio

is never tighter than the base one and meets the contract's device-proven minimums

(tall-script-line-height); TALL_SCRIPT_METRICS equals the TTF's hhea values and AppText pads

the line from them at the drawn size (style times font scale; shifted on iOS, grown on Android)

inside a wrapper that keeps the testID (tall-script-overflow-guard). iOS otherwise clips the

tops of tall glyphs, worst at the large text sizes people choose to read better.

  1. Display text wraps balanced. AppText runs useBalancedWrap for display text; the hook

updates state functionally and probes only narrower widths (balanced-display). The obvious

search passes Jest and stalls on a device.

  1. **The contract declares the fonts: "system" by default; bundled files (opt-in) are pinned and

named once.** With files listed, one expo-font plugin entry embeds every one (font-plugin);

file name = PostScript name = fontFamily (font-family), because Android finds a font by file

name and iOS by the name inside it; each file's sha256 is recorded and its licence ships

(font-files); fonts.ts and the contract agree either way (font-family); with a bundled

Latin family every script of the app's languages has its own family or an explicit null

(font-script-coverage). Expo's object syntax (one family name plus fontWeight) is the

fenced alternative, fonts.weightBy: "fontWeight".

  1. One press surface; its look is a token choice, and persistent states move by layout.

PressableSurface owns the press look (PRESS.kind: opacity by default, scale, or the

opt-in sink), the Android ripple, the disabled style, the feedback seam and the accessibility

state. A sinking key that stays pushed in moves with top: elevation, never a transform

(pressed-by-layout, checked wherever the sink look exists), because VoiceOver, TalkBack and

Maestro report layout frames. Static shadows use shadow()/ring() (boxShadow); legacy

shadow* and elevation keys are banned (no-legacy-shadow): shadowOffset, shadowOpacity

and shadowRadius draw on iOS only, elevation is Android's own shadow, and shadowColor

only tints it on Android 9+.

  1. **Motion comes from tokens, springs are complete, and every moment has a reduce-motion

alternative.** No duration or delay number in an animation (no-raw-duration: withTiming,

withDelay, withRepeat, Animated.timing, LayoutAnimation, .duration(n) layout-animation

builders, CSS transition keys) and no spring numbers in a component (no-raw-spring): inline, in

a same-file const ({ duration: FADE_MS }, .duration(SLIDE), withSpring(1, BOUNCE)) or inside

an expression (isSlow ? 600 : 200, index * 50); every spring token writes damping,

stiffness and mass (spring-config-complete: Reanimated 4.5.1 defaults mass to 4); functional

timers never shorten. Domain layers (src/core, src/data ...) are not scanned: a task's

duration is data.

  1. Colour is never the only signal, and a colour-blind variant must change colours. Shape and

text carry meaning (accessibility-as-code checks the cues); a colorBlind palette that changes

no primary or status colour is refused (palette-colorblind). Brand-invariant roles stay equal

in every palette (palette-invariant).

Visual policies such as flat paint, a maximum radius or the sinking key look are the app's choice,

switched on in the contract or the tokens (no-gradient, no-pill, PRESS.kind), not library rules.

Workflow

  1. Detect first. If package.json has another styling system (NativeWind, Tamagui, Restyle,

Unistyles, styled-components) and no src/theme, the checkers print NOT APPLICABLE: extend that

system in its own idiom (Expo's expo-design-system skill) and never add a second one. A

create-expo-app project's src/constants/theme.ts, src/hooks/use-theme.ts,

use-color-scheme*.ts, themed-text.tsx and themed-view.tsx are values to migrate, not a

system to keep: map them into the token file and delete them (tokens-and-contract.md, "Adopting

the create-expo-app theme"). Routes in app/ at the repo root are found; an app without src/

adds rn-skills.config.json { "srcDir": "." } (tokens-and-contract.md, "Layout keys").

  1. Set up the theme (once). Read references/tokens-and-contract.md,

references/layout-and-shape-tokens.md (spacing and layout

steps, the edge-to-edge screen frame, wide windows, strokes, elevation) and

references/theme-in-react-native.md. Copy

templates/src/theme/, templates/src/ui/, templates/contracts/ and templates/design/ to the

same paths in the app. Replace the demo values in design/tokens.json with the design's, then

copy them into tokens.ts, type-styles.ts and motion.ts (the token file first, always),

including the press look (press in the token file, PRESS in tokens.ts).

  1. Write the palette. Read references/palettes-and-contrast.md.

Run node ${CLAUDE_SKILL_DIR}/scripts/write-palette.mjs . --dry-run until it prints

RESULT: PASS, then without --dry-run. When a component puts a colour on a new ground, declare

the pair in contracts/contrast.json (accessibility-as-code's template, or the shape in the

reference) and rerun; never keep a second table.

  1. Fonts. Read references/text-and-fonts.md. The templates use

the system font (contract "fonts": "system", every script null in SCRIPT_FONTS), which needs

nothing more. Bundle a font only when the design names one: copy the TTFs (each named after its

PostScript name) and their licences into assets/fonts/, replace the contract's "system" with

the files and each shasum -a 256, add the expo-font plugin entry (npx expo install expo-font),

name a family per weight in src/theme/fonts.ts, and copy each tall script's hhea values into

TALL_SCRIPT_METRICS (the checker prints them; the reference gives Noto Sans as a worked example).

  1. Wire dark mode and the providers. Set userInterfaceStyle: 'automatic', run

npx expo install expo-system-ui, and mount AppThemeProvider (with onError from the error

log), TextLocaleProvider, PressFeedbackProvider and NavigationThemeProvider once in

src/app/_layout.tsx, replacing the template's ThemeProvider value={DarkTheme | DefaultTheme},

as examples/root-layout.tsx shows (React Navigation: App.tsx, the

appendix in the theme reference).

  1. Style a component or screen. Imitate examples/task-summary-card.tsx:

makeStyles with const styles = StyleSheet.create(...); return styles;, tokens and roles only,

AppText variants and tones, PressableSurface for the pressable part, shadow() for static

parts. Motion: references/motion-tokens.md.

  1. Run the checks from the repo root and loop until all pass: npm run typecheck,

npx eslint . --max-warnings 0, npx jest --ci, then

node ${CLAUDE_SKILL_DIR}/scripts/check-design-system.mjs . and

node ${CLAUDE_SKILL_DIR}/scripts/check-raw-values.mjs .. Every FAIL line names the file, the

rule and the fix: fix the code or the token file, never the contrast pairs.

  1. Report in plain words what changed, which checks passed, which SKIP lines remain and who

creates their targets, and any value chosen where the design was silent (the decision log). Ask

the reviewer before changing a token the design fixed or adding a contrast exception.

Definition of done

maps every theme export and palette to it.

src/theme and src/ui, and their tests pass (npx jest --ci, iOS and Android projects).

contracts/contrast.json (or the default pairs) passing in light and dark, and the

colour-blind variant if any.

its PostScript name, listed in the expo-font entry, and named per weight in fonts.ts. System

font (the default): the contract says "fonts": "system" and every script of SCRIPT_FONTS is null.

AppThemeProvider with NavigationThemeProvider inside it (and TextLocaleProvider in a

multi-script app); no second theme (constants/theme.ts, another useTheme) is left.

SKIP src/i18n [text-locale-provided] not yet created (i18n-strings-and-catalogs creates it),

SKIP src/app/_layout.tsx [theme-provider-mounted] and [navigation-theme-mapped] not yet created (expo-project-bootstrap creates it) (App.tsx with React Navigation),

SKIP app.config.ts [font-plugin] (bundled fonts only) and [color-scheme-config] not yet created (expo-project-bootstrap creates it).

Note lines (which pairs judged each palette, what was scanned) are information, not problems.

Anti-patterns

copy it, rerun the checker.

the token file and regenerate; declare pairs once, in contracts/contrast.json.

set and let the pairs judge both.

theme.colors through makeStyles or useTheme.

leaves the app theme unmounted, the second leaves headers and screen backgrounds light in dark

mode; mount AppThemeProvider outside and NavigationThemeProvider inside.

with different shapes, and colours no pair ever judged; migrate the values and delete the files.

keep "fonts": "system" until the design names one, then bundle and pin exactly those files.

choose: Android fakes a bold, iOS keeps the face or swaps in another; pick it through a type style.

file name is the PostScript name.

round up to pixels, so only snapToPixels keeps them exact; first check the role the design uses.

overflow; the guard comes from the font's metrics at the drawn size.

on a device while Jest passes; copy use-balanced-wrap.ts.

translate). Every control must answer, sound and announce the same way; compose the press surface

and change its look through PRESS.

use top: elevation.

shadow(), and give a pressable card the press surface.

inherits mass 4 and a slow, bouncy release; use SPRINGS.

usePressFeedback().

variant and carry meaning by shape and text.

look of a screen is proven by design-visual-parity.

Files in this skill

| File | What it is | Read/run when |

|---|---|---|

| references/tokens-and-contract.md | Two tiers, the token file format (plain and DTCG), the colour roles, module mapping, every contract key, flavours, the decision log, multi-package | Workflow step 2, and before changing a token |

| references/layout-and-shape-tokens.md | Spacing scale and named layout steps, the screen frame under Android 15/16 edge-to-edge and safe-area insets, the centred column on wide windows, radii, strokes (dashed state cues, icon strokes), elevation levels, touch targets, component measurements | Workflow step 2, and when laying out a screen |

| references/theme-in-react-native.md | File map, mounting with the navigation theme (Expo Router, React Navigation appendix), the root view, dark mode on both platforms, makeStyles, shadows, the press surface looks, RTL, what is verified | Workflow steps 2 and 5 |

| references/palettes-and-contrast.md | Pairs, the contrast contract, core and default pairs, shapes, translucent colours, exceptions, write-palette, fixing a pair, dark sets, colour-blind variants, palette rule ids | Workflow step 3, any contrast question |

| references/text-and-fonts.md | AppText and its direction on both platforms, roles, the pixel grid and the font scale, glyph nudges, tall scripts and the guard, balanced text, tabular figures, bundled fonts and the demo fonts' source, the system font, the object-syntax alternative, font scaling | Workflow step 4, any text work |

| references/motion-tokens.md | Motion tokens, complete springs, what no-raw-duration and no-raw-spring see, the reduce-motion table, reduce motion in code | Any animation |

| templates/src/theme/ | Theme types, token modules (with PRESS), fonts (system font by default), palette and its core-pair test, contrast, theme set, context, AppThemeProvider, NavigationThemeProvider, makeStyles, text locale and its hook, text style hook, shadow helpers (each with its test); synced from the canonical copy | Workflow steps 2 and 5 (copy) |

| templates/src/ui/ | AppText (+ iOS, Android and balance tests), the balance hook (+ test), the press feedback context (+ test; all synced), PressableSurface (+ iOS and Android tests) | Workflow step 2 (copy) |

| templates/contracts/ | design-system.json (the contract) and its JSON Schema | Workflow step 2 (copy and edit) |

| templates/design/ | tokens.json: the demo token file in two tiers (synced) | Workflow step 2 (copy, then replace the values) |

| examples/task-summary-card.tsx | A themed card with one pressable action, roles and tokens only | Workflow step 6 |

| examples/task-summary-card.test.tsx | Its test: header, tabular count, press, dark theme | Workflow step 6 |

| examples/root-layout.tsx | The root layout mounting the providers and the navigation theme | Workflow step 5 |

| examples/tokens-dtcg-excerpt.json | The DTCG spellings the token reader accepts | Importing tokens from a design tool |

| scripts/check-design-system.mjs | Checker: contract, modules vs token file, palettes against the contrast pairs, text metrics at the font scale, tall scripts, balance, tabular, springs, press surface, fonts, dark-mode config, the provider's behaviour and mounts, the mapped navigation theme, no second theme | Workflow step 7 and at the end |

| scripts/check-raw-values.mjs | Checker: raw colours (named colours on colour props too), sizes, weights, tracking, radii, durations and springs (inline, in a same-file const or in an expression), palette imports, rounded line heights, legacy shadows, makeStyles factories, opt-in policies; scans src and the routes folder | Workflow step 7 and at the end |

| scripts/write-palette.mjs | Generator: palette.ts from the token file, refused while a pair fails | Workflow step 3 |

| scripts/selftest.mjs | Proves the three scripts on the shipped templates and every planted bug | After changing a script or a template |

| scripts/check-lib.mjs | Shared script helper, synced (do not edit here) | Never by hand |

| scripts/lib/ | Token file reader, contract reader, contrast maths and the contrast-contract reader, font table reader, source and import helpers, the synced TypeScript module loader | Never directly |

| assets/shared.json | Declares the synced files (check-lib, the module loader, the canonical theme, AppText, the balance hook, the press feedback context and the demo token file) | When adding a shared file |

| assets/default-contrast.json | The default pairs: a verbatim copy of accessibility-as-code's contracts/contrast.json template, read when the app has no contrast contract | Never by hand (copy the template again when it changes) |

| tests/fixtures/ | Overlay cases per script: good, planted bad, SKIP, NOT APPLICABLE and note cases | When adding a rule |

| tests/bases/ | The base app (the bundled-font variant: stub fonts with real metrics, their fonts.ts and contract; app config, root layout) and the raw-values base with silent planted findings in installed skills | When a case needs a new base file |

Related skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.