Skip to content

Commit

Permalink
replace static class name with calls to __experimentalGetElementClass…
Browse files Browse the repository at this point in the history
…Name
  • Loading branch information
scruffian committed Jun 16, 2022
1 parent d4718ba commit d4ab54e
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 24 deletions.
1 change: 1 addition & 0 deletions lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class WP_Theme_JSON_6_1 extends WP_Theme_JSON_6_0 {
const __EXPERIMENTAL_ELEMENT_CLASS_NAMES = array(
'button' => 'wp-element-button',
'caption' => 'wp-element-caption',
);

/**
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/elements/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ELEMENT_CLASS_NAMES = {
button: 'wp-element-button',
caption: 'wp-element-caption',
};

export const __experimentalGetElementClassName = ( element ) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
RichText,
useBlockProps,
store as blockEditorStore,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { useEffect } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
Expand Down Expand Up @@ -200,7 +201,9 @@ function AudioEdit( {
{ ( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
tagName="figcaption"
className="wp-element-caption"
className={ __experimentalGetElementClassName(
'caption'
) }
aria-label={ __( 'Audio caption text' ) }
placeholder={ __( 'Add caption' ) }
value={ caption }
Expand Down
10 changes: 8 additions & 2 deletions packages/block-library/src/audio/save.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import {
RichText,
useBlockProps,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { autoplay, caption, loop, preload, src } = attributes;
Expand All @@ -20,7 +24,9 @@ export default function save( { attributes } ) {
<RichText.Content
tagName="figcaption"
value={ caption }
className="wp-element-caption"
className={ __experimentalGetElementClassName(
'caption'
) }
/>
) }
</figure>
Expand Down
10 changes: 8 additions & 2 deletions packages/block-library/src/embed/embed-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import classnames from 'classnames/dedupe';
*/
import { __, sprintf } from '@wordpress/i18n';
import { Placeholder, SandBox } from '@wordpress/components';
import { RichText, BlockIcon } from '@wordpress/block-editor';
import {
RichText,
BlockIcon,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { Component } from '@wordpress/element';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';

Expand Down Expand Up @@ -140,7 +144,9 @@ class EmbedPreview extends Component {
{ ( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
tagName="figcaption"
className="wp-element-caption"
className={ __experimentalGetElementClassName(
'caption'
) }
placeholder={ __( 'Add caption' ) }
value={ caption }
onChange={ onCaptionChange }
Expand Down
8 changes: 6 additions & 2 deletions packages/block-library/src/embed/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import classnames from 'classnames/dedupe';
/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import {
RichText,
useBlockProps,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { url, caption, type, providerNameSlug } = attributes;
Expand All @@ -28,7 +32,7 @@ export default function save( { attributes } ) {
</div>
{ ! RichText.isEmpty( caption ) && (
<RichText.Content
className="wp-element-caption"
className={ __experimentalGetElementClassName( 'caption' ) }
tagName="figcaption"
value={ caption }
/>
Expand Down
11 changes: 9 additions & 2 deletions packages/block-library/src/gallery/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { RichText, useInnerBlocksProps } from '@wordpress/block-editor';
import {
RichText,
useInnerBlocksProps,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { VisuallyHidden } from '@wordpress/components';
import { useState, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -82,7 +86,10 @@ export const Gallery = ( props ) => {
captionFocused={ captionFocused }
onFocusCaption={ onFocusCaption }
tagName="figcaption"
className="blocks-gallery-caption wp-element-caption"
className={ classnames(
'blocks-gallery-caption',
__experimentalGetElementClassName( 'caption' )
) }
aria-label={ __( 'Gallery caption text' ) }
placeholder={ __( 'Write gallery caption…' ) }
value={ caption }
Expand Down
6 changes: 5 additions & 1 deletion packages/block-library/src/gallery/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
RichText,
useBlockProps,
useInnerBlocksProps,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';

/**
Expand Down Expand Up @@ -39,7 +40,10 @@ export default function saveWithInnerBlocks( { attributes } ) {
{ ! RichText.isEmpty( caption ) && (
<RichText.Content
tagName="figcaption"
className="blocks-gallery-caption wp-element-caption"
className={ classnames(
'blocks-gallery-caption',
__experimentalGetElementClassName( 'caption' )
) }
value={ caption }
/>
) }
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/gallery/v1/gallery-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
RichText,
MediaPlaceholder,
store as blockEditorStore,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { isBlobURL } from '@wordpress/blob';
import { compose } from '@wordpress/compose';
Expand Down Expand Up @@ -245,7 +246,9 @@ class GalleryImage extends Component {
{ ! isEditing && ( isSelected || caption ) && (
<RichText
tagName="figcaption"
className="wp-element-caption"
className={ __experimentalGetElementClassName(
'caption'
) }
aria-label={ __( 'Image caption text' ) }
placeholder={ isSelected ? __( 'Add caption' ) : null }
value={ caption }
Expand Down
10 changes: 8 additions & 2 deletions packages/block-library/src/gallery/v1/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import {
RichText,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { VisuallyHidden } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
Expand Down Expand Up @@ -94,7 +97,10 @@ export const Gallery = ( props ) => {
<RichTextVisibilityHelper
isHidden={ ! isSelected && RichText.isEmpty( caption ) }
tagName="figcaption"
className="blocks-gallery-caption wp-element-caption"
className={ classnames(
'blocks-gallery-caption',
__experimentalGetElementClassName( 'caption' )
) }
aria-label={ __( 'Gallery caption text' ) }
placeholder={ __( 'Write gallery caption…' ) }
value={ caption }
Expand Down
23 changes: 20 additions & 3 deletions packages/block-library/src/gallery/v1/save.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import {
RichText,
useBlockProps,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';

/**
* Internal dependencies
Expand Down Expand Up @@ -60,7 +69,12 @@ export default function saveV1( { attributes } ) {
{ ! RichText.isEmpty( image.caption ) && (
<RichText.Content
tagName="figcaption"
className="blocks-gallery-item__caption wp-element-caption"
className={ classnames(
'blocks-gallery-item',
__experimentalGetElementClassName(
'caption'
)
) }
value={ image.caption }
/>
) }
Expand All @@ -72,7 +86,10 @@ export default function saveV1( { attributes } ) {
{ ! RichText.isEmpty( caption ) && (
<RichText.Content
tagName="figcaption"
className="blocks-gallery-caption wp-element-caption"
className={ classnames(
'blocks-gallery-caption',
__experimentalGetElementClassName( 'caption' )
) }
value={ caption }
/>
) }
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
BlockAlignmentControl,
__experimentalImageEditor as ImageEditor,
__experimentalImageEditingProvider as ImageEditingProvider,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { useEffect, useMemo, useState, useRef } from '@wordpress/element';
import { __, sprintf, isRTL } from '@wordpress/i18n';
Expand Down Expand Up @@ -576,7 +577,7 @@ export default function Image( {
{ img }
{ ( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
className="wp-element-caption"
className={ __experimentalGetElementClassName( 'caption' ) }
ref={ captionRef }
tagName="figcaption"
aria-label={ __( 'Image caption text' ) }
Expand Down
8 changes: 6 additions & 2 deletions packages/block-library/src/image/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { isEmpty } from 'lodash';
/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import {
RichText,
useBlockProps,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const {
Expand Down Expand Up @@ -61,7 +65,7 @@ export default function save( { attributes } ) {
) }
{ ! RichText.isEmpty( caption ) && (
<RichText.Content
className="wp-element-caption"
className={ __experimentalGetElementClassName( 'caption' ) }
tagName="figcaption"
value={ caption }
/>
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/table/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
useBlockProps,
__experimentalUseColorProps as useColorProps,
__experimentalUseBorderProps as useBorderProps,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import {
Expand Down Expand Up @@ -509,7 +510,7 @@ function TableEdit( {
{ ! isEmpty && (
<RichText
tagName="figcaption"
className="wp-element-caption"
className={ __experimentalGetElementClassName( 'caption' ) }
aria-label={ __( 'Table caption text' ) }
placeholder={ __( 'Add caption' ) }
value={ caption }
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/table/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useBlockProps,
__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,
__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
Expand Down Expand Up @@ -85,7 +86,7 @@ export default function save( { attributes } ) {
<RichText.Content
tagName="figcaption"
value={ caption }
className="wp-element-caption"
className={ __experimentalGetElementClassName( 'caption' ) }
/>
) }
</figure>
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
RichText,
useBlockProps,
store as blockEditorStore,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { useRef, useEffect } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
Expand Down Expand Up @@ -266,7 +267,9 @@ function VideoEdit( {
{ ( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
tagName="figcaption"
className="wp-element-caption"
className={ __experimentalGetElementClassName(
'caption'
) }
aria-label={ __( 'Video caption text' ) }
placeholder={ __( 'Add caption' ) }
value={ caption }
Expand Down
8 changes: 6 additions & 2 deletions packages/block-library/src/video/save.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import {
RichText,
useBlockProps,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';

/**
* Internal dependencies
Expand Down Expand Up @@ -39,7 +43,7 @@ export default function save( { attributes } ) {
) }
{ ! RichText.isEmpty( caption ) && (
<RichText.Content
className="wp-element-caption"
className={ __experimentalGetElementClassName( 'caption' ) }
tagName="figcaption"
value={ caption }
/>
Expand Down

0 comments on commit d4ab54e

Please sign in to comment.