@quintoandar-tokko/collapsible 1.2.373
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/lib/index.js +127 -0
- package/package.json +21 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
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.Collapsible = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _framerMotion = require("framer-motion");
|
|
10
|
+
var _button = require("@quintoandar-tokko/button");
|
|
11
|
+
var _box = require("@quintoandar-tokko/box");
|
|
12
|
+
var _excluded = ["children", "isOpen"],
|
|
13
|
+
_excluded2 = ["children", "isMainButton", "isSmallButtonIcon", "active", "icon", "text", "isExpanded", "isCollapsible", "badgeValue", "badgeVariant", "setExpand"];
|
|
14
|
+
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); }
|
|
15
|
+
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; }
|
|
16
|
+
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); }
|
|
17
|
+
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; }
|
|
18
|
+
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; }
|
|
19
|
+
var CollapsibleContext = /*#__PURE__*/(0, _react.createContext)();
|
|
20
|
+
var Collapsible = exports.Collapsible = function Collapsible(_ref) {
|
|
21
|
+
var children = _ref.children,
|
|
22
|
+
_ref$isOpen = _ref.isOpen,
|
|
23
|
+
isOpen = _ref$isOpen === void 0 ? false : _ref$isOpen,
|
|
24
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
25
|
+
var ref = _react["default"].useRef();
|
|
26
|
+
var value = _react["default"].useMemo(function () {
|
|
27
|
+
return {
|
|
28
|
+
isOpen: isOpen,
|
|
29
|
+
ref: ref
|
|
30
|
+
};
|
|
31
|
+
}, [isOpen]);
|
|
32
|
+
return /*#__PURE__*/_react["default"].createElement(CollapsibleContext.Provider, {
|
|
33
|
+
value: value
|
|
34
|
+
}, /*#__PURE__*/_react["default"].createElement(_box.Box, props, children));
|
|
35
|
+
};
|
|
36
|
+
var useCollapsibleContext = function useCollapsibleContext() {
|
|
37
|
+
var context = (0, _react.useContext)(CollapsibleContext);
|
|
38
|
+
if (!context) {
|
|
39
|
+
throw new Error('Collapsible compound components cannot be rendered outside the Collapsible component');
|
|
40
|
+
}
|
|
41
|
+
return context;
|
|
42
|
+
};
|
|
43
|
+
var CollapsibleButton = function CollapsibleButton(_ref2) {
|
|
44
|
+
var children = _ref2.children,
|
|
45
|
+
_ref2$isMainButton = _ref2.isMainButton,
|
|
46
|
+
isMainButton = _ref2$isMainButton === void 0 ? false : _ref2$isMainButton,
|
|
47
|
+
_ref2$isSmallButtonIc = _ref2.isSmallButtonIcon,
|
|
48
|
+
isSmallButtonIcon = _ref2$isSmallButtonIc === void 0 ? false : _ref2$isSmallButtonIc,
|
|
49
|
+
_ref2$active = _ref2.active,
|
|
50
|
+
active = _ref2$active === void 0 ? false : _ref2$active,
|
|
51
|
+
icon = _ref2.icon,
|
|
52
|
+
text = _ref2.text,
|
|
53
|
+
_ref2$isExpanded = _ref2.isExpanded,
|
|
54
|
+
isExpanded = _ref2$isExpanded === void 0 ? false : _ref2$isExpanded,
|
|
55
|
+
isCollapsible = _ref2.isCollapsible,
|
|
56
|
+
badgeValue = _ref2.badgeValue,
|
|
57
|
+
badgeVariant = _ref2.badgeVariant,
|
|
58
|
+
setExpand = _ref2.setExpand,
|
|
59
|
+
props = _objectWithoutProperties(_ref2, _excluded2);
|
|
60
|
+
if (isSmallButtonIcon || isMainButton) {
|
|
61
|
+
return /*#__PURE__*/_react["default"].createElement(_button.ButtonIcon, _extends({}, props, {
|
|
62
|
+
icon: icon,
|
|
63
|
+
text: text,
|
|
64
|
+
isCollapsible: isCollapsible,
|
|
65
|
+
isExpanded: isExpanded,
|
|
66
|
+
active: active,
|
|
67
|
+
badgeValue: badgeValue,
|
|
68
|
+
badgeVariant: badgeVariant,
|
|
69
|
+
setExpand: setExpand,
|
|
70
|
+
holdPress: true,
|
|
71
|
+
sx: {
|
|
72
|
+
width: isMainButton && '100%',
|
|
73
|
+
'+ .content': {
|
|
74
|
+
overflow: 'hidden'
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
} else {
|
|
79
|
+
return /*#__PURE__*/_react["default"].createElement(_button.Button, _extends({}, props, {
|
|
80
|
+
sx: {
|
|
81
|
+
width: '100%',
|
|
82
|
+
border: 'none',
|
|
83
|
+
borderRadius: '0',
|
|
84
|
+
padding: '10px 0',
|
|
85
|
+
textAlign: 'left',
|
|
86
|
+
position: 'relative',
|
|
87
|
+
display: 'flex',
|
|
88
|
+
justifyContent: 'space-between',
|
|
89
|
+
'+ .content': {
|
|
90
|
+
overflow: 'hidden'
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}), children);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var CollapsibleBody = function CollapsibleBody(_ref3) {
|
|
97
|
+
var children = _ref3.children;
|
|
98
|
+
var _useCollapsibleContex = useCollapsibleContext(),
|
|
99
|
+
isOpen = _useCollapsibleContex.isOpen;
|
|
100
|
+
return /*#__PURE__*/_react["default"].createElement(_framerMotion.AnimatePresence, {
|
|
101
|
+
initial: false
|
|
102
|
+
}, isOpen && /*#__PURE__*/_react["default"].createElement(_framerMotion.motion.div, {
|
|
103
|
+
className: "content",
|
|
104
|
+
initial: "collapsed",
|
|
105
|
+
animate: "open",
|
|
106
|
+
exit: "collapsed",
|
|
107
|
+
variants: {
|
|
108
|
+
open: {
|
|
109
|
+
height: 'auto',
|
|
110
|
+
transition: {
|
|
111
|
+
duration: 0.2,
|
|
112
|
+
ease: 'easeIn'
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
collapsed: {
|
|
116
|
+
height: 0,
|
|
117
|
+
transition: {
|
|
118
|
+
duration: 0.2,
|
|
119
|
+
ease: 'easeOut'
|
|
120
|
+
},
|
|
121
|
+
overflow: 'hidden'
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}, children));
|
|
125
|
+
};
|
|
126
|
+
Collapsible.Button = CollapsibleButton;
|
|
127
|
+
Collapsible.Body = CollapsibleBody;
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quintoandar-tokko/collapsible",
|
|
3
|
+
"version": "1.2.373",
|
|
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
|
+
"@quintoandar-tokko/button": "^1.2.371",
|
|
12
|
+
"framer-motion": "2.9.4"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"react": "^16.8.0"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"gitHead": "3c5995a3482c9cd1b428a69e135c934c37bce2ae"
|
|
21
|
+
}
|