@@ -23,13 +23,13 @@ let styleOptions = [
2323 label : __ ( 'Primary' , 'wp-bootstrap-blocks' ) ,
2424 value : 'primary' ,
2525 bgColor : bgColors . primary ,
26- color : colors . white
26+ textColor : colors . white ,
2727 } ,
2828 {
2929 label : __ ( 'Secondary' , 'wp-bootstrap-blocks' ) ,
3030 value : 'secondary' ,
3131 bgColor : bgColors . secondary ,
32- color : colors . white
32+ textColor : colors . white ,
3333 } ,
3434] ;
3535styleOptions = applyFilters (
@@ -38,7 +38,7 @@ styleOptions = applyFilters(
3838) ;
3939
4040const DEFAULT_BG_COLOR = bgColors . primary ;
41- const DEFAULT_COLOR = colors . white ;
41+ const DEFAULT_TEXT_COLOR = colors . white ;
4242const NEW_TAB_REL_DEFAULT_VALUE = 'noreferrer noopener' ;
4343
4444const BootstrapButtonEdit = ( {
@@ -66,22 +66,33 @@ const BootstrapButtonEdit = ( {
6666 } ) ;
6767 } ;
6868
69+ // Fill empty color values with default values and check for usage of deprecated color attribute in styleOptions
70+ const styleOptionsWithDefault = styleOptions . map ( ( styleOption ) => ( {
71+ ...styleOption ,
72+ textColor : styleOption . textColor || DEFAULT_TEXT_COLOR ,
73+ bgColor : styleOption . bgColor || styleOption . color || DEFAULT_BG_COLOR , // Fallback to deprecated color attribute
74+ } ) ) ;
75+
6976 // Prepare CSS rules for selected button style
7077 let inlineStyle = {
7178 backgroundColor :
72- styleOptions . length > 0 ? styleOptions [ 0 ] . bgColor : DEFAULT_BG_COLOR ,
73- color :
74- styleOptions . length > 0 ? styleOptions [ 0 ] . color : DEFAULT_COLOR ,
79+ styleOptionsWithDefault . length > 0
80+ ? styleOptionsWithDefault [ 0 ] . bgColor
81+ : DEFAULT_BG_COLOR ,
82+ color :
83+ styleOptionsWithDefault . length > 0
84+ ? styleOptionsWithDefault [ 0 ] . textColor
85+ : DEFAULT_TEXT_COLOR ,
7586 } ;
7687
7788 if ( style ) {
78- const selectedButtonColor = styleOptions . find (
89+ const selectedButtonColor = styleOptionsWithDefault . find (
7990 ( styleOption ) => styleOption . value === style
8091 ) ;
81- if ( selectedButtonColor ?. bgColor && selectedButtonColor ?. color ) {
92+ if ( selectedButtonColor ?. bgColor && selectedButtonColor ?. textColor ) {
8293 inlineStyle = {
8394 backgroundColor : selectedButtonColor . bgColor ,
84- color : selectedButtonColor . color
95+ color : selectedButtonColor . textColor ,
8596 } ;
8697 }
8798 }
0 commit comments