mirror of https://github.com/sgoudham/carbon.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.5 KiB
JavaScript
89 lines
2.5 KiB
JavaScript
7 years ago
|
import React from 'react'
|
||
|
import { COLORS } from '../lib/constants'
|
||
|
import Checkmark from './svg/Checkmark'
|
||
7 years ago
|
import { EXPORT_SIZES } from '../lib/constants'
|
||
7 years ago
|
|
||
|
export default class extends React.Component {
|
||
|
constructor(props) {
|
||
|
super()
|
||
|
this.state = { isVisible: false }
|
||
|
this.select = this.select.bind(this)
|
||
|
this.toggle = this.toggle.bind(this)
|
||
|
}
|
||
|
|
||
7 years ago
|
select(exportSize) {
|
||
|
if (this.props.selected !== exportSize) {
|
||
|
this.props.onChange(exportSize)
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
toggle() {
|
||
|
this.setState({ isVisible: !this.state.isVisible })
|
||
|
}
|
||
|
|
||
7 years ago
|
renderExportSizes() {
|
||
|
return EXPORT_SIZES.map((exportSize, i) => {
|
||
7 years ago
|
return (
|
||
7 years ago
|
<div className="list-item" key={i} onClick={this.select.bind(null, exportSize.id)}>
|
||
|
<span style={{ ExportSize: exportSize.id }}>{exportSize.name}</span>
|
||
|
{this.props.selected === exportSize.id ? <Checkmark /> : null}
|
||
7 years ago
|
<style jsx>{`
|
||
|
.list-item {
|
||
|
display: flex;
|
||
|
align-items: center;
|
||
|
justify-content: space-between;
|
||
|
cursor: pointer;
|
||
|
user-select: none;
|
||
|
padding: 8px 16px;
|
||
|
border-bottom: 1px solid ${COLORS.SECONDARY};
|
||
|
background: rgba(255, 255, 255, 0.165);
|
||
|
}
|
||
|
.list-item:first-of-type {
|
||
|
border-top: 1px solid ${COLORS.SECONDARY};
|
||
|
}
|
||
|
.list-item:last-of-type {
|
||
|
border-bottom: none;
|
||
|
}
|
||
|
`}</style>
|
||
|
</div>
|
||
|
)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
render() {
|
||
7 years ago
|
const selectedExportSize =
|
||
|
EXPORT_SIZES.filter(exportSize => exportSize.id === this.props.selected)[0] || {}
|
||
7 years ago
|
return (
|
||
7 years ago
|
<div className="export-size-select-container">
|
||
7 years ago
|
<div
|
||
|
onClick={this.toggle}
|
||
|
className={`display ${this.state.isVisible ? 'is-visible' : ''}`}
|
||
|
>
|
||
7 years ago
|
<span className="label">Export Size</span>
|
||
|
<span style={{ exportSize: selectedExportSize.id }}>{selectedExportSize.name}</span>
|
||
7 years ago
|
</div>
|
||
7 years ago
|
<div className="list">{this.renderExportSizes()}</div>
|
||
7 years ago
|
<style jsx>{`
|
||
|
.display {
|
||
|
display: flex;
|
||
|
align-items: center;
|
||
|
justify-content: space-between;
|
||
|
cursor: pointer;
|
||
|
user-select: none;
|
||
|
padding: 8px;
|
||
|
}
|
||
|
.list {
|
||
|
display: none;
|
||
|
margin-top: -1px;
|
||
|
max-height: 80px;
|
||
|
overflow-y: scroll;
|
||
|
}
|
||
|
.is-visible + .list {
|
||
|
display: block;
|
||
|
}
|
||
|
`}</style>
|
||
|
</div>
|
||
|
)
|
||
|
}
|
||
|
}
|