@arbor-education/design-system.components 0.21.1 → 0.23.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.
- package/CHANGELOG.md +22 -0
- package/component-library.md +77 -14
- package/dist/components/articleCard/ArticleCard.d.ts +2 -2
- package/dist/components/articleCard/ArticleCard.d.ts.map +1 -1
- package/dist/components/articleCard/ArticleCard.js +3 -3
- package/dist/components/articleCard/ArticleCard.js.map +1 -1
- package/dist/components/articleCard/ArticleCard.stories.d.ts +11 -3
- package/dist/components/articleCard/ArticleCard.stories.d.ts.map +1 -1
- package/dist/components/articleCard/ArticleCard.stories.js +16 -11
- package/dist/components/articleCard/ArticleCard.stories.js.map +1 -1
- package/dist/components/combobox/Combobox.js +1 -1
- package/dist/components/combobox/Combobox.js.map +1 -1
- package/dist/components/combobox/Combobox.stories.d.ts +4 -0
- package/dist/components/combobox/Combobox.stories.d.ts.map +1 -1
- package/dist/components/combobox/Combobox.stories.js +144 -12
- package/dist/components/combobox/Combobox.stories.js.map +1 -1
- package/dist/components/combobox/Combobox.test.js +22 -0
- package/dist/components/combobox/Combobox.test.js.map +1 -1
- package/dist/components/combobox/ComboboxButtonTrigger.d.ts +4 -4
- package/dist/components/combobox/ComboboxButtonTrigger.d.ts.map +1 -1
- package/dist/components/combobox/ComboboxButtonTrigger.js +35 -40
- package/dist/components/combobox/ComboboxButtonTrigger.js.map +1 -1
- package/dist/components/combobox/ComboboxTrigger.d.ts.map +1 -1
- package/dist/components/combobox/ComboboxTrigger.js +11 -4
- package/dist/components/combobox/ComboboxTrigger.js.map +1 -1
- package/dist/components/combobox/useVisibleTriggerTags.d.ts +21 -0
- package/dist/components/combobox/useVisibleTriggerTags.d.ts.map +1 -0
- package/dist/components/combobox/useVisibleTriggerTags.js +46 -0
- package/dist/components/combobox/useVisibleTriggerTags.js.map +1 -0
- package/dist/components/combobox/useVisibleTriggerTags.test.d.ts +2 -0
- package/dist/components/combobox/useVisibleTriggerTags.test.d.ts.map +1 -0
- package/dist/components/combobox/useVisibleTriggerTags.test.js +81 -0
- package/dist/components/combobox/useVisibleTriggerTags.test.js.map +1 -0
- package/dist/components/filterBar/FilterBar.d.ts +71 -0
- package/dist/components/filterBar/FilterBar.d.ts.map +1 -0
- package/dist/components/filterBar/FilterBar.js +89 -0
- package/dist/components/filterBar/FilterBar.js.map +1 -0
- package/dist/components/filterBar/FilterBar.stories.d.ts +170 -0
- package/dist/components/filterBar/FilterBar.stories.d.ts.map +1 -0
- package/dist/components/filterBar/FilterBar.stories.js +894 -0
- package/dist/components/filterBar/FilterBar.stories.js.map +1 -0
- package/dist/components/filterBar/FilterBar.test.d.ts +2 -0
- package/dist/components/filterBar/FilterBar.test.d.ts.map +1 -0
- package/dist/components/filterBar/FilterBar.test.js +164 -0
- package/dist/components/filterBar/FilterBar.test.js.map +1 -0
- package/dist/components/icon/allowedIcons.d.ts +1 -0
- package/dist/components/icon/allowedIcons.d.ts.map +1 -1
- package/dist/components/icon/allowedIcons.js +2 -1
- package/dist/components/icon/allowedIcons.js.map +1 -1
- package/dist/components/iconText/IconText.d.ts +43 -0
- package/dist/components/iconText/IconText.d.ts.map +1 -0
- package/dist/components/iconText/IconText.js +29 -0
- package/dist/components/iconText/IconText.js.map +1 -0
- package/dist/components/{icoText/IcoText.stories.d.ts → iconText/IconText.stories.d.ts} +8 -9
- package/dist/components/iconText/IconText.stories.d.ts.map +1 -0
- package/dist/components/{icoText/IcoText.stories.js → iconText/IconText.stories.js} +81 -81
- package/dist/components/iconText/IconText.stories.js.map +1 -0
- package/dist/components/iconText/IconText.test.d.ts +2 -0
- package/dist/components/iconText/IconText.test.d.ts.map +1 -0
- package/dist/components/{icoText/IcoText.test.js → iconText/IconText.test.js} +6 -6
- package/dist/components/iconText/IconText.test.js.map +1 -0
- package/dist/components/modal/Modal.d.ts +1 -0
- package/dist/components/modal/Modal.d.ts.map +1 -1
- package/dist/components/modal/Modal.js +2 -2
- package/dist/components/modal/Modal.js.map +1 -1
- package/dist/components/table/cellRenderers/ComboboxCellRenderer.test.d.ts.map +1 -1
- package/dist/components/table/cellRenderers/ComboboxCellRenderer.test.js +13 -2
- package/dist/components/table/cellRenderers/ComboboxCellRenderer.test.js.map +1 -1
- package/dist/components/tag/Tag.d.ts +14 -1
- package/dist/components/tag/Tag.d.ts.map +1 -1
- package/dist/components/tag/Tag.js +9 -3
- package/dist/components/tag/Tag.js.map +1 -1
- package/dist/components/tag/Tag.stories.d.ts +1 -1
- package/dist/components/tag/Tag.stories.d.ts.map +1 -1
- package/dist/components/tag/Tag.stories.js +3 -3
- package/dist/components/tag/Tag.stories.js.map +1 -1
- package/dist/components/tag/Tag.test.js +36 -5
- package/dist/components/tag/Tag.test.js.map +1 -1
- package/dist/components/tagList/TagList.d.ts +49 -0
- package/dist/components/tagList/TagList.d.ts.map +1 -0
- package/dist/components/tagList/TagList.js +114 -0
- package/dist/components/tagList/TagList.js.map +1 -0
- package/dist/components/tagList/TagList.stories.d.ts +130 -0
- package/dist/components/tagList/TagList.stories.d.ts.map +1 -0
- package/dist/components/tagList/TagList.stories.js +443 -0
- package/dist/components/tagList/TagList.stories.js.map +1 -0
- package/dist/components/{icoText/IcoText.test.d.ts → tagList/TagList.test.d.ts} +1 -1
- package/dist/components/tagList/TagList.test.d.ts.map +1 -0
- package/dist/components/tagList/TagList.test.js +246 -0
- package/dist/components/tagList/TagList.test.js.map +1 -0
- package/dist/components/tagList/useTagListCollapsedLayout.d.ts +19 -0
- package/dist/components/tagList/useTagListCollapsedLayout.d.ts.map +1 -0
- package/dist/components/tagList/useTagListCollapsedLayout.js +48 -0
- package/dist/components/tagList/useTagListCollapsedLayout.js.map +1 -0
- package/dist/components/tagList/useVisibleTags.d.ts +18 -0
- package/dist/components/tagList/useVisibleTags.d.ts.map +1 -0
- package/dist/components/tagList/useVisibleTags.js +41 -0
- package/dist/components/tagList/useVisibleTags.js.map +1 -0
- package/dist/index.css +272 -13
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/hooks/useElementWidth.d.ts.map +1 -0
- package/dist/{components/combobox → utils/hooks}/useElementWidth.js +0 -1
- package/dist/utils/hooks/useElementWidth.js.map +1 -0
- package/dist/utils/hooks/useMeasuredChildWidths.d.ts +8 -0
- package/dist/utils/hooks/useMeasuredChildWidths.d.ts.map +1 -0
- package/dist/utils/hooks/useMeasuredChildWidths.js +26 -0
- package/dist/utils/hooks/useMeasuredChildWidths.js.map +1 -0
- package/dist/utils/hooks/useRovingFocus.d.ts +18 -0
- package/dist/utils/hooks/useRovingFocus.d.ts.map +1 -0
- package/dist/utils/hooks/useRovingFocus.js +130 -0
- package/dist/utils/hooks/useRovingFocus.js.map +1 -0
- package/dist/utils/hooks/useRovingFocus.test.d.ts +2 -0
- package/dist/utils/hooks/useRovingFocus.test.d.ts.map +1 -0
- package/dist/utils/hooks/useRovingFocus.test.js +59 -0
- package/dist/utils/hooks/useRovingFocus.test.js.map +1 -0
- package/dist/utils/spacedWidths.d.ts +3 -0
- package/dist/utils/spacedWidths.d.ts.map +1 -0
- package/dist/utils/spacedWidths.js +28 -0
- package/dist/utils/spacedWidths.js.map +1 -0
- package/dist/utils/spacedWidths.test.d.ts +2 -0
- package/dist/utils/spacedWidths.test.d.ts.map +1 -0
- package/dist/utils/spacedWidths.test.js +17 -0
- package/dist/utils/spacedWidths.test.js.map +1 -0
- package/package.json +1 -1
- package/src/components/articleCard/ArticleCard.stories.tsx +17 -12
- package/src/components/articleCard/ArticleCard.tsx +9 -9
- package/src/components/combobox/Combobox.stories.tsx +186 -12
- package/src/components/combobox/Combobox.test.tsx +53 -0
- package/src/components/combobox/Combobox.tsx +3 -3
- package/src/components/combobox/ComboboxButtonTrigger.tsx +52 -56
- package/src/components/combobox/ComboboxTrigger.tsx +19 -16
- package/src/components/combobox/combobox.scss +8 -3
- package/src/components/combobox/useVisibleTriggerTags.test.tsx +91 -0
- package/src/components/combobox/useVisibleTriggerTags.ts +83 -0
- package/src/components/filterBar/FilterBar.stories.tsx +1199 -0
- package/src/components/filterBar/FilterBar.test.tsx +248 -0
- package/src/components/filterBar/FilterBar.tsx +298 -0
- package/src/components/filterBar/filterBar.scss +143 -0
- package/src/components/icon/allowedIcons.tsx +3 -1
- package/src/components/{icoText/IcoText.stories.tsx → iconText/IconText.stories.tsx} +112 -112
- package/src/components/{icoText/IcoText.test.tsx → iconText/IconText.test.tsx} +10 -10
- package/src/components/{icoText/IcoText.tsx → iconText/IconText.tsx} +27 -20
- package/src/components/modal/Modal.tsx +5 -1
- package/src/components/table/cellRenderers/ComboboxCellRenderer.test.tsx +20 -3
- package/src/components/tag/Tag.stories.tsx +4 -4
- package/src/components/tag/Tag.test.tsx +62 -5
- package/src/components/tag/Tag.tsx +61 -3
- package/src/components/tag/tag.scss +80 -9
- package/src/components/tagList/TagList.stories.tsx +564 -0
- package/src/components/tagList/TagList.test.tsx +342 -0
- package/src/components/tagList/TagList.tsx +296 -0
- package/src/components/tagList/tagList.scss +56 -0
- package/src/components/tagList/useTagListCollapsedLayout.ts +83 -0
- package/src/components/tagList/useVisibleTags.ts +74 -0
- package/src/index.scss +3 -1
- package/src/index.ts +13 -1
- package/src/tokens.scss +3 -1
- package/src/{components/combobox → utils/hooks}/useElementWidth.ts +0 -1
- package/src/utils/hooks/useMeasuredChildWidths.ts +39 -0
- package/src/utils/hooks/useRovingFocus.test.tsx +105 -0
- package/src/utils/hooks/useRovingFocus.ts +163 -0
- package/src/utils/spacedWidths.test.ts +20 -0
- package/src/utils/spacedWidths.ts +37 -0
- package/dist/components/combobox/useElementWidth.d.ts.map +0 -1
- package/dist/components/combobox/useElementWidth.js.map +0 -1
- package/dist/components/combobox/useVisibleChips.d.ts +0 -21
- package/dist/components/combobox/useVisibleChips.d.ts.map +0 -1
- package/dist/components/combobox/useVisibleChips.js +0 -59
- package/dist/components/combobox/useVisibleChips.js.map +0 -1
- package/dist/components/combobox/useVisibleChips.test.d.ts +0 -2
- package/dist/components/combobox/useVisibleChips.test.d.ts.map +0 -1
- package/dist/components/combobox/useVisibleChips.test.js +0 -81
- package/dist/components/combobox/useVisibleChips.test.js.map +0 -1
- package/dist/components/icoText/IcoText.d.ts +0 -37
- package/dist/components/icoText/IcoText.d.ts.map +0 -1
- package/dist/components/icoText/IcoText.js +0 -29
- package/dist/components/icoText/IcoText.js.map +0 -1
- package/dist/components/icoText/IcoText.stories.d.ts.map +0 -1
- package/dist/components/icoText/IcoText.stories.js.map +0 -1
- package/dist/components/icoText/IcoText.test.d.ts.map +0 -1
- package/dist/components/icoText/IcoText.test.js.map +0 -1
- package/src/components/combobox/useVisibleChips.test.tsx +0 -91
- package/src/components/combobox/useVisibleChips.ts +0 -100
- /package/dist/{components/combobox → utils/hooks}/useElementWidth.d.ts +0 -0
- /package/src/components/{icoText/icoText.scss → iconText/iconText.scss} +0 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { computeVisibleTriggerTagsLayout } from './useVisibleTriggerTags.js';
|
|
3
|
+
|
|
4
|
+
describe('computeVisibleTriggerTagsLayout', () => {
|
|
5
|
+
test('shows all tags and no ellipsis when there is no overflow', () => {
|
|
6
|
+
const result = computeVisibleTriggerTagsLayout({
|
|
7
|
+
containerWidth: 300,
|
|
8
|
+
tagWidths: [70, 80, 60],
|
|
9
|
+
tagGap: 4,
|
|
10
|
+
badgeWidth: 24,
|
|
11
|
+
ellipsisWidth: 12,
|
|
12
|
+
showBadge: true,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
expect(result).toEqual({
|
|
16
|
+
visibleTagIndices: [0, 1, 2],
|
|
17
|
+
hiddenTagCount: 0,
|
|
18
|
+
showBadge: true,
|
|
19
|
+
showEllipsis: false,
|
|
20
|
+
hasOverflow: false,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('reserves badge and ellipsis before fitting tags when overflow exists', () => {
|
|
25
|
+
const result = computeVisibleTriggerTagsLayout({
|
|
26
|
+
containerWidth: 160,
|
|
27
|
+
tagWidths: [60, 60, 60],
|
|
28
|
+
tagGap: 4,
|
|
29
|
+
badgeWidth: 24,
|
|
30
|
+
ellipsisWidth: 12,
|
|
31
|
+
showBadge: true,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect(result.visibleTagIndices).toEqual([0]);
|
|
35
|
+
expect(result.hiddenTagCount).toBe(2);
|
|
36
|
+
expect(result.showEllipsis).toBe(true);
|
|
37
|
+
expect(result.hasOverflow).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('allows zero tags when badge and ellipsis take priority in tiny space', () => {
|
|
41
|
+
const result = computeVisibleTriggerTagsLayout({
|
|
42
|
+
containerWidth: 36,
|
|
43
|
+
tagWidths: [80, 80],
|
|
44
|
+
tagGap: 4,
|
|
45
|
+
badgeWidth: 24,
|
|
46
|
+
ellipsisWidth: 12,
|
|
47
|
+
showBadge: true,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(result.visibleTagIndices).toEqual([]);
|
|
51
|
+
expect(result.hiddenTagCount).toBe(2);
|
|
52
|
+
expect(result.showEllipsis).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('reserving badge space reduces visible count', () => {
|
|
56
|
+
const withBadge = computeVisibleTriggerTagsLayout({
|
|
57
|
+
containerWidth: 180,
|
|
58
|
+
tagWidths: [60, 60, 60],
|
|
59
|
+
tagGap: 4,
|
|
60
|
+
badgeWidth: 24,
|
|
61
|
+
ellipsisWidth: 12,
|
|
62
|
+
showBadge: true,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const withoutBadge = computeVisibleTriggerTagsLayout({
|
|
66
|
+
containerWidth: 180,
|
|
67
|
+
tagWidths: [60, 60, 60],
|
|
68
|
+
tagGap: 4,
|
|
69
|
+
badgeWidth: 24,
|
|
70
|
+
ellipsisWidth: 12,
|
|
71
|
+
showBadge: false,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(withoutBadge.visibleTagIndices.length).toBeGreaterThanOrEqual(withBadge.visibleTagIndices.length);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('uses safety buffer to avoid a clipped final tag on boundary widths', () => {
|
|
78
|
+
const result = computeVisibleTriggerTagsLayout({
|
|
79
|
+
containerWidth: 195.5,
|
|
80
|
+
tagWidths: [73.4, 73.4, 20],
|
|
81
|
+
tagGap: 4,
|
|
82
|
+
badgeWidth: 24.2,
|
|
83
|
+
ellipsisWidth: 11.6,
|
|
84
|
+
showBadge: true,
|
|
85
|
+
safetyBuffer: 1,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(result.visibleTagIndices).toEqual([0]);
|
|
89
|
+
expect(result.showEllipsis).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { fitSpacedWidths } from 'Utils/spacedWidths';
|
|
3
|
+
|
|
4
|
+
type ComputeVisibleTriggerTagsLayoutParams = {
|
|
5
|
+
containerWidth: number;
|
|
6
|
+
tagWidths: number[];
|
|
7
|
+
tagGap: number;
|
|
8
|
+
badgeWidth: number;
|
|
9
|
+
ellipsisWidth: number;
|
|
10
|
+
showBadge: boolean;
|
|
11
|
+
safetyBuffer?: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type VisibleTriggerTagsLayout = {
|
|
15
|
+
visibleTagIndices: number[];
|
|
16
|
+
hiddenTagCount: number;
|
|
17
|
+
showBadge: boolean;
|
|
18
|
+
showEllipsis: boolean;
|
|
19
|
+
hasOverflow: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const computeVisibleTriggerTagsLayout = ({
|
|
23
|
+
containerWidth,
|
|
24
|
+
tagWidths,
|
|
25
|
+
tagGap,
|
|
26
|
+
badgeWidth,
|
|
27
|
+
ellipsisWidth,
|
|
28
|
+
showBadge,
|
|
29
|
+
safetyBuffer = 1,
|
|
30
|
+
}: ComputeVisibleTriggerTagsLayoutParams): VisibleTriggerTagsLayout => {
|
|
31
|
+
const selectedCount = tagWidths.length;
|
|
32
|
+
const shouldShowBadge = showBadge && selectedCount > 0;
|
|
33
|
+
|
|
34
|
+
if (selectedCount === 0 || containerWidth <= 0) {
|
|
35
|
+
return {
|
|
36
|
+
visibleTagIndices: [],
|
|
37
|
+
hiddenTagCount: 0,
|
|
38
|
+
showBadge: shouldShowBadge,
|
|
39
|
+
showEllipsis: false,
|
|
40
|
+
hasOverflow: false,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const badgeReserve = shouldShowBadge
|
|
45
|
+
? badgeWidth + tagGap
|
|
46
|
+
: 0;
|
|
47
|
+
|
|
48
|
+
const availableWithoutEllipsis = Math.max(0, containerWidth - badgeReserve - safetyBuffer);
|
|
49
|
+
const countWithoutEllipsis = fitSpacedWidths(availableWithoutEllipsis, tagWidths, tagGap);
|
|
50
|
+
const hasOverflow = countWithoutEllipsis < selectedCount;
|
|
51
|
+
|
|
52
|
+
const ellipsisReserve = hasOverflow
|
|
53
|
+
? ellipsisWidth + tagGap
|
|
54
|
+
: 0;
|
|
55
|
+
const availableForTags = Math.max(0, containerWidth - badgeReserve - ellipsisReserve - safetyBuffer);
|
|
56
|
+
const visibleCount = fitSpacedWidths(availableForTags, tagWidths, tagGap);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
visibleTagIndices: Array.from({ length: visibleCount }, (_, index) => index),
|
|
60
|
+
hiddenTagCount: Math.max(0, selectedCount - visibleCount),
|
|
61
|
+
showBadge: shouldShowBadge,
|
|
62
|
+
showEllipsis: visibleCount < selectedCount,
|
|
63
|
+
hasOverflow: visibleCount < selectedCount,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
type UseVisibleTriggerTagsParams = ComputeVisibleTriggerTagsLayoutParams;
|
|
68
|
+
|
|
69
|
+
export const useVisibleTriggerTags = (params: UseVisibleTriggerTagsParams): VisibleTriggerTagsLayout =>
|
|
70
|
+
// Deps list each field instead of `[params]`: callers often pass a new `params` object every
|
|
71
|
+
// render; depending on object identity would rerun the layout every time even when values are unchanged.
|
|
72
|
+
useMemo(
|
|
73
|
+
() => computeVisibleTriggerTagsLayout(params),
|
|
74
|
+
[
|
|
75
|
+
params.badgeWidth,
|
|
76
|
+
params.containerWidth,
|
|
77
|
+
params.ellipsisWidth,
|
|
78
|
+
params.safetyBuffer,
|
|
79
|
+
params.showBadge,
|
|
80
|
+
params.tagGap,
|
|
81
|
+
params.tagWidths,
|
|
82
|
+
],
|
|
83
|
+
);
|