All Downloads are FREE. Search and download functionalities are using the official Maven repository.

components.form.fields.content.ContentPreview.tsx Maven / Gradle / Ivy

import { Content } from 'helpers/content';
import { useState } from 'react';
// @ts-ignore
import { defaultStyles, FileIcon } from 'react-file-icon';

import { previewable } from './utils';

const ContentPreview = ({content, fallback}: {content: Content, fallback?: JSX.Element}) => {
  const [error, setError] = useState(false)
  const extension         = content.extension
  const style             = defaultStyles.hasOwnProperty(extension) ? defaultStyles[extension] : {}
  const defaultPreview    = fallback ? fallback : 

  if (!content.hasData || error || !previewable(content))
      return defaultPreview

  switch (true) {
    case content.type.startsWith("image/") :
      return (
         { console.error("Unable to load preview image for file: %o", content); setError(true) }}
        />
      )

    default:
      return defaultPreview
  }
}

export default ContentPreview




© 2015 - 2024 Weber Informatics LLC | Privacy Policy