Skip to content
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
18 changes: 18 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,24 @@
"markdown_source": "../packages/block-library/src/cover/README.md",
"parent": "core-blocks-media"
},
{
"title": "Description Detail",
"slug": "core-block-description-detail",
"markdown_source": "../packages/block-library/src/description-detail/README.md",
"parent": "core-blocks-text"
},
{
"title": "Description List",
"slug": "core-block-description-list",
"markdown_source": "../packages/block-library/src/description-list/README.md",
"parent": "core-blocks-text"
},
{
"title": "Description Term",
"slug": "core-block-description-term",
"markdown_source": "../packages/block-library/src/description-term/README.md",
"parent": "core-blocks-text"
},
{
"title": "Details",
"slug": "core-block-details",
Expand Down
29 changes: 29 additions & 0 deletions docs/reference-guides/core-blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,35 @@ Add an image or video with a text overlay.
- **Supports:** align, allowedBlocks, anchor, color (heading, text, ~~background~~, ~~enableContrastChecker~~), dimensions (aspectRatio), filter (duotone), interactivity (clientNavigation), layout (~~allowJustification~~), shadow, spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** allowedVideoProviders, alt, backgroundType, contentPosition, customGradient, customOverlayColor, dimRatio, focalPoint, gradient, hasParallax, id, isDark, isRepeated, isUserOverlayColor, minHeight, minHeightUnit, overlayColor, poster, sizeSlug, tagName, templateLock, url, useFeaturedImage

## Description Detail

Add a description to a term.

- **Name:** [core/description-detail](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-description-detail/)
- **Category:** [text](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/)
- **Parent:** core/description-list
- **Supports:** anchor, color (background, gradients, link, text), interactivity (clientNavigation), spacing (margin, padding), splitting, typography (fontSize, lineHeight), ~~className~~, ~~html~~
- **Attributes:** content, placeholder

## Description List

Create a list of terms and descriptions.

- **Name:** [core/description-list](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-description-list/)
- **Category:** [text](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/)
- **Allowed Blocks:** core/description-term, core/description-detail
- **Supports:** __unstablePasteTextInline, anchor, color (background, gradients, link, text), listView, spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~

## Description Term

Add a term to a description list.

- **Name:** [core/description-term](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-description-term/)
- **Category:** [text](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/)
- **Parent:** core/description-list
- **Supports:** anchor, color (background, gradients, link, text), interactivity (clientNavigation), spacing (margin, padding), splitting, typography (fontSize, lineHeight), ~~className~~, ~~html~~
- **Attributes:** content, placeholder

## Details

Hide and show additional content.
Expand Down
3 changes: 3 additions & 0 deletions docs/reference-guides/core-blocks/category-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

<!-- START TOKEN(Autogenerated block API docs) -->
- [Code](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-code/) — `core/code`: Display code snippets that respect your spacing and tabs.
- [Description Detail](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-description-detail/) — `core/description-detail`: Add a description to a term.
- [Description List](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-description-list/) — `core/description-list`: Create a list of terms and descriptions.
- [Description Term](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-description-term/) — `core/description-term`: Add a term to a description list.
- [Details](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-details/) — `core/details`: Hide and show additional content.
- [Footnotes](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-footnotes/) — `core/footnotes`: Display footnotes added to the page.
- [Classic](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-freeform/) — `core/freeform`: Use the classic WordPress editor.
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Remove the experimental Form, Input Field, Form Submit Button, and Form Submission Notification blocks, along with the "Form and input blocks" experiment that gated them.

### New Features

- Add Description List, Description Term, and Description Detail blocks.

### Enhancements

- Math: Declare `interactivity.clientNavigation` support. The block's front end output is static markup, and without the declaration a Math block inside a Query block forced full page reloads on pagination ([#82248](https://github.com/WordPress/gutenberg/pull/82248)).
Expand Down
68 changes: 68 additions & 0 deletions packages/block-library/src/description-detail/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Description Detail

<!-- START TOKEN(Autogenerated block API docs) -->
Add a description to a term.

- **Name:** `core/description-detail`
- **Category:** [text](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/)
- **API Version:** [3](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/)
- **Block Type:** Unknown

## Block Relationships

**[Parent](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#parent) blocks (direct):**
- [`core/description-list`](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-description-list/)

## Attributes

_Defined via the [`attributes`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/) property in block.json._

| Attribute | [Type](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#type-validation) | [Default](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#default-value) | Description |
|-----------|------|---------|-------------|
| `placeholder` | `string` | — | — |
| `content` | `rich-text` | — | [Source](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#value-source): `rich-text`. [Selector](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#value-source): `dd`. [Role](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#role): `content` |

## Supports

_Defined via the [`supports`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/) property in block.json._

- [`anchor`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#anchor): `true`
- [`html`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#html): `false`
- [`className`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#classname): `false`
- [`splitting`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#splitting): `true`
- [`color`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color):
- [`gradients`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color-gradients): `true`
- [`link`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color-link): `true`
- [`background`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color-background): `true`
- [`spacing`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#spacing):
- `margin`: `true`
- `padding`: `true`
- [`typography`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#typography):
- [`fontSize`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#typography-fontsize): `true`
- [`lineHeight`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#typography-lineheight): `true`
- [`interactivity`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#interactivity):
- `clientNavigation`: `true`

## CSS Selectors

_Defined via the [`selectors`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-selectors/) property in block.json._

- **root**: `.wp-block-description-list > dd`
- **border**: `.wp-block-description-list > dd`

## Block Markup

This is a [**static block**](https://developer.wordpress.org/block-editor/getting-started/fundamentals/static-dynamic-rendering/). The markup is saved directly in the post content.

```html
<!-- wp:description-detail -->
<dd>Description</dd>
<!-- /wp:description-detail -->
```

## Source

- [block.json](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/description-detail/block.json) ([reference](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/))
- [Source directory](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/description-detail/) — browse the `edit` and `save` source files, `index.php`, and more.
Comment thread
coderabbitai[bot] marked this conversation as resolved.

<!-- END TOKEN(Autogenerated block API docs) -->
69 changes: 69 additions & 0 deletions packages/block-library/src/description-detail/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "core/description-detail",
"title": "Description Detail",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps we should call it Definition Description?

"category": "text",
"parent": [ "core/description-list" ],
"description": "Add a description to a term.",
"textdomain": "default",
"attributes": {
"placeholder": {
"type": "string"
},
"content": {
"type": "rich-text",
"source": "rich-text",
"selector": "dd",
"role": "content"
}
},
"supports": {
"anchor": true,
"html": false,
"className": false,
"splitting": true,
"__experimentalBorder": {
"color": true,
"radius": true,
"style": true,
"width": true
},
"color": {
"gradients": true,
"link": true,
"background": true,
"__experimentalDefaultControls": {
"text": true
}
},
"spacing": {
"margin": true,
"padding": true,
"__experimentalDefaultControls": {
"margin": false,
"padding": false
}
},
"typography": {
"fontSize": true,
"lineHeight": true,
"__experimentalFontFamily": true,
"__experimentalFontWeight": true,
"__experimentalFontStyle": true,
"__experimentalTextTransform": true,
"__experimentalTextDecoration": true,
"__experimentalLetterSpacing": true,
"__experimentalDefaultControls": {
"fontSize": true
}
},
"interactivity": {
"clientNavigation": true
}
},
"selectors": {
"root": ".wp-block-description-list > dd",
"border": ".wp-block-description-list > dd"
}
}
58 changes: 58 additions & 0 deletions packages/block-library/src/description-detail/edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { __ } from '@wordpress/i18n';
// @ts-expect-error `@wordpress/block-editor` does not expose type declarations for its entry point.
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { useMergeRefs } from '@wordpress/compose';
import type { BlockEditProps, Block } from '@wordpress/blocks';
import type { RichTextData } from '@wordpress/rich-text';
import useKeyboardTransform from '../description-term/use-keyboard-transform';

type DescriptionListItemAttributes = {
content: string | RichTextData;
placeholder?: string;
};

type DescriptionListItemEditProps =
BlockEditProps< DescriptionListItemAttributes > & {
mergeBlocks?: ( clientIdA: string, clientIdB: string ) => void;
onReplace?: (
blocks: Block[],
indexToSelect?: number,
initialPosition?: number
) => void;
onRemove?: () => void;
};

export default function Edit( {
attributes,
setAttributes,
mergeBlocks,
onReplace,
onRemove,
clientId,
}: DescriptionListItemEditProps ) {
const { content, placeholder } = attributes;
const blockProps = useBlockProps();
const keyboardTransformRef = useKeyboardTransform( {
attributes,
blockName: 'core/description-detail',
clientId,
} );
const ref = useMergeRefs( [ blockProps.ref, keyboardTransformRef ] );

return (
<RichText
identifier="content"
tagName="dd"
{ ...blockProps }
ref={ ref }
value={ content }
onChange={ ( newContent: string ) =>
setAttributes( { content: newContent } )
}
onMerge={ mergeBlocks }
onReplace={ onReplace }
onRemove={ onRemove }
placeholder={ placeholder || __( 'Description' ) }
/>
);
}
38 changes: 38 additions & 0 deletions packages/block-library/src/description-detail/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { listItem as icon } from '@wordpress/icons';
import initBlock from '../utils/init-block';
import edit from './edit';
import metadata from './block.json';
import save from './save';
import transforms from './transforms';

const { name } = metadata;

export { metadata, name };

export const settings = {
icon,
edit,
save,
merge( attributes, attributesToMerge ) {
return {
...attributes,
content: attributes.content + attributesToMerge.content,
};
},
transforms,
__experimentalLabel( attributes, { context } ) {
const { content } = attributes;
const customName = attributes?.metadata?.name;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This all seems a little odd. Isn't this handled by the editor? Are other blocks doing this?

const hasContent = content?.trim().length > 0;

if ( context === 'list-view' && ( customName || hasContent ) ) {
return customName || content;
}

if ( context === 'breadcrumb' && customName ) {
return customName;
}
},
};

export const init = () => initBlock( { name, metadata, settings } );
3 changes: 3 additions & 0 deletions packages/block-library/src/description-detail/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { init } from './';

export default init();
19 changes: 19 additions & 0 deletions packages/block-library/src/description-detail/save.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @ts-expect-error `@wordpress/block-editor` does not expose type declarations for its entry point.
import { RichText, useBlockProps } from '@wordpress/block-editor';
import type { BlockSaveProps } from '@wordpress/blocks';
import type { RichTextData } from '@wordpress/rich-text';

type DescriptionListItemAttributes = {
content: string | RichTextData;
placeholder?: string;
};

export default function save( {
attributes,
}: BlockSaveProps< DescriptionListItemAttributes > ) {
return (
<dd { ...useBlockProps.save() }>
<RichText.Content value={ attributes.content } />
</dd>
);
}
14 changes: 14 additions & 0 deletions packages/block-library/src/description-detail/transforms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createBlock } from '@wordpress/blocks';

const transforms = {
to: [
{
type: 'block',
blocks: [ 'core/description-term' ],
transform: ( attributes ) =>
createBlock( 'core/description-term', attributes ),
},
],
};

export default transforms;
Loading
Loading