office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
68 lines • 4.63 kB
JavaScript
import * as tslib_1 from "tslib";
import * as React from 'react';
import { Image } from '../../../Image';
import { Icon } from '../../../Icon';
import { BaseComponent, classNamesFunction, getNativeProps, inputProperties, createRef } from '../../../Utilities';
var getClassNames = classNamesFunction();
var ChoiceGroupOptionBase = /** @class */ (function (_super) {
tslib_1.__extends(ChoiceGroupOptionBase, _super);
function ChoiceGroupOptionBase(props) {
var _this = _super.call(this, props) || this;
_this._inputElement = createRef();
_this._onRenderField = function (props) {
var _a = props.onRenderLabel, onRenderLabel = _a === void 0 ? _this._onRenderLabel : _a, id = props.id, imageSrc = props.imageSrc, imageAlt = props.imageAlt, selectedImageSrc = props.selectedImageSrc, iconProps = props.iconProps;
var imageSize = props.imageSize ? props.imageSize : { width: 32, height: 32 };
return (React.createElement("label", { htmlFor: id, className: _this._classNames.field },
imageSrc && (React.createElement("div", { className: _this._classNames.innerField, style: { height: imageSize.height, width: imageSize.width } },
React.createElement("div", { className: _this._classNames.imageWrapper },
React.createElement(Image, { src: imageSrc, alt: imageAlt ? imageAlt : '', width: imageSize.width, height: imageSize.height })),
React.createElement("div", { className: _this._classNames.selectedImageWrapper },
React.createElement(Image, { src: selectedImageSrc, alt: imageAlt ? imageAlt : '', width: imageSize.width, height: imageSize.height })))),
iconProps ? (React.createElement("div", { className: _this._classNames.innerField },
React.createElement("div", { className: _this._classNames.iconWrapper },
React.createElement(Icon, tslib_1.__assign({}, iconProps))))) : null,
imageSrc || iconProps ? (React.createElement("div", { className: _this._classNames.labelWrapper, style: { maxWidth: imageSize.width * 2 } }, onRenderLabel(props))) : (onRenderLabel(props))));
};
_this._onRenderLabel = function (props) {
return (React.createElement("span", { id: props.labelId, className: "ms-ChoiceFieldLabel" }, props.text));
};
return _this;
}
ChoiceGroupOptionBase.prototype.render = function () {
var _a = this.props, focused = _a.focused, required = _a.required, theme = _a.theme, iconProps = _a.iconProps, imageSrc = _a.imageSrc, _b = _a.imageSize, imageSize = _b === void 0 ? { width: 32, height: 32 } : _b, disabled = _a.disabled, checked = _a.checked, id = _a.id, styles = _a.styles, name = _a.name, _c = _a.onRenderField, onRenderField = _c === void 0 ? this._onRenderField : _c;
this._classNames = getClassNames(styles, {
theme: theme,
hasIcon: !!iconProps,
hasImage: !!imageSrc,
checked: checked,
disabled: disabled,
imageIsLarge: !!imageSrc && (imageSize.width > 71 || imageSize.height > 71),
focused: focused
});
return (React.createElement("div", { className: this._classNames.root },
React.createElement("div", { className: this._classNames.choiceFieldWrapper },
React.createElement("input", tslib_1.__assign({ ref: this._inputElement, id: id, className: this._classNames.input, type: "radio", name: name, disabled: disabled, checked: checked, required: required, onChange: this._onChange.bind(this, this.props), onFocus: this._onFocus.bind(this, this.props), onBlur: this._onBlur.bind(this, this.props) }, getNativeProps(this.props, inputProperties))),
onRenderField(this.props, this._onRenderField))));
};
ChoiceGroupOptionBase.prototype._onChange = function (props, evt) {
var onChange = props.onChange;
if (onChange) {
onChange(evt, props);
}
};
ChoiceGroupOptionBase.prototype._onBlur = function (props, evt) {
var onBlur = props.onBlur;
if (onBlur) {
onBlur(evt, props);
}
};
ChoiceGroupOptionBase.prototype._onFocus = function (props, evt) {
var onFocus = props.onFocus;
if (onFocus) {
onFocus(evt, props);
}
};
return ChoiceGroupOptionBase;
}(BaseComponent));
export { ChoiceGroupOptionBase };
//# sourceMappingURL=ChoiceGroupOption.base.js.map