Skip to content

Commit

Permalink
Add example for isInserterOpened selector.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwelcher committed Jun 29, 2023
1 parent d1633ed commit af6e01f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 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,24 @@ Namespace: `core/customize-widgets`.

Returns true if the inserter is opened.

_Usage_

```js
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';

const ExampleComponent = () => {
const { isInserterOpened } = useSelect(
( select ) => select( 'core/customize-widgets' ),
[]
);

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

_Parameters_

- _state_ `Object`: Global application state.
Expand Down
17 changes: 17 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,23 @@
*
* @param {Object} state Global application state.
*
* @example
* ```js
* import { __ } from '@wordpress/i18n';
* import { useSelect } from '@wordpress/data';
*
* const ExampleComponent = () => {
* const { isInserterOpened } = useSelect(
* ( select ) => select( 'core/customize-widgets' ),
* []
* );
*
* return isInserterOpened()
* ? __( 'Inserter is open' )
* : __( 'Inserter is closed.' );
* };
* ```
*
* @return {boolean} Whether the inserter is opened.
*/
export function isInserterOpened( state ) {
Expand Down

0 comments on commit af6e01f

Please sign in to comment.