forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(react-tags-preview): update Tag stories with better a11y (micro…
…soft#28909) * stories * md * Update packages/react-components/react-tags-preview/stories/InteractionTag/InteractionTagAppearance.stories.tsx Co-authored-by: Bernardo Sunderhus <bernardo.sunderhus@gmail.com> * Update packages/react-components/react-tags-preview/stories/InteractionTag/InteractionTagAppearance.stories.tsx Co-authored-by: Bernardo Sunderhus <bernardo.sunderhus@gmail.com> * Update packages/react-components/react-tags-preview/stories/InteractionTag/InteractionTagAppearance.stories.tsx Co-authored-by: Bernardo Sunderhus <bernardo.sunderhus@gmail.com> --------- Co-authored-by: Bernardo Sunderhus <bernardo.sunderhus@gmail.com>
- Loading branch information
1 parent
7c278ca
commit b7191ef
Showing
10 changed files
with
106 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 27 additions & 34 deletions
61
...ct-components/react-tags-preview/stories/InteractionTag/InteractionTagDismiss.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,43 @@ | ||
import * as React from 'react'; | ||
import { Avatar, makeStyles } from '@fluentui/react-components'; | ||
import { CalendarMonthRegular } from '@fluentui/react-icons'; | ||
|
||
import { InteractionTag, InteractionTagPrimary, InteractionTagSecondary } from '@fluentui/react-tags-preview'; | ||
import { | ||
InteractionTag, | ||
InteractionTagPrimary, | ||
InteractionTagSecondary, | ||
TagGroup, | ||
TagGroupProps, | ||
} from '@fluentui/react-tags-preview'; | ||
|
||
const useContainerStyles = makeStyles({ | ||
root: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
rowGap: '10px', | ||
}, | ||
}); | ||
const initialTags = [ | ||
{ value: '1', children: 'Tag 1' }, | ||
{ value: '2', children: 'Tag 2' }, | ||
{ value: '3', children: 'Tag 3' }, | ||
]; | ||
|
||
export const Dismiss = () => { | ||
const containerStyles = useContainerStyles(); | ||
const [visibleTags, setVisibleTags] = React.useState(initialTags); | ||
const removeItem: TagGroupProps['onDismiss'] = (_e, { dismissedTagValue }) => { | ||
setVisibleTags([...visibleTags].filter(tag => tag.value !== dismissedTagValue)); | ||
}; | ||
|
||
return ( | ||
<div className={containerStyles.root}> | ||
<InteractionTag> | ||
<InteractionTagPrimary hasSecondaryAction>Primary text</InteractionTagPrimary> | ||
<InteractionTagSecondary /> | ||
</InteractionTag> | ||
<InteractionTag> | ||
<InteractionTagPrimary icon={<CalendarMonthRegular />} hasSecondaryAction> | ||
Primary text | ||
</InteractionTagPrimary> | ||
<InteractionTagSecondary /> | ||
</InteractionTag> | ||
<InteractionTag> | ||
<InteractionTagPrimary | ||
media={<Avatar name="Katri Athokas" badge={{ status: 'busy' }} />} | ||
secondaryText="Secondary text" | ||
hasSecondaryAction | ||
> | ||
Primary text | ||
</InteractionTagPrimary> | ||
<InteractionTagSecondary /> | ||
</InteractionTag> | ||
</div> | ||
<TagGroup onDismiss={removeItem}> | ||
{visibleTags.map(tag => ( | ||
<InteractionTag value={tag.value} key={tag.value}> | ||
<InteractionTagPrimary hasSecondaryAction>{tag.children}</InteractionTagPrimary> | ||
<InteractionTagSecondary aria-label={`${tag.children}, remove`} /> | ||
</InteractionTag> | ||
))} | ||
</TagGroup> | ||
); | ||
}; | ||
|
||
Dismiss.storyName = 'Dismiss'; | ||
Dismiss.parameters = { | ||
docs: { | ||
description: { | ||
story: 'An InteractionTag can have a button that dismisses it', | ||
story: | ||
'An InteractionTag can have a secondary action that is usually dismiss. TagGroup can handle dismiss for a collection of tags.', | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 20 additions & 26 deletions
46
packages/react-components/react-tags-preview/stories/Tag/TagDismiss.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,35 @@ | ||
import * as React from 'react'; | ||
import { Avatar, makeStyles } from '@fluentui/react-components'; | ||
import { CalendarMonthRegular } from '@fluentui/react-icons'; | ||
import { Tag, TagGroup, TagGroupProps } from '@fluentui/react-tags-preview'; | ||
|
||
import { Tag } from '@fluentui/react-tags-preview'; | ||
|
||
const useContainerStyles = makeStyles({ | ||
root: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
rowGap: '10px', | ||
}, | ||
}); | ||
const initialTags = [ | ||
{ value: '1', children: 'Tag 1' }, | ||
{ value: '2', children: 'Tag 2' }, | ||
{ value: '3', children: 'Tag 3' }, | ||
]; | ||
|
||
export const Dismiss = () => { | ||
const containerStyles = useContainerStyles(); | ||
const [visibleTags, setVisibleTags] = React.useState(initialTags); | ||
const removeItem: TagGroupProps['onDismiss'] = (_e, { dismissedTagValue }) => { | ||
setVisibleTags([...visibleTags].filter(tag => tag.value !== dismissedTagValue)); | ||
}; | ||
|
||
return ( | ||
<div className={containerStyles.root}> | ||
<Tag dismissible>Primary text</Tag> | ||
<Tag dismissible icon={<CalendarMonthRegular />}> | ||
Primary text | ||
</Tag> | ||
<Tag | ||
dismissible | ||
media={<Avatar name="Katri Athokas" badge={{ status: 'busy' }} />} | ||
secondaryText="Secondary text" | ||
> | ||
Primary text | ||
</Tag> | ||
</div> | ||
<TagGroup onDismiss={removeItem}> | ||
{visibleTags.map(tag => ( | ||
<Tag dismissible dismissIcon={{ 'aria-label': 'remove' }} value={tag.value} key={tag.value}> | ||
{tag.children} | ||
</Tag> | ||
))} | ||
</TagGroup> | ||
); | ||
}; | ||
|
||
Dismiss.storyName = 'Dismiss'; | ||
Dismiss.parameters = { | ||
docs: { | ||
description: { | ||
story: 'A tag can have a button that dismisses it', | ||
story: | ||
'A tag can have a dismiss icon and become focusable. TagGroup can handle dismiss for a collection of tags.', | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters