Tabs.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. </div>
  24. </div>
  25. )
  26. }
  27. // empty value="" on file input, so that the input is cleared after a file is selected,
  28. // because Uppy will be handling the upload and so we can select same file
  29. // after removing — otherwise browser thinks it’s already selected
  30. return <div class="uppy-DashboardTabs">
  31. <ul class="uppy-DashboardTabs-list" role="tablist">
  32. <li class="uppy-DashboardTab" role="presentation">
  33. <button type="button"
  34. class="uppy-DashboardTab-btn"
  35. role="tab"
  36. tabindex="0"
  37. onclick={this.handleClick}>
  38. {localIcon()}
  39. <div class="uppy-DashboardTab-name">{this.props.i18n('myDevice')}</div>
  40. </button>
  41. <input class="uppy-Dashboard-input"
  42. hidden="true"
  43. aria-hidden="true"
  44. tabindex="-1"
  45. type="file"
  46. name="files[]"
  47. multiple={this.props.maxNumberOfFiles !== 1}
  48. accept={this.props.allowedFileTypes}
  49. onchange={this.props.handleInputChange}
  50. value=""
  51. ref={(input) => { this.input = input }} />
  52. </li>
  53. {this.props.acquirers.map((target) => {
  54. return <li class="uppy-DashboardTab" role="presentation">
  55. <button class="uppy-DashboardTab-btn"
  56. type="button"
  57. role="tab"
  58. tabindex="0"
  59. aria-controls={`uppy-DashboardContent-panel--${target.id}`}
  60. aria-selected={this.props.activePanel.id === target.id}
  61. onclick={() => this.props.showPanel(target.id)}>
  62. {target.icon()}
  63. <h5 class="uppy-DashboardTab-name">{target.name}</h5>
  64. </button>
  65. </li>
  66. })}
  67. </ul>
  68. </div>
  69. }
  70. }
  71. module.exports = Tabs