Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions blocks/src/block/button/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
},
"fontSize": {
"type": "string"
},
"width": {
"type": "string"
}
},
"example": {
Expand Down
36 changes: 36 additions & 0 deletions blocks/src/block/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
SelectControl,
TextControl,
ToggleControl,
Button,
ButtonGroup,
} from '@wordpress/components';
import { Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
Expand Down Expand Up @@ -45,6 +47,7 @@ export function ButtonEdit( props ) {
customBackgroundColor,
customTextColor,
customBorderColor,
width,
} = attributes;

const classes = classnames( className, {
Expand All @@ -57,6 +60,35 @@ export function ButtonEdit( props ) {
'--cocoon-custom-text-color': customTextColor || undefined,
};

function WidthPanel( { selectedWidth, setAttributes } ) {
function handleChange( newWidth ) {
// Check if we are toggling the width off
const width = selectedWidth === newWidth ? undefined : newWidth;

// Update attributes
setAttributes( { width } );
}

return (
<PanelBody title={ __( '幅設定', THEME_NAME ) }>
<ButtonGroup aria-label={ __( 'ボタン幅', THEME_NAME ) }>
{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {
return (
<Button
key={ widthValue }
isSmall
isPrimary={ widthValue === selectedWidth }
onClick={ () => handleChange( widthValue ) }
>
{ widthValue }%
</Button>
);
} ) }
</ButtonGroup>
</PanelBody>
);
}

const blockProps = useBlockProps( {
className: classes,
style: styles,
Expand Down Expand Up @@ -121,6 +153,8 @@ export function ButtonEdit( props ) {
/>
</PanelBody>

<WidthPanel selectedWidth={ width } setAttributes={ setAttributes } />

<PanelBody
title={ __( '文字サイズ', THEME_NAME ) }
className="blocks-font-size"
Expand Down Expand Up @@ -170,6 +204,8 @@ export function ButtonEdit( props ) {
[ textColor.class ]: textColor.class,
[ borderColor.class ]: borderColor.class,
[ fontSize.class ]: fontSize.class,
[ 'has-custom-width' ]: width,
[ `cocoon-block-button__width-${ width }` ]: width,
} ) }
href={ url }
target={ target }
Expand Down
3 changes: 3 additions & 0 deletions blocks/src/block/button/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function save( { attributes } ) {
customTextColor,
customBorderColor,
fontSize,
width,
} = attributes;

const backgroundClass = getColorClassName(
Expand Down Expand Up @@ -64,6 +65,8 @@ export default function save( { attributes } ) {
[ backgroundClass ]: backgroundClass,
[ borderClass ]: borderClass,
[ fontSizeClass ]: fontSizeClass,
[ 'has-custom-width' ]: width,
[ `cocoon-block-button__width-${ width }` ]: width,
} ) }
target={ target }
rel="noopener"
Expand Down