This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
React Native Styled System - a styled-system implementation for React Native. Converts theme tokens (space, sizes, colors, radii, typography) into React Native styles via hooks and HOC patterns.
- packages/core - Main library (
@react-native-styled-system/core). Built with react-native-builder-bob. - packages/util - Theme utilities (
@react-native-styled-system/util). ContainscreateThemeanddefaultTheme. - packages/cli - Theme type generation CLI (
@react-native-styled-system/cli). Built with tsup. ES Module package. - example/ - Expo 51 React Native example app.
- doc/ - Docusaurus v3 documentation site.
Package manager: Yarn v4 (node-modules linker). Monorepo managed with Lerna.
# Install all dependencies (root + example)
yarn
# Run all checks (lint + type + test)
yarn check:all
# Individual checks
yarn check:lint # ESLint (packages only)
yarn check:type # TypeScript noEmit check
yarn check:test # Jest tests
# Run a single test file
yarn check:test --testPathPattern=useSx
# Build all packages
yarn build # runs lerna run prepack
# Example app
yarn example start
yarn example android
yarn example ios
# Docs site
yarn docsTests use Jest with react-native preset and ts-jest. Test files live alongside source:
packages/core/src/hook/*.test.tspackages/core/src/internal/util/*.test.tspackages/util/src/*.test.ts
Test utilities: packages/core/src/__testUtils__/testTheme.ts (provides emptyTheme, baseTheme, responsiveTheme).
- StyledSystemProvider (
provider/StyledSystemProvider.tsx) - React Context providingThemedDict+screenWidth(fromuseWindowDimensions) to the tree. Wraps the raw theme withcreateTheme()to fill defaults. - useSx hook (
hook/useSx.ts) - Main API. Takes component props + options, returns{ getStyle, filteredProps }. Handles shortcut prop expansion, token resolution, style merging, and optional caching via object-hash. - useSxStyle hook (
hook/useSxStyle.ts) - Returns a function(sx: TextSxProps) => StyleProp<TextStyle>for ad-hoc style computation without component props. - useSxTokens hook (
hook/useSxTokens.ts) - Resolves raw token values by type (e.g.,useSxTokens('colors', ['red.500'])returns the resolved color values). - propsToThemedStyle (
util/propsToThemedStyle.ts) - Pure function converting SxProps to React Native TextStyle/ViewStyle using TokenParsers. Central mapping of all style properties. Resolves responsive arrays before parsing. - TokenParser (
internal/TokenParser/) - Factory functions creating parsers for each token type (colors, space, sizes, radii, typography). Each parser resolves theme token keys to concrete values. - createSxComponent / createSxTextComponent (
util/createSxComponent.tsx) - HOC wrapping any RN component with sx prop support viaforwardRef. - createTheme (
@react-native-styled-system/util) - Overloaded:createTheme(partial?)fills empty token categories;createTheme(base, overrides)merges two themes. - defaultTheme (
@react-native-styled-system/util) - Pre-built theme with Tailwind CSS v4 palette + semantic tokens.
Styles merge in this order (later overrides earlier):
fallback < props < sx prop < style prop
Within each level, shortcut props are expanded to their full names first (e.g., bg -> backgroundColor), and the full name takes priority over the shortcut when both are provided.
Defined in SHORTCUT_NAME_MAP (@types/SxProps.ts). Key mappings: bg->backgroundColor, m/mt/mr/mb/ml/mx/my->margin variants, p/pt/pr/pb/pl/px/py->padding variants, w/h->width/height, radius->borderRadius, pos->position, t->typography, weight->fontWeight, align->textAlign.
Style props accept Responsive<T> = T | T[] arrays. Resolution (resolveResponsiveValue) picks the value matching the current screenWidth against breakpoints (defined in ThemedDict.breakpoints, default [480, 768, 1024]). Array index 0 = base value, index N+1 = value when screenWidth >= breakpoints[N]. The transform prop is excluded from responsive wrapping.
defaultTheme(@react-native-styled-system/util) - Pre-built theme with Tailwind CSS v4 palette + shadcn/ui semantic colors. Default semantic colors usebase: 'neutral', theme: 'neutral'.createThemeColors({ base, theme })- Generates light/dark semantic color sets following shadcn/ui convention.baseis a gray scale (slate|gray|zinc|neutral|stone),themeis any Tailwind color name.- Semantic color tokens:
background,foreground,card,card-foreground,popover,popover-foreground,primary,primary-foreground,secondary,secondary-foreground,muted,muted-foreground,accent,accent-foreground,destructive,destructive-foreground,border,input,ring,chart-1~chart-5.
ThemedDict(@types/ThemedDict.ts) - Theme shape:{ space, sizes, colors, radii, typography, breakpoints? }.SxProps/TextSxProps(@types/SxProps.ts) - All supported style props.SxProps= view styles only,TextSxPropsextends with text styles. Both wrap values inResponsive<T>.ResolvedSxProps/ResolvedTextSxProps- Internal types after responsive resolution (no array wrapping).ThemedTypings(@types/ThemedTypings.ts) - Auto-generated type augmentation from CLI for type-safe token keys.BaseColor/ThemeColor(@react-native-styled-system/util) - Type aliases forcreateThemeColorsparameters.Theme(@react-native-styled-system/util) - Utility package theme type used bycreateThemeanddefaultTheme.
generate-theme-type <sourceFile> reads a theme file via bundle-n-require, extracts token keys, and generates TypeScript interface augmentation for type-safe theme tokens.
Theme source file rule:
- Keep
theme.tsimport surface minimal. - Import only theme-related utilities (
createTheme,defaultTheme,createThemeColorsfrom@react-native-styled-system/util) and avoid unrelated runtime imports.
Husky pre-commit hook runs yarn check:all (lint + type + test) before every commit. Commit messages are validated by commitlint.
Root tsconfig.json: strict: true, target: ESNext, module: ESNext. Path aliases:
@react-native-styled-system/core->packages/core/src/index@react-native-styled-system/util->packages/util/src/index
Preset: react-native, environment: node, transform: ts-jest. Ignores node_modules, lib, cli, and .worktrees directories.
- Conventional commits enforced via commitlint (
feat:,fix:,docs:, etc.) - PR base branch:
develop. Publish frommain(Lernapub:version+pub:release). - Branch naming:
[type/scope](e.g.,fix/accordion-hook,feat/new-token). - Prettier: single quotes, trailing commas, 100 char print width,
arrowParens: always,jsxSingleQuote: false. - ESLint:
@mj-studio/eslint-config-react.