@phpsoftbox/react-softbox 1.13.1 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,6 +19,10 @@ type Props = {
|
|
|
19
19
|
separator?: React.ReactNode;
|
|
20
20
|
className?: string;
|
|
21
21
|
as?: LinkComponent;
|
|
22
|
+
maxVisibleItems?: number;
|
|
23
|
+
overflowTailCount?: number;
|
|
24
|
+
overflowLabel?: React.ReactNode;
|
|
25
|
+
overflowAriaLabel?: string;
|
|
22
26
|
};
|
|
23
|
-
export default function Breadcrumbs({ items, separator, className, as }: Props): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
export default function Breadcrumbs({ items, separator, className, as, maxVisibleItems, overflowTailCount, overflowLabel, overflowAriaLabel, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
24
28
|
export {};
|
|
@@ -1,15 +1,47 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Dropdown from '../Menu/Dropdown';
|
|
2
3
|
import styles from './Breadcrumbs.module.css';
|
|
3
|
-
|
|
4
|
+
function resolveRenderNodes(items, maxVisibleItems, overflowTailCount) {
|
|
5
|
+
if (maxVisibleItems < 3 || items.length <= maxVisibleItems) {
|
|
6
|
+
return items.map((item, index) => ({ type: 'item', item, index }));
|
|
7
|
+
}
|
|
8
|
+
const safeTailCount = Math.max(1, Math.min(overflowTailCount, maxVisibleItems - 2));
|
|
9
|
+
const tailStart = Math.max(1, items.length - safeTailCount);
|
|
10
|
+
const hidden = items.slice(1, tailStart).map((item, hiddenIndex) => ({
|
|
11
|
+
item,
|
|
12
|
+
index: hiddenIndex + 1,
|
|
13
|
+
}));
|
|
14
|
+
if (hidden.length === 0) {
|
|
15
|
+
return items.map((item, index) => ({ type: 'item', item, index }));
|
|
16
|
+
}
|
|
17
|
+
const tail = items.slice(tailStart).map((item, tailIndex) => ({
|
|
18
|
+
type: 'item',
|
|
19
|
+
item,
|
|
20
|
+
index: tailStart + tailIndex,
|
|
21
|
+
}));
|
|
22
|
+
return [{ type: 'item', item: items[0], index: 0 }, { type: 'overflow', items: hidden }, ...tail];
|
|
23
|
+
}
|
|
24
|
+
export default function Breadcrumbs({ items, separator = '›', className, as, maxVisibleItems = 4, overflowTailCount = 2, overflowLabel = '...', overflowAriaLabel = 'Show hidden breadcrumbs', }) {
|
|
4
25
|
const hasExplicitCurrent = items.some((item) => item.current);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
26
|
+
const renderNodes = resolveRenderNodes(items, maxVisibleItems, overflowTailCount);
|
|
27
|
+
return (_jsx("nav", { className: [styles.breadcrumbs, className].filter(Boolean).join(' '), "aria-label": "Breadcrumbs", children: _jsx("ol", { className: styles.list, children: renderNodes.map((node, index) => {
|
|
28
|
+
const isLastNode = index === renderNodes.length - 1;
|
|
29
|
+
if (node.type === 'overflow') {
|
|
30
|
+
return (_jsxs("li", { className: [styles.item, styles.overflowItem].join(' '), children: [_jsx(Dropdown, { align: "left", placement: "auto", className: styles.overflowDropdown, trigger: (_jsxs("span", { className: styles.overflowTrigger, children: [overflowLabel, _jsx("span", { className: styles.visuallyHidden, children: overflowAriaLabel })] })), children: _jsx(Dropdown.Nav, { className: styles.overflowMenu, children: node.items.map(({ item, index: originalIndex }) => {
|
|
31
|
+
const isCurrent = item.current ?? (!hasExplicitCurrent && originalIndex === items.length - 1);
|
|
32
|
+
const isDisabled = item.disabled ?? false;
|
|
33
|
+
const canFollowLink = Boolean(item.href && !isDisabled && !isCurrent);
|
|
34
|
+
const itemKey = item.id ?? `hidden-${originalIndex}`;
|
|
35
|
+
return (_jsx(Dropdown.Item, { className: styles.overflowMenuItem, href: canFollowLink ? item.href : undefined, onClick: !isDisabled ? item.onClick : undefined, as: canFollowLink ? (item.as ?? as) : undefined, disabled: isDisabled, static: !canFollowLink, children: item.label }, itemKey));
|
|
36
|
+
}) }) }), !isLastNode ? (_jsx("span", { className: styles.separator, "aria-hidden": "true", children: separator })) : null] }, `overflow-${node.items[0]?.index ?? index}`));
|
|
37
|
+
}
|
|
38
|
+
const item = node.item;
|
|
39
|
+
const key = item.id ?? `${node.index}-${typeof item.label === 'string' ? item.label : 'item'}`;
|
|
40
|
+
const isCurrent = item.current ?? (!hasExplicitCurrent && node.index === items.length - 1);
|
|
9
41
|
const isDisabled = item.disabled ?? false;
|
|
10
42
|
const LinkTag = item.as ?? as ?? 'a';
|
|
11
43
|
const content = (_jsx("span", { className: styles.label, "aria-current": isCurrent ? 'page' : undefined, children: item.label }));
|
|
12
|
-
return (_jsxs("li", { className: styles.item, children: [item.href && !isDisabled && !isCurrent ? (_jsx(LinkTag, { href: item.href, className: styles.link, onClick: item.onClick, children: content })) : (_jsx("span", { className: [styles.link, isDisabled ? styles.disabled : null].filter(Boolean).join(' '), onClick: isDisabled ? undefined : item.onClick, "aria-disabled": isDisabled ? 'true' : undefined, children: content })), !
|
|
44
|
+
return (_jsxs("li", { className: styles.item, children: [item.href && !isDisabled && !isCurrent ? (_jsx(LinkTag, { href: item.href, className: styles.link, onClick: item.onClick, children: content })) : (_jsx("span", { className: [styles.link, isDisabled ? styles.disabled : null].filter(Boolean).join(' '), onClick: isDisabled ? undefined : item.onClick, "aria-disabled": isDisabled ? 'true' : undefined, children: content })), !isLastNode ? (_jsx("span", { className: styles.separator, "aria-hidden": "true", children: separator })) : null] }, key));
|
|
13
45
|
}) }) }));
|
|
14
46
|
}
|
|
15
47
|
//# sourceMappingURL=Breadcrumbs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Breadcrumbs.js","sourceRoot":"","sources":["../../../src/components/Breadcrumbs/Breadcrumbs.tsx"],"names":[],"mappings":";AACA,OAAO,MAAM,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"Breadcrumbs.js","sourceRoot":"","sources":["../../../src/components/Breadcrumbs/Breadcrumbs.tsx"],"names":[],"mappings":";AACA,O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AAC,CAAC,CACF,eACE,SAAS,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EACvF,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,mBAC/B,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,YAE7C,OAAO,GACH,CACR,EACA,CAAC,UAAU,CAAC,CAAC,CAAC,CACb,eAAM,SAAS,EAAE,MAAM,CAAC,SAAS,iBAAc,MAAM,YAClD,SAAS,GACL,CACR,CAAC,CAAC,CAAC,IAAI,KAlBD,GAAG,CAmBP,CACN,CAAC;YACJ,CAAC,CAAC,GACC,GACD,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
.breadcrumbs {
|
|
2
2
|
width: 100%;
|
|
3
|
+
min-width: 0;
|
|
3
4
|
}
|
|
4
5
|
|
|
5
6
|
.list {
|
|
6
7
|
display: flex;
|
|
7
8
|
align-items: center;
|
|
8
|
-
flex-wrap:
|
|
9
|
+
flex-wrap: nowrap;
|
|
9
10
|
gap: 6px;
|
|
10
11
|
list-style: none;
|
|
11
12
|
padding: 0;
|
|
12
13
|
margin: 0;
|
|
14
|
+
min-width: 0;
|
|
15
|
+
overflow: hidden;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
.item {
|
|
16
19
|
display: inline-flex;
|
|
17
20
|
align-items: center;
|
|
18
21
|
gap: 6px;
|
|
22
|
+
min-width: 0;
|
|
23
|
+
flex: 0 1 auto;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
.link {
|
|
@@ -23,6 +28,8 @@
|
|
|
23
28
|
text-decoration: none;
|
|
24
29
|
font-size: 13px;
|
|
25
30
|
transition: color 0.2s ease;
|
|
31
|
+
min-width: 0;
|
|
32
|
+
max-width: 100%;
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
.link:hover {
|
|
@@ -32,11 +39,17 @@
|
|
|
32
39
|
.label {
|
|
33
40
|
display: inline-flex;
|
|
34
41
|
align-items: center;
|
|
42
|
+
min-width: 0;
|
|
43
|
+
max-width: min(42vw, 360px);
|
|
44
|
+
overflow: hidden;
|
|
45
|
+
text-overflow: ellipsis;
|
|
46
|
+
white-space: nowrap;
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
.separator {
|
|
38
50
|
color: var(--color-muted-2);
|
|
39
51
|
font-size: 12px;
|
|
52
|
+
flex: 0 0 auto;
|
|
40
53
|
}
|
|
41
54
|
|
|
42
55
|
.disabled {
|
|
@@ -44,6 +57,48 @@
|
|
|
44
57
|
cursor: not-allowed;
|
|
45
58
|
}
|
|
46
59
|
|
|
60
|
+
.overflowItem {
|
|
61
|
+
flex: 0 0 auto;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.overflowDropdown {
|
|
65
|
+
display: inline-flex;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.overflowTrigger {
|
|
69
|
+
color: var(--color-muted);
|
|
70
|
+
text-decoration: none;
|
|
71
|
+
font-size: 13px;
|
|
72
|
+
display: inline-flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
line-height: 1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.overflowTrigger:hover {
|
|
78
|
+
color: var(--color-teal);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.overflowMenu {
|
|
82
|
+
max-width: min(90vw, 420px);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.overflowMenuItem {
|
|
86
|
+
white-space: normal;
|
|
87
|
+
word-break: break-word;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.visuallyHidden {
|
|
91
|
+
position: absolute;
|
|
92
|
+
width: 1px;
|
|
93
|
+
height: 1px;
|
|
94
|
+
padding: 0;
|
|
95
|
+
margin: -1px;
|
|
96
|
+
overflow: hidden;
|
|
97
|
+
clip: rect(0, 0, 0, 0);
|
|
98
|
+
white-space: nowrap;
|
|
99
|
+
border: 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
47
102
|
[aria-current="page"] {
|
|
48
103
|
color: var(--color-text);
|
|
49
104
|
}
|