wix-style-react
Version:
155 lines (136 loc) • 6.78 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import React from 'react';
import PropTypes from 'prop-types';
import uniqueId from 'lodash/uniqueId';
import classnames from 'classnames';
import { st, classes } from './RadioButton.st.css';
import { withFocusable } from "wix-ui-core/dist/es/src/hocs/Focusable/FocusableHOC";
import Text from '../../Text';
import { dataHooks } from './constants';
import deprecationLog from '../../utils/deprecationLog';
var RadioButton = /*#__PURE__*/function (_React$PureComponent) {
_inherits(RadioButton, _React$PureComponent);
var _super = _createSuper(RadioButton);
function RadioButton(props) {
var _this;
_classCallCheck(this, RadioButton);
_this = _super.call(this, props);
var prefix = props.name && "".concat(props.name, "_");
_this.id = uniqueId(prefix);
deprecationLog("Using \"<RadioButton/>\" is deprecated. Instead, we advise you to use the newer \"<Radio/>\" component. Please refer to it's documentation.");
return _this;
}
_createClass(RadioButton, [{
key: "render",
value: function render() {
var _classnames;
var _this$props = this.props,
dataHook = _this$props.dataHook,
checked = _this$props.checked,
children = _this$props.children,
content = _this$props.content,
disabled = _this$props.disabled,
lineHeight = _this$props.lineHeight,
name = _this$props.name,
_onChange = _this$props.onChange,
style = _this$props.style,
vAlign = _this$props.vAlign,
value = _this$props.value,
tabIndex = _this$props.tabIndex,
focusableOnFocus = _this$props.focusableOnFocus,
focusableOnBlur = _this$props.focusableOnBlur,
className = _this$props.className,
selectionAreaPadding = _this$props.selectionAreaPadding;
return /*#__PURE__*/React.createElement("div", {
className: st(classes.focusableRadioButton, className),
onFocus: focusableOnFocus,
onBlur: focusableOnBlur,
style: style,
"data-hook": dataHook
}, /*#__PURE__*/React.createElement("div", {
className: classnames(classes.radioWrapper, (_classnames = {}, _defineProperty(_classnames, classes.disabled, disabled), _defineProperty(_classnames, classes.checked, checked), _classnames)),
"data-hook": dataHooks.RadioButtonWrapper,
tabIndex: disabled ? null : tabIndex
}, /*#__PURE__*/React.createElement("input", {
"data-hook": dataHooks.RadioButtonInput,
type: "radio",
name: name,
value: value,
id: this.id,
checked: checked,
disabled: disabled,
onChange: function onChange() {
return !checked && !disabled ? _onChange(value) : null;
}
}), /*#__PURE__*/React.createElement("label", {
"data-hook": dataHooks.RadioButtonLabel,
style: {
lineHeight: lineHeight
},
htmlFor: this.id,
className: classes.label
}, /*#__PURE__*/React.createElement("div", {
className: classnames(classes.labelInner, _defineProperty({}, classes.vcenter, vAlign === 'center')),
style: {
padding: selectionAreaPadding
}
}, /*#__PURE__*/React.createElement("div", {
style: {
height: lineHeight
},
className: classes.radioButtonWrapper,
"data-hook": dataHooks.RadioButtonRadio
}, /*#__PURE__*/React.createElement("div", {
className: classnames(classes.radio, _defineProperty({}, classes.radioButtonChecked, checked))
})), children && /*#__PURE__*/React.createElement(Text, {
className: classes.children,
"data-hook": dataHooks.RadioButtonChildren,
tagName: "div",
size: "medium",
weight: "thin",
secondary: true
}, children)))), content && /*#__PURE__*/React.createElement("div", {
className: classes.content,
"data-hook": dataHooks.RadioButtonContent
}, content));
}
}]);
return RadioButton;
}(React.PureComponent);
_defineProperty(RadioButton, "displayName", 'RadioGroup.Radio');
_defineProperty(RadioButton, "propTypes", {
/** Applied as data-hook HTML attribute that can be used in the tests */
dataHook: PropTypes.string,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
vAlign: PropTypes.oneOf(['center', 'top']),
name: PropTypes.string,
onChange: PropTypes.func,
checked: PropTypes.bool,
disabled: PropTypes.bool,
children: PropTypes.any,
style: PropTypes.object,
lineHeight: PropTypes.string,
tabIndex: PropTypes.number,
/** Selection area emphasises the clickable area, none means no emphasis, hover is when the mouse is on the component, and always will show constantly */
selectionArea: PropTypes.oneOf(['none', 'hover', 'always']),
/** optional node to be rendered under label. Clicking it will not trigger `onChange` */
content: PropTypes.node,
className: PropTypes.string,
/** Selection area skin emphasises the style of the clickable area for selectionArea ('hover' or 'always'), filled (default) means selectionArea has backgound, outlined means selectionArea has outline */
selectionAreaSkin: PropTypes.oneOf(['filled', 'outlined']),
/** Selection area padding emphasises the padding of the clickable area, empty means default padding, not empty overrides the default padding*/
selectionAreaPadding: PropTypes.string
});
_defineProperty(RadioButton, "defaultProps", {
vAlign: 'center',
content: null,
tabIndex: 0
});
export default withFocusable(RadioButton);