-
Notifications
You must be signed in to change notification settings - Fork 60
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
fix (icon label): change icon gap #3209
Conversation
🤖 Pull request artifacts
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this should work, I want to suggest whether we can try a different (cleaner) approach.
Approach:
- We create a new attribute
iconGap2
that holds the new value foriconGap
, moving forwardiconGap
will no longer be used, but it will still be kept in the attribute definition - In PHP, in
render_block
if we encounter the block that has aniconGap
attribute, but doesn't have aniconGap2
, we:- Calculate for the new icon gap value, then replace the old CSS with the updated CSS
- Add a special class to say that this block should use the old css
flex: 0 0 64px
- In the editor JS, we have this deprecation entry:
isEligible
returns true if the block contains a value foriconGap
, the migrate the value fromiconGap
toiconGap2
Pros of approach:
- No need to create a new
version
attribute - No need for a new class name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some code organization suggestions
src/block/icon-label/index.php
Outdated
$attributes = $block[ 'attrs' ]; | ||
|
||
// check if the block uses the old icon gap attribute | ||
$use_old_styles = ( isset( $attributes[ 'iconGap' ] ) || isset( $block[ 'innerBlocks' ][0]['attrs']['iconSize'] ) ) && ! isset( $attributes[ 'iconGap2' ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check first for the presence of the elements in $block['innerBlocks']
to prevent fatal errors.
src/block/icon-label/index.php
Outdated
@@ -0,0 +1,25 @@ | |||
<?php | |||
|
|||
// Exit if accessed directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we rename this file to deprecated.php or something so we can denote that it's for deprecation purposes?
@@ -37,6 +37,11 @@ export const attributes = ( version = VERSION ) => { | |||
stkResponsive: true, | |||
default: '', | |||
}, | |||
iconGap2: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment on iconGap
that it's deprecated but kept here for migration purposes
src/block/icon-label/style.js
Outdated
@@ -26,6 +26,7 @@ const Styles = props => { | |||
|
|||
return ( | |||
<> | |||
{ /* For the old icon gap */ } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you should be able to remove the BlockCss
entry for the old iconGap
here and the block should not error out.
src/block/icon-label/style.scss
Outdated
// Default width of the icon width. | ||
.stk-block-icon { | ||
flex: 0 0 64px; | ||
// For old icon gap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move this css to the bottom (isolating it from the rest of the "current" css code) and then label it as "deprecated"
src/block/icon-label/editor.scss
Outdated
flex: 0 0 0; | ||
} | ||
// Icon label can collapse in mobile in the editor. | ||
.stk-preview-device-mobile .stk-block-icon-label .block-editor-block-list__layout [data-type="stackable/icon"] { | ||
flex: 0 0 64px; | ||
flex: 0 0 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work if we remove the flex definition completely since this is for the old 0 0 64px
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it still needs the flex, but i changed it to flex: 0
instead.
@mxkae Issue with Icon Gap has now been fixed. One remaining issue:
Screen.Recording.2024-06-24.at.3.mp4 |
fixes #3126