11import { 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+ */
316export 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
1327export 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 => {
2842const 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