Skip to content

Commit f998dff

Browse files
authored
feat: add theme.state opacity tokens and split theme types (#4917)
* feat: add theme.state opacity tokens and split theme types * feat: add disabled and enabled opacity to theme.state * fix: code review findings
1 parent 1f1102d commit f998dff

16 files changed

Lines changed: 184 additions & 200 deletions

File tree

src/components/Card/CardTitle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type Props = React.ComponentPropsWithRef<typeof View> & {
4040
*
4141
* Body: `bodyLarge`, `bodyMedium`, `bodySmall`
4242
*/
43-
titleVariant?: keyof typeof TypescaleKey;
43+
titleVariant?: TypescaleKey;
4444
/**
4545
* Text for the subtitle. Note that this will only accept a string or `<Text>`-based node.
4646
*/
@@ -69,7 +69,7 @@ export type Props = React.ComponentPropsWithRef<typeof View> & {
6969
*
7070
* Body: `bodyLarge`, `bodyMedium`, `bodySmall`
7171
*/
72-
subtitleVariant?: keyof typeof TypescaleKey;
72+
subtitleVariant?: TypescaleKey;
7373
/**
7474
* Callback which returns a React element to display on the left side.
7575
*/

src/components/Checkbox/CheckboxItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export type Props = {
8686
*
8787
* Body: `bodyLarge`, `bodyMedium`, `bodySmall`
8888
*/
89-
labelVariant?: keyof typeof TypescaleKey;
89+
labelVariant?: TypescaleKey;
9090
/**
9191
* @optional
9292
*/

src/components/Menu/Menu.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
2424
import MenuItem from './MenuItem';
2525
import { useInternalTheme } from '../../core/theming';
2626
import type { Elevation, Theme, ThemeProp } from '../../types';
27-
import { ElevationLevels } from '../../types';
2827
import { addEventListener } from '../../utils/addEventListener';
2928
import { BackHandler } from '../../utils/BackHandler/BackHandler';
3029
import Portal from '../Portal/Portal';
@@ -105,9 +104,14 @@ const EASING = Easing.bezier(0.4, 0, 0.2, 1);
105104
const WINDOW_LAYOUT = Dimensions.get('window');
106105

107106
const DEFAULT_ELEVATION: Elevation = 2;
108-
export const ELEVATION_LEVELS_MAP = Object.values(
109-
ElevationLevels
110-
) as ElevationLevels[];
107+
export const ELEVATION_LEVELS_MAP = [
108+
'level0',
109+
'level1',
110+
'level2',
111+
'level3',
112+
'level4',
113+
'level5',
114+
] as const;
111115

112116
const DEFAULT_MODE = 'elevated';
113117

src/components/RadioButton/RadioButtonItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export type Props = {
8888
*
8989
* Body: `bodyLarge`, `bodyMedium`, `bodySmall`
9090
*/
91-
labelVariant?: keyof typeof TypescaleKey;
91+
labelVariant?: TypescaleKey;
9292
/**
9393
* Specifies the largest possible scale a label font can reach.
9494
*/

src/components/Typography/types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import type { TypescaleKey } from '../../types';
22

33
export type VariantProp<T> =
44
| (T extends string ? (string extends T ? never : T) : never)
5-
| keyof typeof TypescaleKey;
5+
| TypescaleKey;

src/deprecated.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import { DarkTheme } from './theme/schemes/DarkTheme';
1212
import { LightTheme } from './theme/schemes/LightTheme';
1313
import { Palette } from './theme/tokens';
14-
import { TypescaleKey } from './types';
15-
import type { Theme, Elevation } from './types';
14+
import type { Theme, Elevation, TypescaleKey } from './types';
1615

1716
/**
1817
* @deprecated Use `LightTheme` instead. Will be removed in a future version.
@@ -32,8 +31,6 @@ export const MD3Colors = Palette;
3231
/**
3332
* @deprecated Use `TypescaleKey` instead. Will be removed in a future version.
3433
*/
35-
export const MD3TypescaleKey = TypescaleKey;
36-
// eslint-disable-next-line no-redeclare
3734
export type MD3TypescaleKey = TypescaleKey;
3835

3936
/**

src/theme/fonts.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ import { typescale } from './tokens';
22
import type { TypescaleStyle, Typescale, TypescaleKey } from './types';
33

44
type FontsConfig =
5-
| {
6-
[key in TypescaleKey]: Partial<TypescaleStyle>;
7-
}
8-
| {
9-
[key: string]: TypescaleStyle;
10-
}
5+
| Record<TypescaleKey, Partial<TypescaleStyle>>
6+
| Record<string, TypescaleStyle>
117
| Partial<TypescaleStyle>;
128

139
function configureFontsConfig(

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/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+
};

0 commit comments

Comments
 (0)