Skip to content

Commit 37ff34c

Browse files
committed
feat: block styles
1 parent 04c87bc commit 37ff34c

File tree

21 files changed

+829
-33
lines changed

21 files changed

+829
-33
lines changed

plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ function is_frontend() {
238238
require_once( plugin_dir_path( __FILE__ ) . 'src/plugins/global-settings/color-schemes/deprecated/index.php' ); // We need to add this so the filter for deprecation gets applied.
239239
require_once( plugin_dir_path( __FILE__ ) . 'src/plugins/global-settings/color-schemes/index.php' );
240240
require_once( plugin_dir_path( __FILE__ ) . 'src/plugins/global-settings/preset-controls/index.php' );
241+
require_once( plugin_dir_path( __FILE__ ) . 'src/plugins/global-settings/block-styles/index.php' );
241242
require_once( plugin_dir_path( __FILE__ ) . 'src/custom-block-styles.php' );
242243
require_once( plugin_dir_path( __FILE__ ) . 'src/css-optimize.php' );
243244
require_once( plugin_dir_path( __FILE__ ) . 'src/compatibility/index.php' );

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ export const addAttributes = attrObject => {
2323
type: 'string',
2424
default: '',
2525
},
26+
blockStyle: {
27+
type: 'string',
28+
default: '',
29+
},
30+
modifiedBlockStyle: {
31+
type: 'boolean',
32+
default: false,
33+
},
2634
},
2735
versionAdded: '3.0.0',
2836
versionDeprecated: '',

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const BlockDiv = memo( props => {
5656
'stk-block',
5757
blockHoverClass,
5858
attributes.className, // Custom CSS classes.
59+
attributes.blockStyle,
5960
{
6061
[ uniqueBlockClass ]: withUniqueClass,
6162
'stk-block-background': attributes.hasBackground,
@@ -133,6 +134,7 @@ BlockDiv.Content = props => {
133134
className,
134135
'stk-block',
135136
uniqueBlockClass,
137+
attributes.blockStyle,
136138
{
137139
'stk-block-background': attributes.hasBackground,
138140
[ `stk--background-scheme--${ attributes.backgroundColorScheme }` ]: attributes.hasBackground && attributes.backgroundColorScheme,

src/components/block-attributes-get-button/button.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* External dependencies
33
*/
44
import { startCase } from 'lodash'
5-
import { applyBlockDesign } from '~stackable/util'
5+
import { applyBlockDesign, getCleanAttributes } from '~stackable/util'
66

77
/**
88
* WordPress dependencies
@@ -29,7 +29,6 @@ const GetBlockAttributesButton = ( {
2929
blockName: clientId && getBlockName( clientId ) ? getBlockName( clientId ).replace( /^\w+\//g, '' ) : '',
3030
getJSONBlockAttributes: () => {
3131
const { getBlockName } = select( 'core/block-editor' )
32-
const { getBlockType } = select( 'core/blocks' )
3332

3433
if ( ! clientId ) {
3534
return {}
@@ -39,13 +38,7 @@ const GetBlockAttributesButton = ( {
3938
const blockName = getBlockName( clientId ).replace( /^\w+\//g, '' )
4039

4140
// Remove attributes which remain as the default.
42-
const defaultAttributes = getBlockType( getBlockName( clientId ) ).attributes
43-
const cleanedAttributes = Object.keys( blockAttributes ).reduce( ( attrs, attrName ) => {
44-
if ( blockAttributes[ attrName ] !== ( defaultAttributes[ attrName ] ? defaultAttributes[ attrName ].default : '' ) ) {
45-
attrs[ attrName ] = blockAttributes[ attrName ]
46-
}
47-
return attrs
48-
}, {} )
41+
const cleanedAttributes = getCleanAttributes( blockAttributes, getBlockName( clientId ) )
4942

5043
// Remove the unique class. Since this is generated by the block.
5144
cleanedAttributes.uniqueClass = undefined
@@ -99,7 +92,7 @@ const GetBlockAttributesButton = ( {
9992
setOpenPopover( false )
10093
} }
10194
>
102-
<p>{ 'Copy or modify the attributes of the block directly. Use only double quotes "' }</p>
95+
<p>Copy or modify the attributes of the block directly. Use only double quotes &quot;</p>
10396
<textarea onChange={ () => setChanged( true ) }>{ getJSONBlockAttributes() }</textarea>
10497
</Modal>
10598
}

src/components/block-css/use-block-style-generator.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { useQueryLoopInstanceId } from '~stackable/util'
1+
import { useQueryLoopInstanceId, isBlockStyleAttributesModified } from '~stackable/util'
22
import { useMemo, useRef } from '@wordpress/element'
33
import { useRafEffect } from '~stackable/hooks'
44
import CssSaveCompiler from './css-save-compiler'
55

6+
import { select } from '@wordpress/data'
7+
68
export const useBlockCssGenerator = props => {
79
const {
810
blockStyles,
@@ -13,6 +15,8 @@ export const useBlockCssGenerator = props => {
1315
blockState,
1416
} = props
1517

18+
const blockName = select( 'core/block-editor' ).getBlock( clientId )?.name
19+
1620
// Keep the filtered block styles that we will update.
1721
const blockStyleDefsRef = useRef( [] )
1822

@@ -25,11 +29,20 @@ export const useBlockCssGenerator = props => {
2529
// Keep the generated CSS for editor and return it when only the text attribute has changed.
2630
const oldCss = useRef( null )
2731

32+
const generateCssStyles = useMemo( () => isBlockStyleAttributesModified( blockName, attributes.blockStyle, attributes ),
33+
[ clientId, attributes ] )
34+
2835
const editCss = useMemo( () => {
2936
if ( oldText.current !== attributes.text ) {
3037
oldText.current = attributes.text
3138
return oldCss.current
3239
}
40+
41+
if ( ! generateCssStyles ) {
42+
oldCss.current = ''
43+
return ''
44+
}
45+
3346
// Gather only the attributes that have values and all their
3447
// corresponding block style definitions.
3548
const attrNamesWithValues = blockStyles.getAttributesWithValues( attributes )
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
.ugb-block-styles-controls {
2+
padding: 8px 16px;
3+
&.components-panel__body {
4+
border-top: none;
5+
margin-bottom: 1px;
6+
}
7+
8+
.ugb-block-styles-controls__label {
9+
display: inline-flex;
10+
align-items: baseline;
11+
gap: 6px;
12+
}
13+
14+
.components-base-control__field {
15+
display: grid;
16+
grid-template-columns: 1fr auto;
17+
row-gap: 4px;
18+
position: relative;
19+
padding-right: 28px;
20+
21+
> .components-base-control__label {
22+
margin-bottom: 0;
23+
align-self: center;
24+
}
25+
26+
> div:nth-child(2) {
27+
display: flex;
28+
align-items: center;
29+
gap: 6px;
30+
:where(.ugb-button-component:has(.dashicons-update-alt)) {
31+
background: #fff;
32+
}
33+
}
34+
35+
> .ugb-block-styles__select-control {
36+
grid-column: 1/3;
37+
> .ugb-button-component {
38+
background: white;
39+
width: 100%;
40+
border: 1px solid #00000070;
41+
padding: 0px 8px;
42+
height: 32px;
43+
border-radius: 2px;
44+
45+
&:focus:not(:disabled) {
46+
box-shadow: 0 0 0 1px var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9));
47+
}
48+
49+
> .ugb-block-styles__dropdown-icon {
50+
margin-right: 0;
51+
margin-left: auto;
52+
display: inline-flex;
53+
gap: 4px;
54+
}
55+
}
56+
}
57+
58+
> .stk-control__reset-button {
59+
right: unset;
60+
top: unset;
61+
bottom: 4px;
62+
color: var(--stk-skin-error);
63+
}
64+
}
65+
66+
.ugb-button-component.has-icon:hover {
67+
box-shadow: inset 0 0 0 1px var(--stk-skin-dark);
68+
background-color: var(--stk-skin-bg-secondary);
69+
color: var(--stk-skin-dark);
70+
}
71+
}
72+
73+
.ugb-block-styles__new-style-modal {
74+
min-width: max(350px, 35%);
75+
}
76+
.ugb-block-styles__new-style-description {
77+
color: #1e1e1e;
78+
margin-top: 0;
79+
}
80+
.ugb-block-styles__new-style-form {
81+
display: flex;
82+
flex-direction: column;
83+
gap: 16px;
84+
85+
.ugb-button-component {
86+
margin-right: 0;
87+
margin-left: auto;
88+
&.has-icon {
89+
gap: 8px;
90+
}
91+
}
92+
}
93+
94+
.ugb-block-styles__update-style-form {
95+
display: flex;
96+
gap: 8px;
97+
justify-content: flex-end;
98+
}
99+
100+
.ugb-block-styles-control__popover {
101+
.components-popover__content {
102+
width: 205px;
103+
padding: 0;
104+
}
105+
106+
.ugb-button-component {
107+
display: flex;
108+
padding: 8px;
109+
height: 32px;
110+
width: 100%;
111+
align-items: center;
112+
justify-content: space-between;
113+
114+
&:hover {
115+
color: var(--wp-components-color-foreground,#1e1e1e);
116+
background: #0000001a;
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)