Skip to content

Commit

Permalink
PLANET-4924 Re-enable the native buttons block
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarsdeshmukh committed Apr 20, 2020
1 parent 15f7b66 commit 476dcfa
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 35 deletions.
3 changes: 1 addition & 2 deletions admin/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ wp.domReady(() => {
name: 'donate',
label: 'Donate'
});
wp.blocks.unregisterBlockStyle('core/button', 'default');
wp.blocks.unregisterBlockStyle('core/button', 'outline');
wp.blocks.unregisterBlockStyle('core/button', 'squared');
wp.blocks.unregisterBlockStyle('core/button', 'fill');
});
23 changes: 22 additions & 1 deletion assets/src/BlockFilters.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { addFilter } = wp.hooks;

import P4ButtonEdit from './components/p4_button/edit';

export const addBlockFilters = () => {
addFileBlockFilter();
addButtonBlockFilter();
};


const addFileBlockFilter = () => {
const setDownloadButtonToggleDefualtFalse = (settings, name) => {

Expand All @@ -20,3 +21,23 @@ const addFileBlockFilter = () => {

addFilter('blocks.registerBlockType', 'planet4-blocks/filters/file', setDownloadButtonToggleDefualtFalse);
};

const addButtonBlockFilter = () => {

const updateButtonBlockEditMethod = (settings, name) => {

if ('core/button' !== name) {
return settings;
}

if ( settings.name = 'core/button' ) {
lodash.assign( settings, {
edit: P4ButtonEdit,
} );
}

return settings;
};

addFilter('blocks.registerBlockType', 'planet4-blocks/filters/button', updateButtonBlockEditMethod);
};
51 changes: 21 additions & 30 deletions assets/src/components/p4_button/edit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* This file is copy of core button block edit.js (https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/button/edit.js), with customize changes.
* Customize changes(PLANET-4924) :
* - Added `p4_button_text_colors` and `p4_button_bg_colors` custom P4 button colors.
* - Remove the BorderPanel control(button borderRadius).
*/

/**
* External dependencies
*/
Expand Down Expand Up @@ -35,6 +42,17 @@ import { link } from '@wordpress/icons';

const { getComputedStyle } = window;

const p4_button_text_colors = [
{ name: 'dark-shade-black', color: '#1a1a1a' },
{ name: 'white', color: '#ffffff' },
];

const p4_button_bg_colors = [
{ name: 'orange', color: '#f36d3a' },
{ name: 'aquamarine', color: '#68dfde' },
{ name: 'white', color: '#ffffff' },
];

const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { textColor, backgroundColor } = ownProps;
const backgroundColorValue = backgroundColor && backgroundColor.color;
Expand All @@ -57,31 +75,6 @@ const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
} );

const NEW_TAB_REL = 'noreferrer noopener';
const MIN_BORDER_RADIUS_VALUE = 0;
const MAX_BORDER_RADIUS_VALUE = 50;
const INITIAL_BORDER_RADIUS_POSITION = 5;

function BorderPanel( { borderRadius = '', setAttributes } ) {
const setBorderRadius = useCallback(
( newBorderRadius ) => {
setAttributes( { borderRadius: newBorderRadius } );
},
[ setAttributes ]
);
return (
<PanelBody title={ __( 'Border settings' ) }>
<RangeControl
value={ borderRadius }
label={ __( 'Border radius' ) }
min={ MIN_BORDER_RADIUS_VALUE }
max={ MAX_BORDER_RADIUS_VALUE }
initialPosition={ INITIAL_BORDER_RADIUS_POSITION }
allowReset
onChange={ setBorderRadius }
/>
</PanelBody>
);
}

function URLPicker( {
isSelected,
Expand Down Expand Up @@ -121,7 +114,7 @@ function URLPicker( {
<ToolbarGroup>
<ToolbarButton
name="link"
icon={ link }
icon="admin-links"
title={ __( 'Link' ) }
shortcut={ displayShortcut.primary( 'k' ) }
onClick={ openLinkControl }
Expand Down Expand Up @@ -230,11 +223,13 @@ function ButtonEdit( {
title={ __( 'Background & Text Color' ) }
settings={ [
{
colors: p4_button_text_colors,
colorValue: textColor.color,
onColorChange: setTextColor,
label: __( 'Text color' ),
},
{
colors: p4_button_bg_colors,
colorValue: backgroundColor.color,
onColorChange: setBackgroundColor,
gradientValue,
Expand All @@ -255,10 +250,6 @@ function ButtonEdit( {
} }
/>
</PanelColorGradientSettings>
<BorderPanel
borderRadius={ borderRadius }
setAttributes={ setAttributes }
/>
<PanelBody title={ __( 'Link settings' ) }>
<ToggleControl
label={ __( 'Open in new tab' ) }
Expand Down
Loading

0 comments on commit 476dcfa

Please sign in to comment.