Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Move FileSelector to tab-based UI
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixHenninger committed Jan 2, 2019
1 parent 3569260 commit 18798c4
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions packages/builder/src/components/FileSelector/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { ModalHeader, ModalBody } from 'reactstrap'
import { Nav, NavItem, NavLink, ModalBody } from 'reactstrap'
import classnames from 'classnames'

import { addGlobalFile, addLocalFile } from '../../logic/util/files'

import Modal from '../Modal'
import Icon from '../Icon'

import UploadTab from './Components/UploadTab'

Expand All @@ -14,6 +16,7 @@ export default class FileSelector extends Component {

this.state = {
active: false,
activeTab: 'new',
}
this.promiseHandlers = {}

Expand All @@ -34,6 +37,12 @@ export default class FileSelector extends Component {
})
}

toggleTab(name) {
this.setState({
activeTab: name
})
}

handleUpload(content, file) {
const { poolPath } = addGlobalFile(
this.context.store,
Expand Down Expand Up @@ -76,18 +85,47 @@ export default class FileSelector extends Component {
)
}

renderTab() {
switch (this.state.activeTab) {
default:
return <UploadTab handleUpload={ this.handleUpload } />
}
}

render() {
return <Modal
isOpen={ this.state.active }
>
<div className="modal-content">
<ModalHeader
toggle={ this.toggle }
>
New image
</ModalHeader>
<Nav tabs>
<NavItem>
<NavLink
className={ classnames({
active: this.state.activeTab === 'new'
}) }
onClick={ () => this.toggleTab('new') }
>
<Icon icon="plus" weight="s" />
</NavLink>
</NavItem>
<NavItem
className="ml-auto"
style={{
padding: '0.25em 0',
}}
>
<button
type="button"
className="close"
aria-label="Close"
onClick={ this.toggle }
>
<span aria-hidden="true">&times;</span>
</button>
</NavItem>
</Nav>
<ModalBody>
<UploadTab handleUpload={ this.handleUpload } />
{ this.renderTab() }
</ModalBody>
</div>
</Modal>
Expand Down

0 comments on commit 18798c4

Please sign in to comment.