Skip to content

Commit

Permalink
fix #785
Browse files Browse the repository at this point in the history
  • Loading branch information
inc2734 committed Jul 7, 2024
1 parent 755dba3 commit 096e981
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/blocks/testimonial/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"type": "number",
"default": 2
},
"gap": {
"type": "string",
"default": ""
},
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ]
Expand Down
81 changes: 79 additions & 2 deletions src/blocks/testimonial/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@wordpress/block-editor';

import {
BaseControl,
RangeControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
Expand All @@ -33,7 +34,7 @@ export default function ( { attributes, setAttributes, className, clientId } ) {
},
] );

const { md, lg, templateLock } = attributes;
const { md, lg, gap, templateLock } = attributes;

const hasInnerBlocks = useSelect(
( select ) =>
Expand All @@ -43,7 +44,9 @@ export default function ( { attributes, setAttributes, className, clientId } ) {
);

const classes = classnames( 'smb-testimonial', className );
const rowClasses = classnames( 'c-row', 'c-row--margin' );
const rowClasses = classnames( 'c-row', 'c-row--margin', {
[ `c-row--margin-${ gap }` ]: !! gap,
} );

const blockProps = useBlockProps( {
className: classes,
Expand All @@ -64,6 +67,21 @@ export default function ( { attributes, setAttributes, className, clientId } ) {
}
);

const gapOptions = [
{
label: 'S',
value: 1,
},
{
label: 'M',
value: 2,
},
{
label: 'L',
value: 3,
},
];

return (
<>
<InspectorControls>
Expand Down Expand Up @@ -122,6 +140,65 @@ export default function ( { attributes, setAttributes, className, clientId } ) {
</ToolsPanel>
</InspectorControls>

<InspectorControls group="dimensions">
<ToolsPanelItem
hasValue={ () => gap !== metadata.attributes.gap.default }
isShownByDefault
label={ __(
'The gap between each item',
'snow-monkey-blocks'
) }
onDeselect={ () =>
setAttributes( {
gap: metadata.attributes.gap.default,
} )
}
panelId={ clientId }
>
<BaseControl
id="snow-monkey-blocks/testimonials/gap"
label={ __(
'The gap between each item',
'snow-monkey-blocks'
) }
className="spacing-sizes-control"
>
<RangeControl
className="spacing-sizes-control__range-control"
value={
gapOptions.filter(
( option ) =>
option.label?.toLowerCase() === gap
)?.[ 0 ]?.value
}
resetFallbackValue={ undefined }
onChange={ ( value ) =>
setAttributes( {
gap: gapOptions
.filter(
( option ) => option.value === value
)?.[ 0 ]
?.label?.toLowerCase(),
} )
}
withInputField={ false }
min={ 1 }
max={ 3 }
marks
renderTooltipContent={ ( _value ) =>
gapOptions
.filter(
( option ) => option.value === _value
)?.[ 0 ]
?.label?.toUpperCase()
}
hideLabelFromVision
__nextHasNoMarginBottom
/>
</BaseControl>
</ToolsPanelItem>
</InspectorControls>

<div { ...blockProps }>
<div className="smb-testimonial__body">
<div
Expand Down
6 changes: 4 additions & 2 deletions src/blocks/testimonial/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import classnames from 'classnames';
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';

export default function ( { attributes, className } ) {
const { md, lg } = attributes;
const { md, lg, gap } = attributes;

const classes = classnames( 'smb-testimonial', className );
const rowClasses = classnames( 'c-row', 'c-row--margin' );
const rowClasses = classnames( 'c-row', 'c-row--margin', {
[ `c-row--margin-${ gap }` ]: !! gap,
} );

return (
<div { ...useBlockProps.save( { className: classes } ) }>
Expand Down

0 comments on commit 096e981

Please sign in to comment.