@arche-mc2/arche-controls
Version:
We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get
114 lines • 6.24 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var classnames = require("classnames");
var BaseControl_1 = require("../_Common/BaseControl/BaseControl");
var styles_1 = require("./styles");
var typestyle_1 = require("typestyle");
var withTheme_1 = require("../../../Common/theming/withTheme");
var theming_1 = require("../../../Common/theming");
var SvgIcon_1 = require("../../Display/SvgIcon");
var radio_1 = require("./radio");
var RadioGroup = function (props) {
var children = props.children, className = props.className;
return (React.createElement("div", { onClick: function (e) {
e.stopPropagation();
}, className: classnames(className, typestyle_1.style(styles_1.RadioGroupStyles(props))) }, children));
};
var BaseRadioButton = function (props) {
var checked = props.checked, iconName = props.iconName, className = props.className, name = props.name, text = props.text, value = props.value, onChange = props.onChange, intent = props.intent, field = props.toggledElement, tabIndex = props.tabIndex, readonly = props.readonly, disabled = props.disabled, additionalData = props.additionalData;
var isTextArray = Array.isArray(text);
var radioContent = Array.isArray(text) ? (text.map(function (currentElement, index) { return (React.createElement("span", { key: index },
React.createElement("span", null,
React.createElement("b", null,
currentElement.title,
" : ")),
React.createElement("span", null, currentElement.value),
index === 0 && additionalData && (React.createElement("span", { style: {
color: additionalData.color,
marginLeft: '10px',
} },
React.createElement("b", null, additionalData.value))))); })) : (React.createElement("span", null, text));
return (React.createElement(React.Fragment, null,
React.createElement("label", { className: classnames('up-control', 'up-radio', styles_1.getStyles(props), intent ? "up-intent-" + intent : null, className) },
React.createElement("input", { checked: checked, onChange: function (e) {
e.persist();
!readonly && onChange(e);
}, name: name, type: "radio", value: value, tabIndex: tabIndex, disabled: disabled }),
React.createElement("span", { className: "up-control-wrapper " + (isTextArray
? 'up-control-wrapper--adaptive-height'
: 'up-control-wrapper--fixed-height') },
React.createElement("span", { className: "up-control-indicator" }, checked && React.createElement(radio_1.default, null))),
React.createElement("span", { className: "up-control-text " + (isTextArray
? 'up-control-text--adaptive-height'
: 'up-control-text--fixed-height') },
iconName && React.createElement(SvgIcon_1.default, { iconName: iconName }),
radioContent)),
checked && field));
};
var UpRadio = (function (_super) {
tslib_1.__extends(UpRadio, _super);
function UpRadio(props) {
var _this = _super.call(this, props) || this;
_this.dispatchOnChange = function (data, event, error) {
if (_this.props.onChange !== undefined) {
_this.props.onChange(event, data, error);
}
};
return _this;
}
UpRadio.prototype.getValue = function (data) {
return data == null
? null
: data.target != null
? data.target.value
: data;
};
Object.defineProperty(UpRadio.prototype, "isControlled", {
get: function () {
return this.props.value !== undefined;
},
enumerable: true,
configurable: true
});
Object.defineProperty(UpRadio.prototype, "currentValue", {
get: function () {
return this.isControlled ? this.props.value : this.state.value;
},
enumerable: true,
configurable: true
});
UpRadio.prototype.showError = function () {
return this.props.showError !== undefined
? this.props.showError === true
: this.hasError;
};
UpRadio.prototype.showSuccess = function () {
return this.props.showSuccess;
};
UpRadio.prototype.renderControl = function () {
var _this = this;
var options = this.props.options;
var radioGroupClass = classnames('upContainer__groupradio', "upContainer__groupradio-" + this.props.displayMode, "upContainer__groupradio-" + this.props.alignMode, this.props.className);
return (React.createElement(RadioGroup, { readonly: this.props.readonly, className: radioGroupClass, gutter: this.props.gutter, flexWrap: this.props.flexWrap, nbItemsPerRow: this.props.nbItemsPerRow, theme: this.props.theme },
React.createElement("label", { style: { display: 'none' } },
React.createElement("input", { type: "radio" })),
options.map(function (option) {
return (React.createElement(BaseRadioButton, { key: "Key_" + _this.props.name + "_" + option.value, intent: option.intent, onChange: _this.handleChangeEvent, name: _this.props.name, checked: _this.currentValue != null &&
_this.currentValue === option.value, text: option.text, additionalData: option.additionalData, readonly: _this.props.readonly, disabled: option.disabled, iconName: option.iconName, theme: _this.props.theme, value: option.value, toggledElement: option.toggledElement, tabIndex: _this.props.tabIndex }));
})));
};
UpRadio.defaultProps = {
alignMode: 'horizontal',
displayMode: 'normal',
options: [],
name: 'option',
showError: true,
theme: theming_1.default,
};
return UpRadio;
}(BaseControl_1.BaseControlComponent));
exports.UpRadio = UpRadio;
exports.default = withTheme_1.default(UpRadio);
//# sourceMappingURL=UpRadio.js.map