feat(theme): semantic design system and light/dark provider

- brand tokens (primary #609926), light/dark semantic colour palettes
- spacing/radius/typography tokens, monospace font for code and git data
- AppThemeProvider applying persisted light/dark/system preference
This commit is contained in:
JustZoe101 committed 2026-10-09 16:41:10 +02:00
1 parent 26a6eba1e5
commit 7b89c594ea
2 files changed
+235

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
/**
* Theme provider: resolves the user's theme preference (system / light / dark)
* and exposes the design-token palette to the whole tree.
*/
import { DarkTheme, DefaultTheme, type Theme } from '@react-navigation/native';
import { useColorScheme } from 'react-native';
import { useSettingsStore } from '@/features/settings/settings-store';
import { palette, type ThemeColors } from '@/theme/tokens';
import { createContext, useContext, useMemo, type ReactNode } from 'react';
export type ResolvedScheme = 'light' | 'dark';
export interface AppTheme {
scheme: ResolvedScheme;
isDark: boolean;
colors: ThemeColors;
}
const ThemeContext = createContext<AppTheme | null>(null);
export function AppThemeProvider({ children }: { children: ReactNode }) {
const systemScheme = useColorScheme();
const preference = useSettingsStore((s) => s.themePreference);
const scheme: ResolvedScheme =
preference === 'system' ? (systemScheme === 'dark' ? 'dark' : 'light') : preference;
const value = useMemo<AppTheme>(
() => ({ scheme, isDark: scheme === 'dark', colors: palette[scheme] }),
[scheme],
);
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
}
export function useTheme(): AppTheme {
const theme = useContext(ThemeContext);
if (!theme) {
throw new Error('useTheme must be used inside <AppThemeProvider>');
}
return theme;
}
/** Navigation theme so native stacks and headers follow our palette. */
export function useNavigationTheme(): Theme {
const { isDark, colors } = useTheme();
const base = isDark ? DarkTheme : DefaultTheme;
return {
...base,
dark: isDark,
colors: {
...base.colors,
primary: colors.primary,
background: colors.background,
card: colors.surface,
text: colors.text,
border: colors.border,
notification: colors.error,
},
};
}
+172
View File
@@ -0,0 +1,172 @@
/**
* Design tokens for Gitea Native.
*
* Single source of truth for colors, spacing, radii, and typography.
* Never hardcode hex values in components — always read from the active theme.
*/
import { Platform } from 'react-native';
/** Gitea's recognizable green, used for accents and primary actions. */
export const BRAND_PRIMARY = '#609926';
export const palette = {
light: {
background: '#F7F9F6',
surface: '#FFFFFF',
surfaceSecondary: '#EDF1EA',
surfacePressed: '#E2E8DF',
overlay: 'rgba(23, 32, 25, 0.45)',
text: '#172019',
textSecondary: '#55624F',
textTertiary: '#7C877A',
textDisabled: '#A9B2A6',
border: '#DCE3D9',
borderStrong: '#C3CDBF',
primary: BRAND_PRIMARY,
primaryPressed: '#4E7D1F',
primaryMuted: '#E8F1DC',
onPrimary: '#FFFFFF',
link: '#0969DA',
success: '#1A7F37',
successMuted: '#DCF2E3',
warning: '#9A6700',
warningMuted: '#FBF0D9',
error: '#D1242F',
errorMuted: '#FBE3E3',
info: '#0969DA',
infoMuted: '#DFEAF9',
neutral: '#6A7568',
neutralMuted: '#E8EBE6',
merged: '#8250DF',
mergedMuted: '#EFE4FC',
diffAdd: '#E6FFEC',
diffAddText: '#116329',
diffDel: '#FFEBE9',
diffDelText: '#82071E',
diffGutter: '#F2F4F1',
codeBackground: '#F1F4EF',
scrim: '#FFFFFFCC',
},
dark: {
background: '#111713',
surface: '#1B241D',
surfaceSecondary: '#243027',
surfacePressed: '#2C3A30',
overlay: 'rgba(3, 6, 4, 0.6)',
text: '#F1F5F0',
textSecondary: '#A7B3A5',
textTertiary: '#7E8B7C',
textDisabled: '#5C675B',
border: '#2E3B31',
borderStrong: '#3E4E41',
primary: '#74B339',
primaryPressed: '#8BC44E',
primaryMuted: '#22301A',
onPrimary: '#0C1207',
link: '#6CB6FF',
success: '#3FB950',
successMuted: '#132A19',
warning: '#D29922',
warningMuted: '#2E2413',
error: '#F85149',
errorMuted: '#33191A',
info: '#58A6FF',
infoMuted: '#14283D',
neutral: '#8B988A',
neutralMuted: '#232B24',
merged: '#A371F7',
mergedMuted: '#241C36',
diffAdd: '#12261A',
diffAddText: '#7EE787',
diffDel: '#2A1517',
diffDelText: '#FF7B72',
diffGutter: '#161D18',
codeBackground: '#151C17',
scrim: '#0B100DCC',
},
} as const;
export type ColorToken = keyof typeof palette.light;
export type ThemeColors = { [K in ColorToken]: string };
/** Which color families are identical across schemes (for semantic aliases). */
export const spacing = {
none: 0,
xs: 4,
sm: 8,
md: 12,
lg: 16,
xl: 24,
xxl: 32,
xxxl: 48,
} as const;
export type SpacingToken = keyof typeof spacing;
export const radius = {
sm: 6,
md: 10,
lg: 14,
xl: 20,
pill: 999,
} as const;
export type RadiusToken = keyof typeof radius;
export const fontSize = {
xs: 12,
sm: 13,
md: 15,
lg: 17,
xl: 20,
xxl: 24,
xxxl: 30,
} as const;
export const fontWeight = {
regular: '400',
medium: '500',
semibold: '600',
bold: '700',
} as const;
export const fontFamily = {
sans: Platform.select({ ios: 'System', android: 'sans-serif', default: 'System' }),
sansMedium: Platform.select({
ios: 'System',
android: 'sans-serif-medium',
default: 'System',
}),
mono: Platform.select({
ios: 'ui-monospace',
android: 'monospace',
default: 'monospace',
}),
} as const;
/** Minimum touch target per platform HIG. */
export const HIT_TARGET = 44;
export const shadows = {
card: Platform.select({
ios: {
shadowColor: '#000000',
shadowOpacity: 0.08,
shadowRadius: 8,
shadowOffset: { width: 0, height: 2 },
},
android: { elevation: 2 },
default: {},
}),
floating: Platform.select({
ios: {
shadowColor: '#000000',
shadowOpacity: 0.16,
shadowRadius: 16,
shadowOffset: { width: 0, height: 6 },
},
android: { elevation: 6 },
default: {},
}),
} as const;