Skip to content

Commit

Permalink
fix #796
Browse files Browse the repository at this point in the history
  • Loading branch information
inc2734 committed Jul 3, 2024
1 parent f104065 commit 5a3d5f9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 58 deletions.
8 changes: 3 additions & 5 deletions src/blocks/box/block.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"version": "21.0.0",
"textdomain": "snow-monkey-blocks",
"name": "snow-monkey-blocks/box",
"title": "Box",
Expand Down Expand Up @@ -33,10 +34,6 @@
"type": "number",
"default": 1
},
"contentPadding": {
"type": "string",
"default": ""
},
"boxShadow": {
"type": "object",
"default": {
Expand All @@ -57,7 +54,8 @@
"supports": {
"html": false,
"spacing": {
"margin": true
"margin": true,
"padding": true
},
"layout": {
"allowSwitching": false,
Expand Down
16 changes: 16 additions & 0 deletions src/blocks/box/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default [
borderRadius: {
type: 'number',
},
contentPadding: {
type: 'string',
default: '',
},
},

supports: {
Expand Down Expand Up @@ -92,6 +96,10 @@ export default [
borderWidth: {
type: 'number',
},
contentPadding: {
type: 'string',
default: '',
},
},

supports: {
Expand Down Expand Up @@ -168,6 +176,10 @@ export default [
borderWidth: {
type: 'number',
},
contentPadding: {
type: 'string',
default: '',
},
},

save( { attributes, className } ) {
Expand Down Expand Up @@ -201,6 +213,10 @@ export default [
borderWidth: {
type: 'number',
},
contentPadding: {
type: 'string',
default: '',
},
},

save( { attributes } ) {
Expand Down
50 changes: 2 additions & 48 deletions src/blocks/box/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {

import {
RangeControl,
SelectControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
__experimentalBorderBoxControl as BorderBoxControl,
Expand All @@ -29,7 +28,7 @@ import { toNumber } from '@smb/helper';

import metadata from './block.json';

export default function ( { attributes, setAttributes, className, clientId } ) {
export default function ( { attributes, setAttributes, clientId } ) {
const {
backgroundColor,
backgroundGradientColor,
Expand All @@ -39,7 +38,6 @@ export default function ( { attributes, setAttributes, className, clientId } ) {
borderWidth,
borderRadius,
opacity,
contentPadding,
boxShadow,
templateLock,
} = attributes;
Expand Down Expand Up @@ -74,9 +72,7 @@ export default function ( { attributes, setAttributes, className, clientId } ) {
: borderWidth,
};

const classes = classnames( 'smb-box', className, {
[ `smb-box--p-${ contentPadding }` ]: !! contentPadding,
} );
const classes = classnames( 'smb-box' );

const blockProps = useBlockProps( {
className: classes,
Expand Down Expand Up @@ -315,48 +311,6 @@ export default function ( { attributes, setAttributes, className, clientId } ) {
/>
</InspectorControls>

<InspectorControls group="dimensions">
<ToolsPanelItem
hasValue={ () =>
contentPadding !==
metadata.attributes.contentPadding.default
}
isShownByDefault
label={ __( 'Padding', 'snow-monkey-blocks' ) }
onDeselect={ () =>
setAttributes( {
contentPadding:
metadata.attributes.contentPadding.default,
} )
}
panelId={ clientId }
>
<SelectControl
label={ __( 'Padding', 'snow-monkey-blocks' ) }
value={ contentPadding }
options={ [
{
value: 's',
label: __( 'S', 'snow-monkey-blocks' ),
},
{
value: '',
label: __( 'M', 'snow-monkey-blocks' ),
},
{
value: 'l',
label: __( 'L', 'snow-monkey-blocks' ),
},
] }
onChange={ ( value ) =>
setAttributes( {
contentPadding: value,
} )
}
/>
</ToolsPanelItem>
</InspectorControls>

<div { ...blockProps }>
<div className="smb-box__background" />

Expand Down
7 changes: 2 additions & 5 deletions src/blocks/box/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import hexToRgba from 'hex-to-rgba';

import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';

export default function ( { attributes, className } ) {
export default function ( { attributes } ) {
const {
backgroundColor,
backgroundGradientColor,
Expand All @@ -13,7 +13,6 @@ export default function ( { attributes, className } ) {
borderWidth,
borderRadius,
opacity,
contentPadding,
boxShadow,
} = attributes;

Expand All @@ -40,9 +39,7 @@ export default function ( { attributes, className } ) {
: borderWidth,
};

const classes = classnames( 'smb-box', className, {
[ `smb-box--p-${ contentPadding }` ]: !! contentPadding,
} );
const classes = classnames( 'smb-box' );

return (
<div
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/box/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
padding: var(--smb-box--padding);
overflow: visible;

// @deprecated
&--p-s {
--smb-box--padding: var(--_padding-1);
}

// @deprecated
&--p-l {
--smb-box--padding: var(--_padding2);
}
Expand Down

0 comments on commit 5a3d5f9

Please sign in to comment.