Skip to content

Commit 6116b2f

Browse files
committed
fix borderWidth override
1 parent 04936e2 commit 6116b2f

File tree

7 files changed

+25
-50
lines changed

7 files changed

+25
-50
lines changed

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

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

src/block-components/button/style.js

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

216215
Icon.addStyles( blockStyleGenerator, {

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

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

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {
1414
*/
1515
import { Fragment } from '@wordpress/element'
1616
import { __ } from '@wordpress/i18n'
17-
import { useAttributeEditHandlers, useBlockLayoutDefaults } from '~stackable/hooks'
17+
import {
18+
useAttributeEditHandlers, useBlockLayoutDefaults, useBlockSetAttributesContext,
19+
} from '~stackable/hooks'
1820
import { applyFilters } from '@wordpress/hooks'
1921

2022
export const BORDER_CONTROLS = [
@@ -62,11 +64,8 @@ export const BorderControls = props => {
6264
updateAttributes,
6365
} = useAttributeEditHandlers( props.attrNameTemplate )
6466

65-
const { getPlaceholder } = useBlockLayoutDefaults()
66-
67-
const borderTypeValue = getAttribute( 'borderType' ) || props.borderTypeValue
68-
69-
const hasBorderType = borderTypeValue !== '' && borderTypeValue !== 'none'
67+
const setAttributes = useBlockSetAttributesContext()
68+
const { blockLayouts, getPlaceholder } = useBlockLayoutDefaults()
7069

7170
const borderControls = getPlaceholder( `${ props.placeholderTemplate }-border-style` ) !== '' ? BORDER_CONTROLS_WITH_NONE_VALUE : BORDER_CONTROLS
7271

@@ -86,7 +85,7 @@ export const BorderControls = props => {
8685
/>
8786
}
8887

89-
{ hasBorderType && props.hasBorderControls &&
88+
{ props.hasBorderControls &&
9089
<FourRangeControl
9190
label={ __( 'Border Width', i18n ) }
9291
attribute={ getAttrName( 'borderWidth' ) }
@@ -98,10 +97,21 @@ export const BorderControls = props => {
9897
sliderMax={ 5 }
9998
defaultLocked={ true }
10099
placeholder={ props.borderWidthPlaceholder || getPlaceholder( `${ props.placeholderTemplate }-border-width` ) }
100+
changeCallback={ value => {
101+
const hasValue = value?.top || value?.right || value?.bottom || value?.left
102+
const borderStyleProperty = `${ props.placeholderTemplate }-border-style`
103+
104+
// Set borderType to 'solid' if no borderType is selected and no global border settings is set
105+
if ( hasValue && ! ( getAttribute( 'borderType' ) ) && ! blockLayouts?.[ borderStyleProperty ] ) {
106+
setAttributes( { [ getAttrName( 'borderType' ) ]: 'solid' } )
107+
}
108+
109+
return value
110+
} }
101111
/>
102112
}
103113

104-
{ hasBorderType && props.hasBorderControls &&
114+
{ props.hasBorderControls &&
105115
<ColorPaletteControl
106116
label={ __( 'Border Color', i18n ) }
107117
attribute={ getAttrName( 'borderColor' ) }

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { getBlockLayoutDefault } from '~stackable/plugins/global-settings/utils'
2-
31
export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
42
const propsToPass = {
53
...props,
@@ -13,19 +11,9 @@ export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
1311
attrNameTemplate = '%s',
1412
hoverSelector,
1513
borderRadiusSelector,
16-
// borderEnabledCallback = getAttribute => getAttribute( 'borderType' ) !== 'none',
14+
// borderEnabledCallback = getAttribute => getAttribute( 'borderType' ) !== '',
1715
} = props
1816

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-
2917
// The style below is deprecated. We have to keep it because users who have
3018
// updated will suddenly see that they have lost their border radius
3119
blockStyleGenerator.addBlockStyles( 'borderRadius', [ {
@@ -165,7 +153,7 @@ export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
165153
attrName: 'borderColor',
166154
key: 'borderColor',
167155
attrNameTemplate,
168-
enabledCallback: borderEnabledCallback,
156+
// enabledCallback: borderEnabledCallback,
169157
hover: 'all',
170158
hoverSelector,
171159
dependencies: [ 'borderType' ],
@@ -182,7 +170,7 @@ export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
182170
hover: 'all',
183171
hoverSelector,
184172
format: '%spx',
185-
enabledCallback: borderEnabledCallback,
173+
// enabledCallback: borderEnabledCallback,
186174
valuePreCallback: value => value?.top,
187175
dependencies: [ 'borderType' ],
188176
}, {
@@ -196,7 +184,7 @@ export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
196184
hover: 'all',
197185
hoverSelector,
198186
format: '%spx',
199-
enabledCallback: borderEnabledCallback,
187+
// enabledCallback: borderEnabledCallback,
200188
valuePreCallback: value => value?.right,
201189
dependencies: [ 'borderType' ],
202190
}, {
@@ -210,7 +198,7 @@ export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
210198
hover: 'all',
211199
hoverSelector,
212200
format: '%spx',
213-
enabledCallback: borderEnabledCallback,
201+
// enabledCallback: borderEnabledCallback,
214202
valuePreCallback: value => value?.bottom,
215203
dependencies: [ 'borderType' ],
216204
}, {
@@ -224,7 +212,7 @@ export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
224212
hover: 'all',
225213
hoverSelector,
226214
format: '%spx',
227-
enabledCallback: borderEnabledCallback,
215+
// enabledCallback: borderEnabledCallback,
228216
valuePreCallback: value => value?.left,
229217
dependencies: [ 'borderType' ],
230218
} ] )

src/hooks/use-global-block-layout-defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const useBlockLayoutDefaults = () => {
5151
}
5252

5353
return {
54+
blockLayouts,
5455
getPlaceholder,
5556
getDefaults,
5657
}

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

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

2-
import { select } from '@wordpress/data'
3-
42
export const STATES = {
53
ALL: {
64
responsive: true, hover: true, unit: false,
@@ -44,22 +42,3 @@ export const getDefault = ( defaults, property, device ) => {
4442
top: 0, right: 0, bottom: 0, left: 0,
4543
} )
4644
}
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)