const { h, Fragment } = require('preact') const prettierBytes = require('@transloadit/prettier-bytes') const truncateString = require('@uppy/utils/lib/truncateString') const MetaErrorMessage = require('../MetaErrorMessage') const renderFileName = (props) => { const { author, name } = props.file.meta function getMaxNameLength () { if (props.containerWidth <= 352) { return 35 } if (props.containerWidth <= 576) { return 60 } // When `author` is present, we want to make sure // the file name fits on one line so we can place // the author on the second line. return author ? 20 : 30 } return (
{truncateString(name, getMaxNameLength())}
) } const renderAuthor = (props) => { const { author } = props.file.meta const { providerName } = props.file.remote const dot = `\u00B7` if (!author) { return null } return (
{truncateString(author.name, 13)} {providerName ? ( {` ${dot} `} {providerName} ) : null}
) } const renderFileSize = (props) => props.file.size && (
{prettierBytes(props.file.size)}
) const ReSelectButton = (props) => props.file.isGhost && ( {' \u2022 '} ) const ErrorButton = ({ file, onClick }) => { if (file.error) { return ( ) } return null } module.exports = function FileInfo (props) { const { file } = props return (
{renderFileName(props)} alert(props.file.error)} // TODO: move to a custom alert implementation />
{renderAuthor(props)} {renderFileSize(props)} {ReSelectButton(props)}
) }