Also show MultiButton for 3 options

This commit is contained in:
Lukas Martinelli 2016-12-29 22:12:36 +01:00
parent 1f1a919c77
commit 007bdad70a

View file

@ -21,6 +21,14 @@ function labelFromFieldName(fieldName) {
return label return label
} }
function optionsLabelLength(options) {
let sum = 0;
options.forEach(([_, label]) => {
sum += label.length
})
return sum
}
/** Display any field from the Mapbox GL style spec and /** Display any field from the Mapbox GL style spec and
* choose the correct field component based on the @{fieldSpec} * choose the correct field component based on the @{fieldSpec}
* to display @{value}. */ * to display @{value}. */
@ -56,7 +64,8 @@ export default class SpecField extends React.Component {
) )
case 'enum': case 'enum':
const options = Object.keys(this.props.fieldSpec.values).map(v => [v, capitalize(v)]) const options = Object.keys(this.props.fieldSpec.values).map(v => [v, capitalize(v)])
if(options.length < 3) {
if(options.length <= 3 && optionsLabelLength(options) <= 20) {
return <MultiButtonInput return <MultiButtonInput
{...commonProps} {...commonProps}
options={options} options={options}