Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/WDSBT-23 query block related post block #26

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .markdownlintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
blocks
./blocks
build
node_modules
vendor
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
blocks/
./blocks/
build/
node_modules/
vendor/
Expand Down
101 changes: 101 additions & 0 deletions assets/js/block-filters/buttons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { addFilter } from '@wordpress/hooks';
import { createHigherOrderComponent } from '@wordpress/compose';
import { InspectorControls } from '@wordpress/block-editor';
import {
PanelBody,
PanelRow,
ButtonGroup,
Button,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Renders the edit component for the button block.
*
* @param {Object} props - The properties passed to the component.
* @param {Object} props.attributes - The attributes of the button block.
* @param {string} props.attributes.buttonSize - The size of the button.
* @param {Function} props.setAttributes - The function to set the attributes of the button block.
* @return {JSX.Element} The rendered edit component.
*/
function Edit({ attributes: { buttonSize }, setAttributes }) {
const handleChange = (newSize) => {
// Check if we are toggling the size off
const size = buttonSize === newSize ? undefined : newSize;
const buttonClass = buttonSize !== newSize ? 'has-size-' + newSize : '';

// Update attributes.
setAttributes({
buttonSize: size,
className: buttonClass,
});
};

return (
<InspectorControls>
<PanelBody title={__('Button Sizes')}>
<PanelRow>
<ButtonGroup aria-label={__('Button Sizes')}>
{['s', 'm', 'l', 'xl'].map((sizeValue) => {
return (
<Button
key={sizeValue}
size="medium"
variant={
buttonSize === sizeValue
? 'primary'
: undefined
}
onClick={() => handleChange(sizeValue)}
>
{sizeValue.toUpperCase()}
</Button>
);
})}
</ButtonGroup>
</PanelRow>
</PanelBody>
</InspectorControls>
);
}

addFilter(
'blocks.registerBlockType',
'wds-bt/button-sizes',
(settings, name) => {
if (name !== 'core/button') {
return settings;
}

return {
...settings,
attributes: {
...settings.attributes,
buttonSize: {
type: 'string',
selector: 'a',
default: '',
},
},
};
}
);

addFilter(
'editor.BlockEdit',
'wds-bt/button-sizes',
createHigherOrderComponent((BlockEdit) => {
return (props) => {
if (props.name !== 'core/button') {
return <BlockEdit {...props} />;
}

return (
<>
<BlockEdit {...props} />
<Edit {...props} />
</>
);
};
})
);
1 change: 1 addition & 0 deletions assets/js/block-filters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

// Import the block filter file.
import './unregister-core-embed';
import './buttons';
4 changes: 2 additions & 2 deletions assets/scss/blocks/core/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
}
}

&.large {
&.has-size-l {
.wp-block-button__link {
border-radius: 6px;
border-width: 2px;
Expand All @@ -78,7 +78,7 @@
}
}

&.xlarge {
&.has-size-xl {
.wp-block-button__link {
border-radius: 6px;
border-width: 2px;
Expand Down
Loading
Loading