Skip to content

Commit

Permalink
fix #808
Browse files Browse the repository at this point in the history
  • Loading branch information
inc2734 committed Jul 5, 2024
1 parent afd74f8 commit da46f8b
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 20 deletions.
9 changes: 6 additions & 3 deletions src/blocks/btn/style.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
@import '../../css/core/block';

// The style of the global style link (0.1.0) needs to be adjusted in the level of detail as it will be loaded later.
:is(a, span, div).smb-btn {
.smb-btn:not(:root) {
color: var(--smb-btn--color);
text-decoration: none;
}

.smb-btn {
--smb-btn--background-color: var(--wp--preset--color--black);
--smb-btn--background-image: initial;
--smb-btn--border: none;
Expand All @@ -21,10 +26,8 @@
background-image: var(--smb-btn--background-image);
border: var(--smb-btn--border);
border-radius: var(--smb-btn--border-radius);
color: var(--smb-btn--color);
padding: var(--smb-btn--padding-vertical) var(--smb-btn--padding-horizontal);
max-width: 100%;
text-decoration: none;
white-space: nowrap;
@include _transition(all);

Expand Down
8 changes: 7 additions & 1 deletion src/blocks/items/item/block-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@
}
},
"supports": {
"html": false
"html": false,
"color": {
"__experimentalSkipSerialization": true,
"background": true,
"text": true,
"link": true
}
},
"editorScript": "file:./index.js"
}
12 changes: 11 additions & 1 deletion src/blocks/items/item/block-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
__experimentalLinkControl as LinkControl,
__experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown,
__experimentalBorderRadiusControl as BorderRadiusControl,
__experimentalUseColorProps as useColorProps,
} from '@wordpress/block-editor';

import { useState, useRef } from '@wordpress/element';
Expand Down Expand Up @@ -68,6 +69,8 @@ export default function ( {
btnWrap,
} = attributes;

const colorProps = useColorProps( attributes );

const [ isEditingURL, setIsEditingURL ] = useState( false );
const isURLSet = !! url;
const opensInNewTab = target === '_blank';
Expand Down Expand Up @@ -451,7 +454,14 @@ export default function ( {
</InspectorControls>

<div { ...blockProps }>
<div className="smb-items__item smb-items__item--block-link">
<div
className={ classnames(
'smb-items__item',
'smb-items__item--block-link',
colorProps?.className
) }
style={ { ...colorProps?.style } }
>
{ displayImage && (
<div className="smb-items__item__figure">
<Figure
Expand Down
15 changes: 13 additions & 2 deletions src/blocks/items/item/block-link/save.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import classnames from 'classnames';

import { RichText, useBlockProps } from '@wordpress/block-editor';
import {
RichText,
useBlockProps,
__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,
} from '@wordpress/block-editor';

export default function ( { attributes, className } ) {
const {
Expand All @@ -26,6 +30,8 @@ export default function ( { attributes, className } ) {
btnWrap,
} = attributes;

const colorProps = getColorClassesAndStyles( attributes );

const classes = classnames( 'c-row__col', className );

const btnClasses = classnames( 'smb-items__item__btn', 'smb-btn', {
Expand All @@ -45,7 +51,12 @@ export default function ( { attributes, className } ) {
return (
<div { ...useBlockProps.save( { className: classes } ) }>
<a
className="smb-items__item smb-items__item--block-link"
className={ classnames(
'smb-items__item',
'smb-items__item--block-link',
colorProps?.className
) }
style={ { ...colorProps?.style } }
href={ url }
target={ '_self' === target ? undefined : target }
rel={ '_self' === target ? undefined : 'noopener noreferrer' }
Expand Down
10 changes: 10 additions & 0 deletions src/blocks/items/item/free/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
},
"supports": {
"html": false,
"color": {
"__experimentalSkipSerialization": true,
"background": true,
"text": true,
"link": true
},
"spacing": {
"__experimentalSkipSerialization": true,
"padding": true
},
"layout": {
"allowSwitching": false,
"allowEditing": false,
Expand Down
13 changes: 12 additions & 1 deletion src/blocks/items/item/free/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import {
InnerBlocks,
useBlockProps,
useInnerBlocksProps,
__experimentalUseColorProps as useColorProps,
__experimentalGetSpacingClassesAndStyles as useSpacingProps,
} from '@wordpress/block-editor';

import { useSelect } from '@wordpress/data';

export default function ( { attributes, className, clientId } ) {
const { templateLock } = attributes;

const colorProps = useColorProps( attributes );
const spacingProps = useSpacingProps( attributes );

const hasInnerBlocks = useSelect(
( select ) =>
!! select( 'core/block-editor' ).getBlock( clientId )?.innerBlocks
Expand All @@ -22,7 +27,9 @@ export default function ( { attributes, className, clientId } ) {

const itemClasses = classnames(
'smb-items__item',
'smb-items__item--free'
'smb-items__item--free',
colorProps?.className,
spacingProps?.className
);

const blockProps = useBlockProps( {
Expand All @@ -32,6 +39,10 @@ export default function ( { attributes, className, clientId } ) {
const innerBlocksProps = useInnerBlocksProps(
{
className: 'smb-items__item__body',
style: {
...colorProps?.style,
...spacingProps?.style,
},
},
{
templateLock,
Expand Down
20 changes: 17 additions & 3 deletions src/blocks/items/item/free/save.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import classnames from 'classnames';

import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
import {
useBlockProps,
useInnerBlocksProps,
__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,
__experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles,
} from '@wordpress/block-editor';

export default function ( { attributes, className } ) {
const colorProps = getColorClassesAndStyles( attributes );
const spacingProps = getSpacingClassesAndStyles( attributes );

export default function ( { className } ) {
const classes = classnames( 'c-row__col', className );

const itemClasses = classnames(
'smb-items__item',
'smb-items__item--free'
'smb-items__item--free',
colorProps?.className,
spacingProps?.className
);

return (
Expand All @@ -16,6 +26,10 @@ export default function ( { className } ) {
<div
{ ...useInnerBlocksProps.save( {
className: 'smb-items__item__body',
style: {
...colorProps?.style,
...spacingProps?.style,
},
} ) }
/>
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/blocks/items/item/standard/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@
}
},
"supports": {
"html": false
"html": false,
"color": {
"__experimentalSkipSerialization": true,
"background": true,
"text": true,
"link": true
}
},
"editorScript": "file:./index.js"
}
11 changes: 10 additions & 1 deletion src/blocks/items/item/standard/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
__experimentalLinkControl as LinkControl,
__experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown,
__experimentalBorderRadiusControl as BorderRadiusControl,
__experimentalUseColorProps as useColorProps,
} from '@wordpress/block-editor';

import { useState, useRef } from '@wordpress/element';
Expand Down Expand Up @@ -68,6 +69,8 @@ export default function ( {
btnWrap,
} = attributes;

const colorProps = useColorProps( attributes );

const [ isEditingURL, setIsEditingURL ] = useState( false );
const isURLSet = !! url;
const opensInNewTab = target === '_blank';
Expand Down Expand Up @@ -450,7 +453,13 @@ export default function ( {
</InspectorControls>

<div { ...blockProps }>
<div className="smb-items__item">
<div
className={ classnames(
'smb-items__item',
colorProps?.className
) }
style={ { ...colorProps?.style } }
>
{ displayImage && (
<div className="smb-items__item__figure">
<Figure
Expand Down
16 changes: 14 additions & 2 deletions src/blocks/items/item/standard/save.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import classnames from 'classnames';

import { RichText, useBlockProps } from '@wordpress/block-editor';
import {
RichText,
useBlockProps,
__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,
} from '@wordpress/block-editor';

export default function ( { attributes, className } ) {
const {
Expand All @@ -26,6 +30,8 @@ export default function ( { attributes, className } ) {
btnWrap,
} = attributes;

const colorProps = getColorClassesAndStyles( attributes );

const classes = classnames( 'c-row__col', className );

const btnClasses = classnames( 'smb-items__item__btn', 'smb-btn', {
Expand All @@ -44,7 +50,13 @@ export default function ( { attributes, className } ) {

return (
<div { ...useBlockProps.save( { className: classes } ) }>
<div className="smb-items__item">
<div
className={ classnames(
'smb-items__item',
colorProps?.className
) }
style={ { ...colorProps?.style } }
>
{ displayImage && (
<div className="smb-items__item__figure">
<img
Expand Down
19 changes: 14 additions & 5 deletions src/blocks/items/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@
display: block;
position: relative;

&.has-background {
padding: 0;

> .smb-items__item__figure {
margin-bottom: 0;
}

> .smb-items__item__body {
padding: var(--_padding1);
}
}

&__figure {
text-align: center;
}
Expand Down Expand Up @@ -119,11 +131,8 @@
}

&--free {
.smb-items__item__body {
> * {
margin-top: 0;
margin-bottom: 0;
}
&.has-background > .smb-items__item__body {
padding: 0;
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/css/blocks-editor-wrapper.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
@import 'core/block';

.components-tools-panel {
> .block-editor-contrast-checker {
grid-column: 1 / -1;
}
}

.smb-list-icon-selector {
.components-button {
margin: 1px;
Expand Down

0 comments on commit da46f8b

Please sign in to comment.