Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional example for render appender component usage #241

Merged
merged 5 commits into from
Jul 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions components/custom-block-appender/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,39 @@ const MyComponent = ({clientId}) => {
}
```

## Advanced Usage
The following will ensure the render appender button will only show if the parent block or an inner block is currently selected.

```js
import { CustomBlockAppender } from '@10up/block-components';
fabiankaegy marked this conversation as resolved.
Show resolved Hide resolved
import { useSelect } from '@wordpress/data';
const MyComponent = ({clientId, isSelected}) => {

const { hasSelectedInnerBlock } = useSelect( ( select ) => {
const { hasSelectedInnerBlock } = select( 'core/block-editor' );
return {
hasSelectedInnerBlock: hasSelectedInnerBlock
};
} );
fabiankaegy marked this conversation as resolved.
Show resolved Hide resolved

<InnerBlocks
renderAppender={ () => {
return (
( isSelected || hasSelectedInnerBlock( clientId, true ) ) &&
fabiankaegy marked this conversation as resolved.
Show resolved Hide resolved
<CustomBlockAppender
className="custom-classname"
rootClientId={clientId}
icon="heavy-plus"
isTertiary
showTooltip
label={__('Insert Accordion content', '10up-block-library')}
/>
)
}
/>
}
```

## Props

| Name | Type | Default | Description |
Expand Down