UNPKG

@darwino/darwino-react-bootstrap

Version:

A set of Javascript classes and utilities

36 lines (32 loc) 1.2 kB
/* * (c) Copyright Darwino Inc. 2014-2017. */ import React, {Component} from "react"; import { FormControl } from 'react-bootstrap'; class FieldStatic extends Component { static labelFor(options,value) { if(options) { for(let i=0; i<options.length; i++) { const val = options[i] if(typeof(val)==="object" && val.value==value) { return val.label!==undefined ? val.label : val.value } } } return value; } static labelsFor(options,values) { return values.map((v) => FieldStatic.labelFor(options,v)) } render() { const {input, multiple, type, options, editable, separator, disabled, meta, ...props} = this.props; const {value} = input const inputValue = multiple ? (Array.isArray(value) ? FieldStatic.labelsFor(options,value).join(separator||',') : "") : (value!==undefined && value!==null ? FieldStatic.labelFor(options,value.toString()) : "") return ( <FormControl.Static {...props}>{inputValue}</FormControl.Static> ) } } export default FieldStatic