-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5a63f5
commit c500f47
Showing
2 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
46 changes: 42 additions & 4 deletions
46
packages/block-editor/src/components/use-block-display-information/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,44 @@ | ||
`useBlockDisplayInformation` | ||
=========== | ||
# useBlockDisplayInformation | ||
|
||
`useBlockDisplayInformation` | ||
A React Hook that tries to find a matching block variation and returns the appropriate information for display reasons. In order to try to find a match we need to things: | ||
|
||
# TODO | ||
1. Block's client id to extract it's current attributes. | ||
2. A block variation should have set `isActive` prop to a proper function. | ||
|
||
If for any reason a block variaton match cannot be found, the returned information come from the Block Type. | ||
|
||
Note that this is currently experimental, and is available as `__experimentalUseBlockDisplayInformation`. | ||
|
||
### Usage | ||
|
||
The hook returns an object which contains block's title, icon and description. If no blockType is found with the provided `clientId`, returns `null`. | ||
|
||
```jsx | ||
import { | ||
BlockIcon, | ||
__experimentalUseBlockDisplayInformation as useBlockDisplayInformation, | ||
} from '@wordpress/block-editor'; | ||
|
||
function DemoBlockCard( { clientId } ) { | ||
const blockInformation = useBlockDisplayInformation( clientId ); | ||
const { title, icon, description } = blockInformation; | ||
return ( | ||
<div style={ resizeStyles }> | ||
<BlockIcon icon={ icon } showColors /> | ||
<h1>{ title }</h1> | ||
<p>{ description }</p> | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
## Props | ||
|
||
The hook accepts the following props. | ||
|
||
### clientId | ||
|
||
A block's clientId | ||
|
||
- Type: `String` | ||
- Required: Yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters