Skip to content

Commit 440f309

Browse files
authored
TagGroup: Avatar support (#3937)
1 parent 1ddcde7 commit 440f309

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

packages/@adobe/spectrum-css-temp/components/tags/index.css

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ governing permissions and limitations under the License.
2626
--spectrum-focus-ring-border-size: var(--spectrum-tag-border-size);
2727

2828
display: inline-grid;
29-
grid-template-columns: auto 1fr auto;
30-
grid-template-areas: "icon content action";
3129
align-items: center;
3230
box-sizing: border-box;
3331
position: relative;
@@ -52,7 +50,7 @@ governing permissions and limitations under the License.
5250
pointer-events: none;
5351
}
5452

55-
.spectrum-Tag-action {
53+
.spectrum-Tag-removeButton {
5654
grid-area: action;
5755
height: calc(var(--spectrum-tag-height) - (2 * var(--spectrum-tag-border-size)));
5856
width: var(--spectrum-global-dimension-size-300);
@@ -61,12 +59,19 @@ governing permissions and limitations under the License.
6159
.spectrum-Tag-cell {
6260
overflow: hidden;
6361
text-overflow: ellipsis;
64-
display: flex;
62+
display: grid;
6563
align-items: center;
64+
grid-template-columns: auto 1fr auto;
65+
grid-template-areas: "decoration content action";
6666
}
6767

6868
.spectrum-Tag-icon {
69-
grid-area: icon;
69+
grid-area: decoration;
70+
margin-inline-end: var(--spectrum-global-dimension-size-100);
71+
}
72+
73+
.spectrum-Tag-avatar {
74+
grid-area: decoration;
7075
margin-inline-end: var(--spectrum-global-dimension-size-100);
7176
}
7277

packages/@react-spectrum/tag/src/Tag.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ export function Tag<T>(props: SpectrumTagProps<T>) {
7171
<SlotProvider
7272
slots={{
7373
icon: {UNSAFE_className: classNames(styles, 'spectrum-Tag-icon'), size: 'XS'},
74-
text: {UNSAFE_className: classNames(styles, 'spectrum-Tag-content'), ...labelProps}
74+
text: {UNSAFE_className: classNames(styles, 'spectrum-Tag-content'), ...labelProps},
75+
avatar: {UNSAFE_className: classNames(styles, 'spectrum-Tag-avatar'), size: 'avatar-size-50'}
7576
}}>
7677
{typeof children === 'string' ? <Text>{children}</Text> : children}
7778
<ClearSlots>
78-
{allowsRemoving && <TagRemoveButton item={item} {...clearButtonProps} UNSAFE_className={classNames(styles, 'spectrum-Tag-action')} />}
79+
{allowsRemoving && <TagRemoveButton item={item} {...clearButtonProps} UNSAFE_className={classNames(styles, 'spectrum-Tag-removeButton')} />}
7980
</ClearSlots>
8081
</SlotProvider>
8182
</div>

packages/@react-spectrum/tag/stories/TagGroup.stories.tsx

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import {action} from '@storybook/addon-actions';
1414
import Audio from '@spectrum-icons/workflow/Audio';
15+
import {Avatar} from '@react-spectrum/avatar';
1516
import {ComponentMeta, ComponentStoryObj} from '@storybook/react';
1617
import {Item, SpectrumTagGroupProps, TagGroup} from '../src';
1718
import React, {useState} from 'react';
@@ -123,7 +124,43 @@ export const MaxRowsOnRemove: TagGroupStory = {
123124
storyName: 'maxRows + onRemove'
124125
};
125126

127+
export const WithAvatar: TagGroupStory = {
128+
args: {items: [{key: '1', label: 'Cool Person 1'}, {key: '2', label: 'Cool Person 2'}]},
129+
render: (args) => (
130+
<TagGroup aria-label="Tag group with avatars" {...args}>
131+
{(item: any) => (
132+
<Item key={item.key} textValue={item.label}>
133+
<Avatar src="https://i.imgur.com/kJOwAdv.png" alt="default Adobe avatar" />
134+
<Text>{item.label}</Text>
135+
</Item>
136+
)}
137+
</TagGroup>
138+
),
139+
storyName: 'with avatar'
140+
};
141+
142+
export const WithAvatarOnRemove: TagGroupStory = {
143+
render: (args) => <OnRemoveExample withAvatar {...args} />,
144+
storyName: 'with avatar + onRemove'
145+
};
146+
147+
export const WithAction: TagGroupStory = {
148+
args: {onAction: action('clear'), actionLabel: 'Clear'},
149+
storyName: 'with action'
150+
};
151+
152+
export const WithActionAndMaxRows: TagGroupStory = {
153+
args: {
154+
maxRows: 2,
155+
onAction: action('clear'),
156+
actionLabel: 'Clear'
157+
},
158+
decorators: [(Story) => <ResizableContainer>{<Story />}</ResizableContainer>],
159+
storyName: 'with action and maxRows'
160+
};
161+
126162
function OnRemoveExample(props) {
163+
let {withAvatar, ...otherProps} = props;
127164
let [items, setItems] = useState([
128165
{id: 1, label: 'Cool Tag 1'},
129166
{id: 2, label: 'Another cool tag'},
@@ -139,26 +176,14 @@ function OnRemoveExample(props) {
139176
};
140177

141178
return (
142-
<TagGroup allowsRemoving aria-label="Tag group with removable tags" items={items} onRemove={key => onRemove(key)} {...props}>
179+
<TagGroup allowsRemoving aria-label="Tag group with removable tags" items={items} onRemove={key => onRemove(key)} {...otherProps}>
143180
{(item: any) => (
144-
<Item>{item.label}</Item>
181+
<Item key={item.key} textValue={item.label}>
182+
{withAvatar && <Avatar src="https://i.imgur.com/kJOwAdv.png" alt="default Adobe avatar" />}
183+
<Text>{item.label}</Text>
184+
</Item>
145185
)}
146186
</TagGroup>
147187
);
148188
}
149189

150-
export const WithAction: TagGroupStory = {
151-
args: {onAction: action('clear'), actionLabel: 'Clear'},
152-
storyName: 'with action'
153-
};
154-
155-
export const WithActionAndMaxRows: TagGroupStory = {
156-
args: {
157-
maxRows: 2,
158-
onAction: action('clear'),
159-
actionLabel: 'Clear'
160-
},
161-
decorators: [(Story) => <ResizableContainer>{<Story />}</ResizableContainer>],
162-
storyName: 'with action and maxRows'
163-
};
164-

0 commit comments

Comments
 (0)