Skip to content

Commit 335419b

Browse files
committed
Import both bgColors and colors from the constant file and add option to have both bgColor and color set by the user for each buttons style options.
1 parent a5edbec commit 335419b

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/button/edit.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,29 @@ import {
1616
BlockControls,
1717
AlignmentToolbar,
1818
} from '@wordpress/block-editor';
19-
import { colors } from '../constants';
19+
import { bgColors, colors } from '../constants';
2020

2121
let styleOptions = [
2222
{
2323
label: __( 'Primary', 'wp-bootstrap-blocks' ),
2424
value: 'primary',
25-
color: colors.primary,
25+
bgColor: bgColors.primary,
26+
color: colors.white
2627
},
2728
{
2829
label: __( 'Secondary', 'wp-bootstrap-blocks' ),
2930
value: 'secondary',
30-
color: colors.secondary,
31+
bgColor: bgColors.secondary,
32+
color: colors.white
3133
},
3234
];
3335
styleOptions = applyFilters(
3436
'wpBootstrapBlocks.button.styleOptions',
3537
styleOptions
3638
);
3739

38-
const DEFAULT_COLOR = colors.primary;
40+
const DEFAULT_BG_COLOR = bgColors.primary;
41+
const DEFAULT_COLOR = colors.white;
3942
const NEW_TAB_REL_DEFAULT_VALUE = 'noreferrer noopener';
4043

4144
const BootstrapButtonEdit = ( {
@@ -66,16 +69,19 @@ const BootstrapButtonEdit = ( {
6669
// Prepare CSS rules for selected button style
6770
let inlineStyle = {
6871
backgroundColor:
72+
styleOptions.length > 0 ? styleOptions[ 0 ].bgColor : DEFAULT_BG_COLOR,
73+
color:
6974
styleOptions.length > 0 ? styleOptions[ 0 ].color : DEFAULT_COLOR,
7075
};
7176

7277
if ( style ) {
7378
const selectedButtonColor = styleOptions.find(
7479
( styleOption ) => styleOption.value === style
7580
);
76-
if ( selectedButtonColor?.color ) {
81+
if ( selectedButtonColor?.bgColor && selectedButtonColor?.color ) {
7782
inlineStyle = {
78-
backgroundColor: selectedButtonColor.color,
83+
backgroundColor: selectedButtonColor.bgColor,
84+
color: selectedButtonColor.color
7985
};
8086
}
8187
}

0 commit comments

Comments
 (0)