-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore: Add tag group component #29387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b4ecf11
add tag group component
jsartisan 8c2b1d6
update yarn.lock
jsartisan d634241
fix border-radius
jsartisan e38a3a5
refactor styles.css
jsartisan ee9d67c
code review fixes
jsartisan ad30334
code review fixes
jsartisan c0118b0
code review fixes
jsartisan bfe924b
code review fixes
jsartisan b1c12f2
fix types
jsartisan 3976aaa
fix types
jsartisan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
app/client/packages/design-system/widgets/src/components/TagGroup/index.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from "./src"; |
36 changes: 36 additions & 0 deletions
36
app/client/packages/design-system/widgets/src/components/TagGroup/src/Tag.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import clsx from "clsx"; | ||
| import React from "react"; | ||
| import { | ||
| Tag as HeadlessTag, | ||
| Button as HeadlessButton, | ||
| } from "react-aria-components"; | ||
| import { getTypographyClassName } from "@design-system/theming"; | ||
| import type { TagProps as HeadlessTagProps } from "react-aria-components"; | ||
|
|
||
| import styles from "./styles.module.css"; | ||
| import { CloseIcon } from "../../Modal/src/CloseIcon"; | ||
|
KelvinOm marked this conversation as resolved.
|
||
|
|
||
| function Tag({ children, ...props }: HeadlessTagProps) { | ||
| const textValue = typeof children === "string" ? children : undefined; | ||
|
|
||
| return ( | ||
| <HeadlessTag | ||
| textValue={textValue} | ||
| {...props} | ||
| className={clsx(styles["tag"], getTypographyClassName("footnote"))} | ||
| > | ||
| {({ allowsRemoving }) => ( | ||
| <> | ||
| <span>{children}</span> | ||
| {allowsRemoving && ( | ||
| <HeadlessButton slot="remove"> | ||
| <CloseIcon /> | ||
| </HeadlessButton> | ||
| )} | ||
| </> | ||
| )} | ||
| </HeadlessTag> | ||
| ); | ||
| } | ||
|
|
||
| export { Tag }; | ||
66 changes: 66 additions & 0 deletions
66
app/client/packages/design-system/widgets/src/components/TagGroup/src/TagGroup.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import React from "react"; | ||
| import { | ||
| Label as HeadlessLabel, | ||
| TagGroup as HeadlessTagGroup, | ||
| TagList as HeadlessTagList, | ||
| Text as HeadlessText, | ||
| } from "react-aria-components"; | ||
| import type { | ||
| TagGroupProps as HeadlessTagGroupProps, | ||
| TagListProps as HeadlessTagListProps, | ||
| } from "react-aria-components"; | ||
|
|
||
| import { Text } from "../../Text"; | ||
| import styles from "./styles.module.css"; | ||
| import { getTypographyClassName } from "@design-system/theming"; | ||
|
|
||
| interface TagGroupProps<T> | ||
| extends Omit<HeadlessTagGroupProps, "children">, | ||
| Pick<HeadlessTagListProps<T>, "items" | "children" | "renderEmptyState"> { | ||
| label?: string; | ||
| description?: string; | ||
| errorMessage?: string; | ||
| } | ||
|
|
||
| function TagGroup<T extends object>(props: TagGroupProps<T>) { | ||
| const { | ||
| children, | ||
| description, | ||
| errorMessage, | ||
| items, | ||
| label, | ||
| renderEmptyState, | ||
| ...rest | ||
| } = props; | ||
|
|
||
| return ( | ||
| <HeadlessTagGroup {...rest} className={styles["tag-group"]}> | ||
| {Boolean(label) && <HeadlessLabel>{<Text>{label}</Text>}</HeadlessLabel>} | ||
| <HeadlessTagList | ||
| className={styles["tag-list"]} | ||
| items={items} | ||
| renderEmptyState={renderEmptyState} | ||
| > | ||
| {children} | ||
| </HeadlessTagList> | ||
| {Boolean(description) && ( | ||
| <HeadlessText | ||
| className={getTypographyClassName("footnote")} | ||
| slot="description" | ||
| > | ||
| {description} | ||
| </HeadlessText> | ||
| )} | ||
| {Boolean(errorMessage) && ( | ||
| <HeadlessText | ||
| className={getTypographyClassName("footnote")} | ||
| slot="errorMessage" | ||
| > | ||
| {errorMessage} | ||
| </HeadlessText> | ||
| )} | ||
| </HeadlessTagGroup> | ||
| ); | ||
| } | ||
|
|
||
| export { TagGroup }; |
2 changes: 2 additions & 0 deletions
2
app/client/packages/design-system/widgets/src/components/TagGroup/src/index.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { TagGroup } from "./TagGroup"; | ||
| export { Tag } from "./Tag"; |
106 changes: 106 additions & 0 deletions
106
app/client/packages/design-system/widgets/src/components/TagGroup/src/styles.module.css
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| .tag-group { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--inner-spacing-2); | ||
|
|
||
| /** | ||
| * ---------------------------------------------------------------------------- | ||
| * ERROR MESSAGE | ||
| *----------------------------------------------------------------------------- | ||
| */ | ||
| [slot="errorMessage"] { | ||
| color: var(--color-fg-negative); | ||
| } | ||
| } | ||
|
|
||
| .tag-list { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| gap: var(--inner-spacing-2); | ||
| } | ||
|
|
||
| .tag { | ||
| height: var(--sizing-6); | ||
| color: var(--color-fg); | ||
| background-color: var(--color-bg-neutral-subtle); | ||
| border-radius: var(--border-radius-1); | ||
| padding: 0 var(--inner-spacing-2); | ||
| outline: none; | ||
| cursor: default; | ||
| display: flex; | ||
| align-items: center; | ||
| transition: border-color 200ms; | ||
| overflow: hidden; | ||
|
|
||
| &:has([slot="remove"]) { | ||
| padding-inline-end: 0; | ||
| } | ||
|
|
||
| /** | ||
| * ---------------------------------------------------------------------------- | ||
| * HOVERED | ||
| *----------------------------------------------------------------------------- | ||
| */ | ||
| &[data-hovered] { | ||
| background-color: var(--color-bg-neutral-subtle-hover); | ||
| } | ||
|
|
||
| &[data-focus-visible] { | ||
| outline: 2px solid var(--color-bd-focus); | ||
| outline-offset: 2px; | ||
| } | ||
|
|
||
| /** | ||
| * ---------------------------------------------------------------------------- | ||
| * SELECTED TAG | ||
| *----------------------------------------------------------------------------- | ||
| */ | ||
| &[data-selected] { | ||
| border-color: var(--color-bd-neutral); | ||
| background: var(--color-bg-neutral); | ||
| color: var(--color-fg-on-neutral); | ||
| } | ||
|
|
||
| /** | ||
| * ---------------------------------------------------------------------------- | ||
| * REMOVE BUTTON | ||
| *----------------------------------------------------------------------------- | ||
| */ | ||
| [slot="remove"] { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| height: var(--sizing-6); | ||
| width: var(--sizing-6); | ||
| background: none; | ||
| border: none; | ||
| padding: 0; | ||
| margin-inline-start: var(--inner-spacing-1); | ||
| color: var(--color-fg); | ||
| transition: color 200ms; | ||
| outline: none; | ||
| font-size: 0.95em; | ||
|
|
||
| &[data-hovered] { | ||
| background: var(--color-bg-neutral-subtle-hover); | ||
| } | ||
|
|
||
| svg { | ||
| width: 1em; | ||
| height: 1em; | ||
| } | ||
|
|
||
| &[data-hovered] { | ||
| color: var(--remove-button-color-hovered); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * ---------------------------------------------------------------------------- | ||
| * DISABLED TAG | ||
| *----------------------------------------------------------------------------- | ||
| */ | ||
| &[data-disabled] { | ||
| opacity: var(--opacity-disabled); | ||
| } | ||
| } |
157 changes: 157 additions & 0 deletions
157
...ages/design-system/widgets/src/components/TagGroup/stories/TagGroup.stories.mdx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| import { TagGroup, Tag } from "@design-system/widgets"; | ||
| import { Canvas, Meta, Story, ArgsTable } from "@storybook/addon-docs"; | ||
|
|
||
| <Meta | ||
| title="Design-system/Widgets/TagGroup" | ||
| component={TagGroup} | ||
| args={{ | ||
| onRemove: undefined, | ||
| children: ( | ||
| <> | ||
| <Tag id="value-1">Value 1</Tag> | ||
| <Tag id="value-2">Value 2</Tag> | ||
| <Tag id="value-3">Value 3</Tag> | ||
| <Tag id="value-4">Value 4</Tag> | ||
| </> | ||
| ), | ||
| }} | ||
| /> | ||
|
|
||
| export const Template = (args) => <TagGroup {...args} />; | ||
|
KelvinOm marked this conversation as resolved.
|
||
|
|
||
| # Tag Group | ||
|
|
||
| Tag Group is a group of checkboxes that can be selected together. | ||
|
|
||
| <Canvas> | ||
| <Story name="Tag Group">{Template.bind({})}</Story> | ||
| </Canvas> | ||
|
|
||
| ## Props ( Tag Group ) | ||
|
|
||
| <ArgsTable of={TagGroup} /> | ||
|
|
||
| ## Props ( Tag ) | ||
|
|
||
| <ArgsTable of={Tag} /> | ||
|
|
||
| # Single Selection Mode | ||
|
|
||
| Tag Group can be configured to allow only one selection at a time with the `selectionMode` prop. | ||
|
|
||
| <Canvas> | ||
| <Story | ||
| name="Single Selection Mode" | ||
| args={{ | ||
| selectionMode: "single", | ||
| }} | ||
| > | ||
| {Template.bind({})} | ||
| </Story> | ||
| </Canvas> | ||
|
|
||
| # Multiple Selection Mode | ||
|
|
||
| Tag Group can be configured to allow multiple selections at a time with the `selectionMode` prop with value `multiple`. | ||
|
|
||
| <Canvas> | ||
|
KelvinOm marked this conversation as resolved.
|
||
| <Story | ||
| name="Multiple Selection Mode" | ||
| args={{ | ||
| selectionMode: "multiple", | ||
| }} | ||
| > | ||
| {Template.bind({})} | ||
| </Story> | ||
| </Canvas> | ||
|
|
||
| ## Removing Tags | ||
|
|
||
| Tags can be removed with the `onRemove` prop. The Tag will render a close icon when this prop is provided on the TagGroup. | ||
|
|
||
| <Canvas> | ||
| <Story | ||
| name="Removing Tags" | ||
| args={{ | ||
| onRemove: (id) => { | ||
| console.log(id); | ||
| }, | ||
| }} | ||
| > | ||
| {Template.bind({})} | ||
| </Story> | ||
| </Canvas> | ||
|
|
||
| ## Disabled Tags | ||
|
|
||
| Tags can be disabled with the `disabledKeys` prop. | ||
|
|
||
| <Canvas> | ||
| <Story | ||
| name="Disabled Tags" | ||
| args={{ | ||
| selectionMode: "multiple", | ||
| disabledKeys: ["value-2"], | ||
| }} | ||
| > | ||
| {Template.bind({})} | ||
| </Story> | ||
| </Canvas> | ||
|
|
||
| ## Empty State | ||
|
|
||
| <Canvas> | ||
| <Story | ||
| name="Empty State" | ||
| args={{ | ||
| renderEmptyState: () => "No categories.", | ||
| children: undefined, | ||
| }} | ||
| > | ||
| {Template.bind({})} | ||
| </Story> | ||
| </Canvas> | ||
|
|
||
| ## With Label | ||
|
|
||
| <Canvas> | ||
| <Story | ||
| name="With Label" | ||
| args={{ | ||
| label: "Categories", | ||
| selectionMode: "multiple", | ||
| }} | ||
| > | ||
| {Template.bind({})} | ||
| </Story> | ||
| </Canvas> | ||
|
|
||
| ## With Description | ||
|
|
||
| <Canvas> | ||
| <Story | ||
| name="With Description" | ||
| args={{ | ||
| label: "Categories", | ||
| description: "Select one or more categories.", | ||
| selectionMode: "multiple", | ||
| }} | ||
| > | ||
| {Template.bind({})} | ||
| </Story> | ||
| </Canvas> | ||
|
|
||
| ## With Error | ||
|
|
||
| <Canvas> | ||
| <Story | ||
| name="With Error" | ||
| args={{ | ||
| label: "Categories", | ||
| selectionMode: "multiple", | ||
| errorMessage: "Please select at least one category.", | ||
| }} | ||
| > | ||
| {Template.bind({})} | ||
| </Story> | ||
| </Canvas> | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.