@quintoandar-tokko/tabs 1.4.303
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/lib/index.js +168 -0
- package/package.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 One Loop
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Tabs = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _box = require("@quintoandar-tokko/box");
|
|
10
|
+
var _hooks = require("@quintoandar-tokko/hooks");
|
|
11
|
+
var _theme = _interopRequireDefault(require("@quintoandar-tokko/theme"));
|
|
12
|
+
var _excluded = ["children", "variant", "itemTabSelected"],
|
|
13
|
+
_excluded2 = ["id", "children", "variant", "variantBody", "variantFont", "onClick", "refTab"],
|
|
14
|
+
_excluded3 = ["id", "children"];
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
16
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
18
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
19
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
20
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
22
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
23
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
24
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
25
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
26
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
27
|
+
var TabsContext = /*#__PURE__*/(0, _react.createContext)();
|
|
28
|
+
var Tabs = exports.Tabs = function Tabs(_ref) {
|
|
29
|
+
var children = _ref.children,
|
|
30
|
+
_ref$variant = _ref.variant,
|
|
31
|
+
variant = _ref$variant === void 0 ? 'normal' : _ref$variant,
|
|
32
|
+
_ref$itemTabSelected = _ref.itemTabSelected,
|
|
33
|
+
itemTabSelected = _ref$itemTabSelected === void 0 ? 1 : _ref$itemTabSelected,
|
|
34
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
35
|
+
var tabChildren = _react["default"].Children.toArray(children).filter(function (child) {
|
|
36
|
+
return child.type.name === 'Tab' || child.key.toString().match('Tab');
|
|
37
|
+
});
|
|
38
|
+
var _useState = (0, _react.useState)(itemTabSelected && tabChildren[itemTabSelected] !== undefined && tabChildren[itemTabSelected].props.id),
|
|
39
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
40
|
+
active = _useState2[0],
|
|
41
|
+
setActive = _useState2[1];
|
|
42
|
+
var value = _react["default"].useMemo(function () {
|
|
43
|
+
return {
|
|
44
|
+
active: active,
|
|
45
|
+
setActive: setActive
|
|
46
|
+
};
|
|
47
|
+
}, [active]);
|
|
48
|
+
var contentChildren = _react["default"].Children.toArray(children).filter(function (child) {
|
|
49
|
+
return child.type.name === 'Content' || child.key.toString().match('Content');
|
|
50
|
+
});
|
|
51
|
+
return /*#__PURE__*/_react["default"].createElement(TabsContext.Provider, {
|
|
52
|
+
value: value
|
|
53
|
+
}, /*#__PURE__*/_react["default"].createElement(_box.Box, _extends({}, props, {
|
|
54
|
+
tx: "tabs",
|
|
55
|
+
variant: variant
|
|
56
|
+
}), tabChildren), contentChildren.length > 0 && /*#__PURE__*/_react["default"].createElement(_box.Box, {
|
|
57
|
+
__css: {
|
|
58
|
+
paddingTop: '10px'
|
|
59
|
+
}
|
|
60
|
+
}, contentChildren));
|
|
61
|
+
};
|
|
62
|
+
var useTabsContext = function useTabsContext() {
|
|
63
|
+
var context = (0, _react.useContext)(TabsContext);
|
|
64
|
+
if (!context) {
|
|
65
|
+
throw new Error('Tabs compound components cannot be rendered outside the Tabs component');
|
|
66
|
+
}
|
|
67
|
+
return context;
|
|
68
|
+
};
|
|
69
|
+
var Tab = function Tab(_ref2) {
|
|
70
|
+
var id = _ref2.id,
|
|
71
|
+
children = _ref2.children,
|
|
72
|
+
_ref2$variant = _ref2.variant,
|
|
73
|
+
variant = _ref2$variant === void 0 ? 'normal' : _ref2$variant,
|
|
74
|
+
_ref2$variantBody = _ref2.variantBody,
|
|
75
|
+
variantBody = _ref2$variantBody === void 0 ? 'body600' : _ref2$variantBody,
|
|
76
|
+
_ref2$variantFont = _ref2.variantFont,
|
|
77
|
+
variantFont = _ref2$variantFont === void 0 ? 'fontSize12' : _ref2$variantFont,
|
|
78
|
+
onClick = _ref2.onClick,
|
|
79
|
+
refTab = _ref2.refTab,
|
|
80
|
+
props = _objectWithoutProperties(_ref2, _excluded2);
|
|
81
|
+
var _useTabsContext = useTabsContext(),
|
|
82
|
+
active = _useTabsContext.active,
|
|
83
|
+
setActive = _useTabsContext.setActive;
|
|
84
|
+
var _useToggle = (0, _hooks.useToggle)(false),
|
|
85
|
+
_useToggle2 = _slicedToArray(_useToggle, 2),
|
|
86
|
+
hover = _useToggle2[0],
|
|
87
|
+
setHover = _useToggle2[1];
|
|
88
|
+
var fontText = Object.values(_theme["default"].text[variantBody][variantFont]);
|
|
89
|
+
var color;
|
|
90
|
+
var variantValues = Object.values(_theme["default"].tab)[Object.keys(_theme["default"].tab).indexOf(variant)];
|
|
91
|
+
color = variantValues.color;
|
|
92
|
+
if (active === id) {
|
|
93
|
+
color = variantValues[':focus'].color;
|
|
94
|
+
} else if (hover) {
|
|
95
|
+
color = variantValues[':hover'].color;
|
|
96
|
+
}
|
|
97
|
+
var onClickTab = function onClickTab() {
|
|
98
|
+
setActive(id);
|
|
99
|
+
if (onClick) {
|
|
100
|
+
onClick();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
return /*#__PURE__*/_react["default"].createElement(_box.Box, _extends({
|
|
104
|
+
ref: refTab,
|
|
105
|
+
tx: "tab",
|
|
106
|
+
variant: variant,
|
|
107
|
+
onClick: function onClick() {
|
|
108
|
+
return onClickTab();
|
|
109
|
+
},
|
|
110
|
+
onMouseOver: function onMouseOver() {
|
|
111
|
+
return setHover(true);
|
|
112
|
+
},
|
|
113
|
+
onMouseOut: function onMouseOut() {
|
|
114
|
+
return setHover(false);
|
|
115
|
+
}
|
|
116
|
+
}, props, {
|
|
117
|
+
__css: {
|
|
118
|
+
position: 'relative',
|
|
119
|
+
cursor: 'pointer',
|
|
120
|
+
fontFamily: 'Nunito Sans',
|
|
121
|
+
textTransform: variant === 'minimal' ? 'none' : 'uppercase',
|
|
122
|
+
textAlign: 'center',
|
|
123
|
+
display: 'flex',
|
|
124
|
+
flexDirection: 'row',
|
|
125
|
+
justifyContent: 'center',
|
|
126
|
+
alignItems: 'center',
|
|
127
|
+
'*': {
|
|
128
|
+
textDecoration: 'none',
|
|
129
|
+
color: color
|
|
130
|
+
},
|
|
131
|
+
a: {
|
|
132
|
+
display: 'block',
|
|
133
|
+
width: '148px',
|
|
134
|
+
height: '52px',
|
|
135
|
+
lineHeight: '52px'
|
|
136
|
+
},
|
|
137
|
+
'a > *:first-child': {
|
|
138
|
+
marginRight: '10px'
|
|
139
|
+
},
|
|
140
|
+
fontSize: fontText[0],
|
|
141
|
+
fontWeight: fontText[1],
|
|
142
|
+
lineHeight: fontText[2]
|
|
143
|
+
}
|
|
144
|
+
}), children, (active === id || variant !== 'normal' && hover || variant === 'minimal') && /*#__PURE__*/_react["default"].createElement(_box.Box, {
|
|
145
|
+
as: "span",
|
|
146
|
+
__css: {
|
|
147
|
+
borderRadius: variant === 'normal' ? '4px 4px 0 0' : '4px',
|
|
148
|
+
height: variant === 'normal' ? '4px' : undefined,
|
|
149
|
+
display: 'block',
|
|
150
|
+
backgroundColor: color,
|
|
151
|
+
border: variant === 'normal' ? undefined : '1px solid ' + (active === id ? '#df1e02 !important' : color),
|
|
152
|
+
position: 'absolute',
|
|
153
|
+
right: variant === 'normal' ? '10px' : 'calc(25%)',
|
|
154
|
+
left: variant === 'normal' ? '10px' : 'calc(25%)',
|
|
155
|
+
bottom: 0
|
|
156
|
+
}
|
|
157
|
+
}));
|
|
158
|
+
};
|
|
159
|
+
var Content = function Content(_ref3) {
|
|
160
|
+
var id = _ref3.id,
|
|
161
|
+
children = _ref3.children,
|
|
162
|
+
props = _objectWithoutProperties(_ref3, _excluded3);
|
|
163
|
+
var _useTabsContext2 = useTabsContext(),
|
|
164
|
+
active = _useTabsContext2.active;
|
|
165
|
+
return active === id && /*#__PURE__*/_react["default"].createElement(_box.Box, props, children);
|
|
166
|
+
};
|
|
167
|
+
Tabs.Tab = Tab;
|
|
168
|
+
Tabs.Content = Content;
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quintoandar-tokko/tabs",
|
|
3
|
+
"version": "1.4.303",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"module": "src/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib"
|
|
8
|
+
],
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@quintoandar-tokko/box": "^1.2.286"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"react": "^16.8.0"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"gitHead": "d33e426a17c29e62c8ea591ae6afa96300d55ad9"
|
|
19
|
+
}
|