Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/stylebook-edit-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Jul 4, 2023
2 parents d934059 + b1579dd commit c44fa4e
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 2 deletions.
45 changes: 45 additions & 0 deletions docs/reference-guides/data/data-core-customize-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ Namespace: `core/customize-widgets`.

Returns true if the inserter is opened.

_Usage_

```js
import { store as customizeWidgetsStore } from '@wordpress/customize-widgets';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';

const ExampleComponent = () => {
const { isInserterOpened } = useSelect(
( select ) => select( customizeWidgetsStore ),
[]
);

return isInserterOpened()
? __( 'Inserter is open' )
: __( 'Inserter is closed.' );
};
```

_Parameters_

- _state_ `Object`: Global application state.
Expand All @@ -28,6 +47,32 @@ _Returns_

Returns an action object used to open/close the inserter.

_Usage_

```js
import { store as customizeWidgetsStore } from '@wordpress/customize-widgets';
import { __ } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
import { Button } from '@wordpress/components';
import { useState } from '@wordpress/element';

const ExampleComponent = () => {
const { setIsInserterOpened } = useDispatch( customizeWidgetsStore );
const [ isOpen, setIsOpen ] = useState( false );

return (
<Button
onClick={ () => {
setIsInserterOpened( ! isOpen );
setIsOpen( ! isOpen );
} }
>
{ __( 'Open/close inserter' ) }
</Button>
);
};
```

_Parameters_

- _value_ `boolean|Object`: Whether the inserter should be opened (true) or closed (false). To specify an insertion point, use an object.
Expand Down
1 change: 1 addition & 0 deletions packages/customize-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ export function initialize( editorName, blockEditorSettings ) {
);
} );
}
export { store } from './store';
25 changes: 25 additions & 0 deletions packages/customize-widgets/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@
* @param {string} value.rootClientId The root client ID to insert at.
* @param {number} value.insertionIndex The index to insert at.
*
* @example
* ```js
* import { store as customizeWidgetsStore } from '@wordpress/customize-widgets';
* import { __ } from '@wordpress/i18n';
* import { useDispatch } from '@wordpress/data';
* import { Button } from '@wordpress/components';
* import { useState } from '@wordpress/element';
*
* const ExampleComponent = () => {
* const { setIsInserterOpened } = useDispatch( customizeWidgetsStore );
* const [ isOpen, setIsOpen ] = useState( false );
*
* return (
* <Button
* onClick={ () => {
* setIsInserterOpened( ! isOpen );
* setIsOpen( ! isOpen );
* } }
* >
* { __( 'Open/close inserter' ) }
* </Button>
* );
* };
* ```
*
* @return {Object} Action object.
*/
export function setIsInserterOpened( value ) {
Expand Down
18 changes: 18 additions & 0 deletions packages/customize-widgets/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
*
* @param {Object} state Global application state.
*
* @example
* ```js
* import { store as customizeWidgetsStore } from '@wordpress/customize-widgets';
* import { __ } from '@wordpress/i18n';
* import { useSelect } from '@wordpress/data';
*
* const ExampleComponent = () => {
* const { isInserterOpened } = useSelect(
* ( select ) => select( customizeWidgetsStore ),
* []
* );
*
* return isInserterOpened()
* ? __( 'Inserter is open' )
* : __( 'Inserter is closed.' );
* };
* ```
*
* @return {boolean} Whether the inserter is opened.
*/
export function isInserterOpened( state ) {
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,5 @@ const registerBlock = ( block ) => {
}
registerBlockType( name, settings );
};

export { store } from './store';
7 changes: 5 additions & 2 deletions test/e2e/specs/site-editor/pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test.describe( 'Pages', () => {
).toBeVisible();

// Switch to template editing focus.
await page.getByRole( 'button', { name: 'Settings' } ).click();
await editor.openDocumentSettingsSidebar();
await page
.getByRole( 'region', { name: 'Editor settings' } )
.getByRole( 'button', { name: 'Edit template' } )
Expand All @@ -102,7 +102,10 @@ test.describe( 'Pages', () => {
.fill( 'New Site Title' );

// Go back to page editing focus.
await page.getByRole( 'button', { name: 'Back', exact: true } ).click();
await page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Back' } )
.click();

// Site Title and Page entities should have been modified.
await page.getByRole( 'button', { name: 'Save', exact: true } ).click();
Expand Down

0 comments on commit c44fa4e

Please sign in to comment.