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

feature: add consistant illustrator to audio block #66838

Open
wants to merge 4 commits 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
67 changes: 55 additions & 12 deletions packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
SelectControl,
Spinner,
ToggleControl,
Placeholder,
} from '@wordpress/components';
import {
BlockControls,
BlockIcon,
InspectorControls,
MediaPlaceholder,
MediaReplaceFlow,
Expand All @@ -27,6 +27,7 @@ import { useDispatch } from '@wordpress/data';
import { audio as icon } from '@wordpress/icons';
import { store as noticesStore } from '@wordpress/notices';
import { useState } from '@wordpress/element';
import { useResizeObserver } from '@wordpress/compose';

/**
* Internal dependencies
Expand All @@ -44,6 +45,7 @@ function AudioEdit( {
onReplace,
isSelected: isSingleSelected,
insertBlocksAfter,
blockEditingMode,
} ) {
const { id, autoplay, loop, preload, src } = attributes;
const [ temporaryURL, setTemporaryURL ] = useState( attributes.blob );
Expand Down Expand Up @@ -127,19 +129,60 @@ function AudioEdit( {
className: classes,
} );

const [ placeholderResizeListener, { width: placeholderWidth } ] =
useResizeObserver();

const isSmallContainer = placeholderWidth && placeholderWidth < 160;

const isContentOnlyMode = blockEditingMode === 'contentOnly';
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this? It should not be related to this PR.


const autioReplaceFlow = isSingleSelected && (
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const autioReplaceFlow = isSingleSelected && (
const mediaReplaceFlow = isSingleSelected && (

Additionally, the code here should also be replaced with this component.

<BlockControls group={ isContentOnlyMode ? 'inline' : 'other' }>
<MediaReplaceFlow
name={ ! src ? __( 'Add audio' ) : __( 'Replace' ) }
mediaId={ id }
mediaURL={ src }
allowedTypes={ ALLOWED_MEDIA_TYPES }
accept="audio/*"
onSelect={ onSelectAudio }
onSelectURL={ onSelectURL }
onError={ onUploadError }
onReset={ () => onSelectAudio( undefined ) }
/>
</BlockControls>
);

if ( ! src && ! temporaryURL ) {
return (
<div { ...blockProps }>
<MediaPlaceholder
icon={ <BlockIcon icon={ icon } /> }
onSelect={ onSelectAudio }
onSelectURL={ onSelectURL }
accept="audio/*"
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ attributes }
onError={ onUploadError }
/>
</div>
<>
{ autioReplaceFlow }
<div { ...blockProps }>
<MediaPlaceholder
onSelect={ onSelectAudio }
onSelectURL={ onSelectURL }
accept="audio/*"
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ attributes }
onError={ onUploadError }
placeholder={ ( content ) => (
<Placeholder
className="block-editor-media-placeholder"
icon={ ! isSmallContainer && icon }
withIllustration={
! isSingleSelected || isSmallContainer
}
label={ ! isSmallContainer && __( 'Audio' ) }
instructions={ __(
'Upload or drag an audio file here, or pick one from your library.'
) }
>
{ ! isSmallContainer && content }
{ placeholderResizeListener }
</Placeholder>
) }
/>
</div>
</>
);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/audio/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
margin-top: -9px;
margin-left: -9px;
}

.components-placeholder.has-illustration {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.components-placeholder.has-illustration {
.block-editor-media-placeholder.is-small {

Selectors with the .components- prefix should be avoided where possible.

min-height: 60px;
}
}
Loading