index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. const { h } = require('preact')
  2. const copyToClipboard = require('../../../utils/copyToClipboard')
  3. function EditButton ({
  4. file,
  5. uploadInProgressOrComplete,
  6. metaFields,
  7. i18n,
  8. onClick
  9. }) {
  10. if (!uploadInProgressOrComplete &&
  11. metaFields &&
  12. metaFields.length > 0) {
  13. return (
  14. <button
  15. class="uppy-u-reset uppy-Dashboard-Item-action uppy-Dashboard-Item-action--edit"
  16. type="button"
  17. aria-label={i18n('editFile') + ' ' + file.meta.name}
  18. title={i18n('editFile')}
  19. onclick={() => onClick()}
  20. >
  21. <svg aria-hidden="true" focusable="false" class="uppy-c-icon" width="14" height="14" viewBox="0 0 14 14">
  22. <g fill-rule="evenodd">
  23. <path d="M1.5 10.793h2.793A1 1 0 0 0 5 10.5L11.5 4a1 1 0 0 0 0-1.414L9.707.793a1 1 0 0 0-1.414 0l-6.5 6.5A1 1 0 0 0 1.5 8v2.793zm1-1V8L9 1.5l1.793 1.793-6.5 6.5H2.5z" fill-rule="nonzero" />
  24. <rect x="1" y="12.293" width="11" height="1" rx=".5" />
  25. <path fill-rule="nonzero" d="M6.793 2.5L9.5 5.207l.707-.707L7.5 1.793z" />
  26. </g>
  27. </svg>
  28. </button>
  29. )
  30. }
  31. return null
  32. }
  33. function RemoveButton ({ i18n, onClick }) {
  34. return (
  35. <button
  36. class="uppy-u-reset uppy-Dashboard-Item-action uppy-Dashboard-Item-action--remove"
  37. type="button"
  38. aria-label={i18n('removeFile')}
  39. title={i18n('removeFile')}
  40. onclick={() => onClick()}
  41. >
  42. <svg aria-hidden="true" focusable="false" class="uppy-c-icon" width="18" height="18" viewBox="0 0 18 18">
  43. <path d="M9 0C4.034 0 0 4.034 0 9s4.034 9 9 9 9-4.034 9-9-4.034-9-9-9z" />
  44. <path fill="#FFF" d="M13 12.222l-.778.778L9 9.778 5.778 13 5 12.222 8.222 9 5 5.778 5.778 5 9 8.222 12.222 5l.778.778L9.778 9z" />
  45. </svg>
  46. </button>
  47. )
  48. }
  49. const copyLinkToClipboard = (event, props) => {
  50. copyToClipboard(props.file.uploadURL, props.i18n('copyLinkToClipboardFallback'))
  51. .then(() => {
  52. props.log('Link copied to clipboard.')
  53. props.info(props.i18n('copyLinkToClipboardSuccess'), 'info', 3000)
  54. })
  55. .catch(props.log)
  56. // avoid losing focus
  57. .then(() => event.target.focus({ preventScroll: true }))
  58. }
  59. function CopyLinkButton (props) {
  60. return (
  61. <button
  62. class="uppy-u-reset uppy-Dashboard-Item-action uppy-Dashboard-Item-action--copyLink"
  63. type="button"
  64. aria-label={props.i18n('copyLink')}
  65. title={props.i18n('copyLink')}
  66. onclick={(event) => copyLinkToClipboard(event, props)}
  67. >
  68. <svg aria-hidden="true" focusable="false" class="uppy-c-icon" width="14" height="14" viewBox="0 0 14 12">
  69. <path d="M7.94 7.703a2.613 2.613 0 0 1-.626 2.681l-.852.851a2.597 2.597 0 0 1-1.849.766A2.616 2.616 0 0 1 2.764 7.54l.852-.852a2.596 2.596 0 0 1 2.69-.625L5.267 7.099a1.44 1.44 0 0 0-.833.407l-.852.851a1.458 1.458 0 0 0 1.03 2.486c.39 0 .755-.152 1.03-.426l.852-.852c.231-.231.363-.522.406-.824l1.04-1.038zm4.295-5.937A2.596 2.596 0 0 0 10.387 1c-.698 0-1.355.272-1.849.766l-.852.851a2.614 2.614 0 0 0-.624 2.688l1.036-1.036c.041-.304.173-.6.407-.833l.852-.852c.275-.275.64-.426 1.03-.426a1.458 1.458 0 0 1 1.03 2.486l-.852.851a1.442 1.442 0 0 1-.824.406l-1.04 1.04a2.596 2.596 0 0 0 2.683-.628l.851-.85a2.616 2.616 0 0 0 0-3.697zm-6.88 6.883a.577.577 0 0 0 .82 0l3.474-3.474a.579.579 0 1 0-.819-.82L5.355 7.83a.579.579 0 0 0 0 .819z" />
  70. </svg>
  71. </button>
  72. )
  73. }
  74. module.exports = function Buttons (props) {
  75. const {
  76. file,
  77. uploadInProgressOrComplete,
  78. metaFields,
  79. showLinkToFileUploadResult,
  80. showRemoveButton,
  81. i18n,
  82. removeFile,
  83. toggleFileCard,
  84. log,
  85. info
  86. } = props
  87. return (
  88. <div className="uppy-Dashboard-Item-actionWrapper">
  89. <EditButton
  90. i18n={i18n}
  91. file={file}
  92. uploadInProgressOrComplete={uploadInProgressOrComplete}
  93. metaFields={metaFields}
  94. onClick={() => toggleFileCard(file.id)}
  95. />
  96. {showLinkToFileUploadResult && file.uploadURL ? (
  97. <CopyLinkButton
  98. file={file}
  99. i18n={i18n}
  100. info={info}
  101. log={log}
  102. />
  103. ) : null}
  104. {showRemoveButton ? (
  105. <RemoveButton
  106. i18n={i18n}
  107. info={props.info}
  108. log={props.log}
  109. onClick={() => removeFile(file.id)}
  110. />
  111. ) : null}
  112. </div>
  113. )
  114. }