-
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.
List block v2: Add start, ordered and reversed list block attributes (#…
- Loading branch information
1 parent
3983ca4
commit 04265cc
Showing
2 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
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,18 +1,77 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor'; | ||
import { | ||
BlockControls, | ||
useBlockProps, | ||
useInnerBlocksProps, | ||
} from '@wordpress/block-editor'; | ||
import { ToolbarButton } from '@wordpress/components'; | ||
import { isRTL, __ } from '@wordpress/i18n'; | ||
import { | ||
formatListBullets, | ||
formatListBulletsRTL, | ||
formatListNumbered, | ||
formatListNumberedRTL, | ||
} from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import OrderedListSettings from '../ordered-list-settings'; | ||
|
||
const TEMPLATE = [ [ 'core/list-item' ] ]; | ||
|
||
function Edit() { | ||
function Edit( { attributes, setAttributes } ) { | ||
const blockProps = useBlockProps(); | ||
const innerBlocksProps = useInnerBlocksProps( blockProps, { | ||
allowedBlocks: [ 'core/list-item' ], | ||
template: TEMPLATE, | ||
} ); | ||
const { ordered, reversed, start } = attributes; | ||
const TagName = ordered ? 'ol' : 'ul'; | ||
|
||
const controls = ( | ||
<BlockControls group="block"> | ||
<ToolbarButton | ||
icon={ isRTL() ? formatListBulletsRTL : formatListBullets } | ||
title={ __( 'Unordered' ) } | ||
describedBy={ __( 'Convert to unordered list' ) } | ||
isActive={ ordered === false } | ||
onClick={ () => { | ||
setAttributes( { ordered: false } ); | ||
} } | ||
/> | ||
<ToolbarButton | ||
icon={ isRTL() ? formatListNumberedRTL : formatListNumbered } | ||
title={ __( 'Ordered' ) } | ||
describedBy={ __( 'Convert to ordered list' ) } | ||
isActive={ ordered === true } | ||
onClick={ () => { | ||
setAttributes( { ordered: true } ); | ||
} } | ||
/> | ||
</BlockControls> | ||
); | ||
|
||
return <ul { ...innerBlocksProps } />; | ||
return ( | ||
<> | ||
<TagName | ||
reversed={ reversed } | ||
start={ start } | ||
{ ...innerBlocksProps } | ||
/> | ||
{ controls } | ||
{ ordered && ( | ||
<OrderedListSettings | ||
setAttributes={ setAttributes } | ||
ordered={ ordered } | ||
reversed={ reversed } | ||
start={ start } | ||
/> | ||
) } | ||
</> | ||
); | ||
} | ||
|
||
export default Edit; |
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