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

Support Tag icon on right #628

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion src/tag/tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Tag = ({
children,
interactive = false,
icon,
iconPosition = "left",
...otherProps
}: TagProps): JSX.Element => {
return (
Expand All @@ -17,8 +18,9 @@ export const Tag = ({
$interactive={interactive}
{...otherProps}
>
{icon}
{iconPosition === "left" && icon}
<Label>{children}</Label>
{iconPosition === "right" && icon}
</Wrapper>
);
};
1 change: 1 addition & 0 deletions src/tag/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export interface TagProps extends React.HTMLAttributes<HTMLElement> {
type: TagType;
colorType?: TagColorType | undefined;
icon?: JSX.Element | undefined;
iconPosition?: "left" | "right";
interactive?: boolean | undefined;
}
7 changes: 7 additions & 0 deletions stories/tag/props-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ const DATA: ApiTableSectionProps[] = [
description: "A component to be displayed as the icon",
propTypes: ["JSX.Element"],
},
{
name: "iconPosition",
description:
"The position of the icon relative to the label text",
propTypes: [`"left"`, `"right"`],
defaultValue: `"left"`,
},
{
name: "interactive",
description: <>Specifies if the tag is interactive</>,
Expand Down
19 changes: 9 additions & 10 deletions stories/tag/tag.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,21 @@ export const WithIcon: StoryObj<Component> = {
return (
<Wrapper>
<Tag
type="solid"
colorType="blue"
type="outline"
icon={<PlusCircleFillIcon />}
data-testid="first-example"
interactive={true}
interactive
onClick={() => window.alert("Interactive tag clicked!")}
>
Some Label
Icon on left
</Tag>
<Tag
type="outline"
colorType="blue"
icon={<PlaceholderIcon />}
data-testid="second-example"
type="solid"
icon={<PlusCircleFillIcon />}
iconPosition="right"
interactive
onClick={() => window.alert("Interactive tag clicked!")}
>
Some Label
Icon on right
</Tag>
</Wrapper>
);
Expand Down
Loading