github.com/replicatedhq/ship@v0.55.0/web/init/src/components/config_render/ConfigSelectOne.jsx (about) 1 import React from "react"; 2 import map from "lodash/map"; 3 import isEmpty from "lodash/isEmpty"; 4 5 import ConfigItemTitle from "./ConfigItemTitle"; 6 import ConfigRadio from "./ConfigRadio"; 7 import Markdown from "react-remarkable"; 8 9 export default class ConfigSelectOne extends React.Component { 10 11 handleOnChange = (itemName, val) => { 12 if (this.props.handleOnChange && typeof this.props.handleOnChange === "function") { 13 this.props.handleOnChange(itemName, val); 14 } 15 } 16 17 render() { 18 let options = []; 19 map(this.props.items, (childItem, i) => { 20 if (isEmpty(childItem)) return null; 21 options.push( 22 <ConfigRadio 23 key={`${childItem.name}-${i}`} 24 name={childItem.name} 25 title={childItem.title} 26 id={childItem.name} 27 default={this.props.default} 28 group={this.props.name} 29 value={this.props.value} 30 readOnly={this.props.readonly} 31 handleChange={(itemName, val) => this.handleOnChange(itemName, val)} 32 /> 33 ) 34 }); 35 36 var hidden = this.props.hidden || this.props.when === "false"; 37 38 return ( 39 <div className={`field field-type-select-one ${hidden ? "hidden" : "u-marginTop--15"}`}> 40 {this.props.title !== "" ? 41 <ConfigItemTitle 42 title={this.props.title} 43 recommended={this.props.recommended} 44 required={this.props.required} 45 name={this.props.name} 46 error={this.props.error} 47 /> 48 : null} 49 {this.props.help_text !== "" ? 50 <p className="field-section-help-text u-marginTop--small u-lineHeight--normal u-marginLeft--small"> 51 <Markdown 52 options={{ 53 linkTarget: "_blank", 54 linkify: true, 55 }}> 56 {this.props.help_text} 57 </Markdown> 58 </p> 59 : null} 60 <div className="field-input-wrapper u-marginTop--5 flex flexWrap--wrap"> 61 {options} 62 </div> 63 </div> 64 ); 65 } 66 }