@arbor-education/design-system.components 0.5.4 → 0.6.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 +20 -0
- package/dist/components/avatarGroup/AvatarGroup.d.ts +32 -0
- package/dist/components/avatarGroup/AvatarGroup.d.ts.map +1 -0
- package/dist/components/avatarGroup/AvatarGroup.js +37 -0
- package/dist/components/avatarGroup/AvatarGroup.js.map +1 -0
- package/dist/components/avatarGroup/AvatarGroup.stories.d.ts +14 -0
- package/dist/components/avatarGroup/AvatarGroup.stories.d.ts.map +1 -0
- package/dist/components/avatarGroup/AvatarGroup.stories.js +91 -0
- package/dist/components/avatarGroup/AvatarGroup.stories.js.map +1 -0
- package/dist/components/avatarGroup/AvatarGroup.test.d.ts +2 -0
- package/dist/components/avatarGroup/AvatarGroup.test.d.ts.map +1 -0
- package/dist/components/avatarGroup/AvatarGroup.test.js +155 -0
- package/dist/components/avatarGroup/AvatarGroup.test.js.map +1 -0
- package/dist/components/avatarGroup/avatarGroupOverflow.d.ts +8 -0
- package/dist/components/avatarGroup/avatarGroupOverflow.d.ts.map +1 -0
- package/dist/components/avatarGroup/avatarGroupOverflow.js +14 -0
- package/dist/components/avatarGroup/avatarGroupOverflow.js.map +1 -0
- package/dist/components/avatarGroup/collectAvatarGroupChildren.d.ts +4 -0
- package/dist/components/avatarGroup/collectAvatarGroupChildren.d.ts.map +1 -0
- package/dist/components/avatarGroup/collectAvatarGroupChildren.js +26 -0
- package/dist/components/avatarGroup/collectAvatarGroupChildren.js.map +1 -0
- package/dist/components/avatarGroup/useAvatarGroupItems.d.ts +9 -0
- package/dist/components/avatarGroup/useAvatarGroupItems.d.ts.map +1 -0
- package/dist/components/avatarGroup/useAvatarGroupItems.js +24 -0
- package/dist/components/avatarGroup/useAvatarGroupItems.js.map +1 -0
- package/dist/components/table/Table.d.ts +1 -0
- package/dist/components/table/Table.d.ts.map +1 -1
- package/dist/components/table/Table.js +2 -0
- package/dist/components/table/Table.js.map +1 -1
- package/dist/components/table/Table.stories.d.ts.map +1 -1
- package/dist/components/table/Table.stories.js +447 -77
- package/dist/components/table/Table.stories.js.map +1 -1
- package/dist/components/table/Table.test.js +1 -1
- package/dist/components/table/Table.test.js.map +1 -1
- package/dist/components/table/TableSettingsDropdown.d.ts.map +1 -0
- package/dist/components/table/{pagination/TableSettingsDropdown.js → TableSettingsDropdown.js} +6 -6
- package/dist/components/table/TableSettingsDropdown.js.map +1 -0
- package/dist/components/table/cellRenderers/SelectDropdownCellRenderer.d.ts +2 -5
- package/dist/components/table/cellRenderers/SelectDropdownCellRenderer.d.ts.map +1 -1
- package/dist/components/table/cellRenderers/SelectDropdownCellRenderer.js +7 -5
- package/dist/components/table/cellRenderers/SelectDropdownCellRenderer.js.map +1 -1
- package/dist/index.css +39 -5
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/avatarGroup/AvatarGroup.stories.tsx +218 -0
- package/src/components/avatarGroup/AvatarGroup.test.tsx +298 -0
- package/src/components/avatarGroup/AvatarGroup.tsx +127 -0
- package/src/components/avatarGroup/avatarGroup.scss +31 -0
- package/src/components/avatarGroup/avatarGroupOverflow.ts +29 -0
- package/src/components/avatarGroup/collectAvatarGroupChildren.ts +30 -0
- package/src/components/avatarGroup/useAvatarGroupItems.ts +39 -0
- package/src/components/heading/heading.scss +4 -4
- package/src/components/table/Table.stories.tsx +678 -265
- package/src/components/table/Table.test.tsx +1 -1
- package/src/components/table/Table.tsx +2 -0
- package/src/components/table/{pagination/TableSettingsDropdown.tsx → TableSettingsDropdown.tsx} +1 -1
- package/src/components/table/cellRenderers/SelectDropdownCellRenderer.tsx +42 -12
- package/src/global.scss +8 -8
- package/src/index.scss +1 -0
- package/src/index.ts +7 -0
- package/src/tokens.scss +2 -0
- package/tokens/json/Arbor.json +13 -1
- package/dist/components/table/pagination/TableSettingsDropdown.d.ts.map +0 -1
- package/dist/components/table/pagination/TableSettingsDropdown.js.map +0 -1
- /package/dist/components/table/{pagination/TableSettingsDropdown.d.ts → TableSettingsDropdown.d.ts} +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { Avatar, type AvatarSize } from 'Components/avatar/Avatar';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { partitionAvatarGroupOverflow, type AvatarGroupListOrder } from './avatarGroupOverflow';
|
|
5
|
+
import { collectAvatarsFromChildren } from './collectAvatarGroupChildren';
|
|
6
|
+
import { useAvatarGroupItems, type AvatarGroupItem } from './useAvatarGroupItems';
|
|
7
|
+
|
|
8
|
+
export type { AvatarGroupItem, AvatarGroupListOrder };
|
|
9
|
+
|
|
10
|
+
export type AvatarGroupOverflowCountProps = {
|
|
11
|
+
count: number;
|
|
12
|
+
overflowCountLabel?: string | ((count: number) => string);
|
|
13
|
+
className?: string;
|
|
14
|
+
presentAllUpdatesToScreenReader?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function resolveOverflowAriaLabel(
|
|
18
|
+
count: number,
|
|
19
|
+
overflowCountLabel?: string | ((c: number) => string),
|
|
20
|
+
): string {
|
|
21
|
+
if (typeof overflowCountLabel === 'function') {
|
|
22
|
+
return overflowCountLabel(count);
|
|
23
|
+
}
|
|
24
|
+
if (typeof overflowCountLabel === 'string') {
|
|
25
|
+
return overflowCountLabel;
|
|
26
|
+
}
|
|
27
|
+
return `plus ${count} more`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function AvatarGroupOverflowCount({
|
|
31
|
+
count,
|
|
32
|
+
overflowCountLabel,
|
|
33
|
+
className,
|
|
34
|
+
presentAllUpdatesToScreenReader = false,
|
|
35
|
+
}: AvatarGroupOverflowCountProps) {
|
|
36
|
+
return (
|
|
37
|
+
<span
|
|
38
|
+
role="status"
|
|
39
|
+
className={classNames('ds-avatar-group__overflow-count', className)}
|
|
40
|
+
aria-label={resolveOverflowAriaLabel(count, overflowCountLabel)}
|
|
41
|
+
aria-live={presentAllUpdatesToScreenReader ? 'polite' : undefined}
|
|
42
|
+
aria-atomic={presentAllUpdatesToScreenReader ? 'true' : undefined}
|
|
43
|
+
>
|
|
44
|
+
+
|
|
45
|
+
{count}
|
|
46
|
+
</span>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type AvatarGroupSharedProps = {
|
|
51
|
+
showMaxItems?: number;
|
|
52
|
+
listOrder?: AvatarGroupListOrder;
|
|
53
|
+
label?: string;
|
|
54
|
+
overflowCountLabel?: string | ((count: number) => string);
|
|
55
|
+
presentAllUpdatesToScreenReader?: boolean;
|
|
56
|
+
size?: AvatarSize;
|
|
57
|
+
className?: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type AvatarGroupProps = AvatarGroupSharedProps
|
|
61
|
+
& (
|
|
62
|
+
| { items: readonly AvatarGroupItem[]; children?: undefined }
|
|
63
|
+
| { children: React.ReactNode; items?: undefined }
|
|
64
|
+
)
|
|
65
|
+
& Omit<React.HTMLAttributes<HTMLUListElement>, 'children'>;
|
|
66
|
+
|
|
67
|
+
const AvatarGroupRoot = React.forwardRef<HTMLUListElement, AvatarGroupProps>(({
|
|
68
|
+
items,
|
|
69
|
+
children,
|
|
70
|
+
size: groupSize,
|
|
71
|
+
showMaxItems,
|
|
72
|
+
listOrder = 'ascending',
|
|
73
|
+
label,
|
|
74
|
+
overflowCountLabel,
|
|
75
|
+
presentAllUpdatesToScreenReader = false,
|
|
76
|
+
className,
|
|
77
|
+
...rest
|
|
78
|
+
}: AvatarGroupProps, ref) => {
|
|
79
|
+
const sourceItems = React.useMemo(() => {
|
|
80
|
+
if (children != null) {
|
|
81
|
+
return collectAvatarsFromChildren(children);
|
|
82
|
+
}
|
|
83
|
+
return items ?? [];
|
|
84
|
+
}, [children, items]);
|
|
85
|
+
|
|
86
|
+
const normalized = useAvatarGroupItems(sourceItems, groupSize);
|
|
87
|
+
const { visibleItems, overflowCount } = React.useMemo(
|
|
88
|
+
() => partitionAvatarGroupOverflow(normalized, showMaxItems, listOrder),
|
|
89
|
+
[normalized, showMaxItems, listOrder],
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<ul
|
|
94
|
+
ref={ref}
|
|
95
|
+
role="list"
|
|
96
|
+
className={classNames('ds-avatar-group', className)}
|
|
97
|
+
aria-label={label}
|
|
98
|
+
{...rest}
|
|
99
|
+
>
|
|
100
|
+
{visibleItems.map(entry => (
|
|
101
|
+
<li
|
|
102
|
+
key={entry.key}
|
|
103
|
+
className="ds-avatar-group__item"
|
|
104
|
+
>
|
|
105
|
+
<Avatar {...entry.avatarProps} />
|
|
106
|
+
</li>
|
|
107
|
+
))}
|
|
108
|
+
{overflowCount > 0
|
|
109
|
+
? (
|
|
110
|
+
<li className="ds-avatar-group__overflow">
|
|
111
|
+
<AvatarGroupOverflowCount
|
|
112
|
+
count={overflowCount}
|
|
113
|
+
overflowCountLabel={overflowCountLabel}
|
|
114
|
+
presentAllUpdatesToScreenReader={presentAllUpdatesToScreenReader}
|
|
115
|
+
/>
|
|
116
|
+
</li>
|
|
117
|
+
)
|
|
118
|
+
: null}
|
|
119
|
+
</ul>
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
AvatarGroupRoot.displayName = 'AvatarGroup';
|
|
124
|
+
|
|
125
|
+
export const AvatarGroup = Object.assign(AvatarGroupRoot, {
|
|
126
|
+
OverflowCount: AvatarGroupOverflowCount,
|
|
127
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
.ds-avatar-group {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: row;
|
|
4
|
+
align-items: center;
|
|
5
|
+
list-style: none;
|
|
6
|
+
margin: 0;
|
|
7
|
+
padding: 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.ds-avatar-group__item {
|
|
11
|
+
flex-shrink: 0;
|
|
12
|
+
|
|
13
|
+
&:not(:first-child) {
|
|
14
|
+
margin-inline-start: var(--avatar-group-overlap);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.ds-avatar-group__overflow {
|
|
19
|
+
flex-shrink: 0;
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
margin-inline-start: var(--avatar-group-overlap);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.ds-avatar-group__overflow-count {
|
|
26
|
+
display: inline-flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
font-size: var(--avatar-group-overflow-count-font-size);
|
|
29
|
+
font-weight: 600;
|
|
30
|
+
margin-inline-start: var(--spacing-small);
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AvatarGroupNormalizedEntry } from './useAvatarGroupItems';
|
|
2
|
+
|
|
3
|
+
export type AvatarGroupListOrder = 'ascending' | 'descending';
|
|
4
|
+
|
|
5
|
+
export type AvatarGroupOverflowPartition = {
|
|
6
|
+
visibleItems: AvatarGroupNormalizedEntry[];
|
|
7
|
+
overflowCount: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function partitionAvatarGroupOverflow(
|
|
11
|
+
items: readonly AvatarGroupNormalizedEntry[],
|
|
12
|
+
showMaxItems: number | undefined,
|
|
13
|
+
listOrder: AvatarGroupListOrder = 'ascending',
|
|
14
|
+
): AvatarGroupOverflowPartition {
|
|
15
|
+
const total = items.length;
|
|
16
|
+
const maxItems
|
|
17
|
+
= showMaxItems == null || !Number.isFinite(showMaxItems) || showMaxItems < 0
|
|
18
|
+
? total
|
|
19
|
+
: Math.floor(showMaxItems);
|
|
20
|
+
const visibleCount = Math.min(total, maxItems);
|
|
21
|
+
|
|
22
|
+
const overflowCount = total - visibleCount;
|
|
23
|
+
const startIndex = listOrder === 'ascending' ? 0 : overflowCount;
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
visibleItems: items.slice(startIndex, startIndex + visibleCount),
|
|
27
|
+
overflowCount,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Avatar, type AvatarProps } from 'Components/avatar/Avatar';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { AvatarGroupItem } from './useAvatarGroupItems';
|
|
4
|
+
|
|
5
|
+
export function collectAvatarsFromChildren(children: React.ReactNode): AvatarGroupItem[] {
|
|
6
|
+
const out: AvatarGroupItem[] = [];
|
|
7
|
+
|
|
8
|
+
const walk = (node: React.ReactNode) => {
|
|
9
|
+
React.Children.forEach(node, (child) => {
|
|
10
|
+
if (child == null || typeof child === 'boolean') {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (React.isValidElement(child) && child.type === React.Fragment) {
|
|
14
|
+
walk((child.props as { children?: React.ReactNode }).children);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (React.isValidElement<AvatarProps>(child) && child.type === Avatar) {
|
|
18
|
+
out.push(child);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (React.isValidElement(child) && process.env.NODE_ENV !== 'production') {
|
|
23
|
+
console.warn('AvatarGroup only collects `<Avatar />` children when using the children API.');
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
walk(children);
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Avatar, type AvatarProps, type AvatarSize } from 'Components/avatar/Avatar';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
export type AvatarGroupItem = React.ReactElement<AvatarProps> | AvatarProps;
|
|
5
|
+
|
|
6
|
+
export type AvatarGroupNormalizedEntry = {
|
|
7
|
+
key: string;
|
|
8
|
+
avatarProps: AvatarProps;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function useAvatarGroupItems(
|
|
12
|
+
items: readonly AvatarGroupItem[],
|
|
13
|
+
groupSize: AvatarSize | undefined,
|
|
14
|
+
): AvatarGroupNormalizedEntry[] {
|
|
15
|
+
return React.useMemo(
|
|
16
|
+
() =>
|
|
17
|
+
items.map((item, index) => {
|
|
18
|
+
if (React.isValidElement<AvatarProps>(item) && item.type === Avatar) {
|
|
19
|
+
return {
|
|
20
|
+
key: item.key != null ? String(item.key) : String(index),
|
|
21
|
+
avatarProps: {
|
|
22
|
+
...item.props,
|
|
23
|
+
size: groupSize ?? item.props.size,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const props = item as AvatarProps;
|
|
29
|
+
return {
|
|
30
|
+
key: String(index),
|
|
31
|
+
avatarProps: {
|
|
32
|
+
...props,
|
|
33
|
+
size: groupSize ?? props.size,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}),
|
|
37
|
+
[items, groupSize],
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
h1 {
|
|
20
|
-
&.ds-heading, .ds-editable-text__button, .ds-editable-text__input {
|
|
20
|
+
&.ds-heading, &.ds-heading .ds-heading__inner-container, .ds-editable-text__button, .ds-editable-text__input {
|
|
21
21
|
font-family: var(--type-headings-h1-family);
|
|
22
22
|
font-size: var(--type-headings-h1-size);
|
|
23
23
|
font-weight: var(--type-headings-h1-weight);
|
|
@@ -26,7 +26,7 @@ h1 {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
h2 {
|
|
29
|
-
&.ds-heading, .ds-editable-text__button, .ds-editable-text__input {
|
|
29
|
+
&.ds-heading, &.ds-heading .ds-heading__inner-container, .ds-editable-text__button, .ds-editable-text__input {
|
|
30
30
|
font-family: var(--type-headings-h2-family);
|
|
31
31
|
font-size: var(--type-headings-h2-size);
|
|
32
32
|
font-weight: var(--type-headings-h2-weight);
|
|
@@ -35,7 +35,7 @@ h2 {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
h3 {
|
|
38
|
-
&.ds-heading, .ds-editable-text__button, .ds-editable-text__input {
|
|
38
|
+
&.ds-heading, &.ds-heading .ds-heading__inner-container, .ds-editable-text__button, .ds-editable-text__input {
|
|
39
39
|
font-family: var(--type-headings-h3-family);
|
|
40
40
|
font-size: var(--type-headings-h3-size);
|
|
41
41
|
font-weight: var(--type-headings-h3-weight);
|
|
@@ -44,7 +44,7 @@ h3 {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
h4 {
|
|
47
|
-
&.ds-heading, .ds-editable-text__button, .ds-editable-text__input {
|
|
47
|
+
&.ds-heading, &.ds-heading .ds-heading__inner-container, .ds-editable-text__button, .ds-editable-text__input {
|
|
48
48
|
font-family: var(--type-headings-h4-family);
|
|
49
49
|
font-size: var(--type-headings-h4-size);
|
|
50
50
|
font-weight: var(--type-headings-h4-weight);
|