File.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import styled from 'styled-components'
  2. import { endpoint } from '../config'
  3. const FileStyle = styled.div`
  4. display: grid;
  5. grid-template-columns: 250px 100px 1fr;
  6. grid-auto-flow: dense;
  7. align-items: start;
  8. justify-items: start;
  9. align-content: start;
  10. justify-content: start;
  11. a,
  12. img {
  13. grid-row: span 6;
  14. max-width: 230px;
  15. max-height: 140px;
  16. justify-self: center;
  17. }
  18. h2 {
  19. grid-column: span 2;
  20. margin: 0 0 0.5em 0;
  21. line-height: 1;
  22. }
  23. .description {
  24. grid-column: span 2;
  25. }
  26. p {
  27. margin: 0;
  28. line-height: 1.5;
  29. }
  30. `
  31. const FileFields = {
  32. id: null,
  33. name: '',
  34. description: '',
  35. file: null
  36. }
  37. const FileFormFields = props => {
  38. const { state, onChange } = props
  39. return (
  40. <fieldset>
  41. <label htmlFor='name'>Name</label>
  42. <input type='text' name='name' id='name' placeholder='Name'
  43. value={state.name}
  44. onChange={onChange} />
  45. <label htmlFor='description'>Description</label>
  46. <textarea name='description' id='description' placeholder='Description'
  47. value={state.description}
  48. onChange={onChange} />
  49. <input type='file' name='file' onChange={onChange} />
  50. </fieldset>
  51. )
  52. }
  53. const File = props => {
  54. const { path, name, description, filename, mimetype, size } = props.data
  55. const downloadPath = `${endpoint}/${path}`
  56. return (
  57. <FileStyle>
  58. {mimetype.startsWith('image/') ? (
  59. <img src={downloadPath} alt={description} />
  60. ) : (
  61. <a href={downloadPath}>
  62. <img src={`${endpoint}/static/document-download-solid.png`} alt={description} width={75} />
  63. </a>
  64. )}
  65. <h2>{name}</h2>
  66. <p className='description'>{description}</p>
  67. <p>Path</p><p><a href={downloadPath}>{downloadPath}</a></p>
  68. <p>Filename</p><p>{filename}</p>
  69. <p>MIME Type</p><p>{mimetype}</p>
  70. <p>Size</p><p>{size}</p>
  71. </FileStyle>
  72. )
  73. }
  74. export default File
  75. export { FileFormFields }