@adam-milo/ui 1.0.23 → 1.0.24
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.cjs +1 -1
- package/dist/index.js +18 -9
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +53 -59
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +50 -104
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +108 -76
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +77 -26
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +22 -462
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +466 -109
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +111 -30
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +42 -12
- package/dist/index18.cjs +1 -0
- package/dist/index18.js +14 -0
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +1 -1
- package/dist/index20.cjs +1 -1
- package/dist/index20.js +20 -299
- package/dist/index21.cjs +1 -1
- package/dist/index21.js +298 -13
- package/dist/index22.cjs +1 -0
- package/dist/index22.js +16 -0
- package/dist/index25.cjs +1 -0
- package/dist/index25.js +1193 -0
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +2 -2
- package/dist/index33.cjs +1 -1
- package/dist/index33.js +7 -19
- package/dist/index36.cjs +1 -0
- package/dist/index36.js +21 -0
- package/dist/index38.cjs +1 -0
- package/dist/index38.js +6 -0
- package/dist/index39.cjs +1 -0
- package/dist/index39.js +11 -0
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +1 -1
- package/dist/index40.cjs +1 -0
- package/dist/index40.js +70 -0
- package/dist/index41.cjs +1 -0
- package/dist/index41.js +39 -0
- package/dist/index42.cjs +1 -0
- package/dist/index42.js +64 -0
- package/dist/index43.cjs +1 -0
- package/dist/index43.js +10 -0
- package/dist/index44.cjs +1 -0
- package/dist/index44.js +212 -0
- package/dist/index45.cjs +1 -0
- package/dist/index45.js +29 -0
- package/dist/index46.cjs +1 -0
- package/dist/index46.js +208 -0
- package/dist/index47.cjs +1 -0
- package/dist/index47.js +14 -0
- package/dist/index48.cjs +1 -0
- package/dist/index48.js +293 -0
- package/dist/index49.cjs +1 -0
- package/dist/index49.js +18 -0
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +1 -1
- package/dist/index50.cjs +1 -0
- package/dist/index50.js +43 -0
- package/dist/index51.cjs +1 -0
- package/dist/index51.js +89 -0
- package/dist/index52.cjs +1 -0
- package/dist/index52.js +14 -0
- package/dist/index53.cjs +1 -0
- package/dist/index53.js +71 -0
- package/dist/index54.cjs +1 -0
- package/dist/index54.js +6 -0
- package/dist/index55.cjs +1 -0
- package/dist/index55.js +14 -0
- package/dist/index56.cjs +1 -0
- package/dist/index56.js +34 -0
- package/dist/index57.cjs +1 -0
- package/dist/index57.js +122 -0
- package/dist/index58.cjs +1 -0
- package/dist/index58.js +11 -0
- package/dist/index59.cjs +1 -0
- package/dist/index59.js +17 -0
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +2 -2
- package/dist/index60.cjs +1 -0
- package/dist/index60.js +297 -0
- package/dist/index61.cjs +1 -0
- package/dist/index61.js +25 -0
- package/dist/index62.cjs +1 -0
- package/dist/index62.js +39 -0
- package/dist/index63.cjs +1 -0
- package/dist/index63.js +625 -0
- package/dist/index64.cjs +1 -0
- package/dist/index64.js +39 -0
- package/dist/index65.cjs +1 -0
- package/dist/index65.js +38 -0
- package/dist/index66.cjs +1 -0
- package/dist/index66.js +7 -0
- package/dist/index67.cjs +1 -0
- package/dist/index67.js +10 -0
- package/dist/index68.cjs +1 -0
- package/dist/index68.js +5 -0
- package/dist/index69.cjs +1 -0
- package/dist/index69.js +35 -0
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +1 -1
- package/dist/index70.cjs +1 -0
- package/dist/index70.js +180 -0
- package/dist/index71.cjs +1 -0
- package/dist/index71.js +21 -0
- package/dist/index72.cjs +1 -0
- package/dist/index72.js +721 -0
- package/dist/index73.cjs +1 -0
- package/dist/index73.js +154 -0
- package/dist/index74.cjs +1 -0
- package/dist/index74.js +173 -0
- package/dist/index75.cjs +1 -0
- package/dist/index75.js +88 -0
- package/dist/index76.cjs +1 -0
- package/dist/index76.js +47 -0
- package/dist/index77.cjs +1 -0
- package/dist/index77.js +13 -0
- package/dist/index78.cjs +1 -0
- package/dist/index78.js +19 -0
- package/dist/index79.cjs +1 -0
- package/dist/index79.js +102 -0
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +1 -1
- package/dist/index80.cjs +1 -0
- package/dist/index80.js +11 -0
- package/dist/index81.cjs +1 -0
- package/dist/index81.js +29 -0
- package/dist/index82.cjs +1 -0
- package/dist/index82.js +16 -0
- package/dist/index83.cjs +1 -0
- package/dist/index83.js +48 -0
- package/dist/index84.cjs +1 -0
- package/dist/index84.js +9 -0
- package/dist/index85.cjs +1 -0
- package/dist/index85.js +37 -0
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +224 -35
- package/dist/src/components/forms/select/Select.component.d.ts +100 -0
- package/dist/src/components/forms/select/Select.component.d.ts.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +2 -1
- package/dist/index19.cjs +0 -1
- package/dist/index19.js +0 -22
- package/dist/index30.cjs +0 -1
- package/dist/index30.js +0 -9
package/dist/index13.js
CHANGED
|
@@ -1,42 +1,93 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
|
-
import { cn } from "./
|
|
3
|
+
import { cn } from "./index18.js";
|
|
4
4
|
/* empty css */
|
|
5
|
-
const
|
|
5
|
+
const DataTable = forwardRef(
|
|
6
6
|
({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
columns,
|
|
8
|
+
data,
|
|
9
|
+
striped = false,
|
|
10
|
+
hoverable = false,
|
|
10
11
|
className,
|
|
11
|
-
children,
|
|
12
|
-
"data-testid": dataTestId,
|
|
13
12
|
"data-cy": dataCy,
|
|
13
|
+
"data-testid": dataTestId,
|
|
14
14
|
...props
|
|
15
15
|
}, ref) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
`chip--${variant}`,
|
|
19
|
-
selected && "chip--selected",
|
|
20
|
-
disabled && "chip--disabled",
|
|
21
|
-
className
|
|
22
|
-
);
|
|
16
|
+
const finalDataCy = dataCy || "datatable";
|
|
17
|
+
const finalTestId = dataTestId || "datatable";
|
|
23
18
|
return /* @__PURE__ */ jsx(
|
|
24
19
|
"div",
|
|
25
20
|
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"data-testid":
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
className: "datatable-wrapper",
|
|
22
|
+
"data-cy": `${finalDataCy}-wrapper`,
|
|
23
|
+
"data-testid": `${finalTestId}-wrapper`,
|
|
24
|
+
children: /* @__PURE__ */ jsxs(
|
|
25
|
+
"table",
|
|
26
|
+
{
|
|
27
|
+
ref,
|
|
28
|
+
className: cn("datatable", className),
|
|
29
|
+
"data-cy": finalDataCy,
|
|
30
|
+
"data-testid": finalTestId,
|
|
31
|
+
...props,
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ jsx(
|
|
34
|
+
"thead",
|
|
35
|
+
{
|
|
36
|
+
className: "datatable__head",
|
|
37
|
+
"data-cy": `${finalDataCy}-head`,
|
|
38
|
+
"data-testid": `${finalTestId}-head`,
|
|
39
|
+
children: /* @__PURE__ */ jsx("tr", { children: columns.map((column) => /* @__PURE__ */ jsx(
|
|
40
|
+
"th",
|
|
41
|
+
{
|
|
42
|
+
className: "datatable__header-cell",
|
|
43
|
+
"data-cy": `${finalDataCy}-header-${column.key}`,
|
|
44
|
+
"data-testid": `${finalTestId}-header-${column.key}`,
|
|
45
|
+
children: column.header
|
|
46
|
+
},
|
|
47
|
+
column.key
|
|
48
|
+
)) })
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
/* @__PURE__ */ jsx("tbody", { "data-cy": `${finalDataCy}-body`, "data-testid": `${finalTestId}-body`, children: data.length === 0 ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx(
|
|
52
|
+
"td",
|
|
53
|
+
{
|
|
54
|
+
colSpan: columns.length,
|
|
55
|
+
className: "datatable__empty",
|
|
56
|
+
"data-cy": `${finalDataCy}-empty`,
|
|
57
|
+
"data-testid": `${finalTestId}-empty`,
|
|
58
|
+
children: "No data available"
|
|
59
|
+
}
|
|
60
|
+
) }) : data.map((row, rowIndex) => /* @__PURE__ */ jsx(
|
|
61
|
+
"tr",
|
|
62
|
+
{
|
|
63
|
+
className: cn(
|
|
64
|
+
"datatable__body-row",
|
|
65
|
+
hoverable && "datatable__body-row--hoverable",
|
|
66
|
+
striped && "datatable__body-row--striped"
|
|
67
|
+
),
|
|
68
|
+
"data-cy": `${finalDataCy}-row-${rowIndex}`,
|
|
69
|
+
"data-testid": `${finalTestId}-row-${rowIndex}`,
|
|
70
|
+
children: columns.map((column) => /* @__PURE__ */ jsx(
|
|
71
|
+
"td",
|
|
72
|
+
{
|
|
73
|
+
className: "datatable__body-cell",
|
|
74
|
+
"data-cy": `${finalDataCy}-cell-${rowIndex}-${column.key}`,
|
|
75
|
+
"data-testid": `${finalTestId}-cell-${rowIndex}-${column.key}`,
|
|
76
|
+
children: String(row[column.key] ?? "")
|
|
77
|
+
},
|
|
78
|
+
column.key
|
|
79
|
+
))
|
|
80
|
+
},
|
|
81
|
+
rowIndex
|
|
82
|
+
)) })
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
)
|
|
35
86
|
}
|
|
36
87
|
);
|
|
37
88
|
}
|
|
38
89
|
);
|
|
39
|
-
|
|
90
|
+
DataTable.displayName = "DataTable";
|
|
40
91
|
export {
|
|
41
|
-
|
|
92
|
+
DataTable
|
|
42
93
|
};
|
package/dist/index14.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),i=require("./index18.cjs");;/* empty css */const r=a.forwardRef(({variant:a="primary",selected:r=!1,disabled:s=!1,className:t,children:c,"data-testid":d,"data-cy":l,...n},p)=>{const h=i.cn("chip",`chip--${a}`,r&&"chip--selected",s&&"chip--disabled",t);return e.jsx("div",{ref:p,className:h,"data-testid":d||`chip-${a}`,"data-cy":l||`chip-${a}`,"aria-selected":r,"aria-disabled":s,"aria-label":"string"==typeof c?c:void 0,...n,children:e.jsx("span",{className:"chip__label",children:c})})});r.displayName="Chip",exports.Chip=r;
|
package/dist/index14.js
CHANGED
|
@@ -1,482 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { forwardRef
|
|
3
|
-
import { cn } from "./
|
|
4
|
-
import { Chip } from "./index13.js";
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { cn } from "./index18.js";
|
|
5
4
|
/* empty css */
|
|
6
|
-
|
|
7
|
-
import { Icon } from "@adam-milo/icons";
|
|
8
|
-
const parseGapValue = (gapString, rootFontSize, containerFontSize) => {
|
|
9
|
-
if (!gapString) return 0.5 * rootFontSize;
|
|
10
|
-
const match = gapString.match(/^([\d.]+)(px|rem|em)?/);
|
|
11
|
-
if (!match) return 0.5 * rootFontSize;
|
|
12
|
-
const value = parseFloat(match[1]);
|
|
13
|
-
const unit = match[2] || "px";
|
|
14
|
-
switch (unit) {
|
|
15
|
-
case "px":
|
|
16
|
-
return value;
|
|
17
|
-
case "rem":
|
|
18
|
-
return value * rootFontSize;
|
|
19
|
-
case "em":
|
|
20
|
-
return value * containerFontSize;
|
|
21
|
-
default:
|
|
22
|
-
return 0.5 * rootFontSize;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const calculateFittingChips = (items, chipWidths, containerWidth, gap, overflowChipWidth) => {
|
|
26
|
-
let totalWidth = 0;
|
|
27
|
-
let count = 0;
|
|
28
|
-
for (let i = 0; i < items.length; i++) {
|
|
29
|
-
const item = items[i];
|
|
30
|
-
const chipWidth = chipWidths.get(item.value) || 0;
|
|
31
|
-
if (chipWidth === 0) {
|
|
32
|
-
count++;
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
const gapBeforeThisChip = i > 0 ? gap : 0;
|
|
36
|
-
const widthWithThisChip = totalWidth + gapBeforeThisChip + chipWidth;
|
|
37
|
-
const hasMoreItems = i < items.length - 1;
|
|
38
|
-
if (hasMoreItems) {
|
|
39
|
-
const widthWithOverflow = widthWithThisChip + gap + overflowChipWidth;
|
|
40
|
-
if (widthWithOverflow > containerWidth && count > 0) break;
|
|
41
|
-
} else {
|
|
42
|
-
if (widthWithThisChip > containerWidth && count > 0) break;
|
|
43
|
-
}
|
|
44
|
-
totalWidth = widthWithThisChip;
|
|
45
|
-
count++;
|
|
46
|
-
}
|
|
47
|
-
return Math.max(1, count);
|
|
48
|
-
};
|
|
49
|
-
const useDebounce = (callback, delay) => {
|
|
50
|
-
const timeoutRef = useRef();
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
return () => {
|
|
53
|
-
if (timeoutRef.current) {
|
|
54
|
-
clearTimeout(timeoutRef.current);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}, []);
|
|
58
|
-
const debouncedFn = useCallback(
|
|
59
|
-
(...args) => {
|
|
60
|
-
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
61
|
-
timeoutRef.current = setTimeout(() => callback(...args), delay);
|
|
62
|
-
},
|
|
63
|
-
[callback, delay]
|
|
64
|
-
);
|
|
65
|
-
return debouncedFn;
|
|
66
|
-
};
|
|
67
|
-
const useChipOverflow = (items, containerRef, chipRefs, chipWidths, maxVisible) => {
|
|
68
|
-
const [visibleCount, setVisibleCount] = useState(items.length);
|
|
69
|
-
const calculateVisibleChips = useCallback(() => {
|
|
70
|
-
if (maxVisible !== void 0) {
|
|
71
|
-
setVisibleCount(Math.min(maxVisible, items.length));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const container = containerRef.current;
|
|
75
|
-
if (!container) return;
|
|
76
|
-
const containerWidth = container.clientWidth;
|
|
77
|
-
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
78
|
-
const computedStyle = window.getComputedStyle(container);
|
|
79
|
-
const gapString = computedStyle.gap;
|
|
80
|
-
const containerFontSize = parseFloat(computedStyle.fontSize) || 16;
|
|
81
|
-
const gap = parseGapValue(gapString, rootFontSize, containerFontSize);
|
|
82
|
-
const OVERFLOW_CHIP_WIDTH_REM = 3.75;
|
|
83
|
-
const overflowChipWidth = OVERFLOW_CHIP_WIDTH_REM * rootFontSize;
|
|
84
|
-
for (let i = 0; i < items.length; i++) {
|
|
85
|
-
const item = items[i];
|
|
86
|
-
const chip = chipRefs.current[i];
|
|
87
|
-
if (chip) {
|
|
88
|
-
chipWidths.current.set(item.value, chip.offsetWidth);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const count = calculateFittingChips(
|
|
92
|
-
items,
|
|
93
|
-
chipWidths.current,
|
|
94
|
-
containerWidth,
|
|
95
|
-
gap,
|
|
96
|
-
overflowChipWidth
|
|
97
|
-
);
|
|
98
|
-
setVisibleCount(count);
|
|
99
|
-
}, [items, maxVisible, containerRef, chipRefs, chipWidths]);
|
|
100
|
-
const debouncedCalculate = useDebounce(calculateVisibleChips, 100);
|
|
101
|
-
useEffect(() => {
|
|
102
|
-
if (chipRefs.current.length > items.length) {
|
|
103
|
-
chipRefs.current = chipRefs.current.slice(0, items.length);
|
|
104
|
-
}
|
|
105
|
-
const currentValues = new Set(items.map((item) => item.value));
|
|
106
|
-
chipWidths.current.forEach((_, value) => {
|
|
107
|
-
if (!currentValues.has(value)) {
|
|
108
|
-
chipWidths.current.delete(value);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
if (maxVisible === void 0) {
|
|
112
|
-
const hasUnmeasuredItems = items.some((item) => !chipWidths.current.has(item.value));
|
|
113
|
-
if (hasUnmeasuredItems) {
|
|
114
|
-
setVisibleCount(items.length);
|
|
115
|
-
} else {
|
|
116
|
-
setTimeout(calculateVisibleChips, 0);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}, [items, maxVisible, calculateVisibleChips, chipRefs, chipWidths]);
|
|
120
|
-
useEffect(() => {
|
|
121
|
-
const container = containerRef.current;
|
|
122
|
-
if (!container) return;
|
|
123
|
-
const resizeObserver = new ResizeObserver(() => {
|
|
124
|
-
debouncedCalculate();
|
|
125
|
-
});
|
|
126
|
-
resizeObserver.observe(container);
|
|
127
|
-
setTimeout(calculateVisibleChips, 0);
|
|
128
|
-
return () => {
|
|
129
|
-
resizeObserver.disconnect();
|
|
130
|
-
};
|
|
131
|
-
}, [calculateVisibleChips, debouncedCalculate, containerRef]);
|
|
132
|
-
const visibleItems = items.slice(0, visibleCount);
|
|
133
|
-
const hiddenItems = items.slice(visibleCount);
|
|
134
|
-
const hasOverflow = hiddenItems.length > 0;
|
|
135
|
-
return { visibleCount, visibleItems, hiddenItems, hasOverflow };
|
|
136
|
-
};
|
|
137
|
-
const ChipGroup = forwardRef(
|
|
5
|
+
const Chip = forwardRef(
|
|
138
6
|
({
|
|
139
|
-
items,
|
|
140
|
-
selectedValue,
|
|
141
|
-
onSelectionChange,
|
|
142
|
-
removable = false,
|
|
143
|
-
onRemove,
|
|
144
7
|
variant = "primary",
|
|
8
|
+
selected = false,
|
|
145
9
|
disabled = false,
|
|
146
|
-
maxVisible,
|
|
147
10
|
className,
|
|
11
|
+
children,
|
|
148
12
|
"data-testid": dataTestId,
|
|
149
13
|
"data-cy": dataCy,
|
|
150
14
|
...props
|
|
151
15
|
}, ref) => {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const chipWidths = useRef(/* @__PURE__ */ new Map());
|
|
159
|
-
const dropdownRef = useRef(null);
|
|
160
|
-
const [showTooltip, setShowTooltip] = useState(false);
|
|
161
|
-
const [showDropdown, setShowDropdown] = useState(false);
|
|
162
|
-
const dropdownItemRefs = useRef([]);
|
|
163
|
-
const { visibleItems, hiddenItems, hasOverflow } = useChipOverflow(
|
|
164
|
-
validItems,
|
|
165
|
-
containerRef,
|
|
166
|
-
chipRefs,
|
|
167
|
-
chipWidths,
|
|
168
|
-
maxVisible
|
|
169
|
-
);
|
|
170
|
-
const handleChipClick = useCallback(
|
|
171
|
-
(value, itemDisabled, event) => {
|
|
172
|
-
if (disabled || itemDisabled) return;
|
|
173
|
-
if (onSelectionChange) {
|
|
174
|
-
const newValue = selectedValue === value ? null : value;
|
|
175
|
-
onSelectionChange(newValue, event);
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
[disabled, selectedValue, onSelectionChange]
|
|
179
|
-
);
|
|
180
|
-
const handleRemove = useCallback(
|
|
181
|
-
(e, value) => {
|
|
182
|
-
e.stopPropagation();
|
|
183
|
-
if (disabled) return;
|
|
184
|
-
if (onRemove) {
|
|
185
|
-
onRemove(value, e);
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
[disabled, onRemove]
|
|
16
|
+
const classes = cn(
|
|
17
|
+
"chip",
|
|
18
|
+
`chip--${variant}`,
|
|
19
|
+
selected && "chip--selected",
|
|
20
|
+
disabled && "chip--disabled",
|
|
21
|
+
className
|
|
189
22
|
);
|
|
190
|
-
|
|
191
|
-
(e, value, itemDisabled) => {
|
|
192
|
-
if (disabled || itemDisabled) return;
|
|
193
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
194
|
-
e.preventDefault();
|
|
195
|
-
handleChipClick(value, itemDisabled, e);
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
[disabled, handleChipClick]
|
|
199
|
-
);
|
|
200
|
-
const handleOverflowClick = useCallback((e) => {
|
|
201
|
-
e.stopPropagation();
|
|
202
|
-
setShowDropdown((prev) => !prev);
|
|
203
|
-
setShowTooltip(false);
|
|
204
|
-
}, []);
|
|
205
|
-
const handleDropdownKeyDown = useCallback(
|
|
206
|
-
(e, index) => {
|
|
207
|
-
var _a, _b, _c, _d;
|
|
208
|
-
switch (e.key) {
|
|
209
|
-
case "ArrowDown":
|
|
210
|
-
e.preventDefault();
|
|
211
|
-
if (index < hiddenItems.length - 1) {
|
|
212
|
-
(_a = dropdownItemRefs.current[index + 1]) == null ? void 0 : _a.focus();
|
|
213
|
-
}
|
|
214
|
-
break;
|
|
215
|
-
case "ArrowUp":
|
|
216
|
-
e.preventDefault();
|
|
217
|
-
if (index > 0) {
|
|
218
|
-
(_b = dropdownItemRefs.current[index - 1]) == null ? void 0 : _b.focus();
|
|
219
|
-
}
|
|
220
|
-
break;
|
|
221
|
-
case "Home":
|
|
222
|
-
e.preventDefault();
|
|
223
|
-
(_c = dropdownItemRefs.current[0]) == null ? void 0 : _c.focus();
|
|
224
|
-
break;
|
|
225
|
-
case "End":
|
|
226
|
-
e.preventDefault();
|
|
227
|
-
(_d = dropdownItemRefs.current[hiddenItems.length - 1]) == null ? void 0 : _d.focus();
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
[hiddenItems.length]
|
|
232
|
-
);
|
|
233
|
-
const handleClickOutsideRef = useRef();
|
|
234
|
-
const handleEscapeRef = useRef();
|
|
235
|
-
useEffect(() => {
|
|
236
|
-
handleClickOutsideRef.current = (event) => {
|
|
237
|
-
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
238
|
-
setShowDropdown(false);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
handleEscapeRef.current = (event) => {
|
|
242
|
-
if (event.key === "Escape") {
|
|
243
|
-
setShowDropdown(false);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
});
|
|
247
|
-
useEffect(() => {
|
|
248
|
-
if (!showDropdown) return;
|
|
249
|
-
const handleClickOutside = (e) => {
|
|
250
|
-
var _a;
|
|
251
|
-
return (_a = handleClickOutsideRef.current) == null ? void 0 : _a.call(handleClickOutsideRef, e);
|
|
252
|
-
};
|
|
253
|
-
const handleEscape = (e) => {
|
|
254
|
-
var _a;
|
|
255
|
-
return (_a = handleEscapeRef.current) == null ? void 0 : _a.call(handleEscapeRef, e);
|
|
256
|
-
};
|
|
257
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
258
|
-
document.addEventListener("keydown", handleEscape);
|
|
259
|
-
return () => {
|
|
260
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
261
|
-
document.removeEventListener("keydown", handleEscape);
|
|
262
|
-
};
|
|
263
|
-
}, [showDropdown]);
|
|
264
|
-
useEffect(() => {
|
|
265
|
-
if (process.env.NODE_ENV === "development" && validItems.length > 0) {
|
|
266
|
-
const values = validItems.map((item) => item.value);
|
|
267
|
-
const uniqueValues = new Set(values);
|
|
268
|
-
if (values.length !== uniqueValues.size) {
|
|
269
|
-
devWarn(
|
|
270
|
-
"[ChipGroup] Duplicate values detected in items array. Each item should have a unique value."
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}, [validItems]);
|
|
275
|
-
useEffect(() => {
|
|
276
|
-
if (dropdownItemRefs.current.length > hiddenItems.length) {
|
|
277
|
-
dropdownItemRefs.current = dropdownItemRefs.current.slice(0, hiddenItems.length);
|
|
278
|
-
}
|
|
279
|
-
}, [hiddenItems]);
|
|
280
|
-
if (!items || !Array.isArray(items)) {
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
return /* @__PURE__ */ jsxs(
|
|
23
|
+
return /* @__PURE__ */ jsx(
|
|
284
24
|
"div",
|
|
285
25
|
{
|
|
286
26
|
ref,
|
|
287
|
-
className:
|
|
288
|
-
|
|
289
|
-
"
|
|
290
|
-
"
|
|
291
|
-
"
|
|
27
|
+
className: classes,
|
|
28
|
+
"data-testid": dataTestId || `chip-${variant}`,
|
|
29
|
+
"data-cy": dataCy || `chip-${variant}`,
|
|
30
|
+
"aria-selected": selected,
|
|
31
|
+
"aria-disabled": disabled,
|
|
32
|
+
"aria-label": typeof children === "string" ? children : void 0,
|
|
292
33
|
...props,
|
|
293
|
-
children:
|
|
294
|
-
hasOverflow && /* @__PURE__ */ jsxs(
|
|
295
|
-
"div",
|
|
296
|
-
{
|
|
297
|
-
className: "sr-only",
|
|
298
|
-
role: "status",
|
|
299
|
-
"aria-live": "polite",
|
|
300
|
-
"aria-atomic": "true",
|
|
301
|
-
"data-testid": "chip-group-live-region",
|
|
302
|
-
"data-cy": "chip-group-live-region",
|
|
303
|
-
children: [
|
|
304
|
-
hiddenItems.length,
|
|
305
|
-
" additional ",
|
|
306
|
-
hiddenItems.length === 1 ? "chip" : "chips",
|
|
307
|
-
" hidden"
|
|
308
|
-
]
|
|
309
|
-
}
|
|
310
|
-
),
|
|
311
|
-
/* @__PURE__ */ jsxs("div", { ref: containerRef, className: "chip-group__container", children: [
|
|
312
|
-
visibleItems.map((item) => {
|
|
313
|
-
const isSelected = selectedValue === item.value;
|
|
314
|
-
const itemVariant = item.variant || variant;
|
|
315
|
-
const itemDisabled = disabled || item.disabled || false;
|
|
316
|
-
const itemIndexInFullArray = validItems.findIndex((i) => i.value === item.value);
|
|
317
|
-
return /* @__PURE__ */ jsx(
|
|
318
|
-
"div",
|
|
319
|
-
{
|
|
320
|
-
ref: (el) => {
|
|
321
|
-
if (el) {
|
|
322
|
-
chipRefs.current[itemIndexInFullArray] = el;
|
|
323
|
-
} else {
|
|
324
|
-
chipRefs.current[itemIndexInFullArray] = null;
|
|
325
|
-
}
|
|
326
|
-
},
|
|
327
|
-
className: "chip-group__item-wrapper",
|
|
328
|
-
"data-cy": `chip-group-item-wrapper-${item.value}`,
|
|
329
|
-
"data-testid": `chip-group-item-wrapper-${item.value}`,
|
|
330
|
-
children: /* @__PURE__ */ jsxs(
|
|
331
|
-
"div",
|
|
332
|
-
{
|
|
333
|
-
className: "chip-group__item",
|
|
334
|
-
onClick: (e) => handleChipClick(item.value, itemDisabled, e),
|
|
335
|
-
onKeyDown: (e) => handleKeyDown(e, item.value, itemDisabled),
|
|
336
|
-
tabIndex: itemDisabled ? -1 : 0,
|
|
337
|
-
role: "button",
|
|
338
|
-
"aria-pressed": isSelected ? "true" : "false",
|
|
339
|
-
"aria-disabled": itemDisabled ? "true" : "false",
|
|
340
|
-
"data-cy": `chip-group-item-${item.value}`,
|
|
341
|
-
"data-testid": `chip-group-item-${item.value}`,
|
|
342
|
-
children: [
|
|
343
|
-
/* @__PURE__ */ jsx(
|
|
344
|
-
Chip,
|
|
345
|
-
{
|
|
346
|
-
variant: itemVariant,
|
|
347
|
-
selected: isSelected,
|
|
348
|
-
disabled: itemDisabled,
|
|
349
|
-
"data-cy": `chip-${item.value}`,
|
|
350
|
-
"data-testid": `chip-${item.value}`,
|
|
351
|
-
children: item.label
|
|
352
|
-
}
|
|
353
|
-
),
|
|
354
|
-
removable && !disabled && !itemDisabled && /* @__PURE__ */ jsx(
|
|
355
|
-
"button",
|
|
356
|
-
{
|
|
357
|
-
className: "chip-group__remove",
|
|
358
|
-
onClick: (e) => handleRemove(e, item.value),
|
|
359
|
-
"aria-label": `Remove ${item.label}`,
|
|
360
|
-
"data-cy": `chip-remove-${item.value}`,
|
|
361
|
-
"data-testid": `chip-remove-${item.value}`,
|
|
362
|
-
type: "button",
|
|
363
|
-
children: /* @__PURE__ */ jsx(Icon, { name: "Cross2Icon", size: "sm", decorative: true })
|
|
364
|
-
}
|
|
365
|
-
)
|
|
366
|
-
]
|
|
367
|
-
}
|
|
368
|
-
)
|
|
369
|
-
},
|
|
370
|
-
item.value
|
|
371
|
-
);
|
|
372
|
-
}),
|
|
373
|
-
hasOverflow && /* @__PURE__ */ jsxs(
|
|
374
|
-
"div",
|
|
375
|
-
{
|
|
376
|
-
ref: dropdownRef,
|
|
377
|
-
className: "chip-group__overflow",
|
|
378
|
-
role: "button",
|
|
379
|
-
tabIndex: 0,
|
|
380
|
-
"aria-expanded": showDropdown ? "true" : "false",
|
|
381
|
-
"aria-haspopup": "menu",
|
|
382
|
-
"aria-label": `Show ${hiddenItems.length} more ${hiddenItems.length === 1 ? "chip" : "chips"}`,
|
|
383
|
-
onMouseEnter: () => !showDropdown && setShowTooltip(true),
|
|
384
|
-
onMouseLeave: () => setShowTooltip(false),
|
|
385
|
-
onClick: handleOverflowClick,
|
|
386
|
-
onKeyDown: (e) => {
|
|
387
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
388
|
-
e.preventDefault();
|
|
389
|
-
e.stopPropagation();
|
|
390
|
-
setShowDropdown(!showDropdown);
|
|
391
|
-
setShowTooltip(false);
|
|
392
|
-
}
|
|
393
|
-
},
|
|
394
|
-
"data-cy": "chip-group-overflow",
|
|
395
|
-
"data-testid": "chip-group-overflow",
|
|
396
|
-
children: [
|
|
397
|
-
/* @__PURE__ */ jsxs(Chip, { variant, "data-cy": "chip-overflow", "data-testid": "chip-overflow", children: [
|
|
398
|
-
"+",
|
|
399
|
-
hiddenItems.length
|
|
400
|
-
] }),
|
|
401
|
-
showTooltip && !showDropdown && /* @__PURE__ */ jsx(
|
|
402
|
-
"div",
|
|
403
|
-
{
|
|
404
|
-
className: "chip-group__tooltip chip-group__tooltip--hover",
|
|
405
|
-
role: "tooltip",
|
|
406
|
-
"data-cy": "chip-group-tooltip",
|
|
407
|
-
"data-testid": "chip-group-tooltip",
|
|
408
|
-
children: hiddenItems.map((item) => /* @__PURE__ */ jsx(
|
|
409
|
-
"div",
|
|
410
|
-
{
|
|
411
|
-
className: "chip-group__tooltip-item",
|
|
412
|
-
"data-cy": `chip-group-tooltip-item-${item.value}`,
|
|
413
|
-
"data-testid": `chip-group-tooltip-item-${item.value}`,
|
|
414
|
-
children: item.label
|
|
415
|
-
},
|
|
416
|
-
item.value
|
|
417
|
-
))
|
|
418
|
-
}
|
|
419
|
-
),
|
|
420
|
-
showDropdown && /* @__PURE__ */ jsx(
|
|
421
|
-
"div",
|
|
422
|
-
{
|
|
423
|
-
className: "chip-group__dropdown",
|
|
424
|
-
role: "menu",
|
|
425
|
-
"data-cy": "chip-group-dropdown",
|
|
426
|
-
"data-testid": "chip-group-dropdown",
|
|
427
|
-
children: hiddenItems.map((item, index) => /* @__PURE__ */ jsx(
|
|
428
|
-
"div",
|
|
429
|
-
{
|
|
430
|
-
ref: (el) => {
|
|
431
|
-
if (el) {
|
|
432
|
-
dropdownItemRefs.current[index] = el;
|
|
433
|
-
} else {
|
|
434
|
-
dropdownItemRefs.current[index] = null;
|
|
435
|
-
}
|
|
436
|
-
},
|
|
437
|
-
className: cn(
|
|
438
|
-
"chip-group__dropdown-item",
|
|
439
|
-
item.disabled && "chip-group__dropdown-item--disabled"
|
|
440
|
-
),
|
|
441
|
-
role: "menuitem",
|
|
442
|
-
tabIndex: item.disabled ? -1 : 0,
|
|
443
|
-
"aria-disabled": item.disabled ? "true" : "false",
|
|
444
|
-
onClick: (e) => {
|
|
445
|
-
e.stopPropagation();
|
|
446
|
-
if (!item.disabled) {
|
|
447
|
-
handleChipClick(item.value, false, e);
|
|
448
|
-
setShowDropdown(false);
|
|
449
|
-
}
|
|
450
|
-
},
|
|
451
|
-
onKeyDown: (e) => {
|
|
452
|
-
handleDropdownKeyDown(e, index);
|
|
453
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
454
|
-
e.preventDefault();
|
|
455
|
-
e.stopPropagation();
|
|
456
|
-
if (!item.disabled) {
|
|
457
|
-
handleChipClick(item.value, false, e);
|
|
458
|
-
setShowDropdown(false);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
},
|
|
462
|
-
"data-cy": `chip-group-dropdown-item-${item.value}`,
|
|
463
|
-
"data-testid": `chip-group-dropdown-item-${item.value}`,
|
|
464
|
-
children: item.label
|
|
465
|
-
},
|
|
466
|
-
item.value
|
|
467
|
-
))
|
|
468
|
-
}
|
|
469
|
-
)
|
|
470
|
-
]
|
|
471
|
-
}
|
|
472
|
-
)
|
|
473
|
-
] })
|
|
474
|
-
]
|
|
34
|
+
children: /* @__PURE__ */ jsx("span", { className: "chip__label", children })
|
|
475
35
|
}
|
|
476
36
|
);
|
|
477
37
|
}
|
|
478
38
|
);
|
|
479
|
-
|
|
39
|
+
Chip.displayName = "Chip";
|
|
480
40
|
export {
|
|
481
|
-
|
|
41
|
+
Chip
|
|
482
42
|
};
|