@zohodesk/components
Version:
In this Package, we Provide Some Basic Components to Build Web App
189 lines (160 loc) • 11.2 kB
JavaScript
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _defaultProps = require("./props/defaultProps");
var _propTypes = require("./props/propTypes");
var _Label = _interopRequireDefault(require("../Label/Label"));
var _Layout = require("../Layout");
var _CssProvider = _interopRequireDefault(require("../Provider/CssProvider"));
var _RadioModule = _interopRequireDefault(require("./Radio.module.css"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
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 _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
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; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var Radio = /*#__PURE__*/function (_React$Component) {
_inherits(Radio, _React$Component);
var _super = _createSuper(Radio);
function Radio(props) {
var _this;
_classCallCheck(this, Radio);
_this = _super.call(this, props);
_this.onChange = _this.onChange.bind(_assertThisInitialized(_this));
_this.handleGetRef = _this.handleGetRef.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(Radio, [{
key: "onChange",
value: function onChange(e) {
var _this$props = this.props,
onChange = _this$props.onChange,
value = _this$props.value;
onChange && onChange(value, e);
}
}, {
key: "handleGetRef",
value: function handleGetRef(ele) {
var _this$props2 = this.props,
getRef = _this$props2.getRef,
value = _this$props2.value;
getRef && getRef(ele, value);
}
}, {
key: "render",
value: function render() {
var _this$props3 = this.props,
id = _this$props3.id,
name = _this$props3.name,
value = _this$props3.value,
checked = _this$props3.checked,
disabled = _this$props3.disabled,
isReadOnly = _this$props3.isReadOnly,
palette = _this$props3.palette,
disabledTitle = _this$props3.disabledTitle,
title = _this$props3.title,
text = _this$props3.text,
labelPalette = _this$props3.labelPalette,
size = _this$props3.size,
labelSize = _this$props3.labelSize,
variant = _this$props3.variant,
active = _this$props3.active,
isFilled = _this$props3.isFilled,
customClass = _this$props3.customClass,
customProps = _this$props3.customProps,
children = _this$props3.children,
a11y = _this$props3.a11y,
renderRightPlaceholderNode = _this$props3.renderRightPlaceholderNode;
var _customClass$customRa = customClass.customRadioWrap,
customRadioWrap = _customClass$customRa === void 0 ? '' : _customClass$customRa,
_customClass$customRa2 = customClass.customRadio,
customRadio = _customClass$customRa2 === void 0 ? '' : _customClass$customRa2,
_customClass$customLa = customClass.customLabel,
customLabel = _customClass$customLa === void 0 ? '' : _customClass$customLa;
var accessMode = isReadOnly ? _RadioModule["default"].readonly : disabled ? (0, _CssProvider["default"])('isDisabled') : _RadioModule["default"].pointer;
var toolTip = disabled ? disabledTitle : title ? title : null;
var isEditable = !(isReadOnly || disabled);
var ariaHidden = a11y.ariaHidden,
_a11y$role = a11y.role,
role = _a11y$role === void 0 ? 'radio' : _a11y$role,
tabIndex = a11y.tabIndex,
_a11y$ariaChecked = a11y.ariaChecked,
ariaChecked = _a11y$ariaChecked === void 0 ? checked : _a11y$ariaChecked,
ariaLabel = a11y.ariaLabel,
ariaLabelledby = a11y.ariaLabelledby,
_a11y$ariaReadonly = a11y.ariaReadonly,
ariaReadonly = _a11y$ariaReadonly === void 0 ? !isEditable ? true : false : _a11y$ariaReadonly;
var _customProps$Containe = customProps.ContainerProps,
ContainerProps = _customProps$Containe === void 0 ? {} : _customProps$Containe,
_customProps$LabelPro = customProps.LabelProps,
LabelProps = _customProps$LabelPro === void 0 ? {} : _customProps$LabelPro;
return /*#__PURE__*/_react["default"].createElement(_Layout.Container, _extends({
dataId: value ? value.toLowerCase() : 'RadioComp',
isCover: false,
isInline: text ? false : true,
alignBox: "row",
align: "both",
className: "".concat(_RadioModule["default"].container, " ").concat(active && !disabled ? _RadioModule["default"].active : '', " ").concat(accessMode, " ").concat(!isEditable ? '' : _RadioModule["default"].hoverEfffect, " ").concat(checked ? _RadioModule["default"].checked : '', " ").concat(customRadioWrap),
"data-title": toolTip,
onClick: !isReadOnly && !disabled ? this.onChange : '',
"aria-checked": ariaChecked,
tabindex: !isEditable || ariaHidden ? '-1' : tabIndex || '0',
eleRef: this.handleGetRef,
role: role,
"aria-Hidden": ariaHidden,
"aria-label": ariaLabel,
"aria-labelledby": ariaLabelledby,
"aria-readonly": ariaReadonly
}, ContainerProps), /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: "".concat(_RadioModule["default"].radio, " ").concat(checked ? "".concat(_RadioModule["default"]["rdBox".concat(palette)]) : '', " \n ").concat(!isEditable ? '' : "".concat(_RadioModule["default"]["hover".concat(palette)]), " ").concat(_RadioModule["default"][size], " ").concat(isFilled ? _RadioModule["default"].filled : '', " ").concat(_RadioModule["default"]["centerPath".concat(palette)], " ").concat(customRadio, " ").concat(!isEditable ? "".concat(_RadioModule["default"].disabled) : '')
}, /*#__PURE__*/_react["default"].createElement("input", {
type: "hidden",
id: id,
name: name,
value: value
}), /*#__PURE__*/_react["default"].createElement("label", {
className: "".concat(_RadioModule["default"].radioLabel, " ").concat(accessMode)
}, /*#__PURE__*/_react["default"].createElement("svg", {
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 40 40"
}, /*#__PURE__*/_react["default"].createElement("circle", {
cx: "20",
cy: "20",
r: "19",
className: "".concat(_RadioModule["default"].rdBox)
}), checked ? /*#__PURE__*/_react["default"].createElement("circle", {
cx: "20",
cy: "20",
r: "11.03",
className: "".concat(_RadioModule["default"].centerPath)
}) : null))), text && /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
flexible: true,
className: "".concat(_RadioModule["default"].text, " ").concat(disabled ? "".concat(_RadioModule["default"].disabled) : '')
}, /*#__PURE__*/_react["default"].createElement(_Label["default"], _extends({
text: text,
palette: labelPalette,
size: labelSize,
type: "title",
clipped: true,
dataId: "".concat(text, "_label"),
variant: variant,
title: toolTip ? toolTip : text,
customClass: "".concat(checked && active ? "".concat(_RadioModule["default"]["".concat(palette, "checkedActive")]) : '', " \n ").concat(_RadioModule["default"]["".concat(palette, "Label")], " ").concat(isEditable ? _RadioModule["default"].pointer : '', " ").concat(isReadOnly ? _RadioModule["default"].readonly : '', " ").concat(customLabel)
}, LabelProps))), children, renderRightPlaceholderNode ? renderRightPlaceholderNode : null);
}
}]);
return Radio;
}(_react["default"].Component);
exports["default"] = Radio;
Radio.defaultProps = _defaultProps.defaultProps;
Radio.propTypes = _propTypes.propTypes;