@cypress-design/react-docmenu 0.7.1 → 1.0.1

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/dist/index.umd.js CHANGED
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var React = require('react');
4
+ var reactIcon = require('@cypress-design/react-icon');
4
5
  var clsx = require('clsx');
5
- var iconsRegistry = require('@cypress-design/icon-registry');
6
+ var constantsDocmenu = require('@cypress-design/constants-docmenu');
6
7
 
7
8
  function _interopNamespaceDefault(e) {
8
9
  var n = Object.create(null);
@@ -22,52 +23,6 @@ function _interopNamespaceDefault(e) {
22
23
  }
23
24
 
24
25
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
25
- var iconsRegistry__namespace = /*#__PURE__*/_interopNamespaceDefault(iconsRegistry);
26
-
27
- /******************************************************************************
28
- Copyright (c) Microsoft Corporation.
29
-
30
- Permission to use, copy, modify, and/or distribute this software for any
31
- purpose with or without fee is hereby granted.
32
-
33
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
34
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
35
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
36
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
37
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
38
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39
- PERFORMANCE OF THIS SOFTWARE.
40
- ***************************************************************************** */
41
- /* global Reflect, Promise, SuppressedError, Symbol */
42
-
43
-
44
- var __assign$1 = function() {
45
- __assign$1 = Object.assign || function __assign(t) {
46
- for (var s, i = 1, n = arguments.length; i < n; i++) {
47
- s = arguments[i];
48
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
49
- }
50
- return t;
51
- };
52
- return __assign$1.apply(this, arguments);
53
- };
54
-
55
- function __rest$1(s, e) {
56
- var t = {};
57
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
58
- t[p] = s[p];
59
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
60
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
61
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
62
- t[p[i]] = s[p[i]];
63
- }
64
- return t;
65
- }
66
-
67
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
68
- var e = new Error(message);
69
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
70
- };
71
26
 
72
27
  /******************************************************************************
73
28
  Copyright (c) Microsoft Corporation.
@@ -114,80 +69,12 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
114
69
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
115
70
  };
116
71
 
117
- var compileReactIconProperties = function (_a) {
118
- var body = _a.body, defs = _a.defs, compiledClasses = _a.compiledClasses, size = _a.size, name = _a.name, attributes = __rest(_a, ["body", "defs", "compiledClasses", "size", "name"]);
119
- var filteredAttributes = Object.keys(attributes).reduce(function (newAttributes, attrName) {
120
- if (!iconsRegistry.ICON_COLOR_PROP_NAMES.includes(attrName) &&
121
- attrName !== 'name') {
122
- // @ts-expect-error the ky of React's SVGProps is too broad and
123
- // breaks here. Since we do not need to check for it. We keep the expect error
124
- newAttributes[attrName] =
125
- attributes[attrName];
126
- }
127
- return newAttributes;
128
- }, {});
129
- // eslint-disable-next-line react-hooks/rules-of-hooks
130
- React__namespace.useEffect(function () {
131
- var iconFileId = "".concat(name, "_").concat(size);
132
- if (defs) {
133
- if (document.querySelector("[data-cy-svg-defs=\"".concat(iconFileId, "\"]"))) {
134
- return;
135
- }
136
- var svgElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
137
- svgElement.setAttribute('data-cy-svg-defs', iconFileId);
138
- svgElement.setAttribute('width', '0');
139
- svgElement.setAttribute('height', '0');
140
- svgElement.innerHTML = defs;
141
- document.body.appendChild(svgElement);
142
- }
143
- }, [defs, name, size]);
144
- var componentProps = __assign({ width: size, height: size, viewBox: "0 0 ".concat(size, " ").concat(size), fill: 'none', dangerouslySetInnerHTML: {
145
- __html: body,
146
- }, className: undefined }, filteredAttributes);
147
- if (attributes.className) {
148
- compiledClasses.push(attributes.className);
149
- }
150
- if (compiledClasses.length) {
151
- componentProps.className = compiledClasses.join(' ');
152
- }
153
- return componentProps;
154
- };
155
-
156
- function useIconProps(props, iconBodiesAndDefs, availableSizes, name) {
157
- var interactiveColorsOnGroup = props.interactiveColorsOnGroup, cleanProps = __rest(props, ["interactiveColorsOnGroup"]);
158
- var _a = iconsRegistry__namespace.getComponentAttributes(__assign(__assign({}, cleanProps), { availableSizes: availableSizes, interactiveColorsOnGroup: interactiveColorsOnGroup })), size = _a.sizeWithDefault, compiledClasses = _a.compiledClasses;
159
- var _b = iconBodiesAndDefs[size] || {}, body = _b.body, defs = _b.defs;
160
- if (!body) {
161
- throw Error("Icon \"".concat(name, "\" is not available in size ").concat(size));
162
- }
163
- return compileReactIconProperties(__assign(__assign({}, cleanProps), { name: name, size: size, body: body, defs: defs, compiledClasses: compiledClasses }));
164
- }
165
- var IconChevronDownSmall = function (props) { return React__namespace.createElement('svg', useIconProps(props, {
166
- "8": {
167
- "body": "<path stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m1 2.5 3 3 3-3\" class=\"icon-dark\"/>"
168
- },
169
- "16": {
170
- "body": "<path stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m4 6 4 4 4-4\" class=\"icon-dark\"/>"
171
- }
172
- }, ["8", "16"], "chevron-down-small")); };
173
-
174
-
175
- /* <wind-keep class="filter icon-light-secondary icon-dark-secondary"> */
176
-
177
- const classes = {
178
- expandedIcon: 'absolute left-0 transform transition-transform text-gray-400 dark:text-gray-700',
179
- button: 'flex leading-[24px] py-[10px] items-center relative w-full text-start',
180
- topButton: 'leading-[24px] text-[16px] pl-[24px] font-medium',
181
- leafButton: 'leading-[20px] text-[14px] pl-[48px]',
182
- openListBorderLeft: 'absolute left-[8px] top-0 w-[1px] h-full bg-gray-100 dark:bg-gray-900',
183
- };
184
-
185
72
  var DocLink = React__namespace.forwardRef(function (_a, ref) {
186
73
  var item = _a.item, depth = _a.depth, markerIsMoving = _a.markerIsMoving, context = _a.context, onActive = _a.onActive, LinkComponent = _a.LinkComponent;
187
74
  var activeLIRef = React__namespace.useRef(null);
188
75
  var active = React__namespace.useMemo(function () { return item.href === context.activePath; }, [item.href, context.activePath]);
189
76
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
190
- item.label; var itemRest = __rest$1(item, ["label"]);
77
+ item.label; var itemRest = __rest(item, ["label"]);
191
78
  var setActiveMarkerPosition = function () {
192
79
  var _a;
193
80
  if (active) {
@@ -225,7 +112,7 @@ var DocLink = React__namespace.forwardRef(function (_a, ref) {
225
112
  setActiveMarkerPosition: setActiveMarkerPosition,
226
113
  }); });
227
114
  return (React__namespace.createElement("li", { ref: activeLIRef, className: "list-none p-0 scroll-my-10" },
228
- React__namespace.createElement(LinkComponent, __assign$1({}, itemRest, { className: clsx('group relative block w-full pl-[24px]', {
115
+ React__namespace.createElement(LinkComponent, __assign({}, itemRest, { className: clsx('group relative block w-full pl-[24px]', {
229
116
  'text-indigo-500 dark:text-indigo-400': active,
230
117
  'text-gray-700 dark:text-gray-500': !active,
231
118
  'py-[8px] text-[16px] leading-[24px]': depth < 0,
@@ -328,16 +215,16 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
328
215
  }
329
216
  }, [hasActiveItemRecursivelyMemo, updateMarkerPosition]);
330
217
  return (React__namespace.createElement(React__namespace.Fragment, null,
331
- React__namespace.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {},
332
- _b[classes.topButton] = depth === 0,
333
- _b[classes.leafButton] = depth,
218
+ React__namespace.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(constantsDocmenu.classes.button, (_b = {},
219
+ _b[constantsDocmenu.classes.topButton] = depth === 0,
220
+ _b[constantsDocmenu.classes.leafButton] = depth,
334
221
  _b['text-indigo-500 dark:text-indigo-400'] = activePath === group.href,
335
222
  _b['text-gray-900 dark:text-gray-100'] = hasActiveItemRecursivelyMemo && activePath !== group.href,
336
223
  _b['text-gray-800 dark:text-gray-200'] = !hasActiveItemRecursivelyMemo && activePath !== group.href,
337
224
  _b)), style: {
338
225
  paddingLeft: depth >= 1 ? "".concat((depth - 1) * 12 + 48, "px") : undefined,
339
226
  } },
340
- collapsible ? (React__namespace.createElement(IconChevronDownSmall, { "stroke-color": "gray-400", size: depth ? '8' : '16', className: clsx(classes.expandedIcon, {
227
+ collapsible ? (React__namespace.createElement(reactIcon.IconChevronDownSmall, { "stroke-color": "gray-400", size: depth ? '8' : '16', className: clsx(constantsDocmenu.classes.expandedIcon, {
341
228
  'rotate-0': open,
342
229
  '-rotate-90': !open,
343
230
  }), style: {
@@ -351,12 +238,12 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
351
238
  'grid-rows-[1fr]': open,
352
239
  }
353
240
  : null), onTransitionEnd: restoreActiveMarkerAfterTransition },
354
- open && collapsible && depth === 0 ? (React__namespace.createElement("div", { className: classes.openListBorderLeft })) : null,
241
+ open && collapsible && depth === 0 ? (React__namespace.createElement("div", { className: constantsDocmenu.classes.openListBorderLeft })) : null,
355
242
  React__namespace.createElement(DocGroupElements, { ref: $groupElements, className: "overflow-hidden", items: group.items, depth: depth, context: context, markerIsMoving: markerIsMoving, onActivePosition: setActivePosition, updateMarkerPosition: onUpdateMarkerPosition, LinkComponent: LinkComponent }))));
356
243
  });
357
244
  DocGroup.displayName = 'DocMenuDocGroup';
358
245
  var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
359
- var items = _a.items, _b = _a.depth, depth = _b === void 0 ? 0 : _b, onActivePosition = _a.onActivePosition, updateMarkerPosition = _a.updateMarkerPosition, markerIsMoving = _a.markerIsMoving, LinkComponent = _a.LinkComponent, className = _a.className, context = _a.context, rest = __rest$1(_a, ["items", "depth", "onActivePosition", "updateMarkerPosition", "markerIsMoving", "LinkComponent", "className", "context"]);
246
+ var items = _a.items, _b = _a.depth, depth = _b === void 0 ? 0 : _b, onActivePosition = _a.onActivePosition, updateMarkerPosition = _a.updateMarkerPosition, markerIsMoving = _a.markerIsMoving, LinkComponent = _a.LinkComponent, className = _a.className, context = _a.context, rest = __rest(_a, ["items", "depth", "onActivePosition", "updateMarkerPosition", "markerIsMoving", "LinkComponent", "className", "context"]);
360
247
  var $groups = React__namespace.useRef([]);
361
248
  var $items = React__namespace.useRef([]);
362
249
  var reTriggerSetActiveGroup = React__namespace.useCallback(function (index) {
@@ -388,7 +275,7 @@ var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
388
275
  updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
389
276
  }
390
277
  }, [updateMarkerPosition, reTriggerSetActiveGroup, items, activePath]);
391
- return (React__namespace.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', className) }), items.map(function (item, index) {
278
+ return (React__namespace.createElement("ul", __assign({}, rest, { className: clsx('list-none p-0', className) }), items.map(function (item, index) {
392
279
  return 'items' in item ? (React__namespace.createElement("li", { key: index, className: "relative list-none p-0" },
393
280
  React__namespace.createElement(DocGroup, { ref: function (el) {
394
281
  $groups.current[index] = el;
@@ -402,7 +289,7 @@ var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
402
289
  DocGroupElements.displayName = 'DocMenuDocGroupElements';
403
290
 
404
291
  var DocMenu = function (_a) {
405
- var items = _a.items, _b = _a.activePath, activePath = _b === void 0 ? '<unknown>' : _b, _c = _a.collapsible, collapsible = _c === void 0 ? true : _c, _d = _a.LinkComponent, LinkComponent = _d === void 0 ? 'a' : _d, rest = __rest$1(_a, ["items", "activePath", "collapsible", "LinkComponent"]);
292
+ var items = _a.items, _b = _a.activePath, activePath = _b === void 0 ? '<unknown>' : _b, _c = _a.collapsible, collapsible = _c === void 0 ? true : _c, _d = _a.LinkComponent, LinkComponent = _d === void 0 ? 'a' : _d, rest = __rest(_a, ["items", "activePath", "collapsible", "LinkComponent"]);
406
293
  var _e = React__namespace.useState(0), activeTop = _e[0], setActiveTop = _e[1];
407
294
  var _f = React__namespace.useState(36), activeHeight = _f[0], setActiveHeight = _f[1];
408
295
  var _g = React__namespace.useState(false), showMarker = _g[0], setShowMarker = _g[1];
@@ -436,7 +323,7 @@ var DocMenu = function (_a) {
436
323
  ? 'height .3s ease-in-out, top .3s ease-in-out'
437
324
  : 'none',
438
325
  } })) : null,
439
- React__namespace.createElement(DocGroupElements, __assign$1({}, rest, { items: items, depth: -1, markerIsMoving: markerIsMoving, onActivePosition: setActivePosition, LinkComponent: LinkComponent, context: {
326
+ React__namespace.createElement(DocGroupElements, __assign({}, rest, { items: items, depth: -1, markerIsMoving: markerIsMoving, onActivePosition: setActivePosition, LinkComponent: LinkComponent, context: {
440
327
  setMarkerIsMoving: setMarkerIsMoving,
441
328
  activePath: activePath,
442
329
  collapsible: collapsible,
@@ -447,4 +334,4 @@ var DocMenu = function (_a) {
447
334
  module.exports = DocMenu;
448
335
  //# sourceMappingURL=index.umd.js.map
449
336
 
450
- /* <wind-keep class="container relative absolute h-[36px] w-[4px] z-50 rounded-full bg-indigo-500 dark:bg-indigo-400 ml-[6.5px] mt-[4px] transition ease-in-out text-indigo-500 dark:text-indigo-400 text-gray-900 dark:text-gray-100 text-gray-800 dark:text-gray-200 rotate-0 -rotate-90 transition-all grid grid-rows-[0fr] grid-rows-[1fr] overflow-hidden filter list-none p-0 visible block inline scroll-my-10 w-full pl-[24px] text-gray-700 dark:text-gray-500 py-[8px] text-[16px] leading-[24px] leading-[20px] text-[14px] py-[12px] left-[6.5px] top-[4px] bottom-[4px] z-10 hidden group-hover:block bg-gray-300 text-indigo-400 text-gray-500 bg-indigo-400 left-0 transform transition-transform text-gray-400 dark:text-gray-700 flex py-[10px] items-center text-start font-medium pl-[48px] left-[8px] top-0 w-[1px] h-full bg-gray-100 dark:bg-gray-900"> */
337
+ /* <wind-keep class="container relative absolute h-[36px] w-[4px] z-50 rounded-full bg-indigo-500 dark:bg-indigo-400 ml-[6.5px] mt-[4px] transition ease-in-out text-indigo-500 dark:text-indigo-400 text-gray-900 dark:text-gray-100 text-gray-800 dark:text-gray-200 rotate-0 -rotate-90 transition-all grid grid-rows-[0fr] grid-rows-[1fr] overflow-hidden filter list-none p-0 visible block inline scroll-my-10 w-full pl-[24px] text-gray-700 dark:text-gray-500 py-[8px] text-[16px] leading-[24px] leading-[20px] text-[14px] py-[12px] left-[6.5px] top-[4px] bottom-[4px] z-10 hidden group-hover:block bg-gray-300 text-indigo-400 text-gray-500 bg-indigo-400"> */