import clsx from 'clsx'; import { RichText, useBlockProps, __experimentalGetElementClassName, } from '@wordpress/block-editor'; import type { BlockSaveProps } from '@wordpress/blocks'; import type { FileAttributes } from './types'; export default function save( { attributes, }: BlockSaveProps< FileAttributes > ) { const { href, fileId, fileName, textLinkHref, textLinkTarget, showDownloadButton, downloadButtonText, displayPreview, previewHeight, } = attributes; const pdfEmbedLabel = RichText.isEmpty( fileName ) ? 'PDF embed' : // To do: use toPlainText, but we need ensure it's RichTextData. See // https://github.com/WordPress/gutenberg/pull/56710. fileName!.toString(); const hasFilename = ! RichText.isEmpty( fileName ); // Only output an `aria-describedby` when the element it's referring to is // actually rendered. const describedById = hasFilename ? fileId : undefined; // Leave out a download button without text, which would be a link without // an accessible name. const hasDownloadButton = showDownloadButton && ! RichText.isEmpty( downloadButtonText ); return ( href && (
{ displayPreview && ( <> ) } { hasFilename && ( ) } { hasDownloadButton && ( ) } ) ); }