@activecollab/components 1.0.116 → 1.0.117

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.
@@ -19,13 +19,9 @@ var _Button = require("../Button");
19
19
 
20
20
  var _Icons = require("../Icons");
21
21
 
22
- var _lodash = _interopRequireDefault(require("lodash.debounce"));
23
-
24
22
  var _Styles = require("./Styles");
25
23
 
26
- var _excluded = ["children", "className", "separator", "timeout"];
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
+ var _excluded = ["children", "className", "separator"];
29
25
 
30
26
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
27
 
@@ -58,33 +54,33 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
58
54
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
59
55
 
60
56
  var Breadcrumbs = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
57
+ var _dimensions$width, _childDimensions$widt;
58
+
61
59
  var children = _ref.children,
62
60
  className = _ref.className,
63
61
  _ref$separator = _ref.separator,
64
62
  separator = _ref$separator === void 0 ? "/" : _ref$separator,
65
- _ref$timeout = _ref.timeout,
66
- timeout = _ref$timeout === void 0 ? 300 : _ref$timeout,
67
63
  rest = _objectWithoutProperties(_ref, _excluded);
68
64
 
69
65
  var internalRef = (0, _react.useRef)(null);
70
- var prevWidth = (0, _react.useRef)();
66
+ var listWrapperRef = (0, _react.useRef)(null);
67
+ var olRef = (0, _react.useRef)(null);
71
68
  var widthCollectionRef = (0, _react.useRef)([]);
72
69
  var handleRef = (0, _utils.useForkRef)(ref, internalRef);
70
+
71
+ var _useState = (0, _react.useState)(0),
72
+ _useState2 = _slicedToArray(_useState, 2),
73
+ menuBreadcrumbs = _useState2[0],
74
+ setMenuBreadcrumbs = _useState2[1];
75
+
73
76
  var dimensions = (0, _utils.useResizeObserver)(internalRef);
77
+ var childDimensions = (0, _utils.useResizeObserver)(listWrapperRef);
78
+ var parentWidth = (_dimensions$width = dimensions === null || dimensions === void 0 ? void 0 : dimensions.width) !== null && _dimensions$width !== void 0 ? _dimensions$width : 0;
79
+ var childWidth = (_childDimensions$widt = childDimensions === null || childDimensions === void 0 ? void 0 : childDimensions.width) !== null && _childDimensions$widt !== void 0 ? _childDimensions$widt : 0;
74
80
  var childrenCollection = (0, _react.useMemo)(function () {
75
81
  return _react.default.Children.toArray(children);
76
82
  }, [children]);
77
83
 
78
- var _useState = (0, _react.useState)(),
79
- _useState2 = _slicedToArray(_useState, 2),
80
- width = _useState2[0],
81
- setWidth = _useState2[1];
82
-
83
- var _useState3 = (0, _react.useState)(0),
84
- _useState4 = _slicedToArray(_useState3, 2),
85
- menuBreadcrumbs = _useState4[0],
86
- setMenuBreadcrumbs = _useState4[1];
87
-
88
84
  var _useMemo = (0, _react.useMemo)(function () {
89
85
  return [childrenCollection.slice(0, menuBreadcrumbs), childrenCollection.slice(menuBreadcrumbs, childrenCollection.length)];
90
86
  }, [childrenCollection, menuBreadcrumbs]),
@@ -93,27 +89,31 @@ var Breadcrumbs = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
93
89
  listCollection = _useMemo2[1];
94
90
 
95
91
  (0, _react.useEffect)(function () {
96
- var _internalRef$current, _internalRef$current2, _prevWidth$current;
92
+ widthCollectionRef.current = [];
93
+ setMenuBreadcrumbs(0);
94
+ }, [childrenCollection.length]);
95
+ (0, _react.useEffect)(function () {
96
+ var diffWidth = childWidth - parentWidth;
97
97
 
98
- var actualWidth = ((_internalRef$current = internalRef.current) === null || _internalRef$current === void 0 ? void 0 : _internalRef$current.scrollWidth) || 0;
99
- var breadcrumbItems = (_internalRef$current2 = internalRef.current) === null || _internalRef$current2 === void 0 ? void 0 : _internalRef$current2.firstElementChild;
100
- var enabled = ((_prevWidth$current = prevWidth.current) !== null && _prevWidth$current !== void 0 ? _prevWidth$current : 0) > (width !== null && width !== void 0 ? width : 0);
98
+ if (diffWidth > 0) {
99
+ var _offsetWidth, _olRef$current, _olRef$current$queryS, _olRef$current$queryS2, _olRef$current2, _breadcrumbItems$leng;
101
100
 
102
- if (enabled && width && actualWidth > width) {
103
- var diffWidth = actualWidth - width;
101
+ var separatorWidth = (_offsetWidth = (_olRef$current = olRef.current) === null || _olRef$current === void 0 ? void 0 : (_olRef$current$queryS = _olRef$current.querySelectorAll("[data-role=\"separator\"]")[0]) === null || _olRef$current$queryS === void 0 ? void 0 : _olRef$current$queryS.offsetWidth) !== null && _offsetWidth !== void 0 ? _offsetWidth : 0;
102
+ var breadcrumbItems = (_olRef$current$queryS2 = (_olRef$current2 = olRef.current) === null || _olRef$current2 === void 0 ? void 0 : _olRef$current2.querySelectorAll("[data-role=\"item\"]")) !== null && _olRef$current$queryS2 !== void 0 ? _olRef$current$queryS2 : [];
104
103
  var childWidthCollection = [];
105
- var childIndex = widthCollectionRef.current.length === 0 ? 0 : 2;
104
+ var maxIndex = ((_breadcrumbItems$leng = breadcrumbItems === null || breadcrumbItems === void 0 ? void 0 : breadcrumbItems.length) !== null && _breadcrumbItems$leng !== void 0 ? _breadcrumbItems$leng : 1) - 1;
105
+ var currentIndex = 0;
106
106
  var childSumWidth = 0;
107
107
 
108
- while (diffWidth > childSumWidth) {
109
- var _offsetWidth, _breadcrumbItems$chil, _offsetWidth2, _breadcrumbItems$chil2;
108
+ while (diffWidth > childSumWidth && maxIndex >= currentIndex) {
109
+ var _offsetWidth2, _breadcrumbItems$curr;
110
110
 
111
- var childWidth = (_offsetWidth = breadcrumbItems === null || breadcrumbItems === void 0 ? void 0 : (_breadcrumbItems$chil = breadcrumbItems.children[childIndex]) === null || _breadcrumbItems$chil === void 0 ? void 0 : _breadcrumbItems$chil.offsetWidth) !== null && _offsetWidth !== void 0 ? _offsetWidth : 0;
112
- var separatorWidth = (_offsetWidth2 = breadcrumbItems === null || breadcrumbItems === void 0 ? void 0 : (_breadcrumbItems$chil2 = breadcrumbItems.children[childIndex + 1]) === null || _breadcrumbItems$chil2 === void 0 ? void 0 : _breadcrumbItems$chil2.offsetWidth) !== null && _offsetWidth2 !== void 0 ? _offsetWidth2 : 0;
113
- var result = separatorWidth + childWidth;
111
+ var _childWidth = (_offsetWidth2 = (_breadcrumbItems$curr = breadcrumbItems[currentIndex]) === null || _breadcrumbItems$curr === void 0 ? void 0 : _breadcrumbItems$curr.offsetWidth) !== null && _offsetWidth2 !== void 0 ? _offsetWidth2 : 0;
112
+
113
+ var result = separatorWidth + _childWidth;
114
114
  childWidthCollection.push(result);
115
115
  childSumWidth += result;
116
- childIndex += 2;
116
+ currentIndex += 1;
117
117
  }
118
118
 
119
119
  if (childWidthCollection.length === listCollection.length) {
@@ -125,16 +125,11 @@ var Breadcrumbs = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
125
125
  return oldVal + childWidthCollection.length;
126
126
  });
127
127
  }
128
- }, [listCollection.length, width]);
128
+ }, [listCollection.length, parentWidth, childWidth]);
129
129
  (0, _react.useEffect)(function () {
130
- var _internalRef$current3, _breadcrumbItems$last, _breadcrumbItems$last2, _prevWidth$current2;
131
-
132
- var breadcrumbItems = (_internalRef$current3 = internalRef.current) === null || _internalRef$current3 === void 0 ? void 0 : _internalRef$current3.firstElementChild;
133
- var nextWidth = (breadcrumbItems === null || breadcrumbItems === void 0 ? void 0 : (_breadcrumbItems$last = breadcrumbItems.lastElementChild) === null || _breadcrumbItems$last === void 0 ? void 0 : _breadcrumbItems$last.offsetWidth) + (breadcrumbItems === null || breadcrumbItems === void 0 ? void 0 : (_breadcrumbItems$last2 = breadcrumbItems.lastElementChild) === null || _breadcrumbItems$last2 === void 0 ? void 0 : _breadcrumbItems$last2.offsetLeft);
134
- var enabled = ((_prevWidth$current2 = prevWidth.current) !== null && _prevWidth$current2 !== void 0 ? _prevWidth$current2 : 0) < (width !== null && width !== void 0 ? width : 0);
135
- var diffWidth = (width !== null && width !== void 0 ? width : 0) - nextWidth;
130
+ var diffWidth = parentWidth - childWidth;
136
131
 
137
- if (enabled && diffWidth > 0 && widthCollectionRef.current.length > 0) {
132
+ if (diffWidth > 0 && widthCollectionRef.current.length > 0) {
138
133
  var total = widthCollectionRef.current.length;
139
134
 
140
135
  var collection = _toConsumableArray(widthCollectionRef.current);
@@ -157,30 +152,23 @@ var Breadcrumbs = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
157
152
 
158
153
  var totalToDecrease = total - collection.length;
159
154
  setMenuBreadcrumbs(function (oldVal) {
160
- return oldVal - totalToDecrease;
155
+ var newValue = oldVal - totalToDecrease;
156
+ return newValue > 0 ? newValue : 0;
161
157
  });
162
158
  var end = total - totalToDecrease;
163
159
  widthCollectionRef.current = end > 0 ? widthCollectionRef.current.slice(0, end) : [];
164
160
  }
165
- }, [width]);
166
- (0, _react.useEffect)(function () {
167
- var _dimensions$width;
168
-
169
- var debounceWidth = (0, _lodash.default)(function (width) {
170
- setWidth(function (prevState) {
171
- prevWidth.current = prevState !== null && prevState !== void 0 ? prevState : width + 1;
172
- return width;
173
- });
174
- }, timeout);
175
- debounceWidth((_dimensions$width = dimensions === null || dimensions === void 0 ? void 0 : dimensions.width) !== null && _dimensions$width !== void 0 ? _dimensions$width : 0);
176
- return function () {
177
- debounceWidth.cancel();
178
- };
179
- }, [timeout, dimensions === null || dimensions === void 0 ? void 0 : dimensions.width]);
161
+ }, [parentWidth, childWidth]);
180
162
  return /*#__PURE__*/_react.default.createElement(_Styles.StyledNavElement, _extends({
181
163
  className: className,
182
164
  ref: handleRef
183
- }, rest), /*#__PURE__*/_react.default.createElement(_Styles.StyledOList, null, menuCollection.length > 0 ? /*#__PURE__*/_react.default.createElement(_Styles.StyledBreadcrumbListItem, null, /*#__PURE__*/_react.default.createElement(_Menu.Menu, {
165
+ }, rest), /*#__PURE__*/_react.default.createElement(_Styles.StyledListWrapper, {
166
+ ref: listWrapperRef
167
+ }, /*#__PURE__*/_react.default.createElement(_Styles.StyledOList, {
168
+ ref: olRef
169
+ }, menuCollection.length > 0 ? /*#__PURE__*/_react.default.createElement(_Styles.StyledBreadcrumbListItem, {
170
+ "data-role": "menu"
171
+ }, /*#__PURE__*/_react.default.createElement(_Menu.Menu, {
184
172
  target: /*#__PURE__*/_react.default.createElement(_Button.Button, {
185
173
  variant: "text gray"
186
174
  }, /*#__PURE__*/_react.default.createElement(_Icons.TreeDotsIcon, null))
@@ -191,8 +179,12 @@ var Breadcrumbs = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
191
179
  })))) : null, listCollection.map(function (child, index) {
192
180
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
193
181
  key: index
194
- }, index > 0 || menuCollection.length > 0 ? /*#__PURE__*/_react.default.createElement(_Styles.StyledBreadcrumbListItem, null, separator) : null, /*#__PURE__*/_react.default.createElement(_Styles.StyledBreadcrumbListItem, null, child));
195
- })));
182
+ }, index > 0 || menuCollection.length > 0 ? /*#__PURE__*/_react.default.createElement(_Styles.StyledBreadcrumbListItem, {
183
+ "data-role": "separator"
184
+ }, separator) : null, /*#__PURE__*/_react.default.createElement(_Styles.StyledBreadcrumbListItem, {
185
+ "data-role": "item"
186
+ }, child));
187
+ }))));
196
188
  });
197
189
 
198
190
  exports.Breadcrumbs = Breadcrumbs;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Breadcrumbs/Breadcrumbs.tsx"],"names":["Breadcrumbs","React","forwardRef","ref","children","className","separator","timeout","rest","internalRef","prevWidth","widthCollectionRef","handleRef","dimensions","childrenCollection","Children","toArray","width","setWidth","menuBreadcrumbs","setMenuBreadcrumbs","slice","length","menuCollection","listCollection","actualWidth","current","scrollWidth","breadcrumbItems","firstElementChild","enabled","diffWidth","childWidthCollection","childIndex","childSumWidth","childWidth","offsetWidth","separatorWidth","result","push","pop","oldVal","nextWidth","lastElementChild","offsetLeft","total","collection","sumWidth","lastWidth","totalToDecrease","end","debounceWidth","prevState","cancel","map","child","index","displayName"],"mappings":";;;;;;;;;AAAA;;AAOA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcO,IAAMA,WAAW,gBAAGC,eAAMC,UAAN,CAIzB,gBAAmEC,GAAnE,EAA2E;AAAA,MAAxEC,QAAwE,QAAxEA,QAAwE;AAAA,MAA9DC,SAA8D,QAA9DA,SAA8D;AAAA,4BAAnDC,SAAmD;AAAA,MAAnDA,SAAmD,+BAAvC,GAAuC;AAAA,0BAAlCC,OAAkC;AAAA,MAAlCA,OAAkC,6BAAxB,GAAwB;AAAA,MAAhBC,IAAgB;;AAC3E,MAAMC,WAAW,GAAG,mBAA2B,IAA3B,CAApB;AACA,MAAMC,SAAS,GAAG,oBAAlB;AACA,MAAMC,kBAAkB,GAAG,mBAAiB,EAAjB,CAA3B;AACA,MAAMC,SAAS,GAAG,uBAAWT,GAAX,EAAgBM,WAAhB,CAAlB;AACA,MAAMI,UAAU,GAAG,8BAAkBJ,WAAlB,CAAnB;AAEA,MAAMK,kBAAkB,GAAG,oBACzB;AAAA,WAAMb,eAAMc,QAAN,CAAeC,OAAf,CAAuBZ,QAAvB,CAAN;AAAA,GADyB,EAEzB,CAACA,QAAD,CAFyB,CAA3B;;AAKA,kBAA0B,sBAA1B;AAAA;AAAA,MAAOa,KAAP;AAAA,MAAcC,QAAd;;AACA,mBAA8C,qBAAS,CAAT,CAA9C;AAAA;AAAA,MAAOC,eAAP;AAAA,MAAwBC,kBAAxB;;AAEA,iBAAyC,oBAAQ,YAAM;AACrD,WAAO,CACLN,kBAAkB,CAACO,KAAnB,CAAyB,CAAzB,EAA4BF,eAA5B,CADK,EAELL,kBAAkB,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EAAUM,UAAV,aAAUA,UAAV,uBAAUA,UAAU,CAAEI,KAAtB,CAbH;AAeA,sBACE,6BAAC,wBAAD;AAAkB,IAAA,SAAS,EAAEZ,SAA7B;AAAwC,IAAA,GAAG,EAAEO;AAA7C,KAA4DJ,IAA5D,gBACE,6BAAC,mBAAD,QACGe,cAAc,CAACD,MAAf,GAAwB,CAAxB,gBACC,6BAAC,gCAAD,qBACE,6BAAC,UAAD;AACE,IAAA,MAAM,eACJ,6BAAC,cAAD;AAAQ,MAAA,OAAO,EAAC;AAAhB,oBACE,6BAAC,mBAAD,OADF;AAFJ,kBAOE,6BAAC,sBAAD,QACGC,cAAc,CAAC+B,GAAf,CAAmB,UAACC,KAAD,EAAQC,KAAR;AAAA,wBAClB,6BAAC,cAAD;AAAU,MAAA,GAAG,EAAEA;AAAf,OAAuBD,KAAvB,CADkB;AAAA,GAAnB,CADH,CAPF,CADF,CADD,GAgBG,IAjBN,EAkBG/B,cAAc,CAAC8B,GAAf,CAAmB,UAACC,KAAD,EAAQC,KAAR,EAAkB;AACpC,wBACE,6BAAC,cAAD,CAAO,QAAP;AAAgB,MAAA,GAAG,EAAEA;AAArB,OACGA,KAAK,GAAG,CAAR,IAAajC,cAAc,CAACD,MAAf,GAAwB,CAArC,gBACC,6BAAC,gCAAD,QAA2BhB,SAA3B,CADD,GAEG,IAHN,eAIE,6BAAC,gCAAD,QAA2BiD,KAA3B,CAJF,CADF;AAQD,GATA,CAlBH,CADF,CADF;AAiCD,CApJ0B,CAApB;;;AAsJPvD,WAAW,CAACyD,WAAZ,GAA0B,aAA1B","sourcesContent":["import React, {\n ReactElement,\n useRef,\n useMemo,\n useEffect,\n useState,\n} from \"react\";\nimport { useForkRef, useResizeObserver } from \"../../utils\";\nimport { Menu } from \"../Menu\";\nimport { ListItem } from \"../List\";\nimport { Button } from \"../Button\";\nimport { TreeDotsIcon } from \"../Icons\";\nimport debounce from \"lodash.debounce\";\nimport {\n StyledNavElement,\n StyledOList,\n StyledBreadcrumbListItem,\n StyledMenuList,\n} from \"./Styles\";\n\nexport interface BreadcrumbsProps {\n /** Separator element */\n separator?: ReactElement | string;\n /** Resize update timeout */\n timeout?: number;\n}\n\nexport const Breadcrumbs = React.forwardRef<\n HTMLElement,\n BreadcrumbsProps &\n Omit<React.ComponentPropsWithoutRef<\"nav\">, keyof BreadcrumbsProps>\n>(({ children, className, separator = \"/\", timeout = 300, ...rest }, ref) => {\n const internalRef = useRef<HTMLElement | null>(null);\n const prevWidth = useRef<number | undefined>();\n const widthCollectionRef = useRef<number[]>([]);\n const handleRef = useForkRef(ref, internalRef);\n const dimensions = useResizeObserver(internalRef);\n\n const childrenCollection = useMemo(\n () => React.Children.toArray(children),\n [children]\n );\n\n const [width, setWidth] = useState<number | undefined>();\n const [menuBreadcrumbs, setMenuBreadcrumbs] = useState(0);\n\n const [menuCollection, listCollection] = useMemo(() => {\n return [\n childrenCollection.slice(0, menuBreadcrumbs),\n childrenCollection.slice(menuBreadcrumbs, childrenCollection.length),\n ];\n }, [childrenCollection, menuBreadcrumbs]);\n\n useEffect(() => {\n const actualWidth = internalRef.current?.scrollWidth || 0;\n const breadcrumbItems = internalRef.current?.firstElementChild;\n\n const enabled = (prevWidth.current ?? 0) > (width ?? 0);\n\n if (enabled && width && actualWidth > width) {\n const diffWidth = actualWidth - width;\n const childWidthCollection: number[] = [];\n\n let childIndex = widthCollectionRef.current.length === 0 ? 0 : 2;\n let childSumWidth = 0;\n\n while (diffWidth > childSumWidth) {\n const childWidth =\n (breadcrumbItems?.children[childIndex] as HTMLLIElement)\n ?.offsetWidth ?? 0;\n const separatorWidth =\n (breadcrumbItems?.children[childIndex + 1] as HTMLLIElement)\n ?.offsetWidth ?? 0;\n const result = separatorWidth + childWidth;\n childWidthCollection.push(result);\n childSumWidth += result;\n childIndex += 2;\n }\n\n if (childWidthCollection.length === listCollection.length) {\n childWidthCollection.pop();\n }\n\n widthCollectionRef.current = [\n ...widthCollectionRef.current,\n ...childWidthCollection,\n ];\n\n setMenuBreadcrumbs((oldVal) => oldVal + childWidthCollection.length);\n }\n }, [listCollection.length, width]);\n\n useEffect(() => {\n const breadcrumbItems = internalRef.current?.firstElementChild;\n const nextWidth =\n (breadcrumbItems?.lastElementChild as HTMLLIElement)?.offsetWidth +\n (breadcrumbItems?.lastElementChild as HTMLLIElement)?.offsetLeft;\n\n const enabled = (prevWidth.current ?? 0) < (width ?? 0);\n const diffWidth = (width ?? 0) - nextWidth;\n\n if (enabled && diffWidth > 0 && widthCollectionRef.current.length > 0) {\n const total = widthCollectionRef.current.length;\n const collection = [...widthCollectionRef.current];\n\n let sumWidth = 0;\n\n while (diffWidth > sumWidth && collection.length > 0) {\n const lastWidth = collection[collection.length - 1] ?? 0;\n if (diffWidth < lastWidth + sumWidth) {\n sumWidth = diffWidth;\n } else {\n sumWidth += collection.pop() ?? 0;\n }\n }\n\n const totalToDecrease = total - collection.length;\n\n setMenuBreadcrumbs((oldVal) => oldVal - totalToDecrease);\n\n const end = total - totalToDecrease;\n\n widthCollectionRef.current =\n end > 0 ? widthCollectionRef.current.slice(0, end) : [];\n }\n }, [width]);\n\n useEffect(() => {\n const debounceWidth = debounce((width: number) => {\n setWidth((prevState) => {\n prevWidth.current = prevState ?? width + 1;\n return width;\n });\n }, timeout);\n\n debounceWidth(dimensions?.width ?? 0);\n\n return (): void => {\n debounceWidth.cancel();\n };\n }, [timeout, dimensions?.width]);\n\n return (\n <StyledNavElement className={className} ref={handleRef} {...rest}>\n <StyledOList>\n {menuCollection.length > 0 ? (\n <StyledBreadcrumbListItem>\n <Menu\n target={\n <Button variant=\"text gray\">\n <TreeDotsIcon />\n </Button>\n }\n >\n <StyledMenuList>\n {menuCollection.map((child, index) => (\n <ListItem key={index}>{child}</ListItem>\n ))}\n </StyledMenuList>\n </Menu>\n </StyledBreadcrumbListItem>\n ) : null}\n {listCollection.map((child, index) => {\n return (\n <React.Fragment key={index}>\n {index > 0 || menuCollection.length > 0 ? (\n <StyledBreadcrumbListItem>{separator}</StyledBreadcrumbListItem>\n ) : null}\n <StyledBreadcrumbListItem>{child}</StyledBreadcrumbListItem>\n </React.Fragment>\n );\n })}\n </StyledOList>\n </StyledNavElement>\n );\n});\n\nBreadcrumbs.displayName = \"Breadcrumbs\";\n"],"file":"Breadcrumbs.js"}
1
+ {"version":3,"sources":["../../../../src/components/Breadcrumbs/Breadcrumbs.tsx"],"names":["Breadcrumbs","React","forwardRef","ref","children","className","separator","rest","internalRef","listWrapperRef","olRef","widthCollectionRef","handleRef","menuBreadcrumbs","setMenuBreadcrumbs","dimensions","childDimensions","parentWidth","width","childWidth","childrenCollection","Children","toArray","slice","length","menuCollection","listCollection","current","diffWidth","separatorWidth","querySelectorAll","offsetWidth","breadcrumbItems","childWidthCollection","maxIndex","currentIndex","childSumWidth","result","push","pop","oldVal","total","collection","sumWidth","lastWidth","totalToDecrease","newValue","end","map","child","index","displayName"],"mappings":";;;;;;;;;AAAA;;AAOA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaO,IAAMA,WAAW,gBAAGC,eAAMC,UAAN,CAIzB,gBAAoDC,GAApD,EAA4D;AAAA;;AAAA,MAAzDC,QAAyD,QAAzDA,QAAyD;AAAA,MAA/CC,SAA+C,QAA/CA,SAA+C;AAAA,4BAApCC,SAAoC;AAAA,MAApCA,SAAoC,+BAAxB,GAAwB;AAAA,MAAhBC,IAAgB;;AAC5D,MAAMC,WAAW,GAAG,mBAA2B,IAA3B,CAApB;AACA,MAAMC,cAAc,GAAG,mBAA8B,IAA9B,CAAvB;AACA,MAAMC,KAAK,GAAG,mBAAgC,IAAhC,CAAd;AACA,MAAMC,kBAAkB,GAAG,mBAAiB,EAAjB,CAA3B;AACA,MAAMC,SAAS,GAAG,uBAAWT,GAAX,EAAgBK,WAAhB,CAAlB;;AACA,kBAA8C,qBAAS,CAAT,CAA9C;AAAA;AAAA,MAAOK,eAAP;AAAA,MAAwBC,kBAAxB;;AACA,MAAMC,U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;AAAQ,MAAA,OAAO,EAAC;AAAhB,oBACE,6BAAC,mBAAD,OADF;AAFJ,kBAOE,6BAAC,sBAAD,QACGC,cAAc,CAACuB,GAAf,CAAmB,UAACC,KAAD,EAAQC,KAAR;AAAA,wBAClB,6BAAC,cAAD;AAAU,MAAA,GAAG,EAAEA;AAAf,OAAuBD,KAAvB,CADkB;AAAA,GAAnB,CADH,CAPF,CADF,CADD,GAgBG,IAjBN,EAkBGvB,cAAc,CAACsB,GAAf,CAAmB,UAACC,KAAD,EAAQC,KAAR,EAAkB;AACpC,wBACE,6BAAC,cAAD,CAAO,QAAP;AAAgB,MAAA,GAAG,EAAEA;AAArB,OACGA,KAAK,GAAG,CAAR,IAAazB,cAAc,CAACD,MAAf,GAAwB,CAArC,gBACC,6BAAC,gCAAD;AAA0B,mBAAU;AAApC,OACGlB,SADH,CADD,GAIG,IALN,eAME,6BAAC,gCAAD;AAA0B,mBAAU;AAApC,OACG2C,KADH,CANF,CADF;AAYD,GAbA,CAlBH,CADF,CADF,CADF;AAuCD,CAjJ0B,CAApB;;;AAmJPjD,WAAW,CAACmD,WAAZ,GAA0B,aAA1B","sourcesContent":["import React, {\n ReactElement,\n useRef,\n useMemo,\n useEffect,\n useState,\n} from \"react\";\nimport { useForkRef, useResizeObserver } from \"../../utils\";\nimport { Menu } from \"../Menu\";\nimport { ListItem } from \"../List\";\nimport { Button } from \"../Button\";\nimport { TreeDotsIcon } from \"../Icons\";\nimport {\n StyledNavElement,\n StyledOList,\n StyledMenuList,\n StyledListWrapper,\n StyledBreadcrumbListItem,\n} from \"./Styles\";\n\nexport interface BreadcrumbsProps {\n /** Separator element */\n separator?: ReactElement | string;\n}\n\nexport const Breadcrumbs = React.forwardRef<\n HTMLElement,\n BreadcrumbsProps &\n Omit<React.ComponentPropsWithoutRef<\"nav\">, keyof BreadcrumbsProps>\n>(({ children, className, separator = \"/\", ...rest }, ref) => {\n const internalRef = useRef<HTMLElement | null>(null);\n const listWrapperRef = useRef<HTMLDivElement | null>(null);\n const olRef = useRef<HTMLOListElement | null>(null);\n const widthCollectionRef = useRef<number[]>([]);\n const handleRef = useForkRef(ref, internalRef);\n const [menuBreadcrumbs, setMenuBreadcrumbs] = useState(0);\n const dimensions = useResizeObserver(internalRef);\n const childDimensions = useResizeObserver(listWrapperRef);\n\n const parentWidth = dimensions?.width ?? 0;\n const childWidth = childDimensions?.width ?? 0;\n\n const childrenCollection = useMemo(\n () => React.Children.toArray(children),\n [children]\n );\n\n const [menuCollection, listCollection] = useMemo(() => {\n return [\n childrenCollection.slice(0, menuBreadcrumbs),\n childrenCollection.slice(menuBreadcrumbs, childrenCollection.length),\n ];\n }, [childrenCollection, menuBreadcrumbs]);\n\n useEffect(() => {\n widthCollectionRef.current = [];\n setMenuBreadcrumbs(0);\n }, [childrenCollection.length]);\n\n useEffect(() => {\n const diffWidth = childWidth - parentWidth;\n\n if (diffWidth > 0) {\n const separatorWidth =\n (\n olRef.current?.querySelectorAll(\n `[data-role=\"separator\"]`\n )[0] as HTMLLIElement\n )?.offsetWidth ?? 0;\n const breadcrumbItems =\n olRef.current?.querySelectorAll(`[data-role=\"item\"]`) ?? [];\n const childWidthCollection: number[] = [];\n\n const maxIndex = (breadcrumbItems?.length ?? 1) - 1;\n let currentIndex = 0;\n let childSumWidth = 0;\n\n while (diffWidth > childSumWidth && maxIndex >= currentIndex) {\n const childWidth =\n (breadcrumbItems[currentIndex] as HTMLLIElement)?.offsetWidth ?? 0;\n const result = separatorWidth + childWidth;\n childWidthCollection.push(result);\n childSumWidth += result;\n currentIndex += 1;\n }\n\n if (childWidthCollection.length === listCollection.length) {\n childWidthCollection.pop();\n }\n\n widthCollectionRef.current = [\n ...widthCollectionRef.current,\n ...childWidthCollection,\n ];\n\n setMenuBreadcrumbs((oldVal) => oldVal + childWidthCollection.length);\n }\n }, [listCollection.length, parentWidth, childWidth]);\n\n useEffect(() => {\n const diffWidth = parentWidth - childWidth;\n\n if (diffWidth > 0 && widthCollectionRef.current.length > 0) {\n const total = widthCollectionRef.current.length;\n const collection = [...widthCollectionRef.current];\n\n let sumWidth = 0;\n\n while (diffWidth > sumWidth && collection.length > 0) {\n const lastWidth = collection[collection.length - 1] ?? 0;\n if (diffWidth < lastWidth + sumWidth) {\n sumWidth = diffWidth;\n } else {\n sumWidth += collection.pop() ?? 0;\n }\n }\n\n const totalToDecrease = total - collection.length;\n\n setMenuBreadcrumbs((oldVal) => {\n const newValue = oldVal - totalToDecrease;\n return newValue > 0 ? newValue : 0;\n });\n\n const end = total - totalToDecrease;\n\n widthCollectionRef.current =\n end > 0 ? widthCollectionRef.current.slice(0, end) : [];\n }\n }, [parentWidth, childWidth]);\n\n return (\n <StyledNavElement className={className} ref={handleRef} {...rest}>\n <StyledListWrapper ref={listWrapperRef}>\n <StyledOList ref={olRef}>\n {menuCollection.length > 0 ? (\n <StyledBreadcrumbListItem data-role=\"menu\">\n <Menu\n target={\n <Button variant=\"text gray\">\n <TreeDotsIcon />\n </Button>\n }\n >\n <StyledMenuList>\n {menuCollection.map((child, index) => (\n <ListItem key={index}>{child}</ListItem>\n ))}\n </StyledMenuList>\n </Menu>\n </StyledBreadcrumbListItem>\n ) : null}\n {listCollection.map((child, index) => {\n return (\n <React.Fragment key={index}>\n {index > 0 || menuCollection.length > 0 ? (\n <StyledBreadcrumbListItem data-role=\"separator\">\n {separator}\n </StyledBreadcrumbListItem>\n ) : null}\n <StyledBreadcrumbListItem data-role=\"item\">\n {child}\n </StyledBreadcrumbListItem>\n </React.Fragment>\n );\n })}\n </StyledOList>\n </StyledListWrapper>\n </StyledNavElement>\n );\n});\n\nBreadcrumbs.displayName = \"Breadcrumbs\";\n"],"file":"Breadcrumbs.js"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.StyledOList = exports.StyledNavElement = exports.StyledMenuList = exports.StyledBreadcrumbListItem = void 0;
6
+ exports.StyledOList = exports.StyledNavElement = exports.StyledMenuList = exports.StyledListWrapper = exports.StyledBreadcrumbListItem = void 0;
7
7
 
8
8
  var _styledComponents = _interopRequireDefault(require("styled-components"));
9
9
 
@@ -21,34 +21,44 @@ var StyledNavElement = _styledComponents.default.nav.withConfig({
21
21
  })(["", " ", " ", " ", ""], {
22
22
  "width": "100%"
23
23
  }, {
24
- "overflow": "visible"
24
+ "overflow": "hidden"
25
25
  }, _FontStyle.FontStyle, _BoxSizingStyle.BoxSizingStyle);
26
26
 
27
27
  exports.StyledNavElement = StyledNavElement;
28
28
  StyledNavElement.displayName = "StyledNavElement";
29
29
 
30
- var StyledOList = _styledComponents.default.ul.withConfig({
31
- displayName: "Styles__StyledOList",
30
+ var StyledListWrapper = _styledComponents.default.div.withConfig({
31
+ displayName: "Styles__StyledListWrapper",
32
32
  componentId: "sc-rxaesd-1"
33
+ })(["", ""], {
34
+ "display": "inline-block"
35
+ });
36
+
37
+ exports.StyledListWrapper = StyledListWrapper;
38
+ StyledListWrapper.displayName = "StyledListWrapper";
39
+
40
+ var StyledOList = _styledComponents.default.ol.withConfig({
41
+ displayName: "Styles__StyledOList",
42
+ componentId: "sc-rxaesd-2"
33
43
  })(["", " ", " ", " ", " ", " ", ""], {
34
44
  "display": "flex"
35
45
  }, {
36
46
  "alignItems": "flex-start"
47
+ }, {
48
+ "alignItems": "center"
37
49
  }, {
38
50
  "listStyleType": "none"
39
51
  }, {
40
52
  "padding": "0px"
41
53
  }, {
42
54
  "margin": "0px"
43
- }, {
44
- "alignItems": "center"
45
55
  });
46
56
 
47
57
  exports.StyledOList = StyledOList;
48
58
  StyledOList.displayName = "StyledOList";
49
59
  var StyledMenuList = (0, _styledComponents.default)(_List.List).withConfig({
50
60
  displayName: "Styles__StyledMenuList",
51
- componentId: "sc-rxaesd-2"
61
+ componentId: "sc-rxaesd-3"
52
62
  })(["", ""], {
53
63
  "paddingTop": "0.5rem",
54
64
  "paddingBottom": "0.5rem"
@@ -58,10 +68,8 @@ StyledMenuList.displayName = "StyledMenuList";
58
68
 
59
69
  var StyledBreadcrumbListItem = _styledComponents.default.li.withConfig({
60
70
  displayName: "Styles__StyledBreadcrumbListItem",
61
- componentId: "sc-rxaesd-3"
62
- })(["", " ", ""], {
63
- "display": "flex"
64
- }, {
71
+ componentId: "sc-rxaesd-4"
72
+ })(["", ""], {
65
73
  "flexShrink": "0"
66
74
  });
67
75
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Breadcrumbs/Styles.ts"],"names":["StyledNavElement","styled","nav","FontStyle","BoxSizingStyle","displayName","StyledOList","ul","StyledMenuList","List","StyledBreadcrumbListItem","li"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;;;AAEO,IAAMA,gBAAgB,GAAGC,0BAAOC,GAAV;AAAA;AAAA;AAAA,4BACvB;AAAA;AAAA,CADuB,EAEvB;AAAA;AAAA,CAFuB,EAGzBC,oBAHyB,EAIzBC,8BAJyB,CAAtB;;;AAOPJ,gBAAgB,CAACK,WAAjB,GAA+B,kBAA/B;;AAEO,IAAMC,WAAW,GAAGL,0BAAOM,EAAV;AAAA;AAAA;AAAA,sCAClB;AAAA;AAAA,CADkB,EAElB;AAAA;AAAA,CAFkB,EAGlB;AAAA;AAAA,CAHkB,EAIlB;AAAA;AAAA,CAJkB,EAKlB;AAAA;AAAA,CALkB,EAMlB;AAAA;AAAA,CANkB,CAAjB;;;AASPD,WAAW,CAACD,WAAZ,GAA0B,aAA1B;AAEO,IAAMG,cAAc,GAAG,+BAAOC,UAAP,CAAH;AAAA;AAAA;AAAA,aACrB;AAAA;AAAA;AAAA,CADqB,CAApB;;AAIPD,cAAc,CAACH,WAAf,GAA6B,gBAA7B;;AAEO,IAAMK,wBAAwB,GAAGT,0BAAOU,EAAV;AAAA;AAAA;AAAA,kBAC/B;AAAA;AAAA,CAD+B,EAE/B;AAAA;AAAA,CAF+B,CAA9B;;;AAKPD,wBAAwB,CAACL,WAAzB,GAAuC,0BAAvC","sourcesContent":["import styled from \"styled-components\";\nimport tw from \"twin.macro\";\nimport { BoxSizingStyle } from \"../BoxSizingStyle\";\nimport { FontStyle } from \"../FontStyle\";\nimport { List } from \"../List\";\n\nexport const StyledNavElement = styled.nav`\n ${tw`tw-w-full`}\n ${tw`tw-overflow-visible`}\n ${FontStyle}\n ${BoxSizingStyle}\n`;\n\nStyledNavElement.displayName = \"StyledNavElement\";\n\nexport const StyledOList = styled.ul`\n ${tw`tw-flex`}\n ${tw`tw-items-start`}\n ${tw`tw-list-none`}\n ${tw`tw-p-0`}\n ${tw`tw-m-0`}\n ${tw`tw-items-center`}\n`;\n\nStyledOList.displayName = \"StyledOList\";\n\nexport const StyledMenuList = styled(List)`\n ${tw`tw-py-2`}\n`;\n\nStyledMenuList.displayName = \"StyledMenuList\";\n\nexport const StyledBreadcrumbListItem = styled.li`\n ${tw`tw-flex`}\n ${tw`tw-flex-shrink-0`}\n`;\n\nStyledBreadcrumbListItem.displayName = \"StyledBreadcrumbListItem\";\n"],"file":"Styles.js"}
1
+ {"version":3,"sources":["../../../../src/components/Breadcrumbs/Styles.ts"],"names":["StyledNavElement","styled","nav","FontStyle","BoxSizingStyle","displayName","StyledListWrapper","div","StyledOList","ol","StyledMenuList","List","StyledBreadcrumbListItem","li"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;;;AAEO,IAAMA,gBAAgB,GAAGC,0BAAOC,GAAV;AAAA;AAAA;AAAA,4BACvB;AAAA;AAAA,CADuB,EAEvB;AAAA;AAAA,CAFuB,EAGzBC,oBAHyB,EAIzBC,8BAJyB,CAAtB;;;AAOPJ,gBAAgB,CAACK,WAAjB,GAA+B,kBAA/B;;AAEO,IAAMC,iBAAiB,GAAGL,0BAAOM,GAAV;AAAA;AAAA;AAAA,aACxB;AAAA;AAAA,CADwB,CAAvB;;;AAIPD,iBAAiB,CAACD,WAAlB,GAAgC,mBAAhC;;AAEO,IAAMG,WAAW,GAAGP,0BAAOQ,EAAV;AAAA;AAAA;AAAA,sCAClB;AAAA;AAAA,CADkB,EAElB;AAAA;AAAA,CAFkB,EAGlB;AAAA;AAAA,CAHkB,EAIlB;AAAA;AAAA,CAJkB,EAKlB;AAAA;AAAA,CALkB,EAMlB;AAAA;AAAA,CANkB,CAAjB;;;AASPD,WAAW,CAACH,WAAZ,GAA0B,aAA1B;AAEO,IAAMK,cAAc,GAAG,+BAAOC,UAAP,CAAH;AAAA;AAAA;AAAA,aACrB;AAAA;AAAA;AAAA,CADqB,CAApB;;AAIPD,cAAc,CAACL,WAAf,GAA6B,gBAA7B;;AAEO,IAAMO,wBAAwB,GAAGX,0BAAOY,EAAV;AAAA;AAAA;AAAA,aAC/B;AAAA;AAAA,CAD+B,CAA9B;;;AAIPD,wBAAwB,CAACP,WAAzB,GAAuC,0BAAvC","sourcesContent":["import styled from \"styled-components\";\nimport tw from \"twin.macro\";\nimport { BoxSizingStyle } from \"../BoxSizingStyle\";\nimport { FontStyle } from \"../FontStyle\";\nimport { List } from \"../List\";\n\nexport const StyledNavElement = styled.nav`\n ${tw`tw-w-full`}\n ${tw`tw-overflow-hidden`}\n ${FontStyle}\n ${BoxSizingStyle}\n`;\n\nStyledNavElement.displayName = \"StyledNavElement\";\n\nexport const StyledListWrapper = styled.div`\n ${tw`tw-inline-block`}\n`;\n\nStyledListWrapper.displayName = \"StyledListWrapper\";\n\nexport const StyledOList = styled.ol`\n ${tw`tw-flex`}\n ${tw`tw-items-start`}\n ${tw`tw-items-center`}\n ${tw`tw-list-none`}\n ${tw`tw-p-0`}\n ${tw`tw-m-0`}\n`;\n\nStyledOList.displayName = \"StyledOList\";\n\nexport const StyledMenuList = styled(List)`\n ${tw`tw-py-2`}\n`;\n\nStyledMenuList.displayName = \"StyledMenuList\";\n\nexport const StyledBreadcrumbListItem = styled.li`\n ${tw`tw-flex-shrink-0`}\n`;\n\nStyledBreadcrumbListItem.displayName = \"StyledBreadcrumbListItem\";\n"],"file":"Styles.js"}
@@ -1,7 +1,6 @@
1
1
  import React, { ReactElement } from "react";
2
2
  export interface BreadcrumbsProps {
3
3
  separator?: ReactElement | string;
4
- timeout?: number;
5
4
  }
6
- export declare const Breadcrumbs: React.ForwardRefExoticComponent<BreadcrumbsProps & Omit<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "key" | keyof React.HTMLAttributes<HTMLElement>>, keyof BreadcrumbsProps> & React.RefAttributes<HTMLElement>>;
5
+ export declare const Breadcrumbs: React.ForwardRefExoticComponent<BreadcrumbsProps & Omit<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "key" | keyof React.HTMLAttributes<HTMLElement>>, "separator"> & React.RefAttributes<HTMLElement>>;
7
6
  //# sourceMappingURL=Breadcrumbs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Breadcrumbs.d.ts","sourceRoot":"","sources":["../../../../src/components/Breadcrumbs/Breadcrumbs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,YAAY,EAKb,MAAM,OAAO,CAAC;AAcf,MAAM,WAAW,gBAAgB;IAE/B,SAAS,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IAElC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,WAAW,qPAoJtB,CAAC"}
1
+ {"version":3,"file":"Breadcrumbs.d.ts","sourceRoot":"","sources":["../../../../src/components/Breadcrumbs/Breadcrumbs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,YAAY,EAKb,MAAM,OAAO,CAAC;AAcf,MAAM,WAAW,gBAAgB;IAE/B,SAAS,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;CACnC;AAED,eAAO,MAAM,WAAW,0OAiJtB,CAAC"}
@@ -1,40 +1,40 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- var _excluded = ["children", "className", "separator", "timeout"];
3
+ var _excluded = ["children", "className", "separator"];
4
4
  import React, { useRef, useMemo, useEffect, useState } from "react";
5
5
  import { useForkRef, useResizeObserver } from "../../utils";
6
6
  import { Menu } from "../Menu";
7
7
  import { ListItem } from "../List";
8
8
  import { Button } from "../Button";
9
9
  import { TreeDotsIcon } from "../Icons";
10
- import debounce from "lodash.debounce";
11
- import { StyledNavElement, StyledOList, StyledBreadcrumbListItem, StyledMenuList } from "./Styles";
10
+ import { StyledNavElement, StyledOList, StyledMenuList, StyledListWrapper, StyledBreadcrumbListItem } from "./Styles";
12
11
  export var Breadcrumbs = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
12
+ var _dimensions$width, _childDimensions$widt;
13
+
13
14
  var children = _ref.children,
14
15
  className = _ref.className,
15
16
  _ref$separator = _ref.separator,
16
17
  separator = _ref$separator === void 0 ? "/" : _ref$separator,
17
- _ref$timeout = _ref.timeout,
18
- timeout = _ref$timeout === void 0 ? 300 : _ref$timeout,
19
18
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
20
19
 
21
20
  var internalRef = useRef(null);
22
- var prevWidth = useRef();
21
+ var listWrapperRef = useRef(null);
22
+ var olRef = useRef(null);
23
23
  var widthCollectionRef = useRef([]);
24
24
  var handleRef = useForkRef(ref, internalRef);
25
+
26
+ var _useState = useState(0),
27
+ menuBreadcrumbs = _useState[0],
28
+ setMenuBreadcrumbs = _useState[1];
29
+
25
30
  var dimensions = useResizeObserver(internalRef);
31
+ var childDimensions = useResizeObserver(listWrapperRef);
32
+ var parentWidth = (_dimensions$width = dimensions == null ? void 0 : dimensions.width) != null ? _dimensions$width : 0;
33
+ var childWidth = (_childDimensions$widt = childDimensions == null ? void 0 : childDimensions.width) != null ? _childDimensions$widt : 0;
26
34
  var childrenCollection = useMemo(function () {
27
35
  return React.Children.toArray(children);
28
36
  }, [children]);
29
37
 
30
- var _useState = useState(),
31
- width = _useState[0],
32
- setWidth = _useState[1];
33
-
34
- var _useState2 = useState(0),
35
- menuBreadcrumbs = _useState2[0],
36
- setMenuBreadcrumbs = _useState2[1];
37
-
38
38
  var _useMemo = useMemo(function () {
39
39
  return [childrenCollection.slice(0, menuBreadcrumbs), childrenCollection.slice(menuBreadcrumbs, childrenCollection.length)];
40
40
  }, [childrenCollection, menuBreadcrumbs]),
@@ -42,27 +42,31 @@ export var Breadcrumbs = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
42
42
  listCollection = _useMemo[1];
43
43
 
44
44
  useEffect(function () {
45
- var _internalRef$current, _internalRef$current2, _prevWidth$current;
45
+ widthCollectionRef.current = [];
46
+ setMenuBreadcrumbs(0);
47
+ }, [childrenCollection.length]);
48
+ useEffect(function () {
49
+ var diffWidth = childWidth - parentWidth;
46
50
 
47
- var actualWidth = ((_internalRef$current = internalRef.current) == null ? void 0 : _internalRef$current.scrollWidth) || 0;
48
- var breadcrumbItems = (_internalRef$current2 = internalRef.current) == null ? void 0 : _internalRef$current2.firstElementChild;
49
- var enabled = ((_prevWidth$current = prevWidth.current) != null ? _prevWidth$current : 0) > (width != null ? width : 0);
51
+ if (diffWidth > 0) {
52
+ var _offsetWidth, _olRef$current, _olRef$current$queryS, _olRef$current$queryS2, _olRef$current2, _breadcrumbItems$leng;
50
53
 
51
- if (enabled && width && actualWidth > width) {
52
- var diffWidth = actualWidth - width;
54
+ var separatorWidth = (_offsetWidth = (_olRef$current = olRef.current) == null ? void 0 : (_olRef$current$queryS = _olRef$current.querySelectorAll("[data-role=\"separator\"]")[0]) == null ? void 0 : _olRef$current$queryS.offsetWidth) != null ? _offsetWidth : 0;
55
+ var breadcrumbItems = (_olRef$current$queryS2 = (_olRef$current2 = olRef.current) == null ? void 0 : _olRef$current2.querySelectorAll("[data-role=\"item\"]")) != null ? _olRef$current$queryS2 : [];
53
56
  var childWidthCollection = [];
54
- var childIndex = widthCollectionRef.current.length === 0 ? 0 : 2;
57
+ var maxIndex = ((_breadcrumbItems$leng = breadcrumbItems == null ? void 0 : breadcrumbItems.length) != null ? _breadcrumbItems$leng : 1) - 1;
58
+ var currentIndex = 0;
55
59
  var childSumWidth = 0;
56
60
 
57
- while (diffWidth > childSumWidth) {
58
- var _offsetWidth, _breadcrumbItems$chil, _offsetWidth2, _breadcrumbItems$chil2;
61
+ while (diffWidth > childSumWidth && maxIndex >= currentIndex) {
62
+ var _offsetWidth2, _breadcrumbItems$curr;
59
63
 
60
- var childWidth = (_offsetWidth = breadcrumbItems == null ? void 0 : (_breadcrumbItems$chil = breadcrumbItems.children[childIndex]) == null ? void 0 : _breadcrumbItems$chil.offsetWidth) != null ? _offsetWidth : 0;
61
- var separatorWidth = (_offsetWidth2 = breadcrumbItems == null ? void 0 : (_breadcrumbItems$chil2 = breadcrumbItems.children[childIndex + 1]) == null ? void 0 : _breadcrumbItems$chil2.offsetWidth) != null ? _offsetWidth2 : 0;
62
- var result = separatorWidth + childWidth;
64
+ var _childWidth = (_offsetWidth2 = (_breadcrumbItems$curr = breadcrumbItems[currentIndex]) == null ? void 0 : _breadcrumbItems$curr.offsetWidth) != null ? _offsetWidth2 : 0;
65
+
66
+ var result = separatorWidth + _childWidth;
63
67
  childWidthCollection.push(result);
64
68
  childSumWidth += result;
65
- childIndex += 2;
69
+ currentIndex += 1;
66
70
  }
67
71
 
68
72
  if (childWidthCollection.length === listCollection.length) {
@@ -74,16 +78,11 @@ export var Breadcrumbs = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
74
78
  return oldVal + childWidthCollection.length;
75
79
  });
76
80
  }
77
- }, [listCollection.length, width]);
81
+ }, [listCollection.length, parentWidth, childWidth]);
78
82
  useEffect(function () {
79
- var _internalRef$current3, _breadcrumbItems$last, _breadcrumbItems$last2, _prevWidth$current2;
80
-
81
- var breadcrumbItems = (_internalRef$current3 = internalRef.current) == null ? void 0 : _internalRef$current3.firstElementChild;
82
- var nextWidth = (breadcrumbItems == null ? void 0 : (_breadcrumbItems$last = breadcrumbItems.lastElementChild) == null ? void 0 : _breadcrumbItems$last.offsetWidth) + (breadcrumbItems == null ? void 0 : (_breadcrumbItems$last2 = breadcrumbItems.lastElementChild) == null ? void 0 : _breadcrumbItems$last2.offsetLeft);
83
- var enabled = ((_prevWidth$current2 = prevWidth.current) != null ? _prevWidth$current2 : 0) < (width != null ? width : 0);
84
- var diffWidth = (width != null ? width : 0) - nextWidth;
83
+ var diffWidth = parentWidth - childWidth;
85
84
 
86
- if (enabled && diffWidth > 0 && widthCollectionRef.current.length > 0) {
85
+ if (diffWidth > 0 && widthCollectionRef.current.length > 0) {
87
86
  var total = widthCollectionRef.current.length;
88
87
  var collection = [].concat(widthCollectionRef.current);
89
88
  var sumWidth = 0;
@@ -104,30 +103,23 @@ export var Breadcrumbs = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
104
103
 
105
104
  var totalToDecrease = total - collection.length;
106
105
  setMenuBreadcrumbs(function (oldVal) {
107
- return oldVal - totalToDecrease;
106
+ var newValue = oldVal - totalToDecrease;
107
+ return newValue > 0 ? newValue : 0;
108
108
  });
109
109
  var end = total - totalToDecrease;
110
110
  widthCollectionRef.current = end > 0 ? widthCollectionRef.current.slice(0, end) : [];
111
111
  }
112
- }, [width]);
113
- useEffect(function () {
114
- var _dimensions$width;
115
-
116
- var debounceWidth = debounce(function (width) {
117
- setWidth(function (prevState) {
118
- prevWidth.current = prevState != null ? prevState : width + 1;
119
- return width;
120
- });
121
- }, timeout);
122
- debounceWidth((_dimensions$width = dimensions == null ? void 0 : dimensions.width) != null ? _dimensions$width : 0);
123
- return function () {
124
- debounceWidth.cancel();
125
- };
126
- }, [timeout, dimensions == null ? void 0 : dimensions.width]);
112
+ }, [parentWidth, childWidth]);
127
113
  return /*#__PURE__*/React.createElement(StyledNavElement, _extends({
128
114
  className: className,
129
115
  ref: handleRef
130
- }, rest), /*#__PURE__*/React.createElement(StyledOList, null, menuCollection.length > 0 ? /*#__PURE__*/React.createElement(StyledBreadcrumbListItem, null, /*#__PURE__*/React.createElement(Menu, {
116
+ }, rest), /*#__PURE__*/React.createElement(StyledListWrapper, {
117
+ ref: listWrapperRef
118
+ }, /*#__PURE__*/React.createElement(StyledOList, {
119
+ ref: olRef
120
+ }, menuCollection.length > 0 ? /*#__PURE__*/React.createElement(StyledBreadcrumbListItem, {
121
+ "data-role": "menu"
122
+ }, /*#__PURE__*/React.createElement(Menu, {
131
123
  target: /*#__PURE__*/React.createElement(Button, {
132
124
  variant: "text gray"
133
125
  }, /*#__PURE__*/React.createElement(TreeDotsIcon, null))
@@ -138,8 +130,12 @@ export var Breadcrumbs = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
138
130
  })))) : null, listCollection.map(function (child, index) {
139
131
  return /*#__PURE__*/React.createElement(React.Fragment, {
140
132
  key: index
141
- }, index > 0 || menuCollection.length > 0 ? /*#__PURE__*/React.createElement(StyledBreadcrumbListItem, null, separator) : null, /*#__PURE__*/React.createElement(StyledBreadcrumbListItem, null, child));
142
- })));
133
+ }, index > 0 || menuCollection.length > 0 ? /*#__PURE__*/React.createElement(StyledBreadcrumbListItem, {
134
+ "data-role": "separator"
135
+ }, separator) : null, /*#__PURE__*/React.createElement(StyledBreadcrumbListItem, {
136
+ "data-role": "item"
137
+ }, child));
138
+ }))));
143
139
  });
144
140
  Breadcrumbs.displayName = "Breadcrumbs";
145
141
  //# sourceMappingURL=Breadcrumbs.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Breadcrumbs/Breadcrumbs.tsx"],"names":["React","useRef","useMemo","useEffect","useState","useForkRef","useResizeObserver","Menu","ListItem","Button","TreeDotsIcon","debounce","StyledNavElement","StyledOList","StyledBreadcrumbListItem","StyledMenuList","Breadcrumbs","forwardRef","ref","children","className","separator","timeout","rest","internalRef","prevWidth","widthCollectionRef","handleRef","dimensions","childrenCollection","Children","toArray","width","setWidth","menuBreadcrumbs","setMenuBreadcrumbs","slice","length","menuCollection","listCollection","actualWidth","current","scrollWidth","breadcrumbItems","firstElementChild","enabled","diffWidth","childWidthCollection","childIndex","childSumWidth","childWidth","offsetWidth","separatorWidth","result","push","pop","oldVal","nextWidth","lastElementChild","offsetLeft","total","collection","sumWidth","lastWidth","totalToDecrease","end","debounceWidth","prevState","cancel","map","child","index","displayName"],"mappings":";;;AAAA,OAAOA,KAAP,IAEEC,MAFF,EAGEC,OAHF,EAIEC,SAJF,EAKEC,QALF,QAMO,OANP;AAOA,SAASC,UAAT,EAAqBC,iBAArB,QAA8C,aAA9C;AACA,SAASC,IAAT,QAAqB,SAArB;AACA,SAASC,QAAT,QAAyB,SAAzB;AACA,SAASC,MAAT,QAAuB,WAAvB;AACA,SAASC,YAAT,QAA6B,UAA7B;AACA,OAAOC,QAAP,MAAqB,iBAArB;AACA,SACEC,gBADF,EAEEC,WAFF,EAGEC,wBAHF,EAIEC,cAJF,QAKO,UALP;AAcA,OAAO,IAAMC,WAAW,gBAAGhB,KAAK,CAACiB,UAAN,CAIzB,gBAAmEC,GAAnE,EAA2E;AAAA,MAAxEC,QAAwE,QAAxEA,QAAwE;AAAA,MAA9DC,SAA8D,QAA9DA,SAA8D;AAAA,4BAAnDC,SAAmD;AAAA,MAAnDA,SAAmD,+BAAvC,GAAuC;AAAA,0BAAlCC,OAAkC;AAAA,MAAlCA,OAAkC,6BAAxB,GAAwB;AAAA,MAAhBC,IAAgB;;AAC3E,MAAMC,WAAW,GAAGvB,MAAM,CAAqB,IAArB,CAA1B;AACA,MAAMwB,SAAS,GAAGxB,MAAM,EAAxB;AACA,MAAMyB,kBAAkB,GAAGzB,MAAM,CAAW,EAAX,CAAjC;AACA,MAAM0B,SAAS,GAAGtB,UAAU,CAACa,GAAD,EAAMM,WAAN,CAA5B;AACA,MAAMI,UAAU,GAAGtB,iBAAiB,CAACkB,WAAD,CAApC;AAEA,MAAMK,kBAAkB,GAAG3B,OAAO,CAChC;AAAA,WAAMF,KAAK,CAAC8B,QAAN,CAAeC,OAAf,CAAuBZ,QAAvB,CAAN;AAAA,GADgC,EAEhC,CAACA,QAAD,CAFgC,CAAlC;;AAKA,kBAA0Bf,QAAQ,EAAlC;AAAA,MAAO4B,KAAP;AAAA,MAAcC,QAAd;;AACA,mB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UAAD,oBAACA,UAAU,CAAEI,KAAb,gCAAsB,CAAtB,CAAb;AAEA,WAAO,YAAY;AACjBkC,MAAAA,aAAa,CAACE,MAAd;AACD,KAFD;AAGD,GAbQ,EAaN,CAAC9C,OAAD,EAAUM,UAAV,oBAAUA,UAAU,CAAEI,KAAtB,CAbM,CAAT;AAeA,sBACE,oBAAC,gBAAD;AAAkB,IAAA,SAAS,EAAEZ,SAA7B;AAAwC,IAAA,GAAG,EAAEO;AAA7C,KAA4DJ,IAA5D,gBACE,oBAAC,WAAD,QACGe,cAAc,CAACD,MAAf,GAAwB,CAAxB,gBACC,oBAAC,wBAAD,qBACE,oBAAC,IAAD;AACE,IAAA,MAAM,eACJ,oBAAC,MAAD;AAAQ,MAAA,OAAO,EAAC;AAAhB,oBACE,oBAAC,YAAD,OADF;AAFJ,kBAOE,oBAAC,cAAD,QACGC,cAAc,CAAC+B,GAAf,CAAmB,UAACC,KAAD,EAAQC,KAAR;AAAA,wBAClB,oBAAC,QAAD;AAAU,MAAA,GAAG,EAAEA;AAAf,OAAuBD,KAAvB,CADkB;AAAA,GAAnB,CADH,CAPF,CADF,CADD,GAgBG,IAjBN,EAkBG/B,cAAc,CAAC8B,GAAf,CAAmB,UAACC,KAAD,EAAQC,KAAR,EAAkB;AACpC,wBACE,oBAAC,KAAD,CAAO,QAAP;AAAgB,MAAA,GAAG,EAAEA;AAArB,OACGA,KAAK,GAAG,CAAR,IAAajC,cAAc,CAACD,MAAf,GAAwB,CAArC,gBACC,oBAAC,wBAAD,QAA2BhB,SAA3B,CADD,GAEG,IAHN,eAIE,oBAAC,wBAAD,QAA2BiD,KAA3B,CAJF,CADF;AAQD,GATA,CAlBH,CADF,CADF;AAiCD,CApJ0B,CAApB;AAsJPtD,WAAW,CAACwD,WAAZ,GAA0B,aAA1B","sourcesContent":["import React, {\n ReactElement,\n useRef,\n useMemo,\n useEffect,\n useState,\n} from \"react\";\nimport { useForkRef, useResizeObserver } from \"../../utils\";\nimport { Menu } from \"../Menu\";\nimport { ListItem } from \"../List\";\nimport { Button } from \"../Button\";\nimport { TreeDotsIcon } from \"../Icons\";\nimport debounce from \"lodash.debounce\";\nimport {\n StyledNavElement,\n StyledOList,\n StyledBreadcrumbListItem,\n StyledMenuList,\n} from \"./Styles\";\n\nexport interface BreadcrumbsProps {\n /** Separator element */\n separator?: ReactElement | string;\n /** Resize update timeout */\n timeout?: number;\n}\n\nexport const Breadcrumbs = React.forwardRef<\n HTMLElement,\n BreadcrumbsProps &\n Omit<React.ComponentPropsWithoutRef<\"nav\">, keyof BreadcrumbsProps>\n>(({ children, className, separator = \"/\", timeout = 300, ...rest }, ref) => {\n const internalRef = useRef<HTMLElement | null>(null);\n const prevWidth = useRef<number | undefined>();\n const widthCollectionRef = useRef<number[]>([]);\n const handleRef = useForkRef(ref, internalRef);\n const dimensions = useResizeObserver(internalRef);\n\n const childrenCollection = useMemo(\n () => React.Children.toArray(children),\n [children]\n );\n\n const [width, setWidth] = useState<number | undefined>();\n const [menuBreadcrumbs, setMenuBreadcrumbs] = useState(0);\n\n const [menuCollection, listCollection] = useMemo(() => {\n return [\n childrenCollection.slice(0, menuBreadcrumbs),\n childrenCollection.slice(menuBreadcrumbs, childrenCollection.length),\n ];\n }, [childrenCollection, menuBreadcrumbs]);\n\n useEffect(() => {\n const actualWidth = internalRef.current?.scrollWidth || 0;\n const breadcrumbItems = internalRef.current?.firstElementChild;\n\n const enabled = (prevWidth.current ?? 0) > (width ?? 0);\n\n if (enabled && width && actualWidth > width) {\n const diffWidth = actualWidth - width;\n const childWidthCollection: number[] = [];\n\n let childIndex = widthCollectionRef.current.length === 0 ? 0 : 2;\n let childSumWidth = 0;\n\n while (diffWidth > childSumWidth) {\n const childWidth =\n (breadcrumbItems?.children[childIndex] as HTMLLIElement)\n ?.offsetWidth ?? 0;\n const separatorWidth =\n (breadcrumbItems?.children[childIndex + 1] as HTMLLIElement)\n ?.offsetWidth ?? 0;\n const result = separatorWidth + childWidth;\n childWidthCollection.push(result);\n childSumWidth += result;\n childIndex += 2;\n }\n\n if (childWidthCollection.length === listCollection.length) {\n childWidthCollection.pop();\n }\n\n widthCollectionRef.current = [\n ...widthCollectionRef.current,\n ...childWidthCollection,\n ];\n\n setMenuBreadcrumbs((oldVal) => oldVal + childWidthCollection.length);\n }\n }, [listCollection.length, width]);\n\n useEffect(() => {\n const breadcrumbItems = internalRef.current?.firstElementChild;\n const nextWidth =\n (breadcrumbItems?.lastElementChild as HTMLLIElement)?.offsetWidth +\n (breadcrumbItems?.lastElementChild as HTMLLIElement)?.offsetLeft;\n\n const enabled = (prevWidth.current ?? 0) < (width ?? 0);\n const diffWidth = (width ?? 0) - nextWidth;\n\n if (enabled && diffWidth > 0 && widthCollectionRef.current.length > 0) {\n const total = widthCollectionRef.current.length;\n const collection = [...widthCollectionRef.current];\n\n let sumWidth = 0;\n\n while (diffWidth > sumWidth && collection.length > 0) {\n const lastWidth = collection[collection.length - 1] ?? 0;\n if (diffWidth < lastWidth + sumWidth) {\n sumWidth = diffWidth;\n } else {\n sumWidth += collection.pop() ?? 0;\n }\n }\n\n const totalToDecrease = total - collection.length;\n\n setMenuBreadcrumbs((oldVal) => oldVal - totalToDecrease);\n\n const end = total - totalToDecrease;\n\n widthCollectionRef.current =\n end > 0 ? widthCollectionRef.current.slice(0, end) : [];\n }\n }, [width]);\n\n useEffect(() => {\n const debounceWidth = debounce((width: number) => {\n setWidth((prevState) => {\n prevWidth.current = prevState ?? width + 1;\n return width;\n });\n }, timeout);\n\n debounceWidth(dimensions?.width ?? 0);\n\n return (): void => {\n debounceWidth.cancel();\n };\n }, [timeout, dimensions?.width]);\n\n return (\n <StyledNavElement className={className} ref={handleRef} {...rest}>\n <StyledOList>\n {menuCollection.length > 0 ? (\n <StyledBreadcrumbListItem>\n <Menu\n target={\n <Button variant=\"text gray\">\n <TreeDotsIcon />\n </Button>\n }\n >\n <StyledMenuList>\n {menuCollection.map((child, index) => (\n <ListItem key={index}>{child}</ListItem>\n ))}\n </StyledMenuList>\n </Menu>\n </StyledBreadcrumbListItem>\n ) : null}\n {listCollection.map((child, index) => {\n return (\n <React.Fragment key={index}>\n {index > 0 || menuCollection.length > 0 ? (\n <StyledBreadcrumbListItem>{separator}</StyledBreadcrumbListItem>\n ) : null}\n <StyledBreadcrumbListItem>{child}</StyledBreadcrumbListItem>\n </React.Fragment>\n );\n })}\n </StyledOList>\n </StyledNavElement>\n );\n});\n\nBreadcrumbs.displayName = \"Breadcrumbs\";\n"],"file":"Breadcrumbs.js"}
1
+ {"version":3,"sources":["../../../../src/components/Breadcrumbs/Breadcrumbs.tsx"],"names":["React","useRef","useMemo","useEffect","useState","useForkRef","useResizeObserver","Menu","ListItem","Button","TreeDotsIcon","StyledNavElement","StyledOList","StyledMenuList","StyledListWrapper","StyledBreadcrumbListItem","Breadcrumbs","forwardRef","ref","children","className","separator","rest","internalRef","listWrapperRef","olRef","widthCollectionRef","handleRef","menuBreadcrumbs","setMenuBreadcrumbs","dimensions","childDimensions","parentWidth","width","childWidth","childrenCollection","Children","toArray","slice","length","menuCollection","listCollection","current","diffWidth","separatorWidth","querySelectorAll","offsetWidth","breadcrumbItems","childWidthCollection","maxIndex","currentIndex","childSumWidth","result","push","pop","oldVal","total","collection","sumWidth","lastWidth","totalToDecrease","newValue","end","map","child","index","displayName"],"mappings":";;;AAAA,OAAOA,KAAP,IAEEC,MAFF,EAGEC,OAHF,EAIEC,SAJF,EAKEC,QALF,QAMO,OANP;AAOA,SAASC,UAAT,EAAqBC,iBAArB,QAA8C,aAA9C;AACA,SAASC,IAAT,QAAqB,SAArB;AACA,SAASC,QAAT,QAAyB,SAAzB;AACA,SAASC,MAAT,QAAuB,WAAvB;AACA,SAASC,YAAT,QAA6B,UAA7B;AACA,SACEC,gBADF,EAEEC,WAFF,EAGEC,cAHF,EAIEC,iBAJF,EAKEC,wBALF,QAMO,UANP;AAaA,OAAO,IAAMC,WAAW,gBAAGhB,KAAK,CAACiB,UAAN,CAIzB,gBAAoDC,GAApD,EAA4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ADF;AAuCD,CAjJ0B,CAApB;AAmJPhD,WAAW,CAACkD,WAAZ,GAA0B,aAA1B","sourcesContent":["import React, {\n ReactElement,\n useRef,\n useMemo,\n useEffect,\n useState,\n} from \"react\";\nimport { useForkRef, useResizeObserver } from \"../../utils\";\nimport { Menu } from \"../Menu\";\nimport { ListItem } from \"../List\";\nimport { Button } from \"../Button\";\nimport { TreeDotsIcon } from \"../Icons\";\nimport {\n StyledNavElement,\n StyledOList,\n StyledMenuList,\n StyledListWrapper,\n StyledBreadcrumbListItem,\n} from \"./Styles\";\n\nexport interface BreadcrumbsProps {\n /** Separator element */\n separator?: ReactElement | string;\n}\n\nexport const Breadcrumbs = React.forwardRef<\n HTMLElement,\n BreadcrumbsProps &\n Omit<React.ComponentPropsWithoutRef<\"nav\">, keyof BreadcrumbsProps>\n>(({ children, className, separator = \"/\", ...rest }, ref) => {\n const internalRef = useRef<HTMLElement | null>(null);\n const listWrapperRef = useRef<HTMLDivElement | null>(null);\n const olRef = useRef<HTMLOListElement | null>(null);\n const widthCollectionRef = useRef<number[]>([]);\n const handleRef = useForkRef(ref, internalRef);\n const [menuBreadcrumbs, setMenuBreadcrumbs] = useState(0);\n const dimensions = useResizeObserver(internalRef);\n const childDimensions = useResizeObserver(listWrapperRef);\n\n const parentWidth = dimensions?.width ?? 0;\n const childWidth = childDimensions?.width ?? 0;\n\n const childrenCollection = useMemo(\n () => React.Children.toArray(children),\n [children]\n );\n\n const [menuCollection, listCollection] = useMemo(() => {\n return [\n childrenCollection.slice(0, menuBreadcrumbs),\n childrenCollection.slice(menuBreadcrumbs, childrenCollection.length),\n ];\n }, [childrenCollection, menuBreadcrumbs]);\n\n useEffect(() => {\n widthCollectionRef.current = [];\n setMenuBreadcrumbs(0);\n }, [childrenCollection.length]);\n\n useEffect(() => {\n const diffWidth = childWidth - parentWidth;\n\n if (diffWidth > 0) {\n const separatorWidth =\n (\n olRef.current?.querySelectorAll(\n `[data-role=\"separator\"]`\n )[0] as HTMLLIElement\n )?.offsetWidth ?? 0;\n const breadcrumbItems =\n olRef.current?.querySelectorAll(`[data-role=\"item\"]`) ?? [];\n const childWidthCollection: number[] = [];\n\n const maxIndex = (breadcrumbItems?.length ?? 1) - 1;\n let currentIndex = 0;\n let childSumWidth = 0;\n\n while (diffWidth > childSumWidth && maxIndex >= currentIndex) {\n const childWidth =\n (breadcrumbItems[currentIndex] as HTMLLIElement)?.offsetWidth ?? 0;\n const result = separatorWidth + childWidth;\n childWidthCollection.push(result);\n childSumWidth += result;\n currentIndex += 1;\n }\n\n if (childWidthCollection.length === listCollection.length) {\n childWidthCollection.pop();\n }\n\n widthCollectionRef.current = [\n ...widthCollectionRef.current,\n ...childWidthCollection,\n ];\n\n setMenuBreadcrumbs((oldVal) => oldVal + childWidthCollection.length);\n }\n }, [listCollection.length, parentWidth, childWidth]);\n\n useEffect(() => {\n const diffWidth = parentWidth - childWidth;\n\n if (diffWidth > 0 && widthCollectionRef.current.length > 0) {\n const total = widthCollectionRef.current.length;\n const collection = [...widthCollectionRef.current];\n\n let sumWidth = 0;\n\n while (diffWidth > sumWidth && collection.length > 0) {\n const lastWidth = collection[collection.length - 1] ?? 0;\n if (diffWidth < lastWidth + sumWidth) {\n sumWidth = diffWidth;\n } else {\n sumWidth += collection.pop() ?? 0;\n }\n }\n\n const totalToDecrease = total - collection.length;\n\n setMenuBreadcrumbs((oldVal) => {\n const newValue = oldVal - totalToDecrease;\n return newValue > 0 ? newValue : 0;\n });\n\n const end = total - totalToDecrease;\n\n widthCollectionRef.current =\n end > 0 ? widthCollectionRef.current.slice(0, end) : [];\n }\n }, [parentWidth, childWidth]);\n\n return (\n <StyledNavElement className={className} ref={handleRef} {...rest}>\n <StyledListWrapper ref={listWrapperRef}>\n <StyledOList ref={olRef}>\n {menuCollection.length > 0 ? (\n <StyledBreadcrumbListItem data-role=\"menu\">\n <Menu\n target={\n <Button variant=\"text gray\">\n <TreeDotsIcon />\n </Button>\n }\n >\n <StyledMenuList>\n {menuCollection.map((child, index) => (\n <ListItem key={index}>{child}</ListItem>\n ))}\n </StyledMenuList>\n </Menu>\n </StyledBreadcrumbListItem>\n ) : null}\n {listCollection.map((child, index) => {\n return (\n <React.Fragment key={index}>\n {index > 0 || menuCollection.length > 0 ? (\n <StyledBreadcrumbListItem data-role=\"separator\">\n {separator}\n </StyledBreadcrumbListItem>\n ) : null}\n <StyledBreadcrumbListItem data-role=\"item\">\n {child}\n </StyledBreadcrumbListItem>\n </React.Fragment>\n );\n })}\n </StyledOList>\n </StyledListWrapper>\n </StyledNavElement>\n );\n});\n\nBreadcrumbs.displayName = \"Breadcrumbs\";\n"],"file":"Breadcrumbs.js"}
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  export declare const StyledNavElement: import("styled-components").StyledComponent<"nav", any, {}, never>;
3
- export declare const StyledOList: import("styled-components").StyledComponent<"ul", any, {}, never>;
3
+ export declare const StyledListWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
4
+ export declare const StyledOList: import("styled-components").StyledComponent<"ol", any, {}, never>;
4
5
  export declare const StyledMenuList: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../List").IList & import("react").HTMLAttributes<HTMLUListElement> & import("react").RefAttributes<HTMLUListElement>>, any, {}, never>;
5
6
  export declare const StyledBreadcrumbListItem: import("styled-components").StyledComponent<"li", any, {}, never>;
6
7
  //# sourceMappingURL=Styles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Styles.d.ts","sourceRoot":"","sources":["../../../../src/components/Breadcrumbs/Styles.ts"],"names":[],"mappings":";AAMA,eAAO,MAAM,gBAAgB,oEAK5B,CAAC;AAIF,eAAO,MAAM,WAAW,mEAOvB,CAAC;AAIF,eAAO,MAAM,cAAc,sOAE1B,CAAC;AAIF,eAAO,MAAM,wBAAwB,mEAGpC,CAAC"}
1
+ {"version":3,"file":"Styles.d.ts","sourceRoot":"","sources":["../../../../src/components/Breadcrumbs/Styles.ts"],"names":[],"mappings":";AAMA,eAAO,MAAM,gBAAgB,oEAK5B,CAAC;AAIF,eAAO,MAAM,iBAAiB,oEAE7B,CAAC;AAIF,eAAO,MAAM,WAAW,mEAOvB,CAAC;AAIF,eAAO,MAAM,cAAc,sOAE1B,CAAC;AAIF,eAAO,MAAM,wBAAwB,mEAEpC,CAAC"}