UNPKG

@geist-ui/react

Version:

Modern and minimalist React UI library.

98 lines (88 loc) 6.07 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _excluded = ["initialValue", "value", "hideDivider", "children", "onChange", "className"]; import _JSXStyle from "../styled-jsx.es.js"; import React, { useEffect, useMemo, useState } from 'react'; import useTheme from '../use-theme'; import { TabsContext } from './tabs-context'; import useScaleable, { withPureProps, withScaleable } from '../use-scaleable'; var defaultProps = { className: '', hideDivider: false }; var TabsComponent = function TabsComponent(_ref) { var userCustomInitialValue = _ref.initialValue, value = _ref.value, hideDivider = _ref.hideDivider, children = _ref.children, onChange = _ref.onChange, className = _ref.className, props = _objectWithoutProperties(_ref, _excluded); var theme = useTheme(); var _useScaleable = useScaleable(), SCALES = _useScaleable.SCALES; var _useState = useState(userCustomInitialValue), _useState2 = _slicedToArray(_useState, 2), selfValue = _useState2[0], setSelfValue = _useState2[1]; var _useState3 = useState([]), _useState4 = _slicedToArray(_useState3, 2), tabs = _useState4[0], setTabs = _useState4[1]; var register = function register(next) { setTabs(function (last) { var hasItem = last.find(function (item) { return item.value === next.value; }); if (!hasItem) return [].concat(_toConsumableArray(last), [next]); return last.map(function (item) { if (item.value !== next.value) return item; return _extends({}, item, next); }); }); }; var initialValue = useMemo(function () { return { register: register, currentValue: selfValue, inGroup: true }; }, [selfValue]); useEffect(function () { if (typeof value === 'undefined') return; setSelfValue(value); }, [value]); var clickHandler = function clickHandler(value) { setSelfValue(value); onChange && onChange(value); }; return /*#__PURE__*/React.createElement(TabsContext.Provider, { value: initialValue }, /*#__PURE__*/React.createElement("div", _extends({}, withPureProps(props), { className: _JSXStyle.dynamic([["4088875350", [SCALES.font(1), SCALES.width(1, 'initial'), SCALES.height(1, 'auto'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme.palette.border]]]) + " " + "tabs ".concat(className) }), /*#__PURE__*/React.createElement("header", { className: _JSXStyle.dynamic([["4088875350", [SCALES.font(1), SCALES.width(1, 'initial'), SCALES.height(1, 'auto'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme.palette.border]]]) }, /*#__PURE__*/React.createElement("div", { className: _JSXStyle.dynamic([["4088875350", [SCALES.font(1), SCALES.width(1, 'initial'), SCALES.height(1, 'auto'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme.palette.border]]]) + " " + "scroll-container ".concat(hideDivider ? 'hide-divider' : '') }, tabs.map(function (_ref2) { var Cell = _ref2.cell, value = _ref2.value; return /*#__PURE__*/React.createElement(Cell, { key: value, value: selfValue, onClick: clickHandler, className: _JSXStyle.dynamic([["4088875350", [SCALES.font(1), SCALES.width(1, 'initial'), SCALES.height(1, 'auto'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme.palette.border]]]) }); }))), /*#__PURE__*/React.createElement("div", { className: _JSXStyle.dynamic([["4088875350", [SCALES.font(1), SCALES.width(1, 'initial'), SCALES.height(1, 'auto'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme.palette.border]]]) + " " + "content" }, children), /*#__PURE__*/React.createElement(_JSXStyle, { id: "4088875350", dynamic: [SCALES.font(1), SCALES.width(1, 'initial'), SCALES.height(1, 'auto'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme.palette.border] }, ".tabs.__jsx-style-dynamic-selector{font-size:".concat(SCALES.font(1), ";width:").concat(SCALES.width(1, 'initial'), ";height:").concat(SCALES.height(1, 'auto'), ";padding:").concat(SCALES.pt(0), " ").concat(SCALES.pr(0), " ").concat(SCALES.pb(0), " ").concat(SCALES.pl(0), ";margin:").concat(SCALES.mt(0), " ").concat(SCALES.mr(0), " ").concat(SCALES.mb(0), " ").concat(SCALES.ml(0), ";}header.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-wrap:nowrap;-ms-flex-wrap:nowrap;flex-wrap:nowrap;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;overflow-y:hidden;overflow-x:scroll;-webkit-scrollbar-width:none;-moz-scrollbar-width:none;-ms-scrollbar-width:none;scrollbar-width:none;position:relative;}.scroll-container.__jsx-style-dynamic-selector{width:100%;height:100%;-webkit-flex:1;-ms-flex:1;flex:1;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-wrap:nowrap;-ms-flex-wrap:nowrap;flex-wrap:nowrap;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;border-bottom:1px solid ").concat(theme.palette.border, ";}header.__jsx-style-dynamic-selector::-webkit-scrollbar{display:none;}.hide-divider.__jsx-style-dynamic-selector{border-color:transparent;}.content.__jsx-style-dynamic-selector{padding-top:0.625rem;}")))); }; TabsComponent.defaultProps = defaultProps; TabsComponent.displayName = 'GeistTabs'; var Tabs = withScaleable(TabsComponent); export default Tabs;