Docs: Add Block Actions Readme - #69408
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
im3dabasia
left a comment
There was a problem hiding this comment.
@dhruvikpatel18 , Thanks for picking this up!
Left a few feedbacks. Please address them. If you have any doubts please ping me.
The Dependencies, Features, and trailing "For more details…" sections don't appear in other READMEs Could those go?
| | ------------------------------- | ---------- | -------------------------------------------------------------------- | | ||
| | `clientIds` | `string[]` | Array of block client IDs to perform actions on. | | ||
| | `children` | `function` | A render prop function that receives available actions as an object. | | ||
| | `__experimentalUpdateSelection` | `function` | (Experimental) Function to update block selection after an action. | |
There was a problem hiding this comment.
__experimentalUpdateSelection is documented as a function, but it's a boolean, it's passed straight through as the 2nd arg to duplicateBlocks( clientIds, updateSelection = true ).
Would boolean, default true, be more accurate?
| ### Provided Actions | ||
|
|
||
| The `children` function receives an object with the following properties, which can be used to trigger block actions: | ||
|
|
||
| | Action | Type | Description | | ||
| | ---------------- | --------------------- | ------------------------------------------------------ | | ||
| | `onDuplicate` | `() => void` | Duplicates the selected blocks. | | ||
| | `onRemove` | `() => void` | Removes the selected blocks. | | ||
| | `onInsertBefore` | `() => void` | Inserts a new block before the selected blocks. | | ||
| | `onInsertAfter` | `() => void` | Inserts a new block after the selected blocks. | | ||
| | `onGroup` | `() => void` | Groups the selected blocks into a container block. | | ||
| | `onUngroup` | `() => void` | Ungroups a grouped block, extracting its inner blocks. | | ||
| | `onCopy` | `() => void` | Copies the selected block(s) for later pasting. | | ||
| | `onPasteStyles` | `() => Promise<void>` | Pastes styles from copied blocks. | |
There was a problem hiding this comment.
One more thought on structure, the render prop values are currently in their own "Provided Actions" section.
Could they live under children in ###Props instead? That's what Dropdown does for its renderContent callback args, and it keeps everything the consumer touches in one place.
Only hesitation is that Dropdown has 3 args and this has 12, so nested bullets might get hard to scan, your call on which reads better.
Either way though, "Provided Actions" isn't quite right for the four can* flags.
| | `onInsertAfter` | `() => void` | Inserts a new block after the selected blocks. | | ||
| | `onGroup` | `() => void` | Groups the selected blocks into a container block. | | ||
| | `onUngroup` | `() => void` | Ungroups a grouped block, extracting its inner blocks. | | ||
| | `onCopy` | `() => void` | Copies the selected block(s) for later pasting. | |
There was a problem hiding this comment.
onCopy doesn't actually copy, it only flashes the block; the clipboard write lives in the consumer. Worth rewording?
| @@ -0,0 +1,71 @@ | |||
| ## Block Actions | |||
There was a problem hiding this comment.
- The heading is
##; nearly all component READMEs here start with#(markdownlint flags it as MD041 too).
| ### Props | ||
|
|
||
| | Prop | Type | Description | | ||
| | ------------------------------- | ---------- | -------------------------------------------------------------------- | |
There was a problem hiding this comment.
Follow the block-editor README format.
Siblings use
## Development guidelines → ### Usage → ### Props → #### propName with - **Type:**, not a markdown table, see dimension-control/README.md and height-control/README.md.
| ### Usage | ||
|
|
||
| ```jsx | ||
| import BlockActions from './block-actions'; |
There was a problem hiding this comment.
The usage example's import BlockActions from './block-actions' won't work for a reader, the component isn't exported from @wordpress/block-editor at all. Its only consumer imports it relatively. Worth a note that it's component-internal?
| | `onDuplicate` | `() => void` | Duplicates the selected blocks. | | ||
| | `onRemove` | `() => void` | Removes the selected blocks. | |
There was a problem hiding this comment.
onDuplicate / onRemove are typed () => void but both return the dispatch result. Minor, but onPasteStyles got it right so the inconsistency stands out.
| --- | ||
|
|
||
| For more details, refer to the [WordPress Gutenberg repository](https://github.com/WordPress/gutenberg). | ||
|
|
There was a problem hiding this comment.
Many of these READMEs close with the standard "Block Editor components … can only be used under a BlockEditorProvider" footer. Might be worth adding for consistency.
Here is the clause
Block Editor components are components that can be used to compose the UI of your block editor. Thus, they can only be used under a [BlockEditorProvider](https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/provider/README.md) in the components tree.
| ### Related Components | ||
|
|
||
| - `usePasteStyles` – Used to handle copying and pasting block styles. | ||
| - `block-editor/store` – The primary store for managing block actions. |
There was a problem hiding this comment.
We can probably remove this. Doesn't add value imo. What do you think?
Related Components lists usePasteStyles (a hook, and it only pastes, it doesn't copy) and block-editor/store (a store, not a component).
| --- | ||
|
|
||
| For more details, refer to the [WordPress Gutenberg repository](https://github.com/WordPress/gutenberg). |
There was a problem hiding this comment.
The trailing --- + "For more details, refer to the WordPress Gutenberg repository" isn't present in any other README and reads as filler.
I think we can do away with this?
im3dabasia
left a comment
There was a problem hiding this comment.
LGTM ✅
Thanks for working on this!
* Docs: Add Block Actions Readme * Docs: Update README for BlockActions component with clearer usage and props details Co-authored-by: dhruvikpatel18 <dhruvik18@git.wordpress.org> Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>
What?
Part of: #22891
Why?
This PR adds the README for Block Actions component
Testing Instructions
none
Screenshots or screencast
none