@cypress-design/react-docmenu 1.0.0 → 1.0.2
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/.turbo/turbo-build.log +2 -0
- package/CHANGELOG.md +15 -0
- package/dist/index.es.mjs +7 -117
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +8 -118
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
- package/rollup.config.mjs +5 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
var n = Object.create(null);
|
|
@@ -22,52 +22,6 @@ function _interopNamespaceDefault(e) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
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
25
|
|
|
72
26
|
/******************************************************************************
|
|
73
27
|
Copyright (c) Microsoft Corporation.
|
|
@@ -114,70 +68,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
114
68
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
115
69
|
};
|
|
116
70
|
|
|
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 === '>' ? '>' : '<';
|
|
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
71
|
const classes = {
|
|
182
72
|
expandedIcon: 'absolute left-0 transform transition-transform text-gray-400 dark:text-gray-700',
|
|
183
73
|
button: 'flex leading-[24px] py-[10px] items-center relative w-full text-start',
|
|
@@ -191,7 +81,7 @@ var DocLink = React__namespace.forwardRef(function (_a, ref) {
|
|
|
191
81
|
var activeLIRef = React__namespace.useRef(null);
|
|
192
82
|
var active = React__namespace.useMemo(function () { return item.href === context.activePath; }, [item.href, context.activePath]);
|
|
193
83
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
194
|
-
item.label; var itemRest = __rest
|
|
84
|
+
item.label; var itemRest = __rest(item, ["label"]);
|
|
195
85
|
var setActiveMarkerPosition = function () {
|
|
196
86
|
var _a;
|
|
197
87
|
if (active) {
|
|
@@ -229,7 +119,7 @@ var DocLink = React__namespace.forwardRef(function (_a, ref) {
|
|
|
229
119
|
setActiveMarkerPosition: setActiveMarkerPosition,
|
|
230
120
|
}); });
|
|
231
121
|
return (React__namespace.createElement("li", { ref: activeLIRef, className: "list-none p-0 scroll-my-10" },
|
|
232
|
-
React__namespace.createElement(LinkComponent, __assign
|
|
122
|
+
React__namespace.createElement(LinkComponent, __assign({}, itemRest, { className: clsx('group relative block w-full pl-[24px]', {
|
|
233
123
|
'text-indigo-500 dark:text-indigo-400': active,
|
|
234
124
|
'text-gray-700 dark:text-gray-500': !active,
|
|
235
125
|
'py-[8px] text-[16px] leading-[24px]': depth < 0,
|
|
@@ -341,7 +231,7 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
|
|
|
341
231
|
_b)), style: {
|
|
342
232
|
paddingLeft: depth >= 1 ? "".concat((depth - 1) * 12 + 48, "px") : undefined,
|
|
343
233
|
} },
|
|
344
|
-
collapsible ? (React__namespace.createElement(IconChevronDownSmall, { "stroke-color": "gray-400", size: depth ? '8' : '16', className: clsx(classes.expandedIcon, {
|
|
234
|
+
collapsible ? (React__namespace.createElement(reactIcon.IconChevronDownSmall, { "stroke-color": "gray-400", size: depth ? '8' : '16', className: clsx(classes.expandedIcon, {
|
|
345
235
|
'rotate-0': open,
|
|
346
236
|
'-rotate-90': !open,
|
|
347
237
|
}), style: {
|
|
@@ -360,7 +250,7 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
|
|
|
360
250
|
});
|
|
361
251
|
DocGroup.displayName = 'DocMenuDocGroup';
|
|
362
252
|
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
|
|
253
|
+
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
254
|
var $groups = React__namespace.useRef([]);
|
|
365
255
|
var $items = React__namespace.useRef([]);
|
|
366
256
|
var reTriggerSetActiveGroup = React__namespace.useCallback(function (index) {
|
|
@@ -392,7 +282,7 @@ var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
|
|
|
392
282
|
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
393
283
|
}
|
|
394
284
|
}, [updateMarkerPosition, reTriggerSetActiveGroup, items, activePath]);
|
|
395
|
-
return (React__namespace.createElement("ul", __assign
|
|
285
|
+
return (React__namespace.createElement("ul", __assign({}, rest, { className: clsx('list-none p-0', className) }), items.map(function (item, index) {
|
|
396
286
|
return 'items' in item ? (React__namespace.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
397
287
|
React__namespace.createElement(DocGroup, { ref: function (el) {
|
|
398
288
|
$groups.current[index] = el;
|
|
@@ -406,7 +296,7 @@ var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
|
|
|
406
296
|
DocGroupElements.displayName = 'DocMenuDocGroupElements';
|
|
407
297
|
|
|
408
298
|
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
|
|
299
|
+
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
300
|
var _e = React__namespace.useState(0), activeTop = _e[0], setActiveTop = _e[1];
|
|
411
301
|
var _f = React__namespace.useState(36), activeHeight = _f[0], setActiveHeight = _f[1];
|
|
412
302
|
var _g = React__namespace.useState(false), showMarker = _g[0], setShowMarker = _g[1];
|
|
@@ -440,7 +330,7 @@ var DocMenu = function (_a) {
|
|
|
440
330
|
? 'height .3s ease-in-out, top .3s ease-in-out'
|
|
441
331
|
: 'none',
|
|
442
332
|
} })) : null,
|
|
443
|
-
React__namespace.createElement(DocGroupElements, __assign
|
|
333
|
+
React__namespace.createElement(DocGroupElements, __assign({}, rest, { items: items, depth: -1, markerIsMoving: markerIsMoving, onActivePosition: setActivePosition, LinkComponent: LinkComponent, context: {
|
|
444
334
|
setMarkerIsMoving: setMarkerIsMoving,
|
|
445
335
|
activePath: activePath,
|
|
446
336
|
collapsible: collapsible,
|