|
1 | 1 | import { i18n } from 'stackable' |
| 2 | +import { Link } from '~stackable/components' |
2 | 3 |
|
3 | 4 | import { __ } from '@wordpress/i18n' |
4 | | -import { Button } from '@wordpress/components' |
5 | 5 | import { dispatch } from '@wordpress/data' |
6 | 6 |
|
7 | 7 | export const ColorSchemesHelp = () => { |
8 | 8 | 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 ) |
12 | 31 | } |
13 | 32 |
|
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 | + </> |
19 | 37 | } |
20 | 38 |
|
0 commit comments