Skip to content

Commit 968a457

Browse files
committed
make text inline, use plain js to open/close panels
1 parent 678ff69 commit 968a457

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed
Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
import { i18n } from 'stackable'
2+
import { Link } from '~stackable/components'
23

34
import { __ } from '@wordpress/i18n'
4-
import { Button } from '@wordpress/components'
55
import { dispatch } from '@wordpress/data'
66

77
export const ColorSchemesHelp = () => {
88
const onClick = () => {
9-
// Open the global settings sidebar and the color schemes panel.
10-
dispatch( 'core/edit-post' ).openGeneralSidebar( 'stackable-global-settings/sidebar' )
11-
dispatch( 'stackable/global-color-schemes' ).setIsOpen( true )
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 )
1231
}
1332

14-
return <p>
15-
{ __( 'Change the color scheme. ', i18n ) }
16-
<Button variant="link" onClick={ onClick }> { __( 'Manage', i18n ) } </Button>
17-
{ __( ' your color schemes.', i18n ) }
18-
</p>
33+
return <>
34+
<span>{ __( 'Change the color scheme. ', i18n ) }</span>
35+
<Link onClick={ onClick }> { __( 'Manage your color schemes.', i18n ) } </Link>
36+
</>
1937
}
2038

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ export { GlobalColorSchemeStyles } from './editor-loader'
2929

3030
addFilter( 'stackable.global-settings.inspector', 'stackable/global-color-schemes', output => {
3131
const [ itemInEdit, setItemInEdit ] = useState( null )
32+
const [ isOpen, setIsOpen ] = useState( false )
3233
const [ displayHoverNotice, setDisplayHoverNotice ] = useState( false )
33-
const isOpen = useSelect( select => select( 'stackable/global-color-schemes' ).getIsOpen() )
3434

3535
return (
3636
<Fragment>
3737
{ output }
3838
<PanelAdvancedSettings
3939
title={ __( 'Global Color Schemes', i18n ) }
4040
className="ugb-global-color-schemes__panel"
41-
onToggle={ isOpen => dispatch( 'stackable/global-color-schemes' ).setIsOpen( isOpen ) }
42-
isOpen={ isOpen }
41+
onToggle={ isOpen => setIsOpen( isOpen ) }
4342
>
4443
{ isOpen && displayHoverNotice && <span className="stk-global-block-layouts-help-tooltip">
4544
<HelpTooltip

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ const STORE_ACTIONS = {
3232
type: 'UPDATE_SETTINGS',
3333
settings,
3434
} ),
35-
setIsOpen: isOpen => ( {
36-
type: 'SET_IS_OPEN',
37-
isOpen,
38-
} ),
3935
}
4036

4137
const STORE_SELECTORS = {
@@ -45,7 +41,6 @@ const STORE_SELECTORS = {
4541
backgroundModeColorScheme: state.backgroundModeColorScheme || 'scheme-default-2',
4642
containerModeColorScheme: state.containerModeColorScheme || 'scheme-default-1',
4743
} ),
48-
getIsOpen: state => state.isOpen,
4944
}
5045

5146
const STORE_REDUCER = ( state = DEFAULT_STATE, action ) => {
@@ -62,12 +57,6 @@ const STORE_REDUCER = ( state = DEFAULT_STATE, action ) => {
6257
...action.settings,
6358
}
6459
}
65-
case 'SET_IS_OPEN': {
66-
return {
67-
...state,
68-
isOpen: action.isOpen,
69-
}
70-
}
7160
default: {
7261
return state
7362
}

0 commit comments

Comments
 (0)