Skip to content
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

Tags: enhancement to incorporate chips styling #505

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions packages/react-components/src/components/Tag/Tag.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
.bcds-react-aria-Tag {
color: var(--typography-color-primary);
cursor: pointer;
border-radius: var(--layout-margin-hair);
border: var(--layout-border-width-small) solid;
display: flex;
align-items: center;
gap: var(--layout-margin-small);
font: var(--typography-regular-label);
padding: var(--layout-padding-hair) var(--layout-padding-small);
width: fit-content;
}
.bcds-react-aria-Tag .react-aria-Button {
Expand Down Expand Up @@ -63,6 +60,26 @@
border-color: var(--support-border-color-warning);
}

/* Tag style */
.bcds-react-aria-Tag.rectangular {
border-radius: var(--layout-border-radius-small);
}
.bcds-react-aria-Tag.circular {
border-radius: var(--layout-borderRadius-Circular, 9999px);
}

/* Tag size */
.bcds-react-aria-Tag.medium {
height: var(--layout-padding-xlarge);
padding: var(--layout-padding-hair) var(--layout-padding-medium);
gap: var(--layout-margin-medium);
}
.bcds-react-aria-Tag.small {
height: var(--layout-padding-large);
padding: var(--layout-padding-hair) var(--layout-padding-small);
gap: var(--layout-margin-small);
}

/* Selected */
.bcds-react-aria-Tag[data-selected] {
border-radius: var(--layout-border-radius-small);
Expand Down
19 changes: 17 additions & 2 deletions packages/react-components/src/components/Tag/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,27 @@ export interface TagProps extends ReactAriaTagProps {
| "green"
| "red"
| "yellow";
/**
* Style
*/
style?: "rectangular" | "circular";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style prop name already exists on RAC Tag, providing a method for injecting inline CSS into a component.

I'd suggest we rename this to variant (following the pattern of our other components, like Button.)

/**
* size
*/
size?: "small" | "medium";
}

export default function Tag({ color = "blue", icon, id, textValue }: TagProps) {
export default function Tag({
color = "blue",
style = "rectangular",
size = "small",
icon,
id,
textValue,
}: TagProps) {
return (
<ReactAriaTag
className={`bcds-react-aria-Tag ${color}`}
className={`bcds-react-aria-Tag ${color} ${style} ${size}`}
id={id}
textValue={textValue}
>
Expand Down
2 changes: 2 additions & 0 deletions packages/react-components/src/stories/Tag.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const SingleTag: Story = {
args: {
id: "single-tag",
color: "blue",
style: "rectangular",
size: "small",
textValue: "Single tag",
},
render: (args: TagProps) => (
Expand Down
20 changes: 20 additions & 0 deletions packages/react-components/src/stories/TagGroup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ A TagGroup should have either a `label` (rendered on top of the `TagList`) or an

<Canvas of={TagGroupStories.MultipleTags} />

### Styled tags

The `Tag` component can be passed a `style` prop with one of the following values:

- `rectangular`
- `circular`

If no value is passed, the tag style defaults to `rectangular`.

The `Tag` component can be passed a `size` prop with one of the following values:

- `small`
- `medium`

If no value is passed, the tag size defaults to `small`.

<Canvas of={TagGroupStories.MultipleTagsInEachStyle} />

### Coloured tags

The `Tag` component can be passed a `color` prop with one of the following values:
Expand All @@ -69,7 +87,9 @@ The `Tag` component can be passed a `color` prop with one of the following value
If no value is passed, the tag colour defaults to `blue`.

<Canvas of={TagGroupStories.MultipleTagsInEachColor} />
<Canvas of={TagGroupStories.MultipleCircularTagsInEachColor} />
<Canvas of={TagGroupStories.ColorsRemovable} />
<Canvas of={TagGroupStories.CircularColorsRemovable} />

### Tags with icons

Expand Down
105 changes: 105 additions & 0 deletions packages/react-components/src/stories/TagGroup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,118 @@ export const MultipleTagsInEachColor: Story = {
},
};

export const MultipleCircularTagsInEachColor: Story = {
render: (args) => {
return (
<TagGroup label="Colored circular tags" {...args}>
<TagList
items={[
{
id: "bc-blue-circular-tag",
color: "bc-blue",
style: "circular",
textValue: "BC Blue tag",
},
{
id: "bc-gold-circular-tag",
color: "bc-gold",
style: "circular",
textValue: "BC Gold tag",
},
{
id: "dark-circular-tag",
color: "dark",
style: "circular",
textValue: "Dark tag",
},
{
id: "blue-circular-tag",
color: "blue",
style: "circular",
textValue: "Blue tag",
},
{
id: "green-circular-tag",
color: "green",
style: "circular",
textValue: "Green tag",
},
{
id: "yellow-circular-tag",
color: "yellow",
style: "circular",
textValue: "Yellow tag",
},
{
id: "red-circular-tag",
color: "red",
style: "circular",
textValue: "Red tag",
},
{
id: "grey-circular-tag",
color: "grey",
style: "circular",
textValue: "Grey tag",
},
]}
/>
</TagGroup>
);
},
};

export const MultipleTagsInEachStyle: Story = {
render: (args) => {
return (
<TagGroup label="Styled tags" {...args}>
<TagList
items={[
{
id: "rectagular-small-tag",
style: "rectangular",
size: "small",
textValue: "Rectangular small tag",
},
{
id: "rectagular-medium-tag",
style: "rectangular",
size: "medium",
textValue: "Rectangular medium tag",
},
{
id: "circular-small-tag",
style: "circular",
size: "small",
textValue: "Circular small tag",
},
{
id: "circular-medium-tag",
style: "circular",
size: "medium",
textValue: "Circular medium tag",
},
]}
/>
</TagGroup>
);
},
};

export const ColorsRemovable: Story = {
...MultipleTagsInEachColor,
args: {
onRemove: () => alert("onRemove()"),
},
};

export const CircularColorsRemovable: Story = {
...MultipleCircularTagsInEachColor,
args: {
onRemove: () => alert("onRemove()"),
},
};

export const EmptyTagGroup: Story = {
render: () => (
<TagGroup aria-label="Empty tag group">
Expand Down
Loading