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 file block #66839

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion packages/block-library/src/file/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
__unstableGetAnimateClassName as getAnimateClassName,
ResizableBox,
ToolbarButton,
Placeholder,
} from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import {
Expand All @@ -24,7 +25,7 @@ import {
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { useEffect, useState } from '@wordpress/element';
import { useCopyToClipboard } from '@wordpress/compose';
import { useCopyToClipboard, useResizeObserver } from '@wordpress/compose';
import { __, _x } from '@wordpress/i18n';
import { file as icon } from '@wordpress/icons';
import { store as coreStore } from '@wordpress/core-data';
Expand Down Expand Up @@ -193,6 +194,11 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {

const displayPreviewInEditor = browserSupportsPdfs() && displayPreview;

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

const isSmallContainer = placeholderWidth && placeholderWidth < 160;

if ( ! href && ! temporaryURL ) {
return (
<div { ...blockProps }>
Expand All @@ -207,6 +213,22 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {
onSelect={ onSelectFile }
onError={ onUploadError }
accept="*"
placeholder={ ( content ) => (
<Placeholder
className="block-editor-media-placeholder"
icon={ icon }
withIllustration={
! isSelected || isSmallContainer
}
label={ ! isSmallContainer && __( 'File' ) }
instructions={ __(
'Drag and drop a file here, upload, or choose from your library.'
) }
>
{ content }
{ placeholderResizeListener }
</Placeholder>
) }
/>
</div>
);
Expand Down
Loading