-
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
New Block: Description List #20760
base: trunk
Are you sure you want to change the base?
New Block: Description List #20760
Changes from all commits
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,17 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
RichText, | ||
__experimentalBlock as Block, | ||
} from '@wordpress/block-editor'; | ||
|
||
export default function Edit( { attributes, setAttributes } ) { | ||
return ( | ||
<RichText | ||
tagName={ Block.dd } | ||
value={ attributes.content } | ||
onChange={ ( content ) => setAttributes( { content } ) } | ||
/> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import edit from './edit'; | ||
import save from './save'; | ||
|
||
export const name = 'core/description-details'; | ||
|
||
export const settings = { | ||
title: __( 'Description Details' ), | ||
parent: [ 'core/description-details' ], | ||
description: __( 'The details of a term.' ), | ||
category: 'layout', | ||
supports: { | ||
className: false, | ||
lightBlockWrapper: true, | ||
}, | ||
edit, | ||
save, | ||
attributes: { | ||
content: { | ||
type: 'string', | ||
source: 'html', | ||
selector: 'dd', | ||
default: '', | ||
}, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { RichText } from '@wordpress/block-editor'; | ||
|
||
export default function Save( { attributes } ) { | ||
return <RichText.Content tagName="dd" value={ attributes.content } />; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
InnerBlocks, | ||
__experimentalBlock as Block, | ||
} from '@wordpress/block-editor'; | ||
|
||
const ALLOWED_BLOCKS = [ 'core/description-term', 'core/description-details' ]; | ||
const TEMPLATE = [ | ||
[ 'core/description-term' ], | ||
[ 'core/description-details' ], | ||
]; | ||
|
||
export default function Edit() { | ||
return ( | ||
<InnerBlocks | ||
allowedBlocks={ ALLOWED_BLOCKS } | ||
template={ TEMPLATE } | ||
__experimentalTagName={ Block.dl } | ||
/> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Undo default editor styles. | ||
.editor-styles-wrapper .block-editor-block-list__block { | ||
&[data-type="core/description-list"], | ||
&[data-type="core/description-term"], | ||
&[data-type="core/description-details"] { | ||
margin-top: 0; | ||
margin-bottom: 0; | ||
} | ||
|
||
&[data-type="core/description-details"] { | ||
margin-inline-start: 40px; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||
/** | ||||||
* WordPress dependencies | ||||||
*/ | ||||||
import { __ } from '@wordpress/i18n'; | ||||||
|
||||||
/** | ||||||
* Internal dependencies | ||||||
*/ | ||||||
import edit from './edit'; | ||||||
import save from './save'; | ||||||
|
||||||
export const name = 'core/description-list'; | ||||||
|
||||||
export const settings = { | ||||||
title: __( 'Description List' ), | ||||||
description: __( 'List groups of terms and descriptions.' ), | ||||||
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.
Suggested change
|
||||||
keywords: [ __( 'list' ), __( 'definitions' ), __( 'terms' ) ], | ||||||
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 don't think |
||||||
category: 'layout', | ||||||
supports: { | ||||||
className: false, | ||||||
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. Why is this set to For consistency, I think we should add color controls to this block if we add them to the List block. |
||||||
lightBlockWrapper: true, | ||||||
}, | ||||||
edit, | ||||||
save, | ||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { InnerBlocks } from '@wordpress/block-editor'; | ||
|
||
export default function Save() { | ||
return ( | ||
<dl> | ||
<InnerBlocks.Content /> | ||
</dl> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
RichText, | ||
__experimentalBlock as Block, | ||
} from '@wordpress/block-editor'; | ||
|
||
export default function Edit( { attributes, setAttributes } ) { | ||
return ( | ||
<RichText | ||
tagName={ Block.dt } | ||
value={ attributes.content } | ||
onChange={ ( content ) => setAttributes( { content } ) } | ||
/> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import edit from './edit'; | ||
import save from './save'; | ||
|
||
export const name = 'core/description-term'; | ||
|
||
export const settings = { | ||
title: __( 'Description Term' ), | ||
parent: [ 'core/description-list' ], | ||
description: __( 'A term in a description list.' ), | ||
category: 'layout', | ||
supports: { | ||
className: false, | ||
lightBlockWrapper: true, | ||
}, | ||
edit, | ||
save, | ||
attributes: { | ||
content: { | ||
type: 'string', | ||
source: 'html', | ||
selector: 'dt', | ||
default: '', | ||
}, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { RichText } from '@wordpress/block-editor'; | ||
|
||
export default function Save( { attributes } ) { | ||
return <RichText.Content tagName="dt" value={ attributes.content } />; | ||
} |
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, the name, and the category should be moved to a
block.json
. (Same with other blocks being added in this PR.)