-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 initial draft of container block #10562
Changes from 1 commit
3cee715
4a46fdc
83a9704
dee2ba2
872d6fe
b524cd5
5acc4e6
3d33685
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,107 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { Fragment } from '@wordpress/element'; | ||
import { | ||
getColorClassName, | ||
withColors, | ||
InspectorControls, | ||
InnerBlocks, | ||
PanelColorSettings, | ||
} from '@wordpress/editor'; | ||
|
||
export const name = 'core/section'; | ||
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. I think "container" is a better name, since "section" implies the usage of a |
||
|
||
export const settings = { | ||
title: sprintf( | ||
/* translators: Block title modifier */ | ||
__( '%1$s (%2$s)' ), | ||
__( 'Section' ), | ||
__( 'beta' ) | ||
), | ||
|
||
icon: <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="none" d="M0 0h24v24H0V0z" /><g><path d="M21 4H3L2 5v14l1 1h18l1-1V5l-1-1zM8 18H4V6h4v12zm6 0h-4V6h4v12zm6 0h-4V6h4v12z" /></g></svg>, | ||
|
||
category: 'layout', | ||
|
||
attributes: { | ||
align: { | ||
type: 'string', | ||
}, | ||
backgroundColor: { | ||
type: 'string', | ||
}, | ||
customBackgroundColor: { | ||
type: 'string', | ||
}, | ||
}, | ||
|
||
description: __( 'Group a selection of blocks into a container.' ), | ||
|
||
supports: { | ||
align: [ 'wide', 'full' ], | ||
}, | ||
|
||
edit: withColors( 'backgroundColor' )( ( props ) => { | ||
const { | ||
backgroundColor, | ||
className, | ||
setBackgroundColor, | ||
} = props; | ||
|
||
return ( | ||
<Fragment> | ||
<InspectorControls> | ||
<PanelColorSettings | ||
title={ __( 'Color Settings' ) } | ||
initialOpen={ false } | ||
colorSettings={ [ | ||
{ | ||
value: backgroundColor.color, | ||
onChange: setBackgroundColor, | ||
label: __( 'Background Color' ), | ||
}, | ||
] } | ||
/> | ||
</InspectorControls> | ||
<div | ||
className={ classnames( 'wp-block-section', className, { | ||
'has-background': backgroundColor.color, | ||
[ backgroundColor.class ]: backgroundColor.class, | ||
} ) } | ||
style={ { | ||
backgroundColor: backgroundColor.color, | ||
} } | ||
> | ||
<InnerBlocks /> | ||
</div> | ||
</Fragment> | ||
); | ||
} ), | ||
|
||
save( { attributes } ) { | ||
const { | ||
backgroundColor, | ||
customBackgroundColor, | ||
} = attributes; | ||
|
||
const backgroundClass = getColorClassName( 'background-color', backgroundColor ); | ||
|
||
const className = classnames( { | ||
'has-background': backgroundColor || customBackgroundColor, | ||
[ backgroundClass ]: backgroundClass, | ||
} ); | ||
|
||
return ( | ||
<div className={ className }> | ||
<InnerBlocks.Content /> | ||
</div> | ||
); | ||
}, | ||
}; |
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.
This is just a nitpick, but could the imports be put in alphabetical order?
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.
@ZebulanStanphill I’m waiting to get some feedback on the UX but if we determine to move forward I have a lot of tweaks I’ll make to the code itself. Thanks :)