Skip to content

Commit d68ecfc

Browse files
committed
feat: add theme.state opacity tokens and split theme types
1 parent fdb6702 commit d68ecfc

15 files changed

Lines changed: 239 additions & 181 deletions

File tree

src/components/__tests__/__snapshots__/ListSection.test.tsx.snap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ exports[`renders list section with custom title style 1`] = `
188188
},
189189
},
190190
"roundness": 4,
191+
"state": {
192+
"opacity": {
193+
"dragged": 0.16,
194+
"focused": 0.1,
195+
"hovered": 0.08,
196+
"pressed": 0.1,
197+
},
198+
},
191199
}
192200
}
193201
>
@@ -730,6 +738,14 @@ exports[`renders list section with subheader 1`] = `
730738
},
731739
},
732740
"roundness": 4,
741+
"state": {
742+
"opacity": {
743+
"dragged": 0.16,
744+
"focused": 0.1,
745+
"hovered": 0.08,
746+
"pressed": 0.1,
747+
},
748+
},
733749
}
734750
}
735751
>
@@ -1270,6 +1286,14 @@ exports[`renders list section without subheader 1`] = `
12701286
},
12711287
},
12721288
"roundness": 4,
1289+
"state": {
1290+
"opacity": {
1291+
"dragged": 0.16,
1292+
"focused": 0.1,
1293+
"hovered": 0.08,
1294+
"pressed": 0.1,
1295+
},
1296+
},
12731297
}
12741298
}
12751299
>

src/theme/schemes/DarkTheme.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { baseTheme } from './base';
22
import { tokens } from '../tokens';
33
import { buildScheme } from '../tokens/sys/color/roles';
4+
import { defaultState } from '../tokens/sys/state';
45
import type { Theme } from '../types';
56

67
export const DarkTheme: Theme = {
78
...baseTheme,
89
dark: true,
910
mode: 'adaptive',
1011
colors: buildScheme(tokens.md.ref.palette, tokens.md.ref, { mode: 'dark' }),
12+
state: defaultState,
1113
};

src/theme/schemes/DynamicTheme.android.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Platform, PlatformColor } from 'react-native';
22

33
import { DarkTheme } from './DarkTheme';
44
import { LightTheme } from './LightTheme';
5+
import { defaultState } from '../tokens/sys/state';
56
import type { Theme } from '../types';
67

78
const isApi34 = (Platform.Version as number) >= 34;
@@ -494,9 +495,11 @@ const darkColors = {
494495
export const DynamicLightTheme: Theme = {
495496
...LightTheme,
496497
colors: { ...LightTheme.colors, ...lightColors },
498+
state: defaultState,
497499
};
498500

499501
export const DynamicDarkTheme: Theme = {
500502
...DarkTheme,
501503
colors: { ...DarkTheme.colors, ...darkColors },
504+
state: defaultState,
502505
};

src/theme/schemes/LightTheme.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { baseTheme } from './base';
22
import { tokens } from '../tokens';
33
import { buildScheme } from '../tokens/sys/color/roles';
4+
import { defaultState } from '../tokens/sys/state';
45
import type { Theme } from '../types';
56

67
export const LightTheme: Theme = {
78
...baseTheme,
89
dark: false,
910
colors: buildScheme(tokens.md.ref.palette, tokens.md.ref, { mode: 'light' }),
11+
state: defaultState,
1012
};

src/theme/tokens/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ const ref = {
122122
stateOpacity: {
123123
dragged: 0.16,
124124
pressed: 0.1,
125-
focus: 0.1,
126-
hover: 0.08,
125+
focused: 0.1,
126+
hovered: 0.08,
127127
disabled: 0.38,
128128
enabled: 1.0,
129129
},

src/theme/tokens/sys/state.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { ThemeState } from '../../types';
2+
import { tokens } from '../index';
3+
4+
const { stateOpacity } = tokens.md.ref;
5+
6+
export const defaultState: ThemeState = {
7+
opacity: {
8+
hovered: stateOpacity.hovered,
9+
focused: stateOpacity.focused,
10+
pressed: stateOpacity.pressed,
11+
dragged: stateOpacity.dragged,
12+
},
13+
};

src/theme/types.ts

Lines changed: 0 additions & 179 deletions
This file was deleted.

src/theme/types/color.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import type { ElevationColors } from './elevation';
2+
3+
export type ThemeColors = {
4+
primary: string;
5+
primaryContainer: string;
6+
secondary: string;
7+
secondaryContainer: string;
8+
tertiary: string;
9+
tertiaryContainer: string;
10+
surface: string;
11+
surfaceDim: string;
12+
surfaceBright: string;
13+
surfaceContainerLowest: string;
14+
surfaceContainerLow: string;
15+
surfaceContainer: string;
16+
surfaceContainerHigh: string;
17+
surfaceContainerHighest: string;
18+
surfaceVariant: string;
19+
background: string;
20+
error: string;
21+
errorContainer: string;
22+
onPrimary: string;
23+
onPrimaryContainer: string;
24+
onSecondary: string;
25+
onSecondaryContainer: string;
26+
onTertiary: string;
27+
onTertiaryContainer: string;
28+
onSurface: string;
29+
onSurfaceVariant: string;
30+
onError: string;
31+
onErrorContainer: string;
32+
onBackground: string;
33+
outline: string;
34+
outlineVariant: string;
35+
inverseSurface: string;
36+
inverseOnSurface: string;
37+
inversePrimary: string;
38+
primaryFixed: string;
39+
primaryFixedDim: string;
40+
onPrimaryFixed: string;
41+
onPrimaryFixedVariant: string;
42+
secondaryFixed: string;
43+
secondaryFixedDim: string;
44+
onSecondaryFixed: string;
45+
onSecondaryFixedVariant: string;
46+
tertiaryFixed: string;
47+
tertiaryFixedDim: string;
48+
onTertiaryFixed: string;
49+
onTertiaryFixedVariant: string;
50+
shadow: string;
51+
scrim: string;
52+
/** Pre-computed state layer color at press opacity (0.10).
53+
* Used for ripple effects. Avoids runtime alpha manipulation
54+
* which is incompatible with PlatformColor on Android.
55+
* TODO: revisit after https://github.com/facebook/react-native/pull/56395
56+
* @see https://m3.material.io/foundations/interaction/states/state-layers */
57+
stateLayerPressed: string;
58+
elevation: ElevationColors;
59+
};

src/theme/types/elevation.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export type Elevation = 0 | 1 | 2 | 3 | 4 | 5;
2+
3+
export enum ElevationLevels {
4+
'level0',
5+
'level1',
6+
'level2',
7+
'level3',
8+
'level4',
9+
'level5',
10+
}
11+
12+
export type ElevationColors = {
13+
[key in keyof typeof ElevationLevels]: string;
14+
};

src/theme/types/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export * from './color';
2+
export * from './elevation';
3+
export * from './navigation';
4+
export * from './state';
5+
export * from './theme';
6+
export * from './typography';
7+
export * from './utils';

0 commit comments

Comments
 (0)