@cypress-design/react-docmenu 1.0.0 → 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,84 +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, alt = _a.alt, attributes = __rest(_a, ["body", "defs", "compiledClasses", "size", "name", "alt"]);
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: alt
146
- ? "<title>".concat(alt.replace(/[><]/g, function (s) {
147
- return s === '>' ? '&gt;' : '&lt;';
148
- }), "</title>").concat(body)
149
- : body,
150
- }, className: undefined }, filteredAttributes);
151
- if (attributes.className) {
152
- compiledClasses.push(attributes.className);
153
- }
154
- if (compiledClasses.length) {
155
- componentProps.className = compiledClasses.join(' ');
156
- }
157
- return componentProps;
158
- };
159
-
160
- function useIconProps(props, iconBodiesAndDefs, availableSizes, name) {
161
- var interactiveColorsOnGroup = props.interactiveColorsOnGroup, cleanProps = __rest(props, ["interactiveColorsOnGroup"]);
162
- var _a = iconsRegistry__namespace.getComponentAttributes(__assign(__assign({}, cleanProps), { availableSizes: availableSizes, interactiveColorsOnGroup: interactiveColorsOnGroup })), size = _a.sizeWithDefault, compiledClasses = _a.compiledClasses;
163
- var _b = iconBodiesAndDefs[size] || {}, body = _b.body, defs = _b.defs;
164
- if (!body) {
165
- throw Error("Icon \"".concat(name, "\" is not available in size ").concat(size));
166
- }
167
- return compileReactIconProperties(__assign(__assign({}, cleanProps), { name: name, size: size, body: body, defs: defs, compiledClasses: compiledClasses }));
168
- }
169
- var IconChevronDownSmall = function (props) { return React__namespace.createElement('svg', useIconProps(props, {
170
- "8": {
171
- "body": "<path d=\"m1 2.5 3 3 3-3\" stroke=\"currentColor\" class=\"icon-dark\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>"
172
- },
173
- "16": {
174
- "body": "<path d=\"m4 6 4 4 4-4\" stroke=\"currentColor\" class=\"icon-dark\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>"
175
- }
176
- }, ["8", "16"], "chevron-down-small")); };
177
-
178
-
179
- /* <wind-keep class="filter icon-light-secondary icon-dark-secondary"> */
180
-
181
- const classes = {
182
- expandedIcon: 'absolute left-0 transform transition-transform text-gray-400 dark:text-gray-700',
183
- button: 'flex leading-[24px] py-[10px] items-center relative w-full text-start',
184
- topButton: 'leading-[24px] text-[16px] pl-[24px] font-medium',
185
- leafButton: 'leading-[20px] text-[14px] pl-[48px]',
186
- openListBorderLeft: 'absolute left-[8px] top-0 w-[1px] h-full bg-gray-100 dark:bg-gray-900',
187
- };
188
-
189
72
  var DocLink = React__namespace.forwardRef(function (_a, ref) {
190
73
  var item = _a.item, depth = _a.depth, markerIsMoving = _a.markerIsMoving, context = _a.context, onActive = _a.onActive, LinkComponent = _a.LinkComponent;
191
74
  var activeLIRef = React__namespace.useRef(null);
192
75
  var active = React__namespace.useMemo(function () { return item.href === context.activePath; }, [item.href, context.activePath]);
193
76
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
194
- item.label; var itemRest = __rest$1(item, ["label"]);
77
+ item.label; var itemRest = __rest(item, ["label"]);
195
78
  var setActiveMarkerPosition = function () {
196
79
  var _a;
197
80
  if (active) {
@@ -229,7 +112,7 @@ var DocLink = React__namespace.forwardRef(function (_a, ref) {
229
112
  setActiveMarkerPosition: setActiveMarkerPosition,
230
113
  }); });
231
114
  return (React__namespace.createElement("li", { ref: activeLIRef, className: "list-none p-0 scroll-my-10" },
232
- 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]', {
233
116
  'text-indigo-500 dark:text-indigo-400': active,
234
117
  'text-gray-700 dark:text-gray-500': !active,
235
118
  'py-[8px] text-[16px] leading-[24px]': depth < 0,
@@ -332,16 +215,16 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
332
215
  }
333
216
  }, [hasActiveItemRecursivelyMemo, updateMarkerPosition]);
334
217
  return (React__namespace.createElement(React__namespace.Fragment, null,
335
- React__namespace.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {},
336
- _b[classes.topButton] = depth === 0,
337
- _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,
338
221
  _b['text-indigo-500 dark:text-indigo-400'] = activePath === group.href,
339
222
  _b['text-gray-900 dark:text-gray-100'] = hasActiveItemRecursivelyMemo && activePath !== group.href,
340
223
  _b['text-gray-800 dark:text-gray-200'] = !hasActiveItemRecursivelyMemo && activePath !== group.href,
341
224
  _b)), style: {
342
225
  paddingLeft: depth >= 1 ? "".concat((depth - 1) * 12 + 48, "px") : undefined,
343
226
  } },
344
- 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, {
345
228
  'rotate-0': open,
346
229
  '-rotate-90': !open,
347
230
  }), style: {
@@ -355,12 +238,12 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
355
238
  'grid-rows-[1fr]': open,
356
239
  }
357
240
  : null), onTransitionEnd: restoreActiveMarkerAfterTransition },
358
- 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,
359
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 }))));
360
243
  });
361
244
  DocGroup.displayName = 'DocMenuDocGroup';
362
245
  var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
363
- 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"]);
364
247
  var $groups = React__namespace.useRef([]);
365
248
  var $items = React__namespace.useRef([]);
366
249
  var reTriggerSetActiveGroup = React__namespace.useCallback(function (index) {
@@ -392,7 +275,7 @@ var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
392
275
  updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
393
276
  }
394
277
  }, [updateMarkerPosition, reTriggerSetActiveGroup, items, activePath]);
395
- 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) {
396
279
  return 'items' in item ? (React__namespace.createElement("li", { key: index, className: "relative list-none p-0" },
397
280
  React__namespace.createElement(DocGroup, { ref: function (el) {
398
281
  $groups.current[index] = el;
@@ -406,7 +289,7 @@ var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
406
289
  DocGroupElements.displayName = 'DocMenuDocGroupElements';
407
290
 
408
291
  var DocMenu = function (_a) {
409
- 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"]);
410
293
  var _e = React__namespace.useState(0), activeTop = _e[0], setActiveTop = _e[1];
411
294
  var _f = React__namespace.useState(36), activeHeight = _f[0], setActiveHeight = _f[1];
412
295
  var _g = React__namespace.useState(false), showMarker = _g[0], setShowMarker = _g[1];
@@ -440,7 +323,7 @@ var DocMenu = function (_a) {
440
323
  ? 'height .3s ease-in-out, top .3s ease-in-out'
441
324
  : 'none',
442
325
  } })) : null,
443
- 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: {
444
327
  setMarkerIsMoving: setMarkerIsMoving,
445
328
  activePath: activePath,
446
329
  collapsible: collapsible,
@@ -451,4 +334,4 @@ var DocMenu = function (_a) {
451
334
  module.exports = DocMenu;
452
335
  //# sourceMappingURL=index.umd.js.map
453
336
 
454
- /* <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"> */