@cypress-design/react-docmenu 0.1.0
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 +6 -0
- package/CHANGELOG.md +12 -0
- package/DocMenu.rootstory.tsx +7 -0
- package/DocMenu.tsx +34 -0
- package/DocMenuReact.cy.tsx +14 -0
- package/ReadMe.md +77 -0
- package/_DocGroup.tsx +121 -0
- package/_DocLink.tsx +60 -0
- package/dist/constants.d.ts +17 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/index.es.mjs +227 -0
- package/dist/index.es.mjs.map +1 -0
- package/dist/index.umd.js +248 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/react/DocMenu.d.ts +10 -0
- package/dist/react/DocMenu.d.ts.map +1 -0
- package/dist/react/_DocGroup.d.ts +10 -0
- package/dist/react/_DocGroup.d.ts.map +1 -0
- package/dist/react/_DocLink.d.ts +10 -0
- package/dist/react/_DocLink.d.ts.map +1 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.d.ts.map +1 -0
- package/index.ts +2 -0
- package/package.json +26 -0
- package/rollup.config.mjs +3 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var clsx = require('clsx');
|
|
5
|
+
var iconsRegistry = require('@cypress-design/icon-registry');
|
|
6
|
+
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
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
|
+
|
|
42
|
+
var __assign$1 = function() {
|
|
43
|
+
__assign$1 = Object.assign || function __assign(t) {
|
|
44
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
45
|
+
s = arguments[i];
|
|
46
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
47
|
+
}
|
|
48
|
+
return t;
|
|
49
|
+
};
|
|
50
|
+
return __assign$1.apply(this, arguments);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function __rest$1(s, e) {
|
|
54
|
+
var t = {};
|
|
55
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
56
|
+
t[p] = s[p];
|
|
57
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
58
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
59
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
60
|
+
t[p[i]] = s[p[i]];
|
|
61
|
+
}
|
|
62
|
+
return t;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function __spreadArray(to, from, pack) {
|
|
66
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
+
if (ar || !(i in from)) {
|
|
68
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
+
ar[i] = from[i];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
var DocLink = function (_a) {
|
|
76
|
+
var item = _a.item, collapsible = _a.collapsible, _b = _a.depth, depth = _b === void 0 ? -1 : _b, onActive = _a.onActive;
|
|
77
|
+
var activeLIRef = React__namespace.useRef(null);
|
|
78
|
+
// on mount, if the item is active,
|
|
79
|
+
// send the top position to the parent
|
|
80
|
+
React__namespace.useEffect(function () {
|
|
81
|
+
var _a;
|
|
82
|
+
if (item.active) {
|
|
83
|
+
onActive === null || onActive === void 0 ? void 0 : onActive(((_a = activeLIRef === null || activeLIRef === void 0 ? void 0 : activeLIRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop) || 0);
|
|
84
|
+
}
|
|
85
|
+
}, []);
|
|
86
|
+
return (React__namespace.createElement("li", { ref: activeLIRef, className: clsx('list-none p-0', {
|
|
87
|
+
'pl-[16px]': depth >= 0,
|
|
88
|
+
}) },
|
|
89
|
+
React__namespace.createElement("a", { className: clsx('group relative inline-block pl-[24px]', {
|
|
90
|
+
'text-indigo-500 dark:text-indigo-200': item.active,
|
|
91
|
+
'py-[8px] text-[16px] leading-[24px]': depth < 0,
|
|
92
|
+
'py-[12px] leading-[20px] text-[14px]': depth >= 0,
|
|
93
|
+
}), href: item.href },
|
|
94
|
+
depth >= 0 ? (React__namespace.createElement("div", { className: clsx('absolute w-[4px] z-10 top-[10%] h-[80%] rounded-full hidden', {
|
|
95
|
+
'group-hover:block bg-gray-300': !item.active && collapsible,
|
|
96
|
+
}), style: {
|
|
97
|
+
left: "-".concat(18.5 + depth * 8, "px"),
|
|
98
|
+
} })) : null,
|
|
99
|
+
item.text)));
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/******************************************************************************
|
|
103
|
+
Copyright (c) Microsoft Corporation.
|
|
104
|
+
|
|
105
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
106
|
+
purpose with or without fee is hereby granted.
|
|
107
|
+
|
|
108
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
109
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
110
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
111
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
112
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
113
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
114
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
115
|
+
***************************************************************************** */
|
|
116
|
+
|
|
117
|
+
var __assign = function() {
|
|
118
|
+
__assign = Object.assign || function __assign(t) {
|
|
119
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
120
|
+
s = arguments[i];
|
|
121
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
122
|
+
}
|
|
123
|
+
return t;
|
|
124
|
+
};
|
|
125
|
+
return __assign.apply(this, arguments);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
function __rest(s, e) {
|
|
129
|
+
var t = {};
|
|
130
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
131
|
+
t[p] = s[p];
|
|
132
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
133
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
134
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
135
|
+
t[p[i]] = s[p[i]];
|
|
136
|
+
}
|
|
137
|
+
return t;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
var compileReactIconProperties = function (_a) {
|
|
141
|
+
var body = _a.body, compiledClasses = _a.compiledClasses, size = _a.size, attributes = __rest(_a, ["body", "compiledClasses", "size"]);
|
|
142
|
+
var filteredAttributes = Object.keys(attributes).reduce(function (newAttributes, attrName) {
|
|
143
|
+
if (!iconsRegistry.ICON_COLOR_PROP_NAMES.includes(attrName) && attrName !== 'name') {
|
|
144
|
+
newAttributes[attrName] =
|
|
145
|
+
attributes[attrName];
|
|
146
|
+
}
|
|
147
|
+
return newAttributes;
|
|
148
|
+
}, {});
|
|
149
|
+
var componentProps = __assign({ width: size, height: size, viewBox: "0 0 ".concat(size, " ").concat(size), fill: 'none', dangerouslySetInnerHTML: {
|
|
150
|
+
__html: body,
|
|
151
|
+
} }, filteredAttributes);
|
|
152
|
+
if (attributes.className) {
|
|
153
|
+
compiledClasses.push(attributes.className);
|
|
154
|
+
}
|
|
155
|
+
if (compiledClasses.length) {
|
|
156
|
+
componentProps.className = compiledClasses.join(' ');
|
|
157
|
+
}
|
|
158
|
+
return componentProps;
|
|
159
|
+
};
|
|
160
|
+
var IconChevronDownSmall = function (props) {
|
|
161
|
+
var _a = iconsRegistry__namespace.getComponentAttributes(__assign(__assign({}, props), { availableSizes: ["8", "16"] })), size = _a.sizeWithDefault, compiledClasses = _a.compiledClasses;
|
|
162
|
+
var iconBodies = {
|
|
163
|
+
"8": "<path stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m1 2.5 3 3 3-3\" class=\"icon-dark\"/>",
|
|
164
|
+
"16": "<path stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m4 6 4 4 4-4\" class=\"icon-dark\"/>"
|
|
165
|
+
};
|
|
166
|
+
var body = iconBodies[size];
|
|
167
|
+
if (!body) {
|
|
168
|
+
throw Error("Icon \"chevron-down-small\" is not available in size ".concat(size));
|
|
169
|
+
}
|
|
170
|
+
return React__namespace.createElement('svg', compileReactIconProperties(__assign(__assign({}, props), { size: size, body: body, compiledClasses: compiledClasses })));
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
/* <windicss-keep class=""> */
|
|
175
|
+
|
|
176
|
+
var classes = {
|
|
177
|
+
button: 'flex leading-[24px] py-[10px] items-center relative w-full',
|
|
178
|
+
topButton: 'leading-[24px] text-[16px] pl-[24px] font-medium',
|
|
179
|
+
leafButton: 'leading-[20px] text-[14px] pl-[40px]',
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
var DocGroup = function (_a) {
|
|
183
|
+
var _b;
|
|
184
|
+
var group = _a.group, collapsible = _a.collapsible, _c = _a.depth, depth = _c === void 0 ? 0 : _c, setHeight = _a.setHeight;
|
|
185
|
+
var _d = React__namespace.useState(depth === 0), open = _d[0], setOpen = _d[1];
|
|
186
|
+
var _e = React__namespace.useState(Array(group.items.length).fill(1)), itemsHeights = _e[0], setItemsHeights = _e[1];
|
|
187
|
+
React__namespace.useEffect(function () {
|
|
188
|
+
setHeight === null || setHeight === void 0 ? void 0 : setHeight(open ? itemsHeights.reduce(function (a, b) { return a + b; }, 1) : 1);
|
|
189
|
+
}, [itemsHeights, open]);
|
|
190
|
+
var _f = React__namespace.useState(0), activeTop = _f[0], setActiveTop = _f[1];
|
|
191
|
+
React__namespace.useEffect(function () {
|
|
192
|
+
var activeItem = group.items.findIndex(function (item) { return 'href' in item && item.active; });
|
|
193
|
+
if (activeItem >= 0) {
|
|
194
|
+
setActiveTop(itemsHeights.slice(0, activeItem).reduce(function (a, b) { return a + b; }, 1) * 44);
|
|
195
|
+
}
|
|
196
|
+
}, [itemsHeights]);
|
|
197
|
+
function toggleMenu(open) {
|
|
198
|
+
if (!collapsible)
|
|
199
|
+
return;
|
|
200
|
+
setOpen(open);
|
|
201
|
+
}
|
|
202
|
+
function onSetHeight(index, height) {
|
|
203
|
+
setItemsHeights(function (prev) {
|
|
204
|
+
var newHeights = __spreadArray([], prev, true);
|
|
205
|
+
newHeights[index] = height;
|
|
206
|
+
return newHeights;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
var Head = collapsible ? 'button' : group.href ? 'a' : 'div';
|
|
210
|
+
return (React__namespace.createElement(React__namespace.Fragment, null,
|
|
211
|
+
React__namespace.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {},
|
|
212
|
+
_b[classes.topButton] = depth === 0,
|
|
213
|
+
_b[classes.leafButton] = depth,
|
|
214
|
+
_b)) },
|
|
215
|
+
collapsible ? (React__namespace.createElement(IconChevronDownSmall, { "stroke-color": "gray-400", size: depth ? '8' : '16', className: clsx('absolute transform transition-transform left-0', {
|
|
216
|
+
'rotate-0': open,
|
|
217
|
+
'-rotate-90': !open,
|
|
218
|
+
'ml-[16px]': depth,
|
|
219
|
+
}) })) : null,
|
|
220
|
+
group.text),
|
|
221
|
+
collapsible &&
|
|
222
|
+
depth >= 0 &&
|
|
223
|
+
open &&
|
|
224
|
+
group.items.some(function (item) { return 'href' in item && item.active; }) ? (React__namespace.createElement("div", { className: "absolute h-[36px] w-[4px] z-10 rounded-full bg-indigo-500 transition-all duration-300 ml-[6px] mt-[4px]", style: {
|
|
225
|
+
top: "".concat(activeTop, "px"),
|
|
226
|
+
left: "".concat(depth === 0 ? 0.5 : -(depth * 8) - 0.5, "px"),
|
|
227
|
+
} })) : null,
|
|
228
|
+
React__namespace.createElement("ul", { className: clsx('ml-[8px] list-none p-0', {
|
|
229
|
+
'border-l border-gray-100': depth === 0 && collapsible,
|
|
230
|
+
hidden: !open,
|
|
231
|
+
}) }, group.items.map(function (item, index) {
|
|
232
|
+
return 'items' in item ? (React__namespace.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
233
|
+
React__namespace.createElement(DocGroup, { group: item, depth: depth + 1, setHeight: function (height) { return onSetHeight(index, height); }, collapsible: collapsible }))) : (React__namespace.createElement(DocLink, { key: index, item: item, collapsible: collapsible, depth: depth, onActive: function (top) { return setActiveTop(top); } }));
|
|
234
|
+
}))));
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
var DocMenu = function (_a) {
|
|
238
|
+
var items = _a.items, _b = _a.collapsible, collapsible = _b === void 0 ? true : _b, rest = __rest$1(_a, ["items", "collapsible"]);
|
|
239
|
+
return (React__namespace.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', rest.className) }), items.map(function (item, index) {
|
|
240
|
+
return 'items' in item ? (React__namespace.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
241
|
+
React__namespace.createElement(DocGroup, { group: item, collapsible: collapsible }))) : (React__namespace.createElement(DocLink, { key: index, item: item, collapsible: collapsible }));
|
|
242
|
+
})));
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
module.exports = DocMenu;
|
|
246
|
+
//# sourceMappingURL=index.umd.js.map
|
|
247
|
+
|
|
248
|
+
/* <windicss-keep class="list-none p-0 relative pl-[16px] inline-block pl-[24px] text-indigo-500 dark:text-indigo-200 py-[8px] text-[16px] leading-[24px] py-[12px] leading-[20px] text-[14px] absolute w-[4px] z-10 top-[10%] h-[80%] rounded-full hidden group-hover:block bg-gray-300 transform transition-transform left-0 rotate-0 -rotate-90 ml-[16px] h-[36px] bg-indigo-500 transition-all duration-300 ml-[6px] mt-[4px] ml-[8px] border-l border-gray-100 flex py-[10px] items-center w-full font-medium pl-[40px]"> */
|