-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 Columns template options, support InnerBlock templateOptions #16129
Changes from all commits
d1d4796
77ca437
13bd06e
989702c
b41b489
502cfcd
7093427
a2988db
cc37d09
398b5f1
3d246ae
068e9bf
8109601
f5b581a
409e48c
ddc187b
60b7c50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button, IconButton, Placeholder } from '@wordpress/components'; | ||
|
||
function InnerBlocksTemplatePicker( { | ||
options, | ||
onSelect, | ||
allowSkip, | ||
} ) { | ||
const classes = classnames( 'block-editor-inner-blocks__template-picker', { | ||
'has-many-options': options.length > 4, | ||
} ); | ||
|
||
const instructions = allowSkip ? | ||
__( 'Select a layout to start with, or make one yourself.' ) : | ||
__( 'Select a layout to start with.' ); | ||
|
||
return ( | ||
<Placeholder | ||
icon="layout" | ||
label={ __( 'Choose Layout' ) } | ||
instructions={ instructions } | ||
className={ classes } | ||
> | ||
{ | ||
/* | ||
* Disable reason: The `list` ARIA role is redundant but | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not super relevant for this pull request, but is the approach we've taken that we need Currently, it's far too easy to overlook (evidenced by the fact I'd omitted it in my original proposal). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I know we did this for the Block Hierarchy as well. yeah, it does seem like we should have a rule for it. |
||
* Safari+VoiceOver won't announce the list otherwise. | ||
*/ | ||
/* eslint-disable jsx-a11y/no-redundant-roles */ | ||
} | ||
<ul className="block-editor-inner-blocks__template-picker-options" role="list"> | ||
{ options.map( ( templateOption, index ) => ( | ||
<li key={ index }> | ||
<IconButton | ||
isLarge | ||
icon={ templateOption.icon } | ||
onClick={ () => onSelect( templateOption.template ) } | ||
className="block-editor-inner-blocks__template-picker-option" | ||
label={ templateOption.title } | ||
/> | ||
</li> | ||
) ) } | ||
</ul> | ||
{ /* eslint-enable jsx-a11y/no-redundant-roles */ } | ||
{ allowSkip && ( | ||
<div className="block-editor-inner-blocks__template-picker-skip"> | ||
<Button | ||
isLink | ||
onClick={ () => onSelect( undefined ) } | ||
> | ||
{ __( 'Skip' ) } | ||
</Button> | ||
</div> | ||
) } | ||
</Placeholder> | ||
); | ||
} | ||
|
||
export default InnerBlocksTemplatePicker; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something we expect to only be used for inner blocks? Is there a use case for the selection screen to be used for pre-configured block attributes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. It's unclear to me how this might look from a design perspective, since the current concepts seem to align quite closely with how blocks are arranged (technically aligning to the template option), though I don't see any reason why it couldn't be that the options configure a block's own attributes. It speaks a bit to the original questions about whether this be proposed an enhancement to the Placeholder component rather than to the InnerBlocks component, which could be more easily adapted. I still think we could extract something common regardless.
At least as experimental props, we could still opt toward the Placeholder improvements if own-block attributes option selection pans out to be a good idea to pursue.