Skip to content

Commit 4833a0d

Browse files
committed
fix: update state opacity tokens
1 parent f591c8c commit 4833a0d

9 files changed

Lines changed: 31 additions & 24 deletions

File tree

src/components/ToggleButton/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const getToggleButtonColor = ({
1212
}) => {
1313
if (checked) {
1414
return color(theme.colors.onSecondaryContainer)
15-
.alpha(tokens.md.ref.opacity.level2)
15+
.alpha(tokens.md.ref.stateOpacity.pressed)
1616
.rgb()
1717
.string();
1818
}

src/components/__tests__/ToggleButton.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('getToggleButtonColor', () => {
5353
it('should return correct color when checked and theme version 3', () => {
5454
expect(getToggleButtonColor({ theme: getTheme(), checked: true })).toBe(
5555
color(getTheme().colors.onSecondaryContainer)
56-
.alpha(tokens.md.ref.opacity.level2)
56+
.alpha(tokens.md.ref.stateOpacity.pressed)
5757
.rgb()
5858
.string()
5959
);
@@ -62,7 +62,7 @@ describe('getToggleButtonColor', () => {
6262
it('should return correct color when checked and theme version 3, dark theme', () => {
6363
expect(getToggleButtonColor({ theme: getTheme(true), checked: true })).toBe(
6464
color(getTheme(true).colors.onSecondaryContainer)
65-
.alpha(tokens.md.ref.opacity.level2)
65+
.alpha(tokens.md.ref.stateOpacity.pressed)
6666
.rgb()
6767
.string()
6868
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ exports[`renders disabled FAB 1`] = `
527527
collapsable={false}
528528
style={
529529
{
530-
"backgroundColor": "rgba(29, 27, 32, 0.12)",
530+
"backgroundColor": "rgba(29, 27, 32, 0.1)",
531531
"borderRadius": 16,
532532
"opacity": 1,
533533
"shadowColor": "#000",
@@ -551,7 +551,7 @@ exports[`renders disabled FAB 1`] = `
551551
pointerEvents="auto"
552552
style={
553553
{
554-
"backgroundColor": "rgba(29, 27, 32, 0.12)",
554+
"backgroundColor": "rgba(29, 27, 32, 0.1)",
555555
"borderRadius": 16,
556556
"flex": undefined,
557557
"shadowColor": "#000",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ exports[`renders disabled icon button 1`] = `
2626
style={
2727
{
2828
"backgroundColor": "transparent",
29-
"borderColor": "rgba(29, 27, 32, 0.12)",
29+
"borderColor": "rgba(29, 27, 32, 0.1)",
3030
"borderRadius": 20,
3131
"borderWidth": 0,
3232
"elevation": 0,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ exports[`renders list section with custom title style 1`] = `
6969
"surfaceContainerLow": "rgba(247, 242, 250, 1)",
7070
"surfaceContainerLowest": "rgba(255, 255, 255, 1)",
7171
"surfaceDim": "rgba(222, 216, 225, 1)",
72-
"surfaceDisabled": "rgba(29, 27, 32, 0.12)",
72+
"surfaceDisabled": "rgba(29, 27, 32, 0.1)",
7373
"surfaceVariant": "rgba(231, 224, 236, 1)",
7474
"tertiary": "rgba(125, 82, 96, 1)",
7575
"tertiaryContainer": "rgba(255, 216, 228, 1)",
@@ -613,7 +613,7 @@ exports[`renders list section with subheader 1`] = `
613613
"surfaceContainerLow": "rgba(247, 242, 250, 1)",
614614
"surfaceContainerLowest": "rgba(255, 255, 255, 1)",
615615
"surfaceDim": "rgba(222, 216, 225, 1)",
616-
"surfaceDisabled": "rgba(29, 27, 32, 0.12)",
616+
"surfaceDisabled": "rgba(29, 27, 32, 0.1)",
617617
"surfaceVariant": "rgba(231, 224, 236, 1)",
618618
"tertiary": "rgba(125, 82, 96, 1)",
619619
"tertiaryContainer": "rgba(255, 216, 228, 1)",
@@ -1155,7 +1155,7 @@ exports[`renders list section without subheader 1`] = `
11551155
"surfaceContainerLow": "rgba(247, 242, 250, 1)",
11561156
"surfaceContainerLowest": "rgba(255, 255, 255, 1)",
11571157
"surfaceDim": "rgba(222, 216, 225, 1)",
1158-
"surfaceDisabled": "rgba(29, 27, 32, 0.12)",
1158+
"surfaceDisabled": "rgba(29, 27, 32, 0.1)",
11591159
"surfaceVariant": "rgba(231, 224, 236, 1)",
11601160
"tertiary": "rgba(125, 82, 96, 1)",
11611161
"tertiaryContainer": "rgba(255, 216, 228, 1)",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`renders disabled toggle button 1`] = `
55
collapsable={false}
66
style={
77
{
8-
"backgroundColor": "rgba(74, 68, 88, 0.12)",
8+
"backgroundColor": "rgba(74, 68, 88, 0.1)",
99
"borderRadius": 4,
1010
"height": 42,
1111
"margin": 0,
@@ -25,7 +25,7 @@ exports[`renders disabled toggle button 1`] = `
2525
collapsable={false}
2626
style={
2727
{
28-
"backgroundColor": "rgba(74, 68, 88, 0.12)",
28+
"backgroundColor": "rgba(74, 68, 88, 0.1)",
2929
"borderColor": "rgba(121, 116, 126, 1)",
3030
"borderRadius": 4,
3131
"borderWidth": 0,
@@ -144,7 +144,7 @@ exports[`renders toggle button 1`] = `
144144
collapsable={false}
145145
style={
146146
{
147-
"backgroundColor": "rgba(74, 68, 88, 0.12)",
147+
"backgroundColor": "rgba(74, 68, 88, 0.1)",
148148
"borderRadius": 4,
149149
"height": 42,
150150
"margin": 0,
@@ -164,7 +164,7 @@ exports[`renders toggle button 1`] = `
164164
collapsable={false}
165165
style={
166166
{
167-
"backgroundColor": "rgba(74, 68, 88, 0.12)",
167+
"backgroundColor": "rgba(74, 68, 88, 0.1)",
168168
"borderColor": "rgba(121, 116, 126, 1)",
169169
"borderRadius": 4,
170170
"borderWidth": 0,

src/styles/themes/DarkTheme.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MD3LightTheme } from './LightTheme';
44
import { MD3Colors, tokens } from './tokens';
55
import type { MD3Theme } from '../../types';
66

7-
const { palette, opacity } = tokens.md.ref;
7+
const { palette, stateOpacity } = tokens.md.ref;
88

99
export const MD3DarkTheme: MD3Theme = {
1010
...MD3LightTheme,
@@ -25,8 +25,9 @@ export const MD3DarkTheme: MD3Theme = {
2525
surfaceContainerHigh: palette.neutral17,
2626
surfaceContainerHighest: palette.neutral22,
2727
surfaceVariant: palette.neutralVariant30,
28+
//TODO: remove this
2829
surfaceDisabled: color(palette.neutral90)
29-
.alpha(opacity.level2)
30+
.alpha(stateOpacity.pressed)
3031
.rgb()
3132
.string(),
3233
background: palette.neutral6,
@@ -40,8 +41,9 @@ export const MD3DarkTheme: MD3Theme = {
4041
onTertiaryContainer: palette.tertiary90,
4142
onSurface: palette.neutral90,
4243
onSurfaceVariant: palette.neutralVariant80,
44+
//TODO: remove this
4345
onSurfaceDisabled: color(palette.neutral90)
44-
.alpha(opacity.level4)
46+
.alpha(stateOpacity.disabled)
4547
.rgb()
4648
.string(),
4749
onError: palette.error20,
@@ -66,6 +68,7 @@ export const MD3DarkTheme: MD3Theme = {
6668
onTertiaryFixedVariant: palette.tertiary30,
6769
shadow: palette.neutral0,
6870
scrim: palette.neutral0,
71+
//TODO: remove this
6972
backdrop: color(MD3Colors.neutralVariant20).alpha(0.4).rgb().string(),
7073
elevation: {
7174
level0: 'transparent',

src/styles/themes/LightTheme.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MD3Colors, tokens } from './tokens';
44
import type { MD3Theme } from '../../types';
55
import configureFonts from '../fonts';
66

7-
const { palette, opacity } = tokens.md.ref;
7+
const { palette, stateOpacity } = tokens.md.ref;
88

99
export const MD3LightTheme: MD3Theme = {
1010
dark: false,
@@ -26,7 +26,7 @@ export const MD3LightTheme: MD3Theme = {
2626
surfaceContainerHighest: palette.neutral90,
2727
surfaceVariant: palette.neutralVariant90,
2828
surfaceDisabled: color(palette.neutral10)
29-
.alpha(opacity.level2)
29+
.alpha(stateOpacity.pressed)
3030
.rgb()
3131
.string(),
3232
background: palette.neutral98,
@@ -41,7 +41,7 @@ export const MD3LightTheme: MD3Theme = {
4141
onSurface: palette.neutral10,
4242
onSurfaceVariant: palette.neutralVariant30,
4343
onSurfaceDisabled: color(palette.neutral10)
44-
.alpha(opacity.level4)
44+
.alpha(stateOpacity.disabled)
4545
.rgb()
4646
.string(),
4747
onError: palette.error100,

src/styles/themes/tokens.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,15 @@ const ref = {
116116
weightMedium: '500' as Font['fontWeight'],
117117
},
118118

119-
opacity: {
120-
level1: 0.08,
121-
level2: 0.12,
122-
level3: 0.16,
123-
level4: 0.38,
119+
/** State layers opacity
120+
* @see https://m3.material.io/foundations/interaction/states/state-layers
121+
*/
122+
stateOpacity: {
123+
dragged: 0.16,
124+
pressed: 0.1,
125+
focus: 0.1,
126+
hover: 0.08,
127+
disabled: 0.38,
124128
},
125129
};
126130

0 commit comments

Comments
 (0)