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

Add border support to site logo #48354

Open
wants to merge 68 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
3cb7840
Add border support to site logo
carolinan Feb 23, 2023
41cdda1
Update index.php
carolinan Feb 24, 2023
1ea0a5f
Merge branch 'trunk' into add/site-logo-border
carolinan Mar 27, 2023
279019b
Merge branch 'trunk' into add/site-logo-border
carolinan Apr 19, 2023
47125e1
Merge branch 'trunk' into add/site-logo-border
carolinan Apr 21, 2023
53892f4
Merge branch 'trunk' into add/site-logo-border
carolinan May 11, 2023
b91090f
Merge branch 'trunk' into add/site-logo-border
carolinan Jun 14, 2023
860ad11
Merge branch 'trunk' into add/site-logo-border
carolinan Jun 19, 2023
dbf9900
Merge branch 'trunk' into add/site-logo-border
carolinan Jun 26, 2023
6d506b9
Merge branch 'trunk' into add/site-logo-border
carolinan Jun 27, 2023
5602da2
Add a check for the border CSS classes
carolinan Jun 27, 2023
177b072
Add the custom border to the ImageEditor / cropper
carolinan Jun 27, 2023
d30eccd
Merge branch 'trunk' into add/site-logo-border
carolinan Jul 11, 2023
1b00379
Merge branch 'trunk' into add/site-logo-border
carolinan Jul 21, 2023
06b939d
Merge branch 'trunk' into add/site-logo-border
carolinan Aug 7, 2023
501fb91
try height: auto, remove border when placeholder is selected
carolinan Aug 8, 2023
882acf6
try to fix linked image width
carolinan Aug 8, 2023
0c5ab73
Move the CSS for the linked image width
carolinan Aug 8, 2023
8a74ce8
Merge branch 'trunk' into add/site-logo-border
carolinan Aug 11, 2023
97b3a40
Merge branch 'trunk' into add/site-logo-border
carolinan Sep 26, 2023
c340f86
CS: Rename function name
carolinan Sep 26, 2023
09a0c96
Merge branch 'trunk' into add/site-logo-border
carolinan Oct 13, 2023
549e075
Merge branch 'trunk' into add/site-logo-border
carolinan Oct 25, 2023
2249153
Fix editing tool border color by moving the <a> element
carolinan Oct 25, 2023
0df97a5
Merge branch 'trunk' into add/site-logo-border
carolinan Nov 15, 2023
c1d747d
Fix the JavaScript error when the link option is toggled off
carolinan Nov 15, 2023
ab6c5d4
Update the <a> image wrapper and editor styles. Add 'has-custom-boder…
carolinan Nov 20, 2023
4f19a03
Merge branch 'trunk' into add/site-logo-border
carolinan Nov 23, 2023
038906b
Add display:table to centered logos
carolinan Nov 23, 2023
5e438e3
Merge branch 'trunk' into add/site-logo-border
carolinan Nov 24, 2023
a76a4ac
Code cleanup based on review
carolinan Nov 24, 2023
6bb7388
Merge branch 'trunk' into add/site-logo-border
carolinan Nov 24, 2023
6552759
Merge branch 'trunk' into add/site-logo-border
carolinan Jan 3, 2024
db034b7
Merge branch 'trunk' into add/site-logo-border
carolinan Jan 9, 2024
122e4a7
Update editor.scss
carolinan Jan 9, 2024
2e987e5
Try to fix the height difference that occurs when the parent element …
carolinan Jan 10, 2024
17d4c72
Merge branch 'trunk' into add/site-logo-border
carolinan Jan 18, 2024
cf4af0d
Remove undefined check for the borderProps.className
carolinan Jan 18, 2024
45702b0
Remove unwanted and duplicate CSS in editor.scss
carolinan Jan 18, 2024
3b94538
Merge branch 'trunk' into add/site-logo-border
carolinan Jan 25, 2024
9c698f5
Simplify the conditions and assignments in block_core_site_logo_get_b…
carolinan Jan 25, 2024
43eabd8
Move the border selector from supports to selectors.
carolinan Jan 25, 2024
3d8c582
Merge branch 'trunk' into add/site-logo-border
carolinan Feb 3, 2024
90cb781
Update style.scss
carolinan Feb 3, 2024
551db7a
Merge branch 'trunk' into add/site-logo-border
carolinan Feb 14, 2024
0d62516
Merge branch 'trunk' into add/site-logo-border
carolinan Feb 22, 2024
c879a2e
Merge branch 'trunk' into add/site-logo-border
carolinan Mar 20, 2024
cfb275a
Fix coding standard issues
carolinan Mar 20, 2024
33bd8af
Merge branch 'trunk' into add/site-logo-border
carolinan Mar 21, 2024
357bad8
Merge branch 'trunk' into add/site-logo-border
carolinan Apr 4, 2024
bc5a7ef
Revert the change to .wp-block-site-logo.aligncenter.
carolinan Apr 4, 2024
635476c
Try to fix merge conflicts, attempt 1
carolinan Apr 24, 2024
97fa100
Merge branch 'trunk' into add/site-logo-border
carolinan Apr 24, 2024
9fbe66f
Merge branch 'trunk' into add/site-logo-border
carolinan May 7, 2024
7eadd08
Fix issues after the merge conflict
carolinan May 7, 2024
8f91248
Merge branch 'trunk' into add/site-logo-border
carolinan May 31, 2024
8b08a4f
Merge branch 'trunk' into add/site-logo-border
carolinan May 31, 2024
3aa4a50
Merge branch 'trunk' into add/site-logo-border
carolinan Jul 1, 2024
7aeadef
Merge branch 'trunk' into add/site-logo-border
carolinan Jul 10, 2024
d2374e8
Merge branch 'trunk' into add/site-logo-border
carolinan Jul 31, 2024
b9008b8
Remove experimental default controls
carolinan Jul 31, 2024
b4eb312
Border attributes: Use add_class instead of set_attributes
carolinan Jul 31, 2024
07117f1
Try to remove the CSS classes from the ImageWrapper to test if anythi…
carolinan Jul 31, 2024
46c352b
Show block border styles when the placeholder is selected.
carolinan Jul 31, 2024
31f50cf
WIP: update CSS reduce specificity
carolinan Jul 31, 2024
12cdcf0
Add the size limitation back
carolinan Aug 1, 2024
95f264f
Try resetting the box-sizing on the placeholder.
carolinan Aug 1, 2024
1e7f619
Merge branch 'trunk' into add/site-logo-border
carolinan Aug 12, 2024
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
14 changes: 14 additions & 0 deletions packages/block-library/src/site-logo/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@
"html": false,
"align": true,
"alignWide": false,
"__experimentalBorder": {
"color": true,
"radius": true,
"width": true,
"style": true,
"__experimentalSelector": "img, .components-placeholder__illustration, .components-placeholder::before",
"__experimentalSkipSerialization": true,
"__experimentalDefaultControls": {
"color": true,
"radius": true,
"width": true,
"style": true
}
carolinan marked this conversation as resolved.
Show resolved Hide resolved
},
"color": {
"__experimentalDuotone": "img, .components-placeholder__illustration, .components-placeholder::before",
"text": false,
Expand Down
15 changes: 9 additions & 6 deletions packages/block-library/src/site-logo/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
useBlockProps,
store as blockEditorStore,
__experimentalImageEditor as ImageEditor,
__experimentalUseBorderProps as useBorderProps,
} from '@wordpress/block-editor';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
Expand All @@ -62,7 +63,7 @@ const ACCEPT_MEDIA_STRING = 'image/*';

const SiteLogo = ( {
alt,
attributes: { align, width, height, isLink, linkTarget, shouldSyncIcon },
attributes,
containerRef,
isSelected,
setAttributes,
Expand All @@ -74,13 +75,16 @@ const SiteLogo = ( {
setIcon,
canUserEdit,
} ) => {
const { align, width, height, isLink, linkTarget, shouldSyncIcon } =
attributes;
const clientWidth = useClientWidth( containerRef, [ align ] );
const isLargeViewport = useViewportMatch( 'medium' );
const isWideAligned = [ 'wide', 'full' ].includes( align );
const isResizable = ! isWideAligned && isLargeViewport;
const [ { naturalWidth, naturalHeight }, setNaturalSize ] = useState( {} );
const [ isEditingImage, setIsEditingImage ] = useState( false );
const { toggleSelection } = useDispatch( blockEditorStore );
const borderProps = useBorderProps( attributes );
const classes = classnames( 'custom-logo-link', {
'is-transient': isBlobURL( logoUrl ),
} );
Expand Down Expand Up @@ -122,7 +126,7 @@ const SiteLogo = ( {

const img = (
<img
className="custom-logo"
className={ `custom-logo ${ borderProps.className }` }
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
src={ logoUrl }
alt={ alt }
onLoad={ ( event ) => {
Expand All @@ -131,6 +135,7 @@ const SiteLogo = ( {
naturalHeight: event.target.naturalHeight,
} );
} }
style={ borderProps.style }
/>
);

Expand Down Expand Up @@ -403,7 +408,7 @@ export default function LogoEdit( {
} ) {
const { width, shouldSyncIcon } = attributes;
const ref = useRef();

const borderProps = useBorderProps( attributes );
const {
siteLogoId,
canUserEdit,
Expand Down Expand Up @@ -570,9 +575,7 @@ export default function LogoEdit( {
className={ placeholderClassName }
preview={ logoImage }
withIllustration={ true }
style={ {
width,
} }
style={ ( width, borderProps.style ) }
>
{ content }
</Placeholder>
Expand Down
68 changes: 68 additions & 0 deletions packages/block-library/src/site-logo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function render_block_core_site_logo( $attributes ) {
if ( ! $attributes['isLink'] ) {
// Remove the link.
$custom_logo = preg_replace( '#<a.*?>(.*?)</a>#i', '\1', $custom_logo );

preg_replace( '#<a.*?>(.*?)</a>#i', '\1', $custom_logo );
carolinan marked this conversation as resolved.
Show resolved Hide resolved
}

if ( $attributes['isLink'] && '_blank' === $attributes['linkTarget'] ) {
Expand All @@ -48,6 +50,19 @@ function render_block_core_site_logo( $attributes ) {
$custom_logo = $processor->get_updated_html();
}

$border_attributes = get_block_core_site_logo_border_attributes( $attributes );
if ( $border_attributes ) {
$processor = new WP_HTML_Tag_Processor( $custom_logo );
$processor->next_tag( 'img' );
if ( ! empty( $border_attributes['class'] ) ) {
$processor->set_attribute( 'class', $border_attributes['class'] );
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
}
if ( ! empty( $border_attributes['style'] ) ) {
$processor->set_attribute( 'style', $border_attributes['style'] );
}
$custom_logo = $processor->get_updated_html();
}

$classnames = array();
if ( empty( $attributes['width'] ) ) {
$classnames[] = 'is-default-size';
Expand All @@ -58,6 +73,59 @@ function render_block_core_site_logo( $attributes ) {
return $html;
}

/**
* Generates class names and styles to apply the border support styles for
* the site logo block.
*
* @param array $attributes The block attributes.
* @return array The border-related classnames and styles for the block.
*/
function get_block_core_site_logo_border_attributes( $attributes ) {

$border_styles = array();
$sides = array( 'top', 'right', 'bottom', 'left' );

// Border radius.
if ( isset( $attributes['style']['border']['radius'] ) ) {
$border_styles['radius'] = $attributes['style']['border']['radius'];
}

// Border style.
if ( isset( $attributes['style']['border']['style'] ) ) {
$border_styles['style'] = $attributes['style']['border']['style'];
}

// Border width.
if ( isset( $attributes['style']['border']['width'] ) ) {
$border_styles['width'] = $attributes['style']['border']['width'];
}

// Border color.
$preset_color = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null;
$custom_color = _wp_array_get( $attributes, array( 'style', 'border', 'color' ), null );
carolinan marked this conversation as resolved.
Show resolved Hide resolved
$border_styles['color'] = $preset_color ? $preset_color : $custom_color;

// Individual border styles e.g. top, left etc.
foreach ( $sides as $side ) {
$border = _wp_array_get( $attributes, array( 'style', 'border', $side ), null );
carolinan marked this conversation as resolved.
Show resolved Hide resolved
$border_styles[ $side ] = array(
'color' => isset( $border['color'] ) ? $border['color'] : null,
'style' => isset( $border['style'] ) ? $border['style'] : null,
'width' => isset( $border['width'] ) ? $border['width'] : null,
);
}

$styles = wp_style_engine_get_styles( array( 'border' => $border_styles ) );
$attributes = array();
if ( ! empty( $styles['classnames'] ) ) {
$attributes['class'] = $styles['classnames'];
}
if ( ! empty( $styles['css'] ) ) {
$attributes['style'] = $styles['css'];
}
return $attributes;
}

/**
* Register a core site setting for a site logo
*/
Expand Down
Loading