Skip to content

Commit 78c0478

Browse files
committed
apply default color if color is not set in styleOptions
1 parent 6172e8e commit 78c0478

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '7cf780b987df063ad572');
1+
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '6010ac73ad30738b341d');

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e-test-plugins/button-filters/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/* eslint-disable wrap-iife */
22
( function () {
33
function buttonFiltersStyleOptions( styleOptions ) {
4-
return [ ...styleOptions, { label: 'Brand', value: 'brand' } ];
4+
return [
5+
...styleOptions,
6+
{ label: 'Brand', value: 'brand', color: '#FF0000' },
7+
];
58
}
69
wp.hooks.addFilter(
710
'wpBootstrapBlocks.button.styleOptions',

src/button/edit.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ styleOptions = applyFilters(
3939
styleOptions
4040
);
4141

42+
const DEFAULT_COLOR = colors.primary;
4243
const NEW_TAB_REL_DEFAULT_VALUE = 'noreferrer noopener';
4344

4445
class BootstrapButtonEdit extends Component {
@@ -66,14 +67,16 @@ class BootstrapButtonEdit extends Component {
6667
// Prepare CSS rules for selected button style
6768
let inlineStyle = {
6869
backgroundColor:
69-
styleOptions.length > 0 ? styleOptions[ 0 ].color : '',
70+
styleOptions.length > 0
71+
? styleOptions[ 0 ].color
72+
: DEFAULT_COLOR,
7073
};
7174

7275
if ( style ) {
7376
const selectedButtonColor = styleOptions.find(
7477
( styleOption ) => styleOption.value === style
7578
);
76-
if ( selectedButtonColor ) {
79+
if ( selectedButtonColor?.color ) {
7780
inlineStyle = {
7881
backgroundColor: selectedButtonColor.color,
7982
};

0 commit comments

Comments
 (0)