@dt-dds/react-breadcrumb 1.0.0-beta.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,414 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/Breadcrumb.tsx
22
+ import { Tooltip } from "@dt-dds/react-tooltip";
23
+ import { Children as Children2, cloneElement as cloneElement2, isValidElement as isValidElement2 } from "react";
24
+
25
+ // ../../dt-dds-react/core/assets/svgs/AllOut.tsx
26
+ import { jsx, jsxs } from "react/jsx-runtime";
27
+
28
+ // ../../dt-dds-react/core/assets/svgs/Apis.tsx
29
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
30
+
31
+ // ../../dt-dds-react/core/assets/svgs/Apps.tsx
32
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
33
+
34
+ // ../../dt-dds-react/core/assets/svgs/ArrowDropDown.tsx
35
+ import { jsx as jsx4 } from "react/jsx-runtime";
36
+
37
+ // ../../dt-dds-react/core/assets/svgs/ArrowDropUp.tsx
38
+ import { jsx as jsx5 } from "react/jsx-runtime";
39
+
40
+ // ../../dt-dds-react/core/assets/svgs/ArrowLeft.tsx
41
+ import { jsx as jsx6 } from "react/jsx-runtime";
42
+
43
+ // ../../dt-dds-react/core/assets/svgs/ArrowRight.tsx
44
+ import { jsx as jsx7 } from "react/jsx-runtime";
45
+ var ArrowRight = (props) => {
46
+ return /* @__PURE__ */ jsx7(
47
+ "svg",
48
+ __spreadProps(__spreadValues({
49
+ fill: "none",
50
+ height: "12",
51
+ viewBox: "0 0 8 12",
52
+ width: "8",
53
+ xmlns: "http://www.w3.org/2000/svg"
54
+ }, props), {
55
+ children: /* @__PURE__ */ jsx7(
56
+ "path",
57
+ {
58
+ clipRule: "evenodd",
59
+ d: "M6.99468 4.99507C7.18215 5.1826 7.28747 5.4369 7.28747 5.70207C7.28747 5.96723 7.18215 6.22154 6.99468 6.40907L2.40168 11.0021C2.21539 11.1846 1.96458 11.2863 1.70375 11.285C1.44292 11.2837 1.19315 11.1795 1.00871 10.995C0.824278 10.8106 0.72008 10.5608 0.718763 10.3C0.717445 10.0392 0.819115 9.78836 1.00168 9.60207L4.90168 5.70207L1.00168 1.80207C0.819115 1.61578 0.717445 1.36497 0.718763 1.10414C0.72008 0.843312 0.824278 0.593541 1.00871 0.409105C1.19315 0.224668 1.44292 0.120471 1.70375 0.119153C1.96458 0.117836 2.21539 0.219506 2.40168 0.402069L6.99468 4.99507Z",
60
+ fill: "currentColor",
61
+ fillRule: "evenodd"
62
+ }
63
+ )
64
+ })
65
+ );
66
+ };
67
+ var ArrowRight_default = ArrowRight;
68
+
69
+ // ../../dt-dds-react/core/assets/svgs/AvatarThumbnail.tsx
70
+ import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
71
+
72
+ // ../../dt-dds-react/core/assets/svgs/Bolt.tsx
73
+ import { jsx as jsx9 } from "react/jsx-runtime";
74
+
75
+ // ../../dt-dds-react/core/assets/svgs/CalendarMonth.tsx
76
+ import { jsx as jsx10 } from "react/jsx-runtime";
77
+
78
+ // ../../dt-dds-react/core/assets/svgs/Cancel.tsx
79
+ import { jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
80
+
81
+ // ../../dt-dds-react/core/assets/svgs/Check.tsx
82
+ import { jsx as jsx12 } from "react/jsx-runtime";
83
+
84
+ // ../../dt-dds-react/core/assets/svgs/CheckCircle.tsx
85
+ import { jsx as jsx13 } from "react/jsx-runtime";
86
+
87
+ // ../../dt-dds-react/core/assets/svgs/CheckCircleOutline.tsx
88
+ import { jsx as jsx14 } from "react/jsx-runtime";
89
+
90
+ // ../../dt-dds-react/core/assets/svgs/Close.tsx
91
+ import { jsx as jsx15 } from "react/jsx-runtime";
92
+
93
+ // ../../dt-dds-react/core/assets/svgs/Copy.tsx
94
+ import { jsx as jsx16, jsxs as jsxs6 } from "react/jsx-runtime";
95
+
96
+ // ../../dt-dds-react/core/assets/svgs/Delete.tsx
97
+ import { jsx as jsx17, jsxs as jsxs7 } from "react/jsx-runtime";
98
+
99
+ // ../../dt-dds-react/core/assets/svgs/Edit.tsx
100
+ import { jsx as jsx18, jsxs as jsxs8 } from "react/jsx-runtime";
101
+
102
+ // ../../dt-dds-react/core/assets/svgs/Email.tsx
103
+ import { jsx as jsx19, jsxs as jsxs9 } from "react/jsx-runtime";
104
+
105
+ // ../../dt-dds-react/core/assets/svgs/EmailSend.tsx
106
+ import { jsx as jsx20, jsxs as jsxs10 } from "react/jsx-runtime";
107
+
108
+ // ../../dt-dds-react/core/assets/svgs/Error.tsx
109
+ import { useTheme } from "@emotion/react";
110
+ import { jsx as jsx21, jsxs as jsxs11 } from "react/jsx-runtime";
111
+
112
+ // ../../dt-dds-react/core/assets/svgs/ErrorOutline.tsx
113
+ import { jsx as jsx22 } from "react/jsx-runtime";
114
+
115
+ // ../../dt-dds-react/core/assets/svgs/EVStation.tsx
116
+ import { jsx as jsx23 } from "react/jsx-runtime";
117
+
118
+ // ../../dt-dds-react/core/assets/svgs/Info.tsx
119
+ import { jsx as jsx24 } from "react/jsx-runtime";
120
+
121
+ // ../../dt-dds-react/core/assets/svgs/InfoOutline.tsx
122
+ import { jsx as jsx25 } from "react/jsx-runtime";
123
+
124
+ // ../../dt-dds-react/core/assets/svgs/Input.tsx
125
+ import { jsx as jsx26, jsxs as jsxs12 } from "react/jsx-runtime";
126
+
127
+ // ../../dt-dds-react/core/assets/svgs/Language.tsx
128
+ import { jsx as jsx27 } from "react/jsx-runtime";
129
+
130
+ // ../../dt-dds-react/core/assets/svgs/LocationOn.tsx
131
+ import { jsx as jsx28, jsxs as jsxs13 } from "react/jsx-runtime";
132
+
133
+ // ../../dt-dds-react/core/assets/svgs/LocationSearching.tsx
134
+ import { jsx as jsx29 } from "react/jsx-runtime";
135
+
136
+ // ../../dt-dds-react/core/assets/svgs/MenuCompact.tsx
137
+ import { jsx as jsx30 } from "react/jsx-runtime";
138
+
139
+ // ../../dt-dds-react/core/assets/svgs/MenuExpand.tsx
140
+ import { jsx as jsx31 } from "react/jsx-runtime";
141
+
142
+ // ../../dt-dds-react/core/assets/svgs/Menu.tsx
143
+ import { jsx as jsx32 } from "react/jsx-runtime";
144
+
145
+ // ../../dt-dds-react/core/assets/svgs/MoreHorizontal.tsx
146
+ import { jsx as jsx33 } from "react/jsx-runtime";
147
+ var MoreHorizontal = (props) => {
148
+ return /* @__PURE__ */ jsx33(
149
+ "svg",
150
+ __spreadProps(__spreadValues({
151
+ fill: "currentColor",
152
+ height: "24",
153
+ viewBox: "0 0 24 24",
154
+ width: "24",
155
+ xmlns: "http://www.w3.org/2000/svg"
156
+ }, props), {
157
+ children: /* @__PURE__ */ jsx33("path", { d: "M6 10C4.9 10 4 10.9 4 12C4 13.1 4.9 14 6 14C7.1 14 8 13.1 8 12C8 10.9 7.1 10 6 10ZM18 10C16.9 10 16 10.9 16 12C16 13.1 16.9 14 18 14C19.1 14 20 13.1 20 12C20 10.9 19.1 10 18 10ZM12 10C10.9 10 10 10.9 10 12C10 13.1 10.9 14 12 14C13.1 14 14 13.1 14 12C14 10.9 13.1 10 12 10Z" })
158
+ })
159
+ );
160
+ };
161
+ var MoreHorizontal_default = MoreHorizontal;
162
+
163
+ // ../../dt-dds-react/core/assets/svgs/MoreVertical.tsx
164
+ import { jsx as jsx34 } from "react/jsx-runtime";
165
+
166
+ // ../../dt-dds-react/core/assets/svgs/NoData.tsx
167
+ import { useTheme as useTheme2 } from "@emotion/react";
168
+ import { jsx as jsx35, jsxs as jsxs14 } from "react/jsx-runtime";
169
+
170
+ // ../../dt-dds-react/core/assets/svgs/NotFound.tsx
171
+ import { jsx as jsx36, jsxs as jsxs15 } from "react/jsx-runtime";
172
+
173
+ // ../../dt-dds-react/core/assets/svgs/OutlinedArrowDropDown.tsx
174
+ import { jsx as jsx37 } from "react/jsx-runtime";
175
+
176
+ // ../../dt-dds-react/core/assets/svgs/OutlinedArrowDropUp.tsx
177
+ import { jsx as jsx38 } from "react/jsx-runtime";
178
+
179
+ // ../../dt-dds-react/core/assets/svgs/PhoneOutlined.tsx
180
+ import { jsx as jsx39 } from "react/jsx-runtime";
181
+
182
+ // ../../dt-dds-react/core/assets/svgs/Payments.tsx
183
+ import { jsx as jsx40 } from "react/jsx-runtime";
184
+
185
+ // ../../dt-dds-react/core/assets/svgs/Products.tsx
186
+ import { jsx as jsx41, jsxs as jsxs16 } from "react/jsx-runtime";
187
+
188
+ // ../../dt-dds-react/core/assets/svgs/RemoveCircleOutline.tsx
189
+ import { jsx as jsx42 } from "react/jsx-runtime";
190
+
191
+ // ../../dt-dds-react/core/assets/svgs/Share.tsx
192
+ import { jsx as jsx43, jsxs as jsxs17 } from "react/jsx-runtime";
193
+
194
+ // ../../dt-dds-react/core/assets/svgs/Signout.tsx
195
+ import { jsx as jsx44 } from "react/jsx-runtime";
196
+
197
+ // ../../dt-dds-react/core/assets/svgs/Teams.tsx
198
+ import { jsx as jsx45, jsxs as jsxs18 } from "react/jsx-runtime";
199
+
200
+ // ../../dt-dds-react/core/assets/svgs/Timeline.tsx
201
+ import { jsx as jsx46, jsxs as jsxs19 } from "react/jsx-runtime";
202
+
203
+ // ../../dt-dds-react/core/assets/svgs/Topic.tsx
204
+ import { jsx as jsx47, jsxs as jsxs20 } from "react/jsx-runtime";
205
+
206
+ // ../../dt-dds-react/core/assets/svgs/UnfoldLess.tsx
207
+ import { jsx as jsx48 } from "react/jsx-runtime";
208
+
209
+ // ../../dt-dds-react/core/assets/svgs/UnfoldMore.tsx
210
+ import { jsx as jsx49 } from "react/jsx-runtime";
211
+
212
+ // ../../dt-dds-react/core/assets/svgs/Username.tsx
213
+ import { jsx as jsx50, jsxs as jsxs21 } from "react/jsx-runtime";
214
+
215
+ // ../../dt-dds-react/core/assets/svgs/ViewAgenda.tsx
216
+ import { jsx as jsx51, jsxs as jsxs22 } from "react/jsx-runtime";
217
+
218
+ // ../../dt-dds-react/core/assets/svgs/Visibility.tsx
219
+ import { jsx as jsx52, jsxs as jsxs23 } from "react/jsx-runtime";
220
+
221
+ // ../../dt-dds-react/core/assets/svgs/VisibilityOff.tsx
222
+ import { jsx as jsx53, jsxs as jsxs24 } from "react/jsx-runtime";
223
+
224
+ // ../../dt-dds-react/core/assets/svgs/WarningOutline.tsx
225
+ import { jsx as jsx54 } from "react/jsx-runtime";
226
+
227
+ // ../../dt-dds-react/core/assets/svgs/Warning.tsx
228
+ import { jsx as jsx55 } from "react/jsx-runtime";
229
+
230
+ // ../../dt-dds-react/core/assets/svgs/Wifi.tsx
231
+ import { jsx as jsx56 } from "react/jsx-runtime";
232
+
233
+ // ../../dt-dds-react/core/assets/svgs/Settings.tsx
234
+ import { jsx as jsx57 } from "react/jsx-runtime";
235
+
236
+ // src/Breadcrumb.styled.ts
237
+ import styled from "@emotion/styled";
238
+ var BreadcrumbStyled = styled.nav`
239
+ ${({ theme }) => `
240
+ ${theme.fontStyles.body2}
241
+ color: ${theme.palette.secondary.default};
242
+ overflow: hidden;
243
+ `}
244
+ `;
245
+ var ListStyled = styled.ul`
246
+ padding: 0px;
247
+ margin: 0px;
248
+ width: 100%;
249
+ list-style: none;
250
+ display: flex;
251
+ align-items: center;
252
+ white-space: nowrap;
253
+ gap: ${({ theme }) => theme.spacing["4xs"]};
254
+ `;
255
+ var ItemStyled = styled.li`
256
+ ${({ theme }) => `
257
+ display: flex;
258
+
259
+ &:not(:last-child) {
260
+ ${theme.fontStyles.link2}
261
+ color: ${theme.palette.accent.default};
262
+ cursor: pointer;
263
+
264
+ svg {
265
+ color: ${theme.palette.accent.default};
266
+ }
267
+
268
+ & * {
269
+ text-decoration: underline;
270
+ }
271
+
272
+ &:hover {
273
+ color: ${theme.palette.accent.dark};
274
+
275
+ svg {
276
+ color: ${theme.palette.accent.dark};
277
+ }
278
+ }
279
+ }
280
+
281
+ a {
282
+ color: inherit;
283
+ }
284
+
285
+ svg {
286
+ color: ${theme.palette.secondary.default};
287
+ }
288
+
289
+ &:last-child * {
290
+ white-space: nowrap;
291
+ text-overflow: ellipsis;
292
+ overflow: hidden;
293
+ }
294
+ `}
295
+ `;
296
+ var ItemContainerStyled = styled.div`
297
+ ${({ theme }) => `
298
+ display: flex;
299
+ align-items: center;
300
+ gap: ${theme.spacing["5xs"]};
301
+ `}
302
+ `;
303
+
304
+ // src/hooks/useCollapsedBreadcrumb.tsx
305
+ import { useDebounceResize, useMedia } from "@dt-dds/react-core";
306
+ import { useTheme as useTheme3 } from "@emotion/react";
307
+ import {
308
+ Children,
309
+ isValidElement,
310
+ cloneElement,
311
+ useCallback,
312
+ useRef,
313
+ useState
314
+ } from "react";
315
+ import { jsx as jsx58 } from "react/jsx-runtime";
316
+ var isBreadcrumbRefValid = (breadcrumbRef, breadcrumbListRef) => {
317
+ return !!breadcrumbRef.current && !!breadcrumbListRef.current;
318
+ };
319
+ var useCollapsedBreadcrumb = (children) => {
320
+ const breadcrumbRef = useRef(null);
321
+ const breadcrumbListRef = useRef(null);
322
+ const theme = useTheme3();
323
+ const isDesktop = useMedia(`(min-width: ${theme.breakpoints.m}px)`);
324
+ const [visibleChildren, setVisibleChildren] = useState(children);
325
+ const breadcrumbResize = useCallback(() => {
326
+ if (isDesktop || !isBreadcrumbRefValid(breadcrumbRef, breadcrumbListRef)) {
327
+ setVisibleChildren(children);
328
+ return;
329
+ }
330
+ const childrenArray = Children.toArray(children);
331
+ const isBreadcrumbsTooLarge = breadcrumbListRef.current.scrollWidth > breadcrumbRef.current.clientWidth;
332
+ if (isBreadcrumbsTooLarge) {
333
+ const lastChild = childrenArray[childrenArray.length - 1];
334
+ const modifiedChildren = [
335
+ childrenArray[0],
336
+ /* @__PURE__ */ jsx58(Breadcrumb.Item, { children: /* @__PURE__ */ jsx58(MoreHorizontal_default, {}) }, "more-icon"),
337
+ isValidElement(lastChild) ? cloneElement(lastChild, __spreadProps(__spreadValues({}, lastChild.props), {
338
+ style: { overflow: "hidden" }
339
+ })) : lastChild
340
+ ];
341
+ setVisibleChildren(modifiedChildren);
342
+ }
343
+ }, [children, isDesktop, breadcrumbRef, breadcrumbListRef]);
344
+ useDebounceResize(breadcrumbResize);
345
+ return { visibleChildren, breadcrumbRef, breadcrumbListRef };
346
+ };
347
+
348
+ // src/Breadcrumb.tsx
349
+ import { Fragment, jsx as jsx59, jsxs as jsxs25 } from "react/jsx-runtime";
350
+ var BREADCRUMB_CHARACTER_LIMIT = 30;
351
+ var Breadcrumb = ({
352
+ children,
353
+ separator = "slash"
354
+ }) => {
355
+ const { visibleChildren, breadcrumbRef, breadcrumbListRef } = useCollapsedBreadcrumb(children);
356
+ return /* @__PURE__ */ jsx59(
357
+ BreadcrumbStyled,
358
+ {
359
+ "aria-label": "Breadcrumb",
360
+ "data-testid": "breadcrumb",
361
+ ref: breadcrumbRef,
362
+ children: /* @__PURE__ */ jsx59(ListStyled, { ref: breadcrumbListRef, children: withSeparator(visibleChildren, separator) })
363
+ }
364
+ );
365
+ };
366
+ var BreadcrumbItem = ({ children, style }) => {
367
+ const { truncatedChildren, tooltip } = mapTruncateChildren(children);
368
+ return /* @__PURE__ */ jsx59(ItemStyled, { style, children: /* @__PURE__ */ jsxs25(Tooltip, { style: { overflow: "hidden" }, children: [
369
+ /* @__PURE__ */ jsx59(ItemContainerStyled, { children: truncatedChildren }),
370
+ /* @__PURE__ */ jsx59(Tooltip.Content, { children: tooltip })
371
+ ] }) });
372
+ };
373
+ var truncateText = (text) => {
374
+ if (text.length >= BREADCRUMB_CHARACTER_LIMIT) {
375
+ return `${text.substring(0, BREADCRUMB_CHARACTER_LIMIT)}...`;
376
+ }
377
+ return text;
378
+ };
379
+ var mapTruncateChildren = (children) => {
380
+ let tooltip = "";
381
+ return {
382
+ truncatedChildren: Children2.map(children, (child) => {
383
+ if (typeof child === "string") {
384
+ const truncatedText = truncateText(child);
385
+ tooltip = truncatedText !== child ? child : "";
386
+ return truncatedText;
387
+ } else if (isValidElement2(child)) {
388
+ const { truncatedChildren, tooltip: childTooltip } = mapTruncateChildren(child.props.children);
389
+ tooltip = childTooltip;
390
+ return cloneElement2(child, __spreadProps(__spreadValues({}, child.props), {
391
+ children: truncatedChildren
392
+ }));
393
+ } else {
394
+ return null;
395
+ }
396
+ }),
397
+ tooltip
398
+ };
399
+ };
400
+ var withSeparator = (children, separator) => {
401
+ const addSeparator = () => ({
402
+ slash: /* @__PURE__ */ jsx59("span", { children: "/" }),
403
+ arrow: /* @__PURE__ */ jsx59(ArrowRight_default, {})
404
+ })[separator];
405
+ const isLastBreadcrumb = (index) => Children2.count(children) - 1 === index;
406
+ return Children2.map(children, (child, index) => /* @__PURE__ */ jsxs25(Fragment, { children: [
407
+ child,
408
+ !isLastBreadcrumb(index) && addSeparator()
409
+ ] }));
410
+ };
411
+ Breadcrumb.Item = BreadcrumbItem;
412
+ export {
413
+ Breadcrumb
414
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@dt-dds/react-breadcrumb",
3
+ "version": "1.0.0-beta.51",
4
+ "license": "MIT",
5
+ "exports": {
6
+ ".": "./dist/index.js"
7
+ },
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "files": [
12
+ "dist/**"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsup",
16
+ "dev": "tsup --watch",
17
+ "lint": "eslint --cache .",
18
+ "test": "jest",
19
+ "test:report": "open ./jest-coverage/lcov-report/index.html",
20
+ "test:update:snapshot": "jest -u"
21
+ },
22
+ "dependencies": {
23
+ "@dt-dds/react-core": "1.0.0-beta.41",
24
+ "@dt-dds/react-tooltip": "1.0.0-beta.49",
25
+ "@dt-dds/react-icon": "1.0.0-beta.42"
26
+ },
27
+ "devDependencies": {
28
+ "@babel/core": "^7.22.9",
29
+ "@babel/preset-env": "^7.22.9",
30
+ "@babel/preset-react": "^7.22.5",
31
+ "@babel/preset-typescript": "^7.23.3",
32
+ "@emotion/babel-plugin": "^11.11.0",
33
+ "@emotion/css": "^11.7.1",
34
+ "@emotion/jest": "^11.10.0",
35
+ "@emotion/react": "^11.8.2",
36
+ "@emotion/styled": "^11.8.1",
37
+ "@types/react": "^18.0.9",
38
+ "@types/react-dom": "^18.0.4",
39
+ "babel-loader": "^8.3.0",
40
+ "eslint-config-custom": "*",
41
+ "eslint-plugin-storybook": "^9.1.0",
42
+ "jest-config": "*",
43
+ "react": "^18.1.0",
44
+ "react-dom": "^18.2.0",
45
+ "tsconfig": "*",
46
+ "tsup": "^6.6.3",
47
+ "typescript": "^4.5.3"
48
+ },
49
+ "peerDependencies": {
50
+ "@emotion/css": "^11.7.1",
51
+ "@emotion/react": "^11.8.2",
52
+ "@emotion/styled": "^11.8.1",
53
+ "react": ">=17.0.2",
54
+ "react-dom": ">=17.0.2"
55
+ }
56
+ }