AddFiles.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. const ActionBrowseTagline = require('./ActionBrowseTagline')
  2. const { localIcon } = require('./icons')
  3. const { h, Component } = require('preact')
  4. const poweredByUppy = (props) => {
  5. return <a tabindex="-1" href="https://uppy.io" rel="noreferrer noopener" target="_blank" class="uppy-Dashboard-poweredBy">Powered by <svg aria-hidden="true" class="UppyIcon uppy-Dashboard-poweredByIcon" width="11" height="11" viewBox="0 0 11 11" xmlns="http://www.w3.org/2000/svg">
  6. <path d="M7.365 10.5l-.01-4.045h2.612L5.5.806l-4.467 5.65h2.604l.01 4.044h3.718z" fill-rule="evenodd" />
  7. </svg><span class="uppy-Dashboard-poweredByUppy">Uppy</span></a>
  8. }
  9. class AddFiles extends Component {
  10. constructor (props) {
  11. super(props)
  12. this.handleClick = this.handleClick.bind(this)
  13. }
  14. handleClick (ev) {
  15. this.input.click()
  16. }
  17. render () {
  18. const hasAcquirers = this.props.acquirers.length !== 0
  19. if (!hasAcquirers) {
  20. return (
  21. <div class="uppy-DashboardAddFiles">
  22. <div class="uppy-DashboardTabs">
  23. <ActionBrowseTagline
  24. acquirers={this.props.acquirers}
  25. handleInputChange={this.props.handleInputChange}
  26. i18n={this.props.i18n}
  27. i18nArray={this.props.i18nArray}
  28. allowedFileTypes={this.props.allowedFileTypes}
  29. maxNumberOfFiles={this.props.maxNumberOfFiles}
  30. />
  31. </div>
  32. <div class="uppy-DashboardAddFiles-info">
  33. { this.props.note && <div class="uppy-Dashboard-note">{this.props.note}</div> }
  34. { this.props.proudlyDisplayPoweredByUppy && poweredByUppy(this.props) }
  35. </div>
  36. </div>
  37. )
  38. }
  39. // empty value="" on file input, so that the input is cleared after a file is selected,
  40. // because Uppy will be handling the upload and so we can select same file
  41. // after removing — otherwise browser thinks it’s already selected
  42. return (
  43. <div class="uppy-DashboardAddFiles">
  44. <div class="uppy-DashboardTabs">
  45. <ActionBrowseTagline
  46. acquirers={this.props.acquirers}
  47. handleInputChange={this.props.handleInputChange}
  48. i18n={this.props.i18n}
  49. i18nArray={this.props.i18nArray}
  50. allowedFileTypes={this.props.allowedFileTypes}
  51. maxNumberOfFiles={this.props.maxNumberOfFiles}
  52. />
  53. <div class="uppy-DashboardTabs-list" role="tablist">
  54. <div class="uppy-DashboardTab" role="presentation">
  55. <button type="button"
  56. class="uppy-DashboardTab-btn"
  57. role="tab"
  58. tabindex={0}
  59. onclick={this.handleClick}>
  60. {localIcon()}
  61. <div class="uppy-DashboardTab-name">{this.props.i18n('myDevice')}</div>
  62. </button>
  63. <input class="uppy-Dashboard-input"
  64. hidden
  65. aria-hidden="true"
  66. tabindex={-1}
  67. type="file"
  68. name="files[]"
  69. multiple={this.props.maxNumberOfFiles !== 1}
  70. accept={this.props.allowedFileTypes}
  71. onchange={this.props.handleInputChange}
  72. value=""
  73. ref={(input) => { this.input = input }} />
  74. </div>
  75. {this.props.acquirers.map((target) => {
  76. return <div class="uppy-DashboardTab" role="presentation">
  77. <button class="uppy-DashboardTab-btn"
  78. type="button"
  79. role="tab"
  80. tabindex={0}
  81. aria-controls={`uppy-DashboardContent-panel--${target.id}`}
  82. aria-selected={this.props.activePickerPanel.id === target.id}
  83. onclick={() => this.props.showPanel(target.id)}>
  84. {target.icon()}
  85. <div class="uppy-DashboardTab-name">{target.name}</div>
  86. </button>
  87. </div>
  88. })}
  89. </div>
  90. </div>
  91. <div class="uppy-DashboardAddFiles-info">
  92. { this.props.note && <div class="uppy-Dashboard-note">{this.props.note}</div> }
  93. { this.props.proudlyDisplayPoweredByUppy && poweredByUppy(this.props) }
  94. </div>
  95. </div>
  96. )
  97. }
  98. }
  99. module.exports = AddFiles