Skip to content

Commit 604c956

Browse files
committed
minor fixes
translatable text, use lodash's kebabCase, add prefix, use array_column, rename namespace
1 parent 7a989ed commit 604c956

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

src/block-components/block-div/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const BlockDiv = memo( props => {
5757
{
5858
[ uniqueBlockClass ]: withUniqueClass,
5959
'stk-block-background': attributes.hasBackground,
60-
[ `background-${ attributes.backgroundColorScheme }` ]: attributes.hasBackground && attributes.backgroundColorScheme,
60+
[ `stk--background-scheme--${ attributes.backgroundColorScheme }` ]: attributes.hasBackground && attributes.backgroundColorScheme,
6161
// When the block has auto margins, we need to "add" those margins to
6262
// the main block div so we can simulate the effect inside the editor.
6363
// This works in conjunction with the styles in
@@ -133,7 +133,7 @@ BlockDiv.Content = props => {
133133
uniqueBlockClass,
134134
{
135135
'stk-block-background': attributes.hasBackground,
136-
[ `background-${ attributes.backgroundColorScheme }` ]: attributes.hasBackground && attributes.backgroundColorScheme,
136+
[ `stk--background-scheme--${ attributes.backgroundColorScheme }` ]: attributes.hasBackground && attributes.backgroundColorScheme,
137137
// When the block has auto top/bottom margins, we need to force the
138138
// parent container to be 100% height or else the auto won't have any
139139
// effect in the frontend. This is okay in the editor-side.

src/block-components/container-div/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const ContainerDiv = props => {
3939
'stk-hover-parent': attributes.hasContainer && attributes.triggerHoverState, // This is needed to trigger parent-hover hover styles.
4040
'stk--no-background': ! attributes.hasContainer,
4141
'stk--no-padding': ! attributes.hasContainer,
42-
[ `container-${ attributes.containerColorScheme }` ]: attributes.hasContainer && attributes.containerColorScheme,
42+
[ `stk--container-scheme--${ attributes.containerColorScheme }` ]: attributes.hasContainer && attributes.containerColorScheme,
4343
} )
4444

4545
return <Div
@@ -73,7 +73,7 @@ ContainerDiv.Content = props => {
7373
'stk-hover-parent': attributes.hasContainer && attributes.triggerHoverState, // This is needed to trigger parent-hover hover styles.
7474
'stk--no-background': ! attributes.hasContainer,
7575
'stk--no-padding': ! attributes.hasContainer,
76-
[ `container-${ attributes.containerColorScheme }` ]: attributes.hasContainer && attributes.containerColorScheme,
76+
[ `stk--container-scheme--${ attributes.containerColorScheme }` ]: attributes.hasContainer && attributes.containerColorScheme,
7777
} )
7878

7979
return <Div.Content

src/hooks/use-block-color-schemes.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import { i18n } from 'stackable'
2+
import { kebabCase } from 'lodash'
3+
14
import { useSelect } from '@wordpress/data'
25
import { applyFilters } from '@wordpress/hooks'
6+
import { __ } from '@wordpress/i18n'
37

48
export const useBlockColorSchemes = () => {
59
const {
@@ -21,7 +25,7 @@ export const useBlockColorSchemes = () => {
2125

2226
const allColorSchemes = applyFilters( 'stackable.global-settings.global-color-schemes.custom-color-schemes', colorSchemes, true )
2327
const COLOR_SCHEME_OPTIONS = [ {
24-
label: 'Scheme unavailable', // This will be displayed when a custom color scheme is deleted or when a license gets deactivated
28+
label: __( 'Scheme unavailable', i18n ), // This will be displayed when a custom color scheme is deleted or when a license gets deactivated
2529
value: 'scheme-unavailable',
2630
hidden: true,
2731
disabled: true,
@@ -47,8 +51,8 @@ export const useBlockColorSchemes = () => {
4751
// Converts property name to kebab-cased string with scheme key as prefix
4852
// (e.g., backgroundColor --> --stk-scheme-default-1-background-color)
4953
const toKebab = ( property, slug ) => {
50-
const result = property.replace( /([a-z0-9])([A-Z])/g, '$1-$2' )
51-
return '--stk-' + slug + '-' + result.toLowerCase()
54+
const result = kebabCase( property )
55+
return '--stk-' + slug + '-' + result
5256
}
5357

5458
// get color groups for color palette picker.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ const renderGlobalStyles = (
7979

8080
decls = getCSS( scheme, currentHoverState, 'background' )
8181
if ( decls.desktop.length || decls.desktopHover.length ) {
82-
rules.background.push( `.background-${ key }{ ${ [ ...decls.desktop, ...decls.desktopHover ].join( '' ) } }` )
82+
rules.background.push( `.stk--background-scheme--${ key }{ ${ [ ...decls.desktop, ...decls.desktopHover ].join( '' ) } }` )
8383
}
8484
if ( decls.desktopParentHover.length ) {
85-
rules.background.push( `:where(.stk-hover-parent:hover) .background-${ key }{ ${ decls.desktopParentHover.join( '' ) } }` )
85+
rules.background.push( `:where(.stk-hover-parent:hover) .stk--background-scheme--${ key }{ ${ decls.desktopParentHover.join( '' ) } }` )
8686
}
8787

8888
decls = getCSS( scheme, currentHoverState, 'container' )
8989
if ( decls.desktop.length || decls.desktopHover.length ) {
90-
rules.container.push( `.container-${ key }{ ${ [ ...decls.desktop, ...decls.desktopHover ].join( '' ) } }` )
90+
rules.container.push( `.stk--container-scheme--${ key }{ ${ [ ...decls.desktop, ...decls.desktopHover ].join( '' ) } }` )
9191
}
9292
if ( decls.desktopParentHover.length ) {
93-
rules.container.push( `.container-${ key }:where(:hover), :where(.stk-hover-parent:hover) .container-${ key }{ ${ decls.desktopParentHover.join( '' ) } }` )
93+
rules.container.push( `.stk--container-scheme--${ key }:where(:hover), :where(.stk-hover-parent:hover) .stk--container-scheme--${ key }{ ${ decls.desktopParentHover.join( '' ) } }` )
9494
}
9595
} )
9696

src/plugins/global-settings/color-schemes/index.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ public function register_color_schemes() {
122122
);
123123
}
124124

125-
public function sanitize_array_setting( $input ) {
125+
// Make this function static so it can be used when
126+
// registering the custom color schemes in premium
127+
public static function sanitize_array_setting( $input ) {
126128
return ! is_array( $input ) ? array( array() ) : $input;
127129
}
128130

@@ -179,7 +181,7 @@ public function add_global_color_schemes_styles( $current_css ) {
179181
$schemes_array = is_array( get_option( 'stackable_global_color_schemes' ) ) ? get_option( 'stackable_global_color_schemes' ) : [];
180182

181183
// Get all color schemes, including custom color schemes if any
182-
$all_color_schemes = apply_filters( 'stackable_global_color_schemes.get_color_schemes', $schemes_array );
184+
$all_color_schemes = apply_filters( 'stackable_global_color_schemes/get_color_schemes', $schemes_array );
183185

184186
if ( ! is_array( $all_color_schemes ) ) {
185187
return $current_css;
@@ -231,16 +233,16 @@ public function add_global_color_schemes_styles( $current_css ) {
231233
'key' => $key,
232234
'mode' => 'background',
233235
'selectors' => array(
234-
'desktop' => ".background-$key",
235-
'desktopParentHover' => ":where(.stk-hover-parent:hover) .background-$key"
236+
'desktop' => ".stk--background-scheme--$key",
237+
'desktopParentHover' => ":where(.stk-hover-parent:hover) .stk--background-scheme--$key"
236238
)
237239
);
238240
$block_color_schemes['container'][] = array(
239241
'key' => $key,
240242
'mode' => 'container',
241243
'selectors' => array(
242-
'desktop' => ".container-$key",
243-
'desktopParentHover' => array(".container-$key:where(:hover)",":where(.stk-hover-parent:hover) .container-$key")
244+
'desktop' => ".stk--container-scheme--$key",
245+
'desktopParentHover' => array(".stk--container-scheme--$key:where(:hover)",":where(.stk-hover-parent:hover) .stk--container-scheme--$key")
244246
)
245247
);
246248
}
@@ -281,13 +283,7 @@ public function add_global_color_schemes_styles( $current_css ) {
281283
* @return Array
282284
*/
283285
public function convert_to_assoc_array( $schemes_array ) {
284-
$schemes = array();
285-
286-
foreach( $schemes_array as $scheme ) {
287-
$schemes[ $scheme['key'] ] = $scheme[ 'colorScheme' ];
288-
}
289-
290-
return $schemes;
286+
return array_column( $schemes_array, 'colorScheme', 'key' );
291287
}
292288

293289
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { kebabCase } from 'lodash'
2+
13
import { applyFilters } from '@wordpress/hooks'
24

35
/*
@@ -33,10 +35,10 @@ export const schemeHasValue = scheme => {
3335
}
3436

3537
const camelToKebab = property => {
36-
const result = property.replace( /([a-z0-9])([A-Z])/g, '$1-$2' )
38+
const result = kebabCase( property )
3739

3840
// Convert the result to lowercase and return with '--stk-' prefix
39-
return '--stk-' + result.toLowerCase()
41+
return '--stk-' + result
4042
}
4143

4244
const getInheritedValue = ( property, currentState, mode ) => {

0 commit comments

Comments
 (0)