Skip to content

Commit 31bc3d8

Browse files
committed
update selectors for color schemes
1 parent de025c1 commit 31bc3d8

File tree

14 files changed

+121
-61
lines changed

14 files changed

+121
-61
lines changed

src/block/countdown/style.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import "common";
2+
13
.stk-block.stk-block-countdown {
24
text-align: center;
35
&.stk-block-countdown--aligned {
@@ -61,7 +63,7 @@
6163
}
6264

6365
// These are styles added from the global color schemes.
64-
:where(.stk-has-color-schemes) {
66+
:where(#{$stk-has-color-schemes-selector}) {
6567
.stk-block-countdown__digit {
6668
color: var(--stk-accent-color);
6769
&:where(:hover) {

src/block/divider/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
}
99

1010
// These are styles added from the global color schemes.
11-
:where(.stk-has-color-schemes) {
11+
:where(#{$stk-has-color-schemes-selector}) {
1212
.stk-block.stk-block-divider {
1313
hr.stk-block-divider__hr,
1414
.stk-block-divider__dot {

src/block/icon-list/style.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import "common";
2+
13
// Important, we can't use flex since it causes issues with columns.
24
.stk-block-icon-list {
35
.stk-block-icon-list--grid:is(ul, ol) {
@@ -88,7 +90,7 @@
8890
}
8991
}
9092

91-
:where(.stk-has-color-schemes) {
93+
:where(#{$stk-has-color-schemes-selector}) {
9294
.stk-block-icon-list {
9395
--stk-icon-list-marker-color: var(--stk-accent-color);
9496
:where(.stk-block-icon-list-item) {

src/block/number-box/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ div.stk-block-number-box__text {
2121
}
2222

2323
// These are styles added from the global color schemes.
24-
:where(.stk-has-color-schemes) .stk-block-number-box.stk--has-shape {
24+
:where(#{$stk-has-color-schemes-selector}) .stk-block-number-box.stk--has-shape {
2525
.stk-block-number-box__container,
2626
div.stk-block-number-box__text {
2727
color: var(--stk-button-text-color, #fff);

src/block/price/style.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import "common";
2+
13
.stk-block-price {
24
line-height: 1;
35
.stk-block-text {
@@ -12,6 +14,6 @@
1214
line-height: 0.7;
1315
}
1416

15-
:where(.stk-has-color-schemes .stk-block-price) .stk-block-text {
17+
:where(#{$stk-has-color-schemes-selector}) :where(.stk-block-price) .stk-block-text {
1618
color: var(--stk-text-color);
1719
}

src/block/progress-bar/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
}
4848

4949
// These are styles added from the global color schemes.
50-
:where(.stk-has-color-schemes) {
50+
:where(#{$stk-has-color-schemes-selector}) {
5151
.stk-block-progress-bar {
5252
--progress-color-1: var(--stk-accent-color);
5353
}

src/block/progress-circle/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
}
5656

5757
// These are styles added from the global color schemes.
58-
:where(.stk-has-color-schemes) {
58+
:where(#{$stk-has-color-schemes-selector}) {
5959
.stk-block-progress-circle {
6060
--progress-color-1: var(--stk-accent-color);
6161
}

src/block/table-of-contents/style.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import "common";
2+
13
// Important, we can't use flex since it causes issues with columns.
24
.stk-block-table-of-contents {
35
.stk-table-of-contents__table {
@@ -40,7 +42,7 @@
4042
}
4143

4244
// These are styles added from the global color schemes.
43-
:where(.stk-has-color-schemes) {
45+
:where(#{$stk-has-color-schemes-selector}) {
4446
.stk-block-table-of-contents {
4547
// Add this so that it inherits the color from global color schemes.
4648
::marker {

src/block/timeline/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222

2323
// These are styles added from the global color schemes.
24-
:where(.stk-has-color-schemes) {
24+
:where(#{$stk-has-color-schemes-selector}) {
2525
.stk-block-timeline {
2626
--line-accent-bg-color: var(--stk-accent-color, #000);
2727
}

src/plugins/global-settings/color-schemes/editor-loader.js

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -161,29 +161,52 @@ export const GlobalColorSchemeStyles = () => {
161161
// Adds a class to the editor body DOM to indicate that there are global styles for `color schemes`.
162162
useEffect( () => {
163163
if ( editorEl ) {
164-
if ( styles !== '' && editorEl.classList.contains( 'stk-has-color-schemes' ) === false ) {
165-
editorEl.classList.add( 'stk-has-color-schemes' )
166-
addFilter( 'stackable.global-styles.classnames', `stackable/global-settings.color-schemes`, classnames => {
167-
classnames.push( 'stk-has-color-schemes' )
168-
return classnames
169-
} )
170-
}
171-
if ( styles === '' ) {
172-
editorEl.classList.remove( 'stk-has-color-schemes' )
173-
}
164+
const addClassNames = editor => {
165+
const classNamesToAdd = []
166+
const classNamesToRemove = []
167+
if ( styles === '' ) {
168+
editor.classList.remove( 'stk--has-base-scheme', 'stk--has-background-scheme', 'stk--has-container-scheme' )
169+
} else {
170+
if ( ! styles.includes( ':root' ) ) {
171+
classNamesToRemove.push( 'stk--has-base-scheme' )
172+
} else if ( editor.classList.contains( 'stk--has-base-scheme' ) === false ) {
173+
classNamesToAdd.push( 'stk--has-base-scheme' )
174+
}
175+
176+
if ( ! styles.includes( '.stk-block-background' ) ) {
177+
classNamesToRemove.push( 'stk--has-background-scheme' )
178+
} else if ( editor.classList.contains( 'stk--has-background-scheme' ) === false ) {
179+
classNamesToAdd.push( 'stk--has-background-scheme' )
180+
}
181+
182+
if ( ! styles.includes( '.stk-container:where(:not(.stk--no-background))' ) ) {
183+
classNamesToRemove.push( 'stk--has-container-scheme' )
184+
} else if ( editor.classList.contains( 'stk--has-container-scheme' ) === false ) {
185+
classNamesToAdd.push( 'stk--has-container-scheme' )
186+
}
187+
188+
editor.classList.add( ...classNamesToAdd )
189+
editor.classList.remove( ...classNamesToRemove )
174190

175-
// At first load of the editor, the `stk-has-color-schemes` is removed, so we have to re-add it.
176-
const mo = onClassChange( editorEl, () => {
177-
if ( styles !== '' && editorEl?.classList.contains( 'stk-has-color-schemes' ) === false ) {
178-
editorEl?.classList.add( 'stk-has-color-schemes' )
179191
addFilter( 'stackable.global-styles.classnames', `stackable/global-settings.color-schemes`, classnames => {
180-
classnames.push( 'stk-has-color-schemes' )
181-
return classnames
192+
// Remove any classNamesToRemove from classnames
193+
const updatedClassnames = classnames.filter( name => ! classNamesToRemove.includes( name ) )
194+
// Add classNamesToAdd if not already present
195+
classNamesToAdd.forEach( name => {
196+
if ( ! updatedClassnames.includes( name ) ) {
197+
updatedClassnames.push( name )
198+
}
199+
} )
200+
return updatedClassnames
182201
} )
183202
}
184-
if ( styles === '' ) {
185-
editorEl?.classList.remove( 'stk-has-color-schemes' )
186-
}
203+
}
204+
205+
addClassNames( editorEl )
206+
207+
// At first load of the editor, the color scheme classnames removed, so we have to re-add it.
208+
const mo = onClassChange( editorEl, () => {
209+
addClassNames( editorEl )
187210
} )
188211

189212
return () => mo.disconnect()

0 commit comments

Comments
 (0)