Forráskód Böngészése

refactor ActionBrowseTagline into a component

Artur Paikin 7 éve
szülő
commit
fdffdb0cb8

+ 28 - 29
src/plugins/Dashboard/ActionBrowseTagline.js

@@ -1,33 +1,32 @@
-const { h } = require('preact')
+const { h, Component } = require('preact')
 const hyperx = require('hyperx')
 const html = hyperx(h)
 
-let inputEl
-
-module.exports = (props) => {
-  const input = html`
-    <input class="UppyDashboard-input"
-           hidden="true"
-           aria-hidden="true" 
-           tabindex="-1" 
-           type="file" 
-           name="files[]" 
-           multiple="true"
-           onchange=${props.handleInputChange} 
-           ref=${(input) => {
-             inputEl = input
-           }} />`
-
-  return html`
-    <span>
-      ${props.acquirers.length === 0
-        ? props.i18n('dropPaste')
-        : props.i18n('dropPasteImport')
-      }
-      <button type="button"
-              class="UppyDashboard-browse"
-              onclick=${(ev) => inputEl.click()}>${props.i18n('browse')}</button>
-      ${input}
-    </span>
-  `
+class ActionBrowseTagline extends Component {
+  render () {
+    return html`
+      <span>
+        ${this.props.acquirers.length === 0
+          ? this.props.i18n('dropPaste')
+          : this.props.i18n('dropPasteImport')
+        }
+        <button type="button"
+                class="UppyDashboard-browse"
+                onclick=${(ev) => this.input.click()}>${this.props.i18n('browse')}</button>
+        <input class="UppyDashboard-input"
+               hidden="true"
+               aria-hidden="true" 
+               tabindex="-1" 
+               type="file" 
+               name="files[]" 
+               multiple="true"
+               onchange=${this.props.handleInputChange} 
+               ref=${(input) => {
+                 this.input = input
+               }} />
+      </span>
+    `
+  }
 }
+
+module.exports = ActionBrowseTagline

+ 1 - 1
src/plugins/Dashboard/FileList.js

@@ -13,7 +13,7 @@ module.exports = (props) => {
        ? html`<div class="UppyDashboard-bgIcon">
           ${dashboardBgIcon()}
           <h3 class="UppyDashboard-dropFilesTitle">
-            ${ActionBrowseTagline({
+            ${h(ActionBrowseTagline, {
               acquirers: props.acquirers,
               handleInputChange: props.handleInputChange,
               i18n: props.i18n

+ 5 - 5
src/plugins/Dashboard/Tabs.js

@@ -13,11 +13,11 @@ module.exports = (props) => {
     return html`
       <div class="UppyDashboardTabs" aria-hidden="${isHidden}">
         <h3 class="UppyDashboardTabs-title">
-        ${ActionBrowseTagline({
-          acquirers: props.acquirers,
-          handleInputChange: props.handleInputChange,
-          i18n: props.i18n
-        })}
+          ${h(ActionBrowseTagline, {
+            acquirers: props.acquirers,
+            handleInputChange: props.handleInputChange,
+            i18n: props.i18n
+          })}
         </h3>
       </div>
     `