Extract or create a typed design token system for a React Native app. Generates color, spacing, and typography token files with light and dark mode support mapped to iOS HIG values. Use when setting up or refactoring the design system.
Create or extract a typed design token system for this React Native app.
Input: $ARGUMENTS
**/tokens/**, **/theme/**, **/constants/colors.*, **/constants/spacing.*Create token files in the project's preferred location (default: src/tokens/ or tokens/).
colors.ts)export const palette = {
// Brand colors
primary: { light: '#007AFF', dark: '#0A84FF' },
// ... brand-specific colors
// iOS Semantic Colors (map to PlatformColor equivalents)
background: { light: '#FFFFFF', dark: '#000000' },
secondaryBackground: { light: '#F2F2F7', dark: '#1C1C1E' },
tertiaryBackground: { light: '#FFFFFF', dark: '#2C2C2E' },
groupedBackground: { light: '#F2F2F7', dark: '#000000' },
label: { light: '#000000', dark: '#FFFFFF' },
secondaryLabel: { light: '#3C3C43', dark: '#EBEBF5' }, // with 60% opacity
separator: { light: '#3C3C4349', dark: '#54545899' },
// ... extend as needed
} as const;
export type ColorToken = keyof typeof palette;
spacing.ts)export const spacing = {
xxs: 4,
xs: 8,
sm: 12,
md: 16,
lg: 24,
xl: 32,
xxl: 48,
} as const;
export type SpacingToken = keyof typeof spacing;
typography.ts)Map to iOS HIG type scale with Dynamic Type support:
import { Platform, TextStyle } from 'react-native';
export const typography = {
largeTitle: { fontSize: 34, fontWeight: '700', lineHeight: 41 },
title1: { fontSize: 28, fontWeight: '700', lineHeight: 34 },
title2: { fontSize: 22, fontWeight: '700', lineHeight: 28 },
title3: { fontSize: 20, fontWeight: '600', lineHeight: 25 },
headline: { fontSize: 17, fontWeight: '600', lineHeight: 22 },
body: { fontSize: 17, fontWeight: '400', lineHeight: 22 },
callout: { fontSize: 16, fontWeight: '400', lineHeight: 21 },
subheadline: { fontSize: 15, fontWeight: '400', lineHeight: 20 },
footnote: { fontSize: 13, fontWeight: '400', lineHeight: 18 },
caption1: { fontSize: 12, fontWeight: '400', lineHeight: 16 },
caption2: { fontSize: 11, fontWeight: '400', lineHeight: 13 },
} as const satisfies Record<string, TextStyle>;
export type TypographyToken = keyof typeof typography;
useTheme.ts)import { useColorScheme } from 'react-native';
import { palette } from './colors';
export function useTheme() {
const colorScheme = useColorScheme();
const isDark = colorScheme === 'dark';
const colors = Object.fromEntries(
Object.entries(palette).map(([key, value]) => [
key,
isDark ? value.dark : value.light,
])
) as Record<keyof typeof palette, string>;
return { colors, isDark };
}
tailwind.config.jstamagui.config.ts)useTheme hookas const for type safety