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

fix (icon label): change icon gap #3209

Merged
merged 10 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 40 additions & 0 deletions src/block/icon-label/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,48 @@ import {
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity,
deprecateBlockShadowColor, deprecateContainerShadowColor,
} from '~stackable/block-components'
import classnames from 'classnames/dedupe'
import { addFilter } from '@wordpress/hooks'
import { semverCompare } from '~stackable/util'

addFilter( 'stackable.icon-label.save.blockClassNames', 'stackable/3.13.2', ( output, props ) => {
if ( semverCompare( props.version, '<=', '3.13.1' ) ) {
return classnames( output, {
'stk-block-icon-label--v2': false,
} )
}

return output
} )

const deprecated = [
{
attributes: attributes( '3.13.1' ),
save: withVersion( '3.13.1' )( Save ),
isEligible: attributes => {
const isNotV2 = attributes.version < 2 || typeof attributes.version === 'undefined'
return isNotV2
},
migrate: ( attributes, innerBlocks ) => {
const newAttributes = {
...attributes,
version: 2,
}

const { iconGap } = attributes

const iconBlockAttributes = innerBlocks[ 0 ].attributes
const { iconSize } = iconBlockAttributes

const _iconSize = iconSize ? iconSize : 36
const _iconGap = iconGap ? iconGap : 64

const newIconGap = _iconGap - _iconSize >= 0 ? _iconGap - _iconSize : 0
newAttributes.iconGap = newIconGap === 28 ? '' : newIconGap

return newAttributes
},
},
{
// Support the new shadow color.
attributes: attributes( '3.12.11' ),
Expand Down
3 changes: 2 additions & 1 deletion src/block/icon-label/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const Edit = props => {
const blockClassNames = classnames( [
className,
'stk-block-icon-label',
'stk-block-icon-label--v2',
rowClass,
] )

Expand Down Expand Up @@ -92,7 +93,7 @@ const Edit = props => {
responsive="all"
min={ 0 }
sliderMax={ 300 }
placeholder="64"
placeholder="28"
/>
</PanelAdvancedSettings>

Expand Down
8 changes: 6 additions & 2 deletions src/block/icon-label/editor.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.stk-block-icon-label [data-type="stackable/icon"] {
flex: 0 0 64px;
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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

}
.stk-preview-device-mobile .stk-block-icon-label .block-editor-block-list__layout [data-type="stackable/heading"] {
flex: 1 1 0;
Expand All @@ -14,3 +14,7 @@
max-width: unset !important;
}
}

.stk-block-icon-label .stk-inner-blocks .block-editor-block-list__layout {
gap: 28px;
}
8 changes: 6 additions & 2 deletions src/block/icon-label/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
*/
import { InnerBlocks } from '@wordpress/block-editor'
import { compose } from '@wordpress/compose'
import { applyFilters } from '@wordpress/hooks'

export const Save = props => {
const {
Expand All @@ -32,11 +33,13 @@ export const Save = props => {
const blockAlignmentClass = getAlignmentClasses( attributes )
const responsiveClass = getResponsiveClasses( attributes )

const blockClassNames = classnames( [
const blockClassNames = classnames( applyFilters( 'stackable.icon-label.save.blockClassNames', [
className,
'stk-block-icon-label',
'stk-block-icon-label--v2',
responsiveClass,
] )
], props )
)

const contentClassNames = classnames( [
rowClass,
Expand All @@ -50,6 +53,7 @@ export const Save = props => {
className={ blockClassNames }
attributes={ attributes }
version={ props.version }
data-v={ props.attributes.version }
>
<IconLabelStyles.Content version={ props.version } attributes={ attributes } />
<CustomCSS.Content attributes={ attributes } />
Expand Down
14 changes: 14 additions & 0 deletions src/block/icon-label/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,25 @@ export const attributes = ( version = VERSION ) => {
stkResponsive: true,
default: '',
},
version: {
type: 'number',
source: 'attribute',
attribute: 'data-v',
default: undefined,
},
},
versionAdded: '3.0.0',
versionDeprecated: '',
} )

attrObject.addDefaultValues( {
attributes: {
version: 2,
},
versionAdded: '3.13.2',
versionDeprecated: '',
} )

return attrObject.getMerged( version )
}

Expand Down
8 changes: 4 additions & 4 deletions src/block/icon-label/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ const Styles = props => {
<BlockCss
{ ...propsToPass }
renderIn="save"
selector=".stk-block-icon"
selector=".stk-inner-blocks"
attrName="iconGap"
key="iconGap-save"
styleRule="flexBasis"
styleRule="gap"
format="%spx"
responsive="all"
/>
<BlockCss
{ ...propsToPass }
renderIn="edit"
selector={ `.stk-inner-blocks [data-block][data-type="stackable/icon"]` }
selector=".stk-inner-blocks .block-editor-block-list__layout"
attrName="iconGap"
key="iconGap"
styleRule="flexBasis"
styleRule="gap"
format="%spx"
responsive="all"
/>
Expand Down
7 changes: 6 additions & 1 deletion src/block/icon-label/style.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
.stk-block-icon-label {
// Default width of the icon width.
.stk-block-icon {
&:not(.stk-block-icon-label--v2) .stk-block-icon {
flex: 0 0 64px;
}

&.stk-block-icon-label--v2 .stk-inner-blocks {
gap: 28px;
}

// Remove margins and make sure the icon and text are both centered.
:is(.stk-block-icon, .stk-block-heading) {
--stk-block-margin-bottom: 0;
Expand Down
Loading