UNPKG

@zohodesk/dot

Version:

In this Library, we Provide Some Basic Components to Build Your Application

199 lines (168 loc) 9.83 kB
"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 _icons = require("@zohodesk/icons"); var _Layout = require("@zohodesk/components/es/Layout"); var _semanticButtonModule = _interopRequireDefault(require("@zohodesk/components/es/semantic/Button/semanticButton.module.css")); var _RippleEffect = _interopRequireDefault(require("@zohodesk/components/es/RippleEffect/RippleEffect")); var _IconButtonModule = _interopRequireDefault(require("./IconButton.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 IconButton = /*#__PURE__*/function (_React$Component) { _inherits(IconButton, _React$Component); var _super = _createSuper(IconButton); function IconButton(props) { var _this; _classCallCheck(this, IconButton); _this = _super.call(this, props); _this.state = { isPressed: false }; _this.handleToggle = _this.handleToggle.bind(_assertThisInitialized(_this)); _this.triggerClick = _this.triggerClick.bind(_assertThisInitialized(_this)); _this.triggerMouseDown = _this.triggerMouseDown.bind(_assertThisInitialized(_this)); _this.triggerMouseOver = _this.triggerMouseOver.bind(_assertThisInitialized(_this)); _this.onBlur = _this.onBlur.bind(_assertThisInitialized(_this)); return _this; } _createClass(IconButton, [{ key: "handleToggle", value: function handleToggle(e) { if (e.key === ' ' || e.key === 'Enter' || e.key === 'Spacebar') { e.preventDefault(); // this.triggerClick(e); this.triggerMouseDown(e); } } }, { key: "triggerClick", value: function triggerClick(e) { var _this$props = this.props, onClick = _this$props.onClick, isDisabled = _this$props.isDisabled; !isDisabled ? (onClick && onClick(e), this.setState({ isPressed: true })) : null; } }, { key: "triggerMouseOver", value: function triggerMouseOver(e) { var _this$props2 = this.props, onMouseOver = _this$props2.onMouseOver, isDisabled = _this$props2.isDisabled; !isDisabled ? (onMouseOver && onMouseOver(e), this.setState({ isPressed: true })) : null; } }, { key: "triggerMouseDown", value: function triggerMouseDown(e) { var _this$props3 = this.props, onMouseDown = _this$props3.onMouseDown, isDisabled = _this$props3.isDisabled; !isDisabled ? (onMouseDown && onMouseDown(e), this.setState({ isPressed: true })) : null; } }, { key: "onBlur", value: function onBlur(e) { var isDisabled = this.props.isDisabled; !isDisabled ? this.setState({ isPressed: false }) : null; } }, { key: "render", value: function render() { var _this$props4 = this.props, palette = _this$props4.palette, iconSize = _this$props4.iconSize, size = _this$props4.size, iconName = _this$props4.iconName, className = _this$props4.className, iconClass = _this$props4.iconClass, dataId = _this$props4.dataId, dataSelectorId = _this$props4.dataSelectorId, eleRef = _this$props4.eleRef, isActive = _this$props4.isActive, tourId = _this$props4.tourId, isDisabled = _this$props4.isDisabled, children = _this$props4.children, hoverType = _this$props4.hoverType, title = _this$props4.title, isBold = _this$props4.isBold, isNeedEffect = _this$props4.isNeedEffect, needButtonTag = _this$props4.needButtonTag, a11y = _this$props4.a11y, dataIsHtml = _this$props4.dataIsHtml, customProps = _this$props4.customProps; var isPressed = this.state.isPressed; var ariaHaspopup = a11y.ariaHaspopup, ariaExpanded = a11y.ariaExpanded, ariaLabel = a11y.ariaLabel, ariaControls = a11y.ariaControls, ariaLabelledby = a11y.ariaLabelledby; return /*#__PURE__*/_react["default"].createElement(_RippleEffect["default"], { palette: palette, isActive: isActive, hoverType: hoverType, isDisabled: isDisabled, isNeedEffect: isNeedEffect }, /*#__PURE__*/_react["default"].createElement(_Layout.Container, _extends({ "aria-label": ariaLabel, "aria-haspopup": ariaHaspopup, "aria-expanded": ariaExpanded, "aria-controls": ariaControls, "aria-labelledby": ariaLabelledby, tagName: needButtonTag ? 'button' : 'div', isInline: true, tourId: tourId, align: "both", isCover: false, className: "".concat(needButtonTag ? _semanticButtonModule["default"].buttonReset : '', " ").concat(_IconButtonModule["default"][size], " ").concat(_IconButtonModule["default"].wrapper, " ").concat(className || '', " ").concat(isActive ? _IconButtonModule["default"]["".concat(palette, "_active")] : _IconButtonModule["default"][palette]), dataId: dataId, dataSelectorId: dataSelectorId, onClick: this.triggerClick, "data-title": title, "data-ishtml": dataIsHtml, eleRef: eleRef, onMouseDown: this.triggerMouseDown, onMouseEnter: this.triggerMouseOver, "aria-pressed": isPressed, onKeyDown: this.handleToggle, onFocus: this.triggerMouseOver, onBlur: this.onBlur, disabled: isDisabled }, customProps), iconName ? /*#__PURE__*/_react["default"].createElement(_icons.Icon, { isBold: isBold, size: iconSize, name: iconName, iconClass: "".concat(iconClass, " ").concat(_IconButtonModule["default"].icon_button_center) }) : null, children ? children : null)); } }]); return IconButton; }(_react["default"].Component); exports["default"] = IconButton; IconButton.propTypes = _propTypes.propTypes; IconButton.defaultProps = _defaultProps.defaultProps; // if (__DOCS__) { // IconButton.docs = { // componentGroup: 'Atom' // }; // }