UNPKG

wix-style-react

Version:
128 lines (100 loc) 4.83 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; 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"; var _excluded = ["skin", "className", "priority", "size", "children", "dataHook", "ariaLabel", "ariaLabelledBy"]; 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, { PureComponent } from 'react'; import { ButtonNext } from "wix-ui-core/dist/es/src/components/button-next"; import PropTypes from 'prop-types'; import { iconChildSize } from './constants'; import { generateDataAttr } from '../utils/generateDataAttr'; import { st, classes } from './IconButton.st.css'; var IconButton = /*#__PURE__*/function (_PureComponent) { _inherits(IconButton, _PureComponent); var _super = _createSuper(IconButton); function IconButton(props) { var _this; _classCallCheck(this, IconButton); _this = _super.call(this, props); _defineProperty(_assertThisInitialized(_this), "focus", function () { _this.button.current && _this.button.current.focus(); }); _this.button = /*#__PURE__*/React.createRef(); return _this; } /** * Sets focus on the button element */ _createClass(IconButton, [{ key: "render", value: function render() { var _this$props = this.props, skin = _this$props.skin, className = _this$props.className, priority = _this$props.priority, size = _this$props.size, children = _this$props.children, dataHook = _this$props.dataHook, ariaLabel = _this$props.ariaLabel, ariaLabelledBy = _this$props.ariaLabelledBy, rest = _objectWithoutProperties(_this$props, _excluded); var childSize = iconChildSize[size]; return /*#__PURE__*/React.createElement(ButtonNext, _extends({}, rest, { ref: this.button, className: st(classes.root, { skin: skin, priority: priority, size: size }, className) }, generateDataAttr(this.props, ['skin', 'priority', 'size']), { "data-hook": dataHook, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy }), children && /*#__PURE__*/React.cloneElement(children, { size: childSize, width: childSize, height: childSize })); } }]); return IconButton; }(PureComponent); _defineProperty(IconButton, "displayName", 'IconButton'); _defineProperty(IconButton, "propTypes", { /** render as some other component or DOM tag */ as: PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.string]), /** Classes to be applied to the root element */ className: PropTypes.string, /** Used for passing any wix-style-react icon. For external icon make sure to follow ux sizing guidelines */ children: PropTypes.node, /** Button skins */ skin: PropTypes.oneOf(['standard', 'inverted', 'light', 'transparent', 'premium']), /** Button priority */ priority: PropTypes.oneOf(['primary', 'secondary']), /** Button size */ size: PropTypes.oneOf(['tiny', 'small', 'medium', 'large']), /** Click event handler */ onClick: PropTypes.func, /** Applies disabled styles */ disabled: PropTypes.bool, /** String based data hook */ dataHook: PropTypes.string, /** Defines a string value that labels the button element */ ariaLabel: PropTypes.string, /** Identifies the element that labels the button element */ ariaLabelledBy: PropTypes.string }); _defineProperty(IconButton, "defaultProps", { skin: 'standard', priority: 'primary', size: 'medium', disabled: false }); export default IconButton;