@quintoandar-tokko/dropdown 1.2.388

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.
Files changed (2) hide show
  1. package/lib/index.js +302 -0
  2. package/package.json +22 -0
package/lib/index.js ADDED
@@ -0,0 +1,302 @@
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.Dropdown = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _box = require("@quintoandar-tokko/box");
10
+ var _button = require("@quintoandar-tokko/button");
11
+ var _icons = require("@quintoandar-tokko/icons");
12
+ var _list = require("@quintoandar-tokko/list");
13
+ var _hooks = require("@quintoandar-tokko/hooks");
14
+ var _text = require("@quintoandar-tokko/text");
15
+ var _theme = _interopRequireDefault(require("@quintoandar-tokko/theme"));
16
+ var _excluded = ["children"],
17
+ _excluded2 = ["icon", "text", "variant", "disabled", "filled", "isButtonIcon", "isArrowStatic", "variantSize", "selection"],
18
+ _excluded3 = ["children", "width", "height", "clickClose"],
19
+ _excluded4 = ["disabled", "variantSize"],
20
+ _excluded5 = ["disabled", "active", "variantSize"],
21
+ _excluded6 = ["disabled", "active", "icon", "variantSize"];
22
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
23
+ 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); }
24
+ 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; }
25
+ 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); }
26
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
27
+ 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."); }
28
+ 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; } }
29
+ 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; }
30
+ 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; } }
31
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
32
+ 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; }
33
+ 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; }
34
+ var DropdownContext = /*#__PURE__*/(0, _react.createContext)();
35
+ var Dropdown = exports.Dropdown = function Dropdown(_ref) {
36
+ var children = _ref.children,
37
+ props = _objectWithoutProperties(_ref, _excluded);
38
+ var ref = _react["default"].useRef();
39
+ var _useState = (0, _react.useState)(false),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ open = _useState2[0],
42
+ setIsOpen = _useState2[1];
43
+ (0, _hooks.useOnClickOutside)(ref, function () {
44
+ return setIsOpen(false);
45
+ });
46
+ var value = _react["default"].useMemo(function () {
47
+ return {
48
+ open: open,
49
+ setIsOpen: setIsOpen,
50
+ ref: ref
51
+ };
52
+ }, [open]);
53
+ return /*#__PURE__*/_react["default"].createElement(DropdownContext.Provider, {
54
+ value: value
55
+ }, /*#__PURE__*/_react["default"].createElement(_box.Box, _extends({
56
+ ref: ref
57
+ }, props, {
58
+ __css: {
59
+ position: 'relative',
60
+ height: '200px'
61
+ }
62
+ }), children));
63
+ };
64
+ var useDropdownContext = function useDropdownContext() {
65
+ var context = (0, _react.useContext)(DropdownContext);
66
+ if (!context) {
67
+ throw new Error('Dropdown compound components cannot be rendered outside the Dropdown component');
68
+ }
69
+ return context;
70
+ };
71
+ var DropdownButton = function DropdownButton(_ref2) {
72
+ var icon = _ref2.icon,
73
+ text = _ref2.text,
74
+ _ref2$variant = _ref2.variant,
75
+ variant = _ref2$variant === void 0 ? 'dropdown' : _ref2$variant,
76
+ _ref2$disabled = _ref2.disabled,
77
+ disabled = _ref2$disabled === void 0 ? false : _ref2$disabled,
78
+ _ref2$filled = _ref2.filled,
79
+ filled = _ref2$filled === void 0 ? false : _ref2$filled,
80
+ _ref2$isButtonIcon = _ref2.isButtonIcon,
81
+ isButtonIcon = _ref2$isButtonIcon === void 0 ? false : _ref2$isButtonIcon,
82
+ _ref2$isArrowStatic = _ref2.isArrowStatic,
83
+ isArrowStatic = _ref2$isArrowStatic === void 0 ? false : _ref2$isArrowStatic,
84
+ _ref2$variantSize = _ref2.variantSize,
85
+ variantSize = _ref2$variantSize === void 0 ? 'dropdownSizeNormal' : _ref2$variantSize,
86
+ selection = _ref2.selection,
87
+ props = _objectWithoutProperties(_ref2, _excluded2);
88
+ var _useDropdownContext = useDropdownContext(),
89
+ setIsOpen = _useDropdownContext.setIsOpen;
90
+ var variantValues = Object.values(_theme["default"].buttons)[Object.keys(_theme["default"].buttons).indexOf(variant)];
91
+ var colorFilled = variantValues.colorFilled;
92
+ var backgroundColorFilled = variantValues.backgroundColorFilled;
93
+ var colorArrowFilled = variantValues.colorArrowFilled;
94
+ var borderFilled = variantValues.borderFilled;
95
+ var sizeArrow = variantValues.sizeArrow;
96
+ if (sizeArrow === undefined) {
97
+ sizeArrow = '12px';
98
+ }
99
+ // ESTO FALLA CON LOS CASOS QUE MENCIONO MARIAN
100
+ // Porque llamo al buttonIcon
101
+ if (isButtonIcon) {
102
+ return /*#__PURE__*/_react["default"].createElement(_button.ButtonIcon, {
103
+ variant: [variant, variantSize],
104
+ icon: icon,
105
+ filled: filled,
106
+ holdPress: true,
107
+ onClick: !disabled ? function () {
108
+ return setIsOpen(function (prevState) {
109
+ return !prevState;
110
+ });
111
+ } : undefined
112
+ });
113
+ }
114
+ return /*#__PURE__*/_react["default"].createElement(_button.Button, _extends({
115
+ variant: [variant, variantSize]
116
+ }, props, {
117
+ onClick: !disabled ? function () {
118
+ return setIsOpen(function (prevState) {
119
+ return !prevState;
120
+ });
121
+ } : undefined,
122
+ sx: {
123
+ display: 'flex',
124
+ flexDirection: 'row',
125
+ alignItems: 'center',
126
+ textOverflow: 'ellipsis',
127
+ fontFamily: 'Nunito Sans',
128
+ overflow: 'hidden',
129
+ whiteSpace: 'nowrap',
130
+ textAlign: 'start',
131
+ color: filled && colorFilled,
132
+ border: filled && borderFilled,
133
+ backgroundColor: filled && backgroundColorFilled,
134
+ justifyContent: isArrowStatic ? 'center' : 'flex-start',
135
+ '& span': {
136
+ flex: 1
137
+ }
138
+ }
139
+ }), icon && (!filled ? /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
140
+ icon: icon,
141
+ fontSize: "16px"
142
+ }) : /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
143
+ icon: icon,
144
+ fontSize: "16px",
145
+ style: {
146
+ color: colorFilled
147
+ }
148
+ })), !filled ? /*#__PURE__*/_react["default"].createElement("span", null, text) : /*#__PURE__*/_react["default"].createElement("span", {
149
+ style: {
150
+ color: colorFilled,
151
+ overflow: 'hidden',
152
+ width: '95%',
153
+ textOverflow: 'ellipsis'
154
+ }
155
+ }, text), selection && /*#__PURE__*/_react["default"].createElement("span", {
156
+ style: disabled ? {
157
+ color: '#AEBAC0',
158
+ fontWeight: 700
159
+ } : {
160
+ color: '#384248',
161
+ fontWeight: 700
162
+ }
163
+ }, selection), !filled ? /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
164
+ icon: "icon-dropdown",
165
+ fontSize: sizeArrow,
166
+ style: {
167
+ position: isArrowStatic ? 'static' : 'absolute',
168
+ right: '12px',
169
+ transform: 'rotate(0deg)'
170
+ }
171
+ }) : /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
172
+ icon: "icon-dropdown",
173
+ fontSize: sizeArrow,
174
+ style: {
175
+ position: isArrowStatic ? 'static' : 'absolute',
176
+ right: '12px',
177
+ transform: 'rotate(0deg)',
178
+ color: colorArrowFilled
179
+ }
180
+ }));
181
+ };
182
+ var DropdownList = function DropdownList(_ref3) {
183
+ var children = _ref3.children,
184
+ _ref3$width = _ref3.width,
185
+ width = _ref3$width === void 0 ? '236px' : _ref3$width,
186
+ _ref3$height = _ref3.height,
187
+ height = _ref3$height === void 0 ? '150px' : _ref3$height,
188
+ _ref3$clickClose = _ref3.clickClose,
189
+ clickClose = _ref3$clickClose === void 0 ? false : _ref3$clickClose,
190
+ props = _objectWithoutProperties(_ref3, _excluded3);
191
+ var _useDropdownContext2 = useDropdownContext(),
192
+ open = _useDropdownContext2.open,
193
+ setIsOpen = _useDropdownContext2.setIsOpen;
194
+ return open && /*#__PURE__*/_react["default"].createElement(_list.List, _extends({
195
+ onClick: clickClose ? function () {
196
+ return setIsOpen(false);
197
+ } : function () {}
198
+ }, props, {
199
+ sx: {
200
+ display: 'flex',
201
+ flexDirection: 'column',
202
+ flexGrow: 1,
203
+ py: '5px',
204
+ backgroundColor: 'white',
205
+ boxShadow: 'active',
206
+ borderRadius: 'input',
207
+ position: 'absolute',
208
+ top: '38px',
209
+ zIndex: 1,
210
+ width: width,
211
+ maxHeight: height
212
+ }
213
+ }), children);
214
+ };
215
+ var DropdownListSearch = function DropdownListSearch(props) {
216
+ return /*#__PURE__*/_react["default"].createElement(_list.List.Search, props);
217
+ };
218
+ var DropdownListItem = function DropdownListItem(props) {
219
+ return /*#__PURE__*/_react["default"].createElement(_list.List.Item, _extends({}, props, {
220
+ sx: {
221
+ cursor: 'pointer',
222
+ fontSize: '2',
223
+ color: 'darkGray'
224
+ }
225
+ }));
226
+ };
227
+ var DropdownListDefault = function DropdownListDefault(_ref4) {
228
+ var disabled = _ref4.disabled,
229
+ _ref4$variantSize = _ref4.variantSize,
230
+ variantSize = _ref4$variantSize === void 0 ? 'dropdownSizeNormal' : _ref4$variantSize,
231
+ props = _objectWithoutProperties(_ref4, _excluded4);
232
+ return /*#__PURE__*/_react["default"].createElement(_list.List.Default, _extends({
233
+ disabled: disabled,
234
+ variantSize: variantSize
235
+ }, props, {
236
+ sx: {
237
+ cursor: disabled ? 'default' : 'pointer',
238
+ pointerEvents: disabled ? 'none' : undefined,
239
+ userSelect: disabled ? 'none' : undefined,
240
+ fontSize: '2',
241
+ color: 'darkGray'
242
+ }
243
+ }));
244
+ };
245
+ var DropdownListMultiselect = function DropdownListMultiselect(_ref5) {
246
+ var disabled = _ref5.disabled,
247
+ active = _ref5.active,
248
+ _ref5$variantSize = _ref5.variantSize,
249
+ variantSize = _ref5$variantSize === void 0 ? 'dropdownSizeNormal' : _ref5$variantSize,
250
+ props = _objectWithoutProperties(_ref5, _excluded5);
251
+ return /*#__PURE__*/_react["default"].createElement(_list.List.Multiselect, _extends({
252
+ disabled: disabled,
253
+ isActive: active,
254
+ variantSize: variantSize
255
+ }, props, {
256
+ sx: {
257
+ cursor: disabled ? 'default' : 'pointer',
258
+ pointerEvents: disabled ? 'none' : undefined,
259
+ userSelect: disabled ? 'none' : undefined,
260
+ fontSize: '2',
261
+ color: 'darkGray'
262
+ }
263
+ }));
264
+ };
265
+ var DropdownListIcon = function DropdownListIcon(_ref6) {
266
+ var disabled = _ref6.disabled,
267
+ active = _ref6.active,
268
+ icon = _ref6.icon,
269
+ _ref6$variantSize = _ref6.variantSize,
270
+ variantSize = _ref6$variantSize === void 0 ? 'dropdownSizeNormal' : _ref6$variantSize,
271
+ props = _objectWithoutProperties(_ref6, _excluded6);
272
+ return /*#__PURE__*/_react["default"].createElement(_list.List.Icon, _extends({
273
+ disabled: disabled,
274
+ icon: icon,
275
+ variantSize: variantSize
276
+ }, props, {
277
+ sx: {
278
+ cursor: disabled ? 'default' : 'pointer',
279
+ pointerEvents: disabled ? 'none' : undefined,
280
+ userSelect: disabled ? 'none' : undefined,
281
+ fontSize: '2',
282
+ color: 'darkGray'
283
+ }
284
+ }));
285
+ };
286
+ var DropdownText = function DropdownText(_ref7) {
287
+ var children = _ref7.children;
288
+ return /*#__PURE__*/_react["default"].createElement(_text.Text, {
289
+ variant: "body.fontSize12",
290
+ style: {
291
+ padding: '9px 12px 9px 12px'
292
+ }
293
+ }, children);
294
+ };
295
+ Dropdown.Button = DropdownButton;
296
+ Dropdown.Items = DropdownList;
297
+ Dropdown.Item = DropdownListItem;
298
+ Dropdown.Default = DropdownListDefault;
299
+ Dropdown.Multiselect = DropdownListMultiselect;
300
+ Dropdown.Icon = DropdownListIcon;
301
+ Dropdown.Text = DropdownText;
302
+ Dropdown.Search = DropdownListSearch;
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@quintoandar-tokko/dropdown",
3
+ "version": "1.2.388",
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
+ "@quintoandar-tokko/hooks": "^1.2.308",
13
+ "@quintoandar-tokko/list": "^1.2.365"
14
+ },
15
+ "peerDependencies": {
16
+ "react": "^16.8.0"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "gitHead": "3c5995a3482c9cd1b428a69e135c934c37bce2ae"
22
+ }