File component

File component renders a given file, so it can be used in GUI operations such as drag and drop, preview, page browsing, etc.

The file prop has to be a JavaScript object with keys:

An example of a file object property:

{
  id: '1',
  name: 'example.pdf',
  mimetype: 'application/pdf',
  numPages: 5,
  size: 12834,
  content: {
    base64: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYm(...)'
  }
}

PDF File

0
Laster ned PDF...

PDF file renders a page with a default width/height and a folded-corner style.

If the PDF file has additional pages, one can see arrows in the sides of the page, when the mouse hovers the page.

While you can override width and height params, it is easier to set a scale value (scale 1.0 matches a width of 100px and height of 140 px).

<File file={samplePDF} scale={2}/>

Image file

cat.jpg

Image file renders the base64 content of an image with a fixed max-height given my heightproperty (with defaylt 100px as a scale 1.0).

Like the PDF file, you can use the scale property to set the image size while preserving the aspect ratio

<File file={sampleJPG} scale={1.5}/>

Other file

json

Other files renders as a blank page with is extension (derived from filename) as the center title.

<File file={sampleOther} scale={1.5}/>

File context buttons

PDF file renders a page with a default width/height and a folded-corner style.

If the PDF file has additional pages, one can see arrows in the sides of the page, when the mouse hovers the page.

While you can override width and height params, it is easier to set a scale value (scale 1.0 matches a width of 100px and height of 140 px).

2
Laster ned PDF...
<File 
  file={samplePDF}
  buttonsVisibility='always'
  buttonsPosition='inside'
  viewOnePage=true
  initialPage={2}
  showAddButton
  showDeleteButton
  showDownloadButton
  showPreviewButton
  onAddFile={(file) => console.log('onAddFile: ', file)}
  onDeleteFile={(file) => console.log('onDeleteFile: ', file)}
  onDownloadFile={(file) => console.log('onDownloadFile: ', file)}
  onPreviewFile={(file) => console.log('onPreviewFile: ', file)}
  onContentClick={(file) => console.log('onContentClick: ', file)}
  onPreviousPage={(file) => console.log('onPreviousPage: ', file)}
  onNextPage={(file) => console.log('onNextPage: ', file)}
  scale={2}/>

Component import

import File from 'forhandsvisningsfil'

React props

PropertyTypeRequiredDescriptionDefault
animatebooleanfalseAnimate the file renderingtrue
buttonsPositionstringfalseWhen to place context buttons. It can be one of values inside (over the file div) orheader above the file divinside
buttonsVisibilitystringfalseWhen to show context buttons. It can be one of values always (always visible), hover (visible only when hovering file), or nonehover
classNamestringfalseAdditional classnames-
fileobjecttrueFile object. See above for a sample on how the object should be-
heightnumberfalseFile height, in pixels140
highContrastbooleanfalseRender in high contrast theme or notfalse
initialPagenumberfalseSet the intial page for PDF rendering-
labelsobjectfalseOptional label object to override the default labels-
onAddFilefunctionfalseCallback function triggered when the Add button is clicked-
onContentClickfunctionfalseCallback function triggered when the file content is clicked-
onDeleteFilefunctionfalseCallback function triggered when the Delete button is clicked-
onLoadSuccessfunctionfalseCallback function triggered when the file content is loaded (PDF file only)-
onPreviewFilefunctionfalseCallback function triggered when the Preview button is clicked-
onPreviousPagefunctionfalseCallback function triggered when the Previous page button is clicked-
onNextPagefunctionfalseCallback function triggered when the Next page button is clicked-
scalenumberfalseScale of the file1.0
showAddButtonbooleanfalseDisplay toggle for the Add buttonfalse
showDeleteButtonbooleanfalseDisplay toggle for the Delete buttonfalse
showDownloadButtonbooleanfalseDisplay toggle for the Download buttonfalse
showPreviewButtonbooleanfalseDisplay toggle for the Preview buttonfalse
viewOnePagebooleantrueFor PDFs, toggle between view one page at a time, or render all pages at oncetrue
widthnumberfalseFile width, in pixels100