Skip to content
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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ const elements = [
'ol',
'ul',
'figure',
'dl',
'dt',
'dd',
];

const ExtendedBlockComponent = elements.reduce( ( acc, element ) => {
Expand Down
17 changes: 17 additions & 0 deletions packages/block-library/src/description-details/edit.js
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 } ) }
/>
);
}
33 changes: 33 additions & 0 deletions packages/block-library/src/description-details/index.js
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: {
Copy link
Member

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.)

content: {
type: 'string',
source: 'html',
selector: 'dd',
default: '',
},
},
};
8 changes: 8 additions & 0 deletions packages/block-library/src/description-details/save.js
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 } />;
}
23 changes: 23 additions & 0 deletions packages/block-library/src/description-list/edit.js
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 }
/>
);
}
13 changes: 13 additions & 0 deletions packages/block-library/src/description-list/editor.scss
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;
}
}
25 changes: 25 additions & 0 deletions packages/block-library/src/description-list/index.js
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.' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: __( 'List groups of terms and descriptions.' ),
description: __( 'List of terms and their descriptions.' ),

keywords: [ __( 'list' ), __( 'definitions' ), __( 'terms' ) ],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think list is a necessary keyword when the title already includes that word. Maybe glossary would be a better keyword to use here?

category: 'layout',
supports: {
className: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this set to false?

For consistency, I think we should add color controls to this block if we add them to the List block.

lightBlockWrapper: true,
},
edit,
save,
};
12 changes: 12 additions & 0 deletions packages/block-library/src/description-list/save.js
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>
);
}
17 changes: 17 additions & 0 deletions packages/block-library/src/description-term/edit.js
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 } ) }
/>
);
}
33 changes: 33 additions & 0 deletions packages/block-library/src/description-term/index.js
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: '',
},
},
};
8 changes: 8 additions & 0 deletions packages/block-library/src/description-term/save.js
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 } />;
}
1 change: 1 addition & 0 deletions packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@import "./code/editor.scss";
@import "./columns/editor.scss";
@import "./cover/editor.scss";
@import "./description-list/editor.scss";
@import "./embed/editor.scss";
@import "./file/editor.scss";
@import "./classic/editor.scss";
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import * as code from './code';
import * as columns from './columns';
import * as column from './column';
import * as cover from './cover';
import * as descriptionList from './description-list';
import * as descriptionTerm from './description-term';
import * as descriptionDetails from './description-details';
import * as embed from './embed';
import * as file from './file';
import * as html from './html';
Expand Down Expand Up @@ -125,6 +128,9 @@ export const registerCoreBlocks = () => {
columns,
column,
cover,
descriptionList,
descriptionTerm,
descriptionDetails,
embed,
...embed.common,
...embed.others,
Expand Down