Skip to content

Commit 27caa97

Browse files
committed
fix accent scale
1 parent d4dbb6c commit 27caa97

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

packages/components/src/button/style.scss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,16 @@
4848

4949
&.is-primary {
5050
white-space: nowrap;
51-
background: $components-color-accent;
52-
color: $components-color-accent-inverted;
51+
background: var(--wp-theme-color-primary-bg-strong);
52+
color: var(--wp-theme-color-primary-text-inverse-strong);
5353
text-decoration: none;
5454
text-shadow: none;
5555

5656
// Show the boundary of the button, in High Contrast Mode.
5757
outline: 1px solid transparent;
5858

5959
&:hover:not(:disabled) {
60-
background: $components-color-accent-darker-10;
61-
color: $components-color-accent-inverted;
60+
background: var(--wp-theme-color-primary-bg-strong-hover);
6261
}
6362

6463
&:active:not(:disabled) {

packages/theme/color.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const COLOR_MAP = {
4545
default: 6,
4646
hover: 7,
4747
},
48+
muted: 4,
4849
hover: 6,
4950
},
5051
};
@@ -83,13 +84,33 @@ const generateNeutralColors = ( {
8384

8485
const generatePrimaryColors = ( {
8586
color = PRIMARY_DEFAULT,
87+
bg,
8688
isDark = false,
8789
} ) => {
8890
const base = colord( color ).toHsl();
8991
const lightValues = isDark ? DARK_VALUES : LIGHT_VALUES;
9092

91-
const colors = lightValues.map( ( value ) =>
92-
colord( { ...base, l: value } ).toHex()
93+
// if the color given has enough contrast agains the background, use that as the solid background colour and adjust the surrounding scale to proportionally move with it
94+
const length = lightValues.length;
95+
// Calculate the difference between the new value and the old value
96+
const diff = base.l - lightValues[ 8 ];
97+
// Calculate the weight for adjusting values. Closer to base colour should adjust more.
98+
const weight = ( index ) => 1 - Math.abs( 8 - index ) / ( length - 1 );
99+
// Adjust all values in the array based on their weight
100+
let adjustedArray = [ ...lightValues ];
101+
if ( colord( bg ).isReadable( base ) ) {
102+
adjustedArray = lightValues.map( ( value, index ) => {
103+
const adjustment = diff * weight( index );
104+
return index === 8 ? base.l : value + adjustment;
105+
} );
106+
}
107+
108+
// convert colours to hex and set min and max lightness values
109+
const colors = adjustedArray.map( ( value ) =>
110+
colord( {
111+
...base,
112+
l: Math.min( Math.max( parseInt( value ), 0 ), 100 ),
113+
} ).toHex()
93114
);
94115

95116
return mapColors( colors, COLOR_MAP );

packages/theme/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@wordpress/theme",
33
"version": "1.0.0",
4-
"description": "A collection of takens that make up a WordPress theme.",
4+
"description": "A collection of tokens that make up a WordPress theme.",
55
"author": "The WordPress Contributors",
66
"license": "GPL-2.0-or-later",
77
"keywords": [

packages/theme/theme.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import { generateColors } from './color';
55

66
// // theme object
77
export const defaultTheme = {
8-
//shadows: {...},
8+
// shadows: {...},
9+
// spacing: { ... },
10+
// borderRadius: { ... },
11+
// fonts: { ... },
12+
// fontSizes: { ... },
13+
// fontWeights: { ... },
14+
// lineHeights: { ... },
915
colors: generateColors( {} ),
1016
};

0 commit comments

Comments
 (0)