substance
Version:
Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing system. It is developed to power our online editing platform [Substance](http://substance.io).
27 lines (23 loc) • 678 B
JavaScript
import { $$, Component } from '../dom'
export default class Select extends Component {
render () {
const { options, placeholder, value: selectedValue } = this.props
const el = $$('select', { class: 'sc-select' })
if (placeholder) {
el.append(
$$('option', {}, placeholder)
)
}
el.append(
options.map(option => {
if (typeof option === 'object') {
const { value, label } = option
return $$('option', { value, selected: value === selectedValue }, label)
} else {
return $$('option', { option, selected: option === selectedValue }, option)
}
})
)
return el
}
}