Skip to content

Commit d4bf783

Browse files
GambitGambit
authored andcommitted
fix bug (border width and border type)
1 parent 3330405 commit d4bf783

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

src/block-components/block-div/style.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const addStyles = ( blockStyleGenerator, props = {} ) => {
1414
addBorderStyles( blockStyleGenerator, {
1515
...props,
1616
attrNameTemplate: 'block%s',
17+
borderTypeGlobalProperty: '--stk-block-background-border-style',
1718
} )
1819
addSizeStyles( blockStyleGenerator, {
1920
...props,

src/block-components/button/style.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ export const addStyles = ( blockStyleGenerator, props = {} ) => {
210210
hoverSelector: borderHoverSelector,
211211
borderRadiusSelector: selector,
212212
attrNameTemplate,
213+
borderTypeGlobalProperty: '--stk-button-border-style',
213214
} )
214215

215216
Icon.addStyles( blockStyleGenerator, {

src/block-components/container-div/style.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const addStyles = ( blockStyleGenerator, props = {} ) => {
2929
attrNameTemplate: 'container%s',
3030
selector: borderSelector,
3131
hoverSelector: `${ borderSelector }:hover`,
32+
borderTypeGlobalProperty: '--stk-container-border-style',
3233
} )
3334
addSizeStyles( blockStyleGenerator, {
3435
...props,

src/block-components/helpers/borders/style.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getBlockLayoutDefault } from '~stackable/plugins/global-settings/utils'
2+
13
export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
24
const propsToPass = {
35
...props,
@@ -11,9 +13,19 @@ export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
1113
attrNameTemplate = '%s',
1214
hoverSelector,
1315
borderRadiusSelector,
14-
borderEnabledCallback = getAttribute => getAttribute( 'borderType' ) !== '' && getAttribute( 'borderType' ) !== 'none',
16+
// borderEnabledCallback = getAttribute => getAttribute( 'borderType' ) !== 'none',
1517
} = props
1618

19+
const defaultBorderEnabledCallback = getAttribute => {
20+
const defaultBorderType = props.borderTypeGlobalProperty ? getBlockLayoutDefault( props.borderTypeGlobalProperty ) : ''
21+
22+
const value = defaultBorderType !== '' ? 'none' : ''
23+
24+
return getAttribute( 'borderType' ) !== value
25+
}
26+
27+
const borderEnabledCallback = props.borderEnabledCallback ?? defaultBorderEnabledCallback
28+
1729
// The style below is deprecated. We have to keep it because users who have
1830
// updated will suddenly see that they have lost their border radius
1931
blockStyleGenerator.addBlockStyles( 'borderRadius', [ {

src/plugins/global-settings/utils/block-layout-utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
import { select } from '@wordpress/data'
3+
24
export const STATES = {
35
ALL: {
46
responsive: true, hover: true, unit: false,
@@ -42,3 +44,22 @@ export const getDefault = ( defaults, property, device ) => {
4244
top: 0, right: 0, bottom: 0, left: 0,
4345
} )
4446
}
47+
48+
export const getBlockLayoutDefault = ( property, device = 'desktop' ) => {
49+
const spacingAndBorders = select( 'stackable/global-spacing-and-borders' ).getBlockLayouts()
50+
const buttonsAndIcons = select( 'stackable/global-buttons-and-icons' ).getBlockLayouts()
51+
52+
const blockLayouts = { ...spacingAndBorders, ...buttonsAndIcons }
53+
54+
let defaultValue = blockLayouts?.[ property ]?.[ device ]
55+
56+
if ( device === 'mobile' && ! defaultValue ) {
57+
defaultValue = blockLayouts[ property ].tablet
58+
}
59+
60+
if ( ( device === 'mobile' || device === 'tablet' ) && ! defaultValue ) {
61+
defaultValue = blockLayouts[ property ].desktop
62+
}
63+
64+
return defaultValue || ''
65+
}

0 commit comments

Comments
 (0)