UNPKG

cosmo-ui

Version:
36 lines 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); var web_1 = require("../web"); var styles = require('../../src/styles/components/radio.scss'); var RadioGroup = (function (_super) { tslib_1.__extends(RadioGroup, _super); function RadioGroup() { var _this = _super !== null && _super.apply(this, arguments) || this; /** * Radio options have the exact same problem as select options * You can't set an object as a radio option's value, so inorder to get round this * you need to find the object by id and then pass that in as the value */ _this.mkHandleChange = function (id) { return function (e) { var selected = _this.props.options.find(function (o) { return o.label === id; }); _this.props.onChange(selected); }; }; return _this; } RadioGroup.prototype.render = function () { var _this = this; return (React.createElement(web_1.Row, { column: "xs", row: "sm", justify: "space-between" }, this.props.options.map(function (o) { return React.createElement(web_1.RadioButton, { isSelected: _this.isSelected(o), onChange: _this.mkHandleChange(o.label), key: o.label, name: _this.props.formName, label: o.label, value: o, img: o.img }); }))); }; RadioGroup.prototype.isSelected = function (option) { return this.props.selected && this.props.selected.label === option.label; }; return RadioGroup; }(React.Component)); exports.RadioGroup = RadioGroup; //# sourceMappingURL=radio-group.js.map