AddFiles.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 isHidden = Object.keys(this.props.files).length === 0
  19. const hasAcquirers = this.props.acquirers.length !== 0
  20. if (!hasAcquirers) {
  21. return (
  22. <div class="uppy-DashboarAddFiles">
  23. <div class="uppy-DashboardTabs">
  24. <ActionBrowseTagline
  25. acquirers={this.props.acquirers}
  26. handleInputChange={this.props.handleInputChange}
  27. i18n={this.props.i18n}
  28. i18nArray={this.props.i18nArray}
  29. allowedFileTypes={this.props.allowedFileTypes}
  30. maxNumberOfFiles={this.props.maxNumberOfFiles}
  31. />
  32. </div>
  33. <div class="uppy-DashboarAddFiles-info">
  34. { this.props.note && <div class="uppy-Dashboard-note">{this.props.note}</div> }
  35. { this.props.proudlyDisplayPoweredByUppy && poweredByUppy(this.props) }
  36. </div>
  37. </div>
  38. )
  39. }
  40. // empty value="" on file input, so that the input is cleared after a file is selected,
  41. // because Uppy will be handling the upload and so we can select same file
  42. // after removing — otherwise browser thinks it’s already selected
  43. return (
  44. <div class="uppy-DashboarAddFiles">
  45. <div class="uppy-DashboardTabs">
  46. <ActionBrowseTagline
  47. acquirers={this.props.acquirers}
  48. handleInputChange={this.props.handleInputChange}
  49. i18n={this.props.i18n}
  50. i18nArray={this.props.i18nArray}
  51. allowedFileTypes={this.props.allowedFileTypes}
  52. maxNumberOfFiles={this.props.maxNumberOfFiles}
  53. />
  54. <div class="uppy-DashboardTabs-list" role="tablist">
  55. <div class="uppy-DashboardTab" role="presentation">
  56. <button type="button"
  57. class="uppy-DashboardTab-btn"
  58. role="tab"
  59. tabindex={0}
  60. onclick={this.handleClick}>
  61. {localIcon()}
  62. <div class="uppy-DashboardTab-name">{this.props.i18n('myDevice')}</div>
  63. </button>
  64. <input class="uppy-Dashboard-input"
  65. hidden
  66. aria-hidden="true"
  67. tabindex={-1}
  68. type="file"
  69. name="files[]"
  70. multiple={this.props.maxNumberOfFiles !== 1}
  71. accept={this.props.allowedFileTypes}
  72. onchange={this.props.handleInputChange}
  73. value=""
  74. ref={(input) => { this.input = input }} />
  75. </div>
  76. {this.props.acquirers.map((target) => {
  77. return <div class="uppy-DashboardTab" role="presentation">
  78. <button class="uppy-DashboardTab-btn"
  79. type="button"
  80. role="tab"
  81. tabindex={0}
  82. aria-controls={`uppy-DashboardContent-panel--${target.id}`}
  83. aria-selected={this.props.activePickerPanel.id === target.id}
  84. onclick={() => this.props.showPanel(target.id)}>
  85. {target.icon()}
  86. <div class="uppy-DashboardTab-name">{target.name}</div>
  87. </button>
  88. </div>
  89. })}
  90. </div>
  91. </div>
  92. <div class="uppy-DashboarAddFiles-info">
  93. { this.props.note && <div class="uppy-Dashboard-note">{this.props.note}</div> }
  94. { this.props.proudlyDisplayPoweredByUppy && poweredByUppy(this.props) }
  95. </div>
  96. </div>
  97. )
  98. }
  99. }
  100. module.exports = AddFiles