github.com/replicatedhq/ship@v0.55.0/web/init/src/components/config_render/ConfigRadio.jsx (about)

     1  import React from "react";
     2  import get from "lodash/get";
     3  
     4  export default class ConfigRadio extends React.Component {
     5  
     6    handleOnChange = (e) => {
     7      const { group } = this.props;
     8      if (this.props.handleChange && typeof this.props.handleChange === "function") {
     9        this.props.handleChange(group, e.target.value);
    10      }
    11    }
    12  
    13    render() {
    14  
    15      let val = get(this.props, "value");
    16      if (!val || val.length === 0) {
    17        val = this.props.default;
    18      }
    19      const checked = val === this.props.name;
    20  
    21      return (
    22        <div className="flex alignItems--center u-marginRight--20 u-marginTop--10">
    23          <input
    24            type="radio"
    25            name={this.props.group}
    26            id={`${this.props.group}-${this.props.name}`}
    27            value={this.props.name}
    28            checked={checked}
    29            disabled={this.props.readOnly}
    30            onChange={(e) => this.handleOnChange(e)}
    31            className={`${this.props.className || ""} ${this.props.readOnly ? "readonly" : ""}`} />
    32          <label htmlFor={`${this.props.group}-${this.props.name}`} className={`u-marginLeft--small header-color field-section-sub-header u-userSelect--none ${this.props.readOnly ? "u-cursor--default" : "u-cursor--pointer"}`}>{this.props.title}</label>
    33        </div>
    34      );
    35    }
    36  }