@zohodesk/components
Version:
In this Package, we Provide Some Basic Components to Build Web App
223 lines (194 loc) • 12.9 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 _propTypes = require("./props/propTypes");
var _defaultProps = require("./props/defaultProps");
var _Label = _interopRequireDefault(require("../Label/Label"));
var _Layout = require("../Layout");
var _CssProvider = _interopRequireDefault(require("../Provider/CssProvider"));
var _CheckBoxModule = _interopRequireDefault(require("./CheckBox.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 CheckBox = /*#__PURE__*/function (_React$Component) {
_inherits(CheckBox, _React$Component);
var _super = _createSuper(CheckBox);
function CheckBox(props) {
var _this;
_classCallCheck(this, CheckBox);
_this = _super.call(this, props);
_this.onChange = _this.onChange.bind(_assertThisInitialized(_this));
_this.handleGetContainerRef = _this.handleGetContainerRef.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(CheckBox, [{
key: "onChange",
value: function onChange(e) {
var _this$props = this.props,
onChange = _this$props.onChange,
checked = _this$props.checked;
onChange && onChange(!checked, e);
}
}, {
key: "handleGetContainerRef",
value: function handleGetContainerRef(ele) {
var _this$props2 = this.props,
getContainerRef = _this$props2.getContainerRef,
id = _this$props2.id;
getContainerRef && getContainerRef(ele, id);
}
}, {
key: "render",
value: function render() {
var _this$props3 = this.props,
id = _this$props3.id,
checked = _this$props3.checked,
disabled = _this$props3.disabled,
isReadOnly = _this$props3.isReadOnly,
disabledTitle = _this$props3.disabledTitle,
title = _this$props3.title,
palette = _this$props3.palette,
text = _this$props3.text,
size = _this$props3.size,
labelPalette = _this$props3.labelPalette,
labelSize = _this$props3.labelSize,
isFilled = _this$props3.isFilled,
isClipped = _this$props3.isClipped,
getRef = _this$props3.getRef,
variant = _this$props3.variant,
active = _this$props3.active,
dataId = _this$props3.dataId,
name = _this$props3.name,
activeStyle = _this$props3.activeStyle,
a11y = _this$props3.a11y,
customClass = _this$props3.customClass,
customProps = _this$props3.customProps,
dataSelectorId = _this$props3.dataSelectorId,
renderRightPlaceholderNode = _this$props3.renderRightPlaceholderNode;
var _customProps$CheckBox = customProps.CheckBoxProps,
CheckBoxProps = _customProps$CheckBox === void 0 ? {} : _customProps$CheckBox,
_customProps$LabelPro = customProps.LabelProps,
LabelProps = _customProps$LabelPro === void 0 ? {} : _customProps$LabelPro;
var _customClass$customCh = customClass.customCheckBox,
customCheckBox = _customClass$customCh === void 0 ? '' : _customClass$customCh,
_customClass$customLa = customClass.customLabel,
customLabel = _customClass$customLa === void 0 ? '' : _customClass$customLa,
_customClass$customCB = customClass.customCBoxSize,
customCBoxSize = _customClass$customCB === void 0 ? '' : _customClass$customCB,
_customClass$customTi = customClass.customTickSize,
customTickSize = _customClass$customTi === void 0 ? '' : _customClass$customTi;
var accessMode = isReadOnly ? _CheckBoxModule["default"].readonly : disabled ? (0, _CssProvider["default"])('isDisabled') : _CheckBoxModule["default"].pointer;
var toolTip = disabled ? disabledTitle : title ? title : null;
var ariaLabel = a11y.ariaLabel,
ariaLabelledby = a11y.ariaLabelledby,
ariaHidden = a11y.ariaHidden,
_a11y$role = a11y.role,
role = _a11y$role === void 0 ? 'checkbox' : _a11y$role,
_a11y$ariaChecked = a11y.ariaChecked,
ariaChecked = _a11y$ariaChecked === void 0 ? checked : _a11y$ariaChecked;
var isEditable = !(isReadOnly || disabled);
return /*#__PURE__*/_react["default"].createElement(_Layout.Container, _extends({
dataId: dataId,
isCover: false,
isInline: text ? false : true,
alignBox: "row",
align: "vertical",
className: "".concat(_CheckBoxModule["default"].container, " ").concat(accessMode, " ").concat(!isEditable ? '' : "".concat(_CheckBoxModule["default"][palette]), " \n ").concat(checked ? "".concat(_CheckBoxModule["default"]["checked".concat(palette)]) : '', " ").concat(customCheckBox),
"data-title": toolTip,
onClick: !isEditable ? null : this.onChange,
tabIndex: !isEditable || ariaHidden ? '-1' : '0',
"aria-checked": ariaChecked,
eleRef: this.handleGetContainerRef,
role: role,
"aria-label": ariaLabel,
"aria-labelledby": ariaLabelledby,
"aria-hidden": ariaHidden,
dataSelectorId: dataSelectorId || id
}, CheckBoxProps), /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: "".concat(_CheckBoxModule["default"].boxContainer, " ").concat(_CheckBoxModule["default"][size], " ").concat(customCBoxSize, " ").concat(isFilled ? _CheckBoxModule["default"].filled : '', " ").concat(!isEditable ? "".concat(_CheckBoxModule["default"]["disabled"]) : '')
}, /*#__PURE__*/_react["default"].createElement("input", {
type: "hidden",
id: id,
ref: getRef,
name: name
}), /*#__PURE__*/_react["default"].createElement("label", {
className: "".concat(_CheckBoxModule["default"].checkbox, " ").concat(accessMode, " ").concat(_CheckBoxModule["default"][size], " ").concat(customCBoxSize)
}, activeStyle == 'tick' ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("svg", {
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 40 40"
}, checked ? /*#__PURE__*/_react["default"].createElement("path", {
xmlns: "http://www.w3.org/2000/svg",
d: "M39,20V35a4,4,0,0,1-4,4H5a4,4,0,0,1-4-4V5A4,4,0,0,1,5,1H28.44",
className: "".concat(_CheckBoxModule["default"].cbBox)
}) : /*#__PURE__*/_react["default"].createElement("rect", {
xmlns: "http://www.w3.org/2000/svg",
x: "1",
y: "1",
width: "38",
height: "38",
rx: "4",
className: "".concat(_CheckBoxModule["default"].cbBox)
})), checked ? /*#__PURE__*/_react["default"].createElement("svg", {
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 44 44",
className: "".concat(_CheckBoxModule["default"].tick, " ").concat(_CheckBoxModule["default"]["".concat(size, "tick")], " ").concat(customTickSize, " ").concat(disabled ? (0, _CssProvider["default"])('isDisabled') : '')
}, /*#__PURE__*/_react["default"].createElement("polyline", {
points: "12.56 19 19.61 26.06 40.39 5.28",
className: "".concat(_CheckBoxModule["default"].tickPath, " ").concat(_CheckBoxModule["default"].checkedtickPath)
})) : null) : /*#__PURE__*/_react["default"].createElement("svg", {
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 40 40"
}, /*#__PURE__*/_react["default"].createElement("rect", {
xmlns: "http://www.w3.org/2000/svg",
x: "1",
y: "1",
width: "38",
height: "38",
rx: "4",
className: "".concat(_CheckBoxModule["default"].cbBox)
}), checked ? /*#__PURE__*/_react["default"].createElement("line", {
xmlns: "http://www.w3.org/2000/svg",
className: "".concat(_CheckBoxModule["default"].linePath, " ").concat(_CheckBoxModule["default"].cbBox),
x1: "11.47",
y1: "20",
x2: "28.53",
y2: "20"
}) : null))), text && /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
flexible: true,
className: _CheckBoxModule["default"].text
}, /*#__PURE__*/_react["default"].createElement(_Label["default"], _extends({
text: text,
palette: disabled ? 'disable' : labelPalette,
id: id,
size: labelSize,
type: "title",
clipped: isClipped,
variant: variant,
customClass: "".concat(active && !disabled ? "".concat(_CheckBoxModule["default"]["active".concat(palette, "Label")]) : '', "\n ").concat(checked && active ? "".concat(_CheckBoxModule["default"]["checked".concat(palette, "Label")]) : '', " \n ").concat(accessMode, " ").concat(customLabel),
title: toolTip ? toolTip : text
}, LabelProps))), renderRightPlaceholderNode ? renderRightPlaceholderNode : null);
}
}]);
return CheckBox;
}(_react["default"].Component);
exports["default"] = CheckBox;
CheckBox.defaultProps = _defaultProps.defaultProps;
CheckBox.propTypes = _propTypes.propTypes; // if (__DOCS__) {
// CheckBox.docs = {
// componentGroup: 'Form Elements',
// folderName: 'Style Guide'
// };
// }