@cypress-design/react-docmenu 0.2.3 → 0.3.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.
@@ -2,5 +2,5 @@ $ yarn build:module && yarn build:types
2
2
  $ rollup -c ./rollup.config.mjs
3
3
  
4
4
  ./index.ts → ./dist/index.umd.js, ./dist/index.es.mjs...
5
- created ./dist/index.umd.js, ./dist/index.es.mjs in 17.1s
5
+ created ./dist/index.umd.js, ./dist/index.es.mjs in 33.9s
6
6
  $ tsc --project ./tsconfig.build.json
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @cypress-design/react-docmenu
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#310](https://github.com/cypress-io/cypress-design/pull/310) [`a3a323f`](https://github.com/cypress-io/cypress-design/commit/a3a323fde7acf5e5407b298b4faa0c90314c6139) Thanks [@elevatebart](https://github.com/elevatebart)! - Add-eslint-react-hooks
8
+
9
+ - Updated dependencies [[`630ad4a`](https://github.com/cypress-io/cypress-design/commit/630ad4ae2e6ba65350951949767a4ebdc4c7eb0a), [`a3a323f`](https://github.com/cypress-io/cypress-design/commit/a3a323fde7acf5e5407b298b4faa0c90314c6139)]:
10
+ - @cypress-design/react-icon@0.24.0
11
+
12
+ ## 0.3.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#272](https://github.com/cypress-io/cypress-design/pull/272) [`9a3e358`](https://github.com/cypress-io/cypress-design/commit/9a3e3582b8ca2dfdadd9198054042c9f0083be01) Thanks [@elevatebart](https://github.com/elevatebart)! - remove dark mode implementation to avoid wrong side effects
17
+
3
18
  ## 0.2.3
4
19
 
5
20
  ### Patch Changes
package/_DocGroup.tsx CHANGED
@@ -19,25 +19,25 @@ export const DocGroup: React.FC<DocGroupProps> = ({
19
19
  }) => {
20
20
  const [open, setOpen] = React.useState(depth === 0)
21
21
  const [itemsHeights, setItemsHeights] = React.useState<number[]>(
22
- Array(group.items.length).fill(1)
22
+ Array(group.items.length).fill(1),
23
23
  )
24
24
 
25
25
  React.useEffect(() => {
26
26
  setHeight?.(open ? itemsHeights.reduce((a, b) => a + b, 1) : 1)
27
- }, [itemsHeights, open])
27
+ }, [itemsHeights, open, setHeight])
28
28
 
29
29
  const [activeTop, setActiveTop] = React.useState(0)
30
30
 
31
31
  React.useEffect(() => {
32
32
  const activeItem = group.items.findIndex(
33
- (item) => 'href' in item && item.active
33
+ (item) => 'href' in item && item.active,
34
34
  )
35
35
  if (activeItem >= 0) {
36
36
  setActiveTop(
37
- itemsHeights.slice(0, activeItem).reduce((a, b) => a + b, 1) * 44
37
+ itemsHeights.slice(0, activeItem).reduce((a, b) => a + b, 1) * 44,
38
38
  )
39
39
  }
40
- }, [itemsHeights])
40
+ }, [itemsHeights, group.items])
41
41
 
42
42
  function toggleMenu(open: boolean) {
43
43
  if (!collapsible) return
@@ -60,7 +60,7 @@ export const DocGroup: React.FC<DocGroupProps> = ({
60
60
  onClick={() => toggleMenu(!open)}
61
61
  href={group.href}
62
62
  className={clsx(classes.button, {
63
- 'text-indigo-500 dark:text-indigo-200': group.active,
63
+ 'text-indigo-500': group.active,
64
64
  [classes.topButton]: depth === 0,
65
65
  [classes.leafButton]: depth,
66
66
  })}
@@ -114,7 +114,7 @@ export const DocGroup: React.FC<DocGroupProps> = ({
114
114
  depth={depth}
115
115
  onActive={(top) => setActiveTop(top)}
116
116
  />
117
- )
117
+ ),
118
118
  )}
119
119
  </ul>
120
120
  </>
package/_DocLink.tsx CHANGED
@@ -23,6 +23,8 @@ export const DocLink: React.FC<DocLinkProps> = ({
23
23
  if (item.active) {
24
24
  onActive?.(activeLIRef?.current?.offsetTop || 0)
25
25
  }
26
+ // supposed to happen only on mount
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
26
28
  }, [])
27
29
 
28
30
  return (
@@ -34,7 +36,7 @@ export const DocLink: React.FC<DocLinkProps> = ({
34
36
  >
35
37
  <a
36
38
  className={clsx('group relative inline-block pl-[24px]', {
37
- 'text-indigo-500 dark:text-indigo-200': item.active,
39
+ 'text-indigo-500': item.active,
38
40
  'py-[8px] text-[16px] leading-[24px]': depth < 0,
39
41
  'py-[12px] leading-[20px] text-[14px]': depth >= 0,
40
42
  })}
@@ -46,7 +48,7 @@ export const DocLink: React.FC<DocLinkProps> = ({
46
48
  'absolute w-[4px] z-10 top-[10%] h-[80%] rounded-full hidden',
47
49
  {
48
50
  'group-hover:block bg-gray-300': !item.active && collapsible,
49
- }
51
+ },
50
52
  )}
51
53
  style={{
52
54
  left: `-${18.5 + depth * 8}px`,
@@ -1 +1 @@
1
- {"version":3,"file":"_DocLink.d.ts","sourceRoot":"./","sources":["_DocLink.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;AAE/D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,WAAW,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CACjC;AAED,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAgD1C,CAAA"}
1
+ {"version":3,"file":"_DocLink.d.ts","sourceRoot":"./","sources":["_DocLink.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;AAE/D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,WAAW,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CACjC;AAED,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAkD1C,CAAA"}
package/dist/index.es.mjs CHANGED
@@ -17,7 +17,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
17
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
18
  PERFORMANCE OF THIS SOFTWARE.
19
19
  ***************************************************************************** */
20
- /* global Reflect, Promise */
20
+ /* global Reflect, Promise, SuppressedError, Symbol */
21
21
 
22
22
 
23
23
  var __assign$1 = function() {
@@ -51,7 +51,12 @@ function __spreadArray(to, from, pack) {
51
51
  }
52
52
  }
53
53
  return to.concat(ar || Array.prototype.slice.call(from));
54
- }
54
+ }
55
+
56
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
57
+ var e = new Error(message);
58
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
59
+ };
55
60
 
56
61
  var DocLink = function (_a) {
57
62
  var item = _a.item, collapsible = _a.collapsible, _b = _a.depth, depth = _b === void 0 ? -1 : _b, onActive = _a.onActive;
@@ -63,12 +68,14 @@ var DocLink = function (_a) {
63
68
  if (item.active) {
64
69
  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);
65
70
  }
71
+ // supposed to happen only on mount
72
+ // eslint-disable-next-line react-hooks/exhaustive-deps
66
73
  }, []);
67
74
  return (React.createElement("li", { ref: activeLIRef, className: clsx('list-none p-0', {
68
75
  'pl-[16px]': depth >= 0,
69
76
  }) },
70
77
  React.createElement("a", { className: clsx('group relative inline-block pl-[24px]', {
71
- 'text-indigo-500 dark:text-indigo-200': item.active,
78
+ 'text-indigo-500': item.active,
72
79
  'py-[8px] text-[16px] leading-[24px]': depth < 0,
73
80
  'py-[12px] leading-[20px] text-[14px]': depth >= 0,
74
81
  }), href: item.href },
@@ -94,7 +101,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
94
101
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
95
102
  PERFORMANCE OF THIS SOFTWARE.
96
103
  ***************************************************************************** */
97
- /* global Reflect, Promise */
104
+ /* global Reflect, Promise, SuppressedError, Symbol */
98
105
 
99
106
 
100
107
  var __assign = function() {
@@ -118,10 +125,15 @@ function __rest(s, e) {
118
125
  t[p[i]] = s[p[i]];
119
126
  }
120
127
  return t;
121
- }
128
+ }
129
+
130
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
131
+ var e = new Error(message);
132
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
133
+ };
122
134
 
123
135
  var compileReactIconProperties = function (_a) {
124
- var body = _a.body, compiledClasses = _a.compiledClasses, size = _a.size, attributes = __rest(_a, ["body", "compiledClasses", "size"]);
136
+ var body = _a.body, defs = _a.defs, compiledClasses = _a.compiledClasses, size = _a.size, name = _a.name, attributes = __rest(_a, ["body", "defs", "compiledClasses", "size", "name"]);
125
137
  var filteredAttributes = Object.keys(attributes).reduce(function (newAttributes, attrName) {
126
138
  if (!ICON_COLOR_PROP_NAMES.includes(attrName) &&
127
139
  attrName !== 'name') {
@@ -132,6 +144,21 @@ var compileReactIconProperties = function (_a) {
132
144
  }
133
145
  return newAttributes;
134
146
  }, {});
147
+ // eslint-disable-next-line react-hooks/rules-of-hooks
148
+ React.useEffect(function () {
149
+ var iconFileId = "".concat(name, "_").concat(size);
150
+ if (defs) {
151
+ if (document.querySelector("[data-cy-svg-defs=\"".concat(iconFileId, "\"]"))) {
152
+ return;
153
+ }
154
+ var svgElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
155
+ svgElement.setAttribute('data-cy-svg-defs', iconFileId);
156
+ svgElement.setAttribute('width', '0');
157
+ svgElement.setAttribute('height', '0');
158
+ svgElement.innerHTML = defs;
159
+ document.body.appendChild(svgElement);
160
+ }
161
+ }, [defs, name, size]);
135
162
  var componentProps = __assign({ width: size, height: size, viewBox: "0 0 ".concat(size, " ").concat(size), fill: 'none', dangerouslySetInnerHTML: {
136
163
  __html: body,
137
164
  }, className: undefined }, filteredAttributes);
@@ -143,21 +170,27 @@ var compileReactIconProperties = function (_a) {
143
170
  }
144
171
  return componentProps;
145
172
  };
146
- var IconChevronDownSmall = function (props) {
147
- var _a = iconsRegistry.getComponentAttributes(__assign(__assign({}, props), { availableSizes: ["8", "16"] })), size = _a.sizeWithDefault, compiledClasses = _a.compiledClasses;
148
- var iconBodies = {
149
- "8": "<path stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m1 2.5 3 3 3-3\" class=\"icon-dark\"/>",
150
- "16": "<path stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m4 6 4 4 4-4\" class=\"icon-dark\"/>"
151
- };
152
- var body = iconBodies[size];
173
+
174
+ function useIconProps(props, iconBodiesAndDefs, availableSizes, name) {
175
+ var interactiveColorsOnGroup = props.interactiveColorsOnGroup, cleanProps = __rest(props, ["interactiveColorsOnGroup"]);
176
+ var _a = iconsRegistry.getComponentAttributes(__assign(__assign({}, cleanProps), { availableSizes: availableSizes, interactiveColorsOnGroup: interactiveColorsOnGroup })), size = _a.sizeWithDefault, compiledClasses = _a.compiledClasses;
177
+ var _b = iconBodiesAndDefs[size] || {}, body = _b.body, defs = _b.defs;
153
178
  if (!body) {
154
- throw Error("Icon \"chevron-down-small\" is not available in size ".concat(size));
179
+ throw Error("Icon \"".concat(name, "\" is not available in size ").concat(size));
155
180
  }
156
- return React.createElement('svg', compileReactIconProperties(__assign(__assign({}, props), { size: size, body: body, compiledClasses: compiledClasses })));
157
- };
181
+ return compileReactIconProperties(__assign(__assign({}, cleanProps), { name: name, size: size, body: body, defs: defs, compiledClasses: compiledClasses }));
182
+ }
183
+ var IconChevronDownSmall = function (props) { return React.createElement('svg', useIconProps(props, {
184
+ "8": {
185
+ "body": "<path stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m1 2.5 3 3 3-3\" class=\"icon-dark\"/>"
186
+ },
187
+ "16": {
188
+ "body": "<path stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m4 6 4 4 4-4\" class=\"icon-dark\"/>"
189
+ }
190
+ }, ["8", "16"], "chevron-down-small")); };
158
191
 
159
192
 
160
- /* <wind-keep class="filter"> */
193
+ /* <wind-keep class="filter icon-light-secondary icon-dark-secondary"> */
161
194
 
162
195
  const classes = {
163
196
  button: 'flex leading-[24px] py-[10px] items-center relative w-full',
@@ -172,14 +205,14 @@ var DocGroup = function (_a) {
172
205
  var _e = React.useState(Array(group.items.length).fill(1)), itemsHeights = _e[0], setItemsHeights = _e[1];
173
206
  React.useEffect(function () {
174
207
  setHeight === null || setHeight === void 0 ? void 0 : setHeight(open ? itemsHeights.reduce(function (a, b) { return a + b; }, 1) : 1);
175
- }, [itemsHeights, open]);
208
+ }, [itemsHeights, open, setHeight]);
176
209
  var _f = React.useState(0), activeTop = _f[0], setActiveTop = _f[1];
177
210
  React.useEffect(function () {
178
211
  var activeItem = group.items.findIndex(function (item) { return 'href' in item && item.active; });
179
212
  if (activeItem >= 0) {
180
213
  setActiveTop(itemsHeights.slice(0, activeItem).reduce(function (a, b) { return a + b; }, 1) * 44);
181
214
  }
182
- }, [itemsHeights]);
215
+ }, [itemsHeights, group.items]);
183
216
  function toggleMenu(open) {
184
217
  if (!collapsible)
185
218
  return;
@@ -195,7 +228,7 @@ var DocGroup = function (_a) {
195
228
  var Head = collapsible ? 'button' : group.href ? 'a' : 'div';
196
229
  return (React.createElement(React.Fragment, null,
197
230
  React.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {
198
- 'text-indigo-500 dark:text-indigo-200': group.active
231
+ 'text-indigo-500': group.active
199
232
  },
200
233
  _b[classes.topButton] = depth === 0,
201
234
  _b[classes.leafButton] = depth,
@@ -233,4 +266,4 @@ var DocMenu = function (_a) {
233
266
  export { DocMenu as default };
234
267
  //# sourceMappingURL=index.es.mjs.map
235
268
 
236
- /* <wind-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 text-indigo-200 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]"> */
269
+ /* <wind-keep class="list-none p-0 relative pl-[16px] inline-block pl-[24px] text-indigo-500 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]"> */