UNPKG

wix-style-react

Version:
129 lines (100 loc) 4.82 kB
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 = ["sideContent", "dataHook"]; 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 SideContent from './core/SideContent'; import TabItems from './core/TabItems'; import { classes, st } from './Tabs.st.css'; var Tabs = /*#__PURE__*/function (_React$Component) { _inherits(Tabs, _React$Component); var _super = _createSuper(Tabs); function Tabs() { var _this; _classCallCheck(this, Tabs); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "_getTabItemsProps", function () { /* eslint-disable no-unused-vars */ var _this$props = _this.props, sideContent = _this$props.sideContent, dataHook = _this$props.dataHook, tabItemsProps = _objectWithoutProperties(_this$props, _excluded); return tabItemsProps; }); return _this; } _createClass(Tabs, [{ key: "render", value: function render() { var _this$props2 = this.props, sideContent = _this$props2.sideContent, hasDivider = _this$props2.hasDivider, dataHook = _this$props2.dataHook, size = _this$props2.size, className = _this$props2.className; var tabItemsProps = this._getTabItemsProps(); return /*#__PURE__*/React.createElement("div", { "data-divider": hasDivider, "data-hook": dataHook, className: st(classes.container, { hasDivider: hasDivider, size: size }, className) }, /*#__PURE__*/React.createElement(TabItems, tabItemsProps), /*#__PURE__*/React.createElement(SideContent, { content: sideContent })); } }]); return Tabs; }(React.Component); _defineProperty(Tabs, "displayName", 'Tabs'); _defineProperty(Tabs, "defaultProps", { hasDivider: true, size: 'medium' }); Tabs.propTypes = { /** Applied as data-hook HTML attribute that can be used in the tests */ dataHook: PropTypes.string, /** A css class to be applied to the component's root element */ className: PropTypes.string, /** A selected tab id */ activeId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** Places a divider on bottom */ hasDivider: PropTypes.bool, /** An array of tabs | propName | propType | isRequired | description | |----------|----------|------------|-------------| | id | string or number| + | Item id | | title | node | + | Tab title | | dataHook | string | - | Datahook | */ items: PropTypes.arrayOf(PropTypes.shape({ id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), title: PropTypes.node, dataHook: PropTypes.string })).isRequired, /** A minimum width of the container */ minWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** One of: '', compact, compactSide, uniformSide, uniformFull */ type: PropTypes.oneOf(['', 'compact', 'compactSide', 'uniformSide', 'uniformFull']), /** One of: medium, small*/ size: PropTypes.oneOf(['medium', 'small']), /** Can be either string or renderable node */ sideContent: PropTypes.node, /** A specific width of a tab (only for uniformSide type) */ width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** Click event handler */ onClick: PropTypes.func }; export default Tabs;