Tabs.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const ActionBrowseTagline = require('./ActionBrowseTagline')
  2. const { localIcon } = require('./icons')
  3. const { h, Component } = require('preact')
  4. class Tabs extends Component {
  5. constructor (props) {
  6. super(props)
  7. this.handleClick = this.handleClick.bind(this)
  8. }
  9. handleClick (ev) {
  10. this.input.click()
  11. }
  12. render () {
  13. const isHidden = Object.keys(this.props.files).length === 0
  14. const hasAcquirers = this.props.acquirers.length !== 0
  15. if (!hasAcquirers) {
  16. return (
  17. <div class="uppy-DashboardTabs" aria-hidden={isHidden}>
  18. <div class="uppy-DashboardTabs-title">
  19. <ActionBrowseTagline
  20. acquirers={this.props.acquirers}
  21. handleInputChange={this.props.handleInputChange}
  22. i18n={this.props.i18n}
  23. i18nArray={this.props.i18nArray} />
  24. </div>
  25. </div>
  26. )
  27. }
  28. // empty value="" on file input, so that the input is cleared after a file is selected,
  29. // because Uppy will be handling the upload and so we can select same file
  30. // after removing — otherwise browser thinks it’s already selected
  31. return <div class="uppy-DashboardTabs">
  32. <ul class="uppy-DashboardTabs-list" role="tablist">
  33. <li class="uppy-DashboardTab" role="presentation">
  34. <button type="button"
  35. class="uppy-DashboardTab-btn"
  36. role="tab"
  37. tabindex={0}
  38. onclick={this.handleClick}>
  39. {localIcon()}
  40. <div class="uppy-DashboardTab-name">{this.props.i18n('myDevice')}</div>
  41. </button>
  42. <input class="uppy-Dashboard-input"
  43. hidden
  44. aria-hidden="true"
  45. tabindex={-1}
  46. type="file"
  47. name="files[]"
  48. multiple={this.props.maxNumberOfFiles !== 1}
  49. accept={this.props.allowedFileTypes}
  50. onchange={this.props.handleInputChange}
  51. value=""
  52. ref={(input) => { this.input = input }} />
  53. </li>
  54. {this.props.acquirers.map((target) => {
  55. return <li class="uppy-DashboardTab" role="presentation">
  56. <button class="uppy-DashboardTab-btn"
  57. type="button"
  58. role="tab"
  59. tabindex={0}
  60. aria-controls={`uppy-DashboardContent-panel--${target.id}`}
  61. aria-selected={this.props.activePanel.id === target.id}
  62. onclick={() => this.props.showPanel(target.id)}>
  63. {target.icon()}
  64. <div class="uppy-DashboardTab-name">{target.name}</div>
  65. </button>
  66. </li>
  67. })}
  68. </ul>
  69. </div>
  70. }
  71. }
  72. module.exports = Tabs