Skip to content

Commit 82039e4

Browse files
fix(theme): update tokens with opacity/alpha for improved visibility (#10256)
* fix(theme): update tokens with opacity/alpha for improved visibility * fix(theme): correct adjustAlpha syntax error * docs(search): add disabled story * docs(theme): adjustAlpha comment improvements Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 085a45d commit 82039e4

File tree

7 files changed

+47
-22
lines changed

7 files changed

+47
-22
lines changed

packages/react/src/components/Search/next/Search.stories.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ export const Default = () => (
2323
/>
2424
);
2525

26+
export const Disabled = () => (
27+
<Search
28+
disabled
29+
size="lg"
30+
defaultValue="A default value"
31+
labelText="Search"
32+
closeButtonLabelText="Clear search input"
33+
id="search-1"
34+
onChange={() => {}}
35+
onKeyDown={() => {}}
36+
/>
37+
);
38+
2639
export const Expandable = () => (
2740
<ExpandableSearch
2841
size="lg"

packages/styles/scss/components/button/_tokens.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,11 @@ $button-disabled: (
330330
),
331331
(
332332
theme: themes.$g90,
333-
value: #6f6f6f,
333+
value: rgba(141, 141, 141, 0.3),
334334
),
335335
(
336336
theme: themes.$g100,
337-
value: #525252,
337+
value: rgba(141, 141, 141, 0.3),
338338
),
339339
),
340340
) !default;

packages/themes/src/next/g10.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
white,
4040
whiteHover,
4141
} from '@carbon/colors';
42-
import { adjustLightness } from '../tools';
42+
import { adjustLightness, adjustAlpha } from '../tools';
4343

4444
// Background
4545
export const background = gray10;
@@ -137,18 +137,18 @@ export const borderInverse = gray100;
137137
export const borderInteractive = blue60;
138138

139139
// border
140-
export const borderDisabled = white;
140+
export const borderDisabled = gray30;
141141

142142
// Text
143143
export const textPrimary = gray100;
144144
export const textSecondary = gray70;
145-
export const textPlaceholder = gray40;
145+
export const textPlaceholder = adjustAlpha(textPrimary, 0.4);
146146
export const textHelper = gray60;
147147
export const textError = red60;
148148
export const textInverse = white;
149149
export const textOnColor = white;
150150
export const textOnColorDisabled = gray50;
151-
export const textDisabled = gray30;
151+
export const textDisabled = adjustAlpha(textPrimary, 0.25);
152152

153153
// Link
154154
export const linkPrimary = blue60;

packages/themes/src/next/g100.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
// Tools
4747
rgba,
4848
} from '@carbon/colors';
49-
import { adjustLightness } from '../tools';
49+
import { adjustLightness, adjustAlpha } from '../tools';
5050

5151
// Background
5252
export const background = gray100;
@@ -144,18 +144,18 @@ export const borderInverse = gray10;
144144
export const borderInteractive = blue50;
145145

146146
// border
147-
export const borderDisabled = gray90;
147+
export const borderDisabled = adjustAlpha(gray50, 0.5);
148148

149149
// Text
150150
export const textPrimary = gray10;
151151
export const textSecondary = gray30;
152-
export const textPlaceholder = gray60;
152+
export const textPlaceholder = adjustAlpha(textPrimary, 0.4);
153153
export const textHelper = gray40;
154154
export const textError = red30;
155155
export const textInverse = gray100;
156156
export const textOnColor = white;
157-
export const textOnColorDisabled = gray40;
158-
export const textDisabled = gray70;
157+
export const textOnColorDisabled = adjustAlpha(textOnColor, 0.25);
158+
export const textDisabled = adjustAlpha(textPrimary, 0.25);
159159

160160
// Link
161161
export const linkPrimary = blue40;
@@ -169,7 +169,7 @@ export const iconPrimary = gray10;
169169
export const iconSecondary = gray30;
170170
export const iconInverse = gray100;
171171
export const iconOnColor = white;
172-
export const iconOnColorDisabled = gray40;
172+
export const iconOnColorDisabled = adjustAlpha(iconOnColor, 0.25);
173173
export const iconDisabled = gray70;
174174

175175
// Support

packages/themes/src/next/g90.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
// Tools
4646
rgba,
4747
} from '@carbon/colors';
48-
import { adjustLightness } from '../tools';
48+
import { adjustLightness, adjustAlpha } from '../tools';
4949

5050
// Background
5151
export const background = gray90;
@@ -143,18 +143,18 @@ export const borderInverse = gray10;
143143
export const borderInteractive = blue50;
144144

145145
// border
146-
export const borderDisabled = gray80;
146+
export const borderDisabled = adjustAlpha(gray50, 0.5);
147147

148148
// Text
149149
export const textPrimary = gray10;
150150
export const textSecondary = gray30;
151-
export const textPlaceholder = gray50;
151+
export const textPlaceholder = adjustAlpha(textPrimary, 0.4);
152152
export const textHelper = gray30;
153153
export const textError = red30;
154154
export const textInverse = gray100;
155155
export const textOnColor = white;
156-
export const textOnColorDisabled = gray40;
157-
export const textDisabled = gray60;
156+
export const textOnColorDisabled = adjustAlpha(textOnColor, 0.25);
157+
export const textDisabled = adjustAlpha(textPrimary, 0.25);
158158

159159
// Link
160160
export const linkPrimary = blue40;
@@ -168,7 +168,7 @@ export const iconPrimary = gray10;
168168
export const iconSecondary = gray30;
169169
export const iconInverse = gray100;
170170
export const iconOnColor = white;
171-
export const iconOnColorDisabled = gray40;
171+
export const iconOnColorDisabled = adjustAlpha(iconOnColor, 0.25);
172172
export const iconDisabled = gray60;
173173

174174
// Support

packages/themes/src/next/white.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
white,
3939
whiteHover,
4040
} from '@carbon/colors';
41-
import { adjustLightness } from '../tools';
41+
import { adjustLightness, adjustAlpha } from '../tools';
4242

4343
// Background
4444
export const background = white;
@@ -136,18 +136,18 @@ export const borderInverse = gray100;
136136
export const borderInteractive = blue60;
137137

138138
// border
139-
export const borderDisabled = gray10;
139+
export const borderDisabled = gray30;
140140

141141
// Text
142142
export const textPrimary = gray100;
143143
export const textSecondary = gray70;
144-
export const textPlaceholder = gray40;
144+
export const textPlaceholder = adjustAlpha(textPrimary, 0.4);
145145
export const textHelper = gray60;
146146
export const textError = red60;
147147
export const textInverse = white;
148148
export const textOnColor = white;
149149
export const textOnColorDisabled = gray50;
150-
export const textDisabled = gray30;
150+
export const textDisabled = adjustAlpha(textPrimary, 0.25);
151151

152152
// Link
153153
export const linkPrimary = blue60;

packages/themes/src/tools.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,15 @@ export function adjustLightness(token, shift) {
2323
.hex()
2424
.toLowerCase();
2525
}
26+
27+
/**
28+
* Adjust a given token's alpha by a specified amount
29+
* Example: token = rgba(10, 10, 10, 1.0);
30+
* adjustAlpha(token, 0.3) === rgba(10, 10, 10, 0.3);
31+
* @param {string} token
32+
* @param {float} alpha
33+
* @returns {string}
34+
*/
35+
export function adjustAlpha(token, alpha) {
36+
return Color(token).rgb().alpha(alpha).string();
37+
}

0 commit comments

Comments
 (0)