Skip to content

Commit 6df8f39

Browse files
kaeizenbfintal
andauthored
Feat (Color Schemes): Add help description to manage color schemes (#3478)
* add help * update comments * add space * move space * make text inline, use plain js to open/close panels * Update store.js * Update src/components/color-schemes-help/index.js --------- Co-authored-by: Benjamin Intal <[email protected]>
1 parent 69ce610 commit 6df8f39

File tree

7 files changed

+48
-1
lines changed

7 files changed

+48
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
InspectorStyleControls,
1717
PanelAdvancedSettings,
1818
AdvancedSelectControl,
19+
ColorSchemesHelp,
1920
} from '~stackable/components'
2021
import {
2122
useBlockAttributesContext,
@@ -100,6 +101,7 @@ export const Edit = memo( props => {
100101
return colorScheme
101102
} }
102103
default={ backgroundModeColorScheme }
104+
help={ <ColorSchemesHelp /> }
103105
/>
104106
<BackgroundControls
105107
attrNameTemplate="block%s"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
AdvancedToggleControl,
1818
InspectorBlockControls,
1919
AdvancedSelectControl,
20+
ColorSchemesHelp,
2021
} from '~stackable/components'
2122
import {
2223
useBlockAttributesContext,
@@ -71,6 +72,7 @@ export const Edit = props => {
7172
return colorScheme
7273
} }
7374
default={ containerModeColorScheme }
75+
help={ <ColorSchemesHelp /> }
7476
/>
7577
<SizeControls.Layout
7678
attrNameTemplate="container%s"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { i18n } from 'stackable'
2+
import { Link } from '~stackable/components'
3+
4+
import { __ } from '@wordpress/i18n'
5+
import { dispatch } from '@wordpress/data'
6+
7+
export const ColorSchemesHelp = () => {
8+
const onClick = () => {
9+
// Open the global settings sidebar.
10+
dispatch( 'core/edit-post' )?.openGeneralSidebar( 'stackable-global-settings/sidebar' ) // For Block Editor
11+
dispatch( 'core/edit-site' )?.openGeneralSidebar( 'stackable-global-settings/sidebar' ) // For Site Editor
12+
13+
// Add a small delay to ensure DOM elements are fully rendered and accessible after the sidebar opens
14+
setTimeout( () => {
15+
// Closes all panels except the color scheme panel
16+
const panels = document.querySelectorAll( '.ugb-global-settings__inspector > .ugb-toggle-panel-body.is-opened' )
17+
panels?.forEach( panel => {
18+
if ( panel.classList.contains( 'ugb-global-color-schemes__panel' ) ) {
19+
return
20+
}
21+
const toggle = panel.querySelector( '.components-panel__body-title > .components-panel__body-toggle' )
22+
toggle?.click()
23+
} )
24+
25+
const colorSchemeToggle = document.querySelector( '.ugb-global-color-schemes__panel .components-panel__body-title > .components-panel__body-toggle' )
26+
// Opens the color scheme panel
27+
if ( colorSchemeToggle.getAttribute( 'aria-expanded' ) === 'false' ) {
28+
colorSchemeToggle?.click()
29+
}
30+
}, 10 )
31+
}
32+
33+
return <>
34+
<span>{ __( 'Change the color scheme.', i18n ) }</span>
35+
&nbsp;
36+
<Link onClick={ onClick }> { __( 'Manage your color schemes.', i18n ) } </Link>
37+
</>
38+
}
39+

src/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,4 @@ export {
124124
ColorSchemePresetPicker,
125125
DEFAULT_COLOR_SCHEME_COLORS,
126126
} from './color-scheme-preview'
127+
export { ColorSchemesHelp } from './color-schemes-help'

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export const GlobalColorSchemeStyles = () => {
134134
currentHoverState,
135135
] )
136136

137+
// Adds a class to the editor body DOM to indicate that there are global styles for `color schemes`.
137138
useEffect( () => {
138139
if ( editorEl ) {
139140
if ( styles !== '' && editorEl.classList.contains( 'stk-has-color-schemes' ) === false ) {
@@ -143,7 +144,7 @@ export const GlobalColorSchemeStyles = () => {
143144
editorEl.classList.remove( 'stk-has-color-schemes' )
144145
}
145146

146-
// At first load of the editor, the `stk-preview-device-*` and `stk--is-*-theme` are removed, so we have to re-add it.
147+
// At first load of the editor, the `stk-has-color-schemes` is removed, so we have to re-add it.
147148
const mo = onClassChange( editorEl, () => {
148149
if ( styles !== '' && editorEl?.classList.contains( 'stk-has-color-schemes' ) === false ) {
149150
editorEl?.classList.add( 'stk-has-color-schemes' )

src/plugins/global-settings/color-schemes/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-color-scheme
3737
{ output }
3838
<PanelAdvancedSettings
3939
title={ __( 'Global Color Schemes', i18n ) }
40+
className="ugb-global-color-schemes__panel"
4041
onToggle={ isOpen => setIsOpen( isOpen ) }
4142
>
4243
{ isOpen && displayHoverNotice && <span className="stk-global-block-layouts-help-tooltip">

src/plugins/global-settings/utils/use-block-layout-editor-loader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export const useBlockLayoutEditorLoader = ( storeName, classSuffix ) => {
157157
}
158158
}, [ blockLayouts, currentHoverState, SelectedParentHoverBlock ] )
159159

160+
// Adds a class to the editor body DOM to indicate that there are global styles for `spacing and borders` or `buttons and icons`.
160161
useEffect( () => {
161162
if ( editorEl ) {
162163
const className = `stk-has-design-system-${ classSuffix }`

0 commit comments

Comments
 (0)