Skip to content

Commit 60f859f

Browse files
authored
Merge pull request #118 from isaumya/improvement/better-property-names
Improvement to the property name and how the button styles are generated
2 parents 1846253 + 08041da commit 60f859f

6 files changed

Lines changed: 23 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ Modify available button styles.
562562

563563
```javascript
564564
function myButtonStyleOptions( styleOptions ) {
565-
styleOptions.push( { label: 'My Option', value: 'my-option', color: '#FF0000' } );
565+
styleOptions.push( { label: 'My Option', value: 'my-option', bgColor: '#FF0000', color: '#FFFFFF } );
566566
return styleOptions;
567567
}
568568
wp.hooks.addFilter(

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-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '9b6fd2a0b07ab4882cb6');
1+
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '50cb7b11519b5b7cfb75');

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.

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
}

src/column/edit.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
verticalAlignCenter,
2424
verticalAlignTop,
2525
} from '../icons';
26-
import { colors } from '../constants';
26+
import { bgColors } from '../constants';
2727

2828
const contentVerticalAlignmentControls = [
2929
{
@@ -67,8 +67,8 @@ const ColumnSizeRangeControl = ( {
6767
};
6868

6969
export let bgColorOptions = [
70-
{ name: 'primary', color: colors.primary },
71-
{ name: 'secondary', color: colors.secondary },
70+
{ name: 'primary', color: bgColors.primary },
71+
{ name: 'secondary', color: bgColors.secondary },
7272
];
7373

7474
bgColorOptions = applyFilters(

src/constants.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export const colors = {
1+
export const bgColors = {
22
primary: '#007bff',
33
secondary: '#6c757d',
44
};
5+
6+
export const colors = {
7+
white: '#ffffff'
8+
};

0 commit comments

Comments
 (0)