Skip to content

Commit a4adf45

Browse files
committed
add documentation
1 parent af1460e commit a4adf45

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/plugins/global-settings/color-schemes/color-scheme-picker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ const ColorSchemePicker = props => {
225225
}
226226

227227
Object.entries( colors ).forEach( ( [ property, color ] ) => {
228+
// Don't add color if it is disabled
228229
if ( isDisabled( property ) ) {
229230
return
230231
}
@@ -316,6 +317,9 @@ const ColorSchemePicker = props => {
316317
}
317318

318319
const isDisabled = property => {
320+
// Color Palette Controls are disabled for:
321+
// 1. Background Color when it is a gradient and not in the normal state
322+
// 2. Heading Color, Text Color, Accent Color when it is in the hover state
319323
if ( property === 'backgroundColor' ) {
320324
if ( isGradient( itemInEdit?.colorScheme[ property ]?.desktop ) && currentHoverState !== 'normal' ) {
321325
return false
@@ -340,6 +344,7 @@ const ColorSchemePicker = props => {
340344
}
341345

342346
const getAllowedHover = property => {
347+
// Background Color cannot be edited in the hover state if it is a gradient
343348
if ( property === 'backgroundColor' && isGradient( itemInEdit?.colorScheme[ property ]?.desktop ) ) {
344349
return false
345350
}
@@ -348,6 +353,7 @@ const ColorSchemePicker = props => {
348353
}
349354

350355
const getToggleProps = settings => {
356+
// If the property is disabled, pass the disabled tooltip label as props to the Color Palette Control
351357
const disabled = isDisabled( settings.property )
352358
const gradient = isGradient( itemInEdit?.colorScheme[ settings.property ]?.desktop )
353359
if ( ! disabled || ! settings.disabledTooltip ) {

src/plugins/global-settings/color-schemes/editor-loader.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ const renderGlobalStyles = (
3232
}
3333
const colorSchemes = convertToObj( colorSchemesArray )
3434

35+
/**
36+
* The following order should be followed to ensure that blocks use the correct color scheme:
37+
* 1. Base color scheme
38+
* 2. Default Background color scheme
39+
* 3. Default Container color scheme
40+
* 4. Background color schemes (used by blocks that opt to use non-default background schemes)
41+
* 5. Container color schemes (used by blocks that opt to use non-default container schemes)
42+
*/
43+
3544
if ( baseColorScheme in colorSchemes && schemeHasValue( colorSchemes[ baseColorScheme ] ) ) {
3645
decls = getCSS( colorSchemes[ baseColorScheme ], currentHoverState )
3746
if ( decls.desktop.length || decls.desktopHover.length ) {

src/plugins/global-settings/color-schemes/utils.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import { applyFilters } from '@wordpress/hooks'
22

3+
/*
4+
* colorSchemes is originally an array of objects:
5+
* [ {
6+
* name: 'Default Scheme',
7+
* key: 'scheme-default-1',
8+
* colorScheme: Object
9+
* hideInPicker: false,
10+
* }, ... ]
11+
*
12+
* This returns an object with the color scheme key as the key
13+
* and the color scheme object as the value:
14+
*
15+
*/
316
export const convertToObj = colorSchemes => {
417
const obj = {}
518

@@ -10,6 +23,7 @@ export const convertToObj = colorSchemes => {
1023
return obj
1124
}
1225

26+
// Check if the color scheme contains a value for any of the states
1327
export const schemeHasValue = scheme => {
1428
const hasValue = Object.values( scheme ).some( states => {
1529
return Object.values( states ).some( value => value !== '' )
@@ -28,6 +42,7 @@ const camelToKebab = property => {
2842
const getInheritedValue = ( property, currentState, mode ) => {
2943
let value = property?.[ currentState ]
3044

45+
// The block should inherit the desktopParentHover value on hover state if it is a container scheme
3146
if ( ! value && currentState === 'desktopHover' && mode === 'container' ) {
3247
value = property?.desktopParentHover
3348
}
@@ -67,6 +82,7 @@ export const getCSS = ( scheme, currentHoverState = 'normal', mode = '' ) => {
6782
const customProperty = property === 'backgroundColor'
6883
? `--stk-${ varname }-background-color` : camelToKebab( property )
6984

85+
// Add background color only if it is a background or container scheme
7086
if ( property === 'backgroundColor' && ! mode ) {
7187
return
7288
}
@@ -89,12 +105,17 @@ export const getCSS = ( scheme, currentHoverState = 'normal', mode = '' ) => {
89105
decls.desktopHover.push( `${ customProperty }-current-hover: var(${ customProperty }${ currentHover });` )
90106
}
91107

108+
// If button background color is gradient, plain style buuttons should use the button outline color.
92109
if ( property === 'buttonBackgroundColor' && isGradient( scheme[ property ]?.[ state ] ) ) {
93110
decls[ state ].push( `:where(.is-style-plain){ --stk-button-plain-text-color${ suffix }: var(--stk-button-outline-color${ suffix }); }` )
94111
}
95112
} )
96113
} )
97114

115+
// if the button background color is gradient on normal or parent-hover states,
116+
// and there's no button background color set on hover,
117+
// plain-style buttons will turn black.
118+
// To prevent this, use button-outline-color-hover.
98119
if ( isGradient( scheme.buttonBackgroundColor?.desktop ) && ! scheme.buttonBackgroundColor?.desktopHover ) {
99120
decls.desktopHover.push( `:where(.is-style-plain){ --stk-button-plain-text-color-hover: var(--stk-button-outline-color-hover); }` )
100121
}
@@ -103,6 +124,9 @@ export const getCSS = ( scheme, currentHoverState = 'normal', mode = '' ) => {
103124
decls.desktopParentHover.push( `:where(.is-style-plain){ --stk-button-plain-text-color-hover: var(--stk-button-outline-color-hover); }` )
104125
}
105126

127+
// if the button background color is gradient on normal state and solid on parent-hover state,
128+
// we need to unset the --stk-button-plain-text-color,
129+
// so that plain-style buttons on parent-hover state will use the button background color.
106130
if ( isGradient( scheme.buttonBackgroundColor?.desktop ) &&
107131
scheme.buttonBackgroundColor?.desktopParentHover && ! isGradient( scheme.buttonBackgroundColor?.desktopParentHover ) ) {
108132
decls.desktopParentHover.push( `:where(.is-style-plain){ --stk-button-plain-text-color: unset;--stk-button-plain-text-color-hover:unset; }` )

0 commit comments

Comments
 (0)