Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components: Update default accent color #50193

Merged
merged 15 commits into from
May 5, 2023
Merged
8 changes: 6 additions & 2 deletions bin/packages/build-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ async function buildCSS( file ) {
'animations',
'z-index',
]
// Editor styles should be excluded from the default CSS vars output.
// Editor and component styles should be excluded from the default CSS vars output.
.concat(
file.includes( 'common.scss' ) || ! file.includes( 'block-library' )
file.includes( 'common.scss' ) ||
! (
file.includes( 'block-library' ) ||
file.includes( 'components' )
)
Comment on lines +106 to +112
Copy link
Member Author

@mirka mirka May 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part in the build process where all the --wp-admin-theme-color* variables are prepended to the main stylesheet of each package.

By excluding the components package from this step, the built stylesheet of wp-components will no longer include the default admin scheme vars.

Instead, we will manually include the admin scheme variables for the Blueberry color.

Eventually, we should stop providing --wp-admin-theme-* variables in the wp-components package.

? [ 'default-custom-properties' ]
: []
)
Expand Down
3 changes: 3 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Enhancements

- Change the default color scheme to use the new WP Blueberry color. See PR description for instructions on how to restore the previous color scheme when using in a non-WordPress context ([#50193](https://github.com/WordPress/gutenberg/pull/50193)).
- `CheckboxControl`, `CustomGradientPicker`, `FormToggle`, : Refactor and correct the focus style for consistency ([#50127](https://github.com/WordPress/gutenberg/pull/50127)).

### Internal
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/button/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@
padding: $grid-unit-15 * 0.5; // This reduces the horizontal padding on tertiary/text buttons, so as to space them optically.

&:hover:not(:disabled) {
// TODO: Prepare for theming (https://github.com/WordPress/gutenberg/pull/45466/files#r1030872724)
background: rgba(var(--wp-admin-theme-color--rgb), 0.04);
}

&:active:not(:disabled) {
// TODO: Prepare for theming (https://github.com/WordPress/gutenberg/pull/45466/files#r1030872724)
Comment on lines +166 to +171
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These styles were added after our initial theming effort. Adding a TODO comment now.

background: rgba(var(--wp-admin-theme-color--rgb), 0.08);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Include the default WP Components color variables.
// TODO: Remove this once all admin-scheme variables are accounted for in the wp-components fallback values.
:root {
@include admin-scheme(#3858e9);
}

// Variables
@import "./utils/theme-variables.scss";

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/theme/color-algorithms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function checkContrasts(
outputs: ThemeOutputValues[ 'colors' ]
) {
const background = inputs.background || COLORS.white;
const accent = inputs.accent || '#007cba';
const accent = inputs.accent || '#3858e9';
const foreground = outputs.foreground || COLORS.gray[ 900 ];
const gray = outputs.gray || COLORS.gray;

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/theme/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const ColorScheme: ComponentStory< typeof Theme > = ( {
);
};
ColorScheme.args = {
accent: '#007cba',
accent: '#3858e9',
background: '#fff',
};
ColorScheme.argTypes = {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/theme/test/color-algorithms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ describe( 'Theme color algorithms', () => {
'wp.components.Theme: The background color ("#000") does not have sufficient contrast against the accent color ("#111").'
);

generateThemeVariables( { background: '#eee' } );
generateThemeVariables( { background: '#1a1a1a' } );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this to a color that does trigger a contrast error with the new accent color.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand on this? We still want to use the existing grayscale for components:

// WordPress grays.
$black: #000;			// Use only when you truly need pure black. For UI, use $gray-900.
$gray-900: #1e1e1e;
$gray-800: #2f2f2f;
$gray-700: #757575;		// Meets 4.6:1 text contrast against white.
$gray-600: #949494;		// Meets 3:1 UI or large text contrast against white.
$gray-400: #ccc;
$gray-300: #ddd;		// Used for most borders.
$gray-200: #e0e0e0;		// Used sparingly for light borders.
$gray-100: #f0f0f0;		// Used for light gray backgrounds.
$white: #fff;

While we can update them, we should be careful in doing so as it affects so much componentry. So I would do that separately from this PR.

Which warning does it trigger? And it's good that it does, it's another reason to merge this soon so we can address those.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no worries, this is just a unit test that verifies that our contrast-checking algorithm is working as expected 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sounds great. Thanks again!

expect( console ).toHaveWarnedWith(
'wp.components.Theme: The background color ("#eee") does not have sufficient contrast against the accent color ("#007cba").'
'wp.components.Theme: The background color ("#1a1a1a") does not have sufficient contrast against the accent color ("#3858e9").'
);
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
}

.emotion-8:focus-within {
border-color: var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #006ba1));
box-shadow: 0 0 0 0.5px var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
border-color: var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #2145e6));
box-shadow: 0 0 0 0.5px var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9));
outline: none;
z-index: 1;
}
Expand Down Expand Up @@ -400,8 +400,8 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
}

.emotion-8:focus-within {
border-color: var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #006ba1));
box-shadow: 0 0 0 0.5px var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
border-color: var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #2145e6));
box-shadow: 0 0 0 0.5px var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9));
outline: none;
z-index: 1;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/utils/colors-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ const ALERT = {
green: '#4ab866',
};

// Matches @wordpress/base-styles
// Matches the Modern admin scheme in @wordpress/base-styles
const ADMIN = {
theme: 'var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba))',
theme: 'var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9))',
themeDark10:
'var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #006ba1))',
'var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #2145e6))',
mirka marked this conversation as resolved.
Show resolved Hide resolved
};

const UI = {
Expand Down
8 changes: 4 additions & 4 deletions packages/components/src/utils/theme-variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//
// If the `--wp-components-color-accent` variable is not defined, fallback to
// `--wp-admin-theme-color`. If the `--wp-admin-theme-color` variable is not
// defined, fallback to the default theme color (WP blue).
$components-color-accent: var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
$components-color-accent-darker-10: var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #006ba1));
$components-color-accent-darker-20: var(--wp-components-color-accent-darker-20, var(--wp-admin-theme-color-darker-20, #005a87));
// defined, fallback to the default theme color (WP blueberry).
$components-color-accent: var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9));
$components-color-accent-darker-10: var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #2145e6));
$components-color-accent-darker-20: var(--wp-components-color-accent-darker-20, var(--wp-admin-theme-color-darker-20, #183ad6));
mirka marked this conversation as resolved.
Show resolved Hide resolved

// Used when placing text on the accent color.
$components-color-accent-inverted: var(--wp-components-color-accent-inverted, $white);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,13 @@ exports[`EditPostPreferencesModal should match snapshot when the modal is active
}

.emotion-13:hover {
color: var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
color: var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9));
}

.emotion-13:focus {
background-color: transparent;
color: var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
border-color: var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
color: var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9));
border-color: var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9));
outline: 3px solid transparent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ exports[`PostPublishPanel should render the spinner if the post is being saved 1
display: inline-block;
margin: 5px 11px 0;
position: relative;
color: var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
color: var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9));
overflow: visible;
opacity: 1;
background-color: transparent;
Expand Down
4 changes: 2 additions & 2 deletions storybook/decorators/with-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const themes = {
accent: '#3858e9',
background: '#f0f0f0',
},
modern: {
accent: '#3858e9',
classic: {
accent: '#007cba',
},
};

Expand Down
3 changes: 1 addition & 2 deletions storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { WithMarginChecker } from './decorators/with-margin-checker';
import { WithMaxWidthWrapper } from './decorators/with-max-width-wrapper';
import { WithRTL } from './decorators/with-rtl';
import { WithTheme } from './decorators/with-theme';
import './style.scss';

export const globalTypes = {
direction: {
Expand All @@ -31,7 +30,7 @@ export const globalTypes = {
{ value: 'default', title: 'Default' },
{ value: 'darkBg', title: 'Dark (background)' },
{ value: 'lightGrayBg', title: 'Light gray (background)' },
{ value: 'modern', title: 'Modern (accent)' },
{ value: 'classic', title: 'Classic (accent)' },
],
},
},
Expand Down
11 changes: 0 additions & 11 deletions storybook/style.scss

This file was deleted.