Skip to content

Commit 08ecaeb

Browse files
authored
refactor: improve structure of reference and system tokens (#4952)
* add focusIndicator tokens * add shadow overrides * include mass in toRawSpring * add contentColorFor helper
1 parent 3381515 commit 08ecaeb

40 files changed

Lines changed: 583 additions & 425 deletions

src/components/Button/utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { tokens } from '../../theme/tokens';
55
import type { InternalTheme, Theme } from '../../types';
66
import { splitStyles } from '../../utils/splitStyles';
77

8-
const { stateOpacity } = tokens.md.ref;
8+
const stateOpacity = tokens.md.sys.state.opacity;
99

1010
export type ButtonMode =
1111
| 'text'

src/components/Checkbox/CheckboxItem.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111

1212
import Checkbox from './Checkbox';
1313
import { useInternalTheme } from '../../core/theming';
14-
import { tokens } from '../../theme/tokens';
14+
import { getStateLayer } from '../../theme/utils/state';
1515
import type { ThemeProp, TypescaleKey } from '../../types';
1616
import TouchableRipple, {
1717
Props as TouchableRippleProps,
@@ -145,14 +145,10 @@ const CheckboxItem = ({
145145
const isLeading = position === 'leading';
146146
const checkbox = <Checkbox {...checkboxProps} />;
147147

148-
const textColor = theme.colors.onSurface;
149148
const textAlign = isLeading ? 'right' : 'left';
150149

151150
const computedStyle = {
152-
color: textColor,
153-
opacity: disabled
154-
? tokens.md.ref.stateOpacity.disabled
155-
: tokens.md.ref.stateOpacity.enabled,
151+
...getStateLayer(theme, 'onSurface', disabled ? 'disabled' : 'enabled'),
156152
textAlign,
157153
} as TextStyle;
158154

src/components/Checkbox/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ColorValue } from 'react-native';
33
import { tokens } from '../../theme/tokens';
44
import type { InternalTheme } from '../../types';
55

6-
const { stateOpacity } = tokens.md.ref;
6+
const stateOpacity = tokens.md.sys.state.opacity;
77

88
const getCheckedColor = ({
99
theme,

src/components/Chip/helpers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { InternalTheme, Theme } from '../../types';
77

88
const md3 = (theme: InternalTheme) => theme as Theme;
99

10-
const { stateOpacity } = tokens.md.ref;
10+
const stateOpacity = tokens.md.sys.state.opacity;
1111

1212
export type ChipAvatarProps = {
1313
style?: StyleProp<ViewStyle>;

src/components/HelperText/utils.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { tokens } from '../../theme/tokens';
1+
import { getStateLayer } from '../../theme/utils/state';
22
import type { InternalTheme } from '../../types';
33

4-
const { stateOpacity } = tokens.md.ref;
5-
64
type BaseProps = {
75
theme: InternalTheme;
86
disabled?: boolean;
@@ -11,18 +9,11 @@ type BaseProps = {
119

1210
export function getTextColor({ theme, disabled, type }: BaseProps) {
1311
if (type === 'error') {
14-
return { color: theme.colors.error, opacity: stateOpacity.enabled };
15-
}
16-
17-
if (disabled) {
18-
return {
19-
color: theme.colors.onSurfaceVariant,
20-
opacity: stateOpacity.disabled,
21-
};
12+
return getStateLayer(theme, 'error', 'enabled');
2213
}
23-
24-
return {
25-
color: theme.colors.onSurfaceVariant,
26-
opacity: stateOpacity.enabled,
27-
};
14+
return getStateLayer(
15+
theme,
16+
'onSurfaceVariant',
17+
disabled ? 'disabled' : 'enabled'
18+
);
2819
}

src/components/IconButton/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ColorValue } from 'react-native';
33
import { tokens } from '../../theme/tokens';
44
import type { InternalTheme } from '../../types';
55

6-
const { stateOpacity } = tokens.md.ref;
6+
const stateOpacity = tokens.md.sys.state.opacity;
77

88
type IconButtonMode = 'outlined' | 'contained' | 'contained-tonal';
99

src/components/Menu/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { tokens } from '../../theme/tokens';
22
import type { InternalTheme } from '../../types';
33
import type { IconSource } from '../Icon';
44

5-
const { stateOpacity } = tokens.md.ref;
5+
const stateOpacity = tokens.md.sys.state.opacity;
66

77
export const MIN_WIDTH = 112;
88
export const MAX_WIDTH = 280;

src/components/Modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { addEventListener } from '../utils/addEventListener';
2020
import { BackHandler } from '../utils/BackHandler/BackHandler';
2121
import useAnimatedValue from '../utils/useAnimatedValue';
2222

23-
const { scrimAlpha } = tokens.md.ref;
23+
const scrimAlpha = tokens.md.sys.scrim.alpha;
2424

2525
export type Props = {
2626
/**

src/components/RadioButton/RadioButtonItem.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { RadioButtonContext, RadioButtonContextType } from './RadioButtonGroup';
1515
import RadioButtonIOS from './RadioButtonIOS';
1616
import { handlePress, isChecked } from './utils';
1717
import { useInternalTheme } from '../../core/theming';
18-
import { tokens } from '../../theme/tokens';
18+
import { getStateLayer } from '../../theme/utils/state';
1919
import type { ThemeProp, TypescaleKey } from '../../types';
2020
import TouchableRipple, {
2121
Props as TouchableRippleProps,
@@ -179,14 +179,10 @@ const RadioButtonItem = ({
179179
radioButton = <RadioButton {...radioButtonProps} />;
180180
}
181181

182-
const textColor = theme.colors.onSurface;
183182
const textAlign = isLeading ? 'right' : 'left';
184183

185184
const computedStyle = {
186-
color: textColor,
187-
opacity: disabled
188-
? tokens.md.ref.stateOpacity.disabled
189-
: tokens.md.ref.stateOpacity.enabled,
185+
...getStateLayer(theme, 'onSurface', disabled ? 'disabled' : 'enabled'),
190186
textAlign,
191187
} as TextStyle;
192188

src/components/RadioButton/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ColorValue, GestureResponderEvent } from 'react-native';
33
import { tokens } from '../../theme/tokens';
44
import type { InternalTheme } from '../../types';
55

6-
const { stateOpacity } = tokens.md.ref;
6+
const stateOpacity = tokens.md.sys.state.opacity;
77

88
export const handlePress = ({
99
onPress,

0 commit comments

Comments
 (0)