Skip to content

Commit

Permalink
Tag Improvements (#519)
Browse files Browse the repository at this point in the history
- Added Square tag variant
- Added grey colored tag

Signed-off-by: Benjamin Perez <[email protected]>
  • Loading branch information
bexsoft authored Oct 4, 2023
1 parent a9c166e commit 94284e7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
52 changes: 48 additions & 4 deletions src/components/Tag/Tag.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,27 @@ export default {
argTypes: {},
} as Meta<typeof Tag>;

const Template: Story<TagProps> = ({ label, id, onDelete, sx, color }) => {
const Template: Story<TagProps> = ({
label,
id,
onDelete,
sx,
color,
square,
}) => {
return (
<StoryThemeProvider>
<GlobalStyles />
<Tag label={label} color={color} id={id} sx={sx} />
<Tag label={label} color={color} id={id} sx={sx} square={square} />
&nbsp;
<Tag label={label} color={color} id={id} onDelete={onDelete} sx={sx}>
<Tag
label={label}
color={color}
id={id}
onDelete={onDelete}
sx={sx}
square={square}
>
{" "}
with on Delete
</Tag>
Expand All @@ -47,12 +61,20 @@ const Template: Story<TagProps> = ({ label, id, onDelete, sx, color }) => {
onDelete={onDelete}
sx={sx}
variant={"outlined"}
square={square}
>
{" "}
Outlined
</Tag>
&nbsp;
<Tag label={label} color={color} id={id} sx={sx} icon={<AddIcon />}>
<Tag
label={label}
color={color}
id={id}
sx={sx}
icon={<AddIcon />}
square={square}
>
{" "}
With an Icon
</Tag>
Expand All @@ -64,6 +86,7 @@ const Template: Story<TagProps> = ({ label, id, onDelete, sx, color }) => {
sx={sx}
variant={"outlined"}
icon={<AddIcon />}
square={square}
>
{" "}
Outlined With an Icon
Expand Down Expand Up @@ -112,6 +135,16 @@ Warn.args = {
},
};

export const Grey = Template.bind({});
Grey.args = {
label: "A Tag",
id: "tag-test",
color: "grey",
onDelete: () => {
alert("Clicked Delete Button!");
},
};

export const Ok = Template.bind({});
Ok.args = {
label: "A Tag",
Expand All @@ -122,6 +155,17 @@ Ok.args = {
},
};

export const Square = Template.bind({});
Square.args = {
label: "A Tag",
id: "tag-test",
color: "default",
onDelete: () => {
alert("Clicked Delete Button!");
},
square: true,
};

export const CustomStyles = Template.bind({});
CustomStyles.args = {
label: "A Tag",
Expand Down
16 changes: 12 additions & 4 deletions src/components/Tag/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import AlertCloseIcon from "../Icons/AlertCloseIcon";
import { lightColors } from "../../global/themes";

const TagBase = styled.span<TagConstructProps>(
({ theme, color, variant, sx }) => {
({ theme, color, variant, square, sx }) => {
return {
position: "relative",
margin: 0,
userSelect: "none",
appearance: "none",
maxWidth: "100%",
fontFamily: "'Inter', sans-serif",
fontSize: 14,
fontSize: 13,
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
Expand All @@ -43,7 +43,7 @@ const TagBase = styled.span<TagConstructProps>(
variant === "regular"
? get(theme, `tag.${color}.background`, lightColors.mainBlue)
: "transparent",
borderRadius: 16,
borderRadius: square ? 3 : 16,
whiteSpace: "nowrap",
cursor: "default",
outline: 0,
Expand Down Expand Up @@ -104,10 +104,18 @@ const Tag: FC<TagProps & React.HTMLAttributes<HTMLSpanElement>> = ({
label,
variant = "regular",
icon,
square = false,
...props
}) => {
return (
<TagBase id={id} color={color} sx={sx} variant={variant} {...props}>
<TagBase
id={id}
color={color}
sx={sx}
variant={variant}
square={square}
{...props}
>
{icon}
<span>
{label}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Tag/Tag.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ export interface TagMainProps {
}

export interface TagConstructProps {
color?: "default" | "secondary" | "warn" | "alert" | "ok";
color?: "default" | "secondary" | "warn" | "alert" | "ok" | "grey";
sx?: CSSObject;
variant?: "regular" | "outlined";
square?: boolean;
}

export type TagProps = TagMainProps & TagConstructProps;
1 change: 1 addition & 0 deletions src/global/global.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ export interface TagThemeProps {
warn: TagVariantProps;
alert: TagVariantProps;
ok: TagVariantProps;
grey: TagVariantProps;
}

interface SnackBarColorElements {
Expand Down
10 changes: 10 additions & 0 deletions src/global/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ export const lightTheme: ThemeDefinitionProps = {
label: lightColors.defaultFontColor,
deleteColor: lightColors.defaultFontColor,
},
grey: {
background: lightColors.actionDisabledGrey,
label: lightColors.defaultFontColor,
deleteColor: lightColors.defaultFontColor,
},
},
snackbar: {
error: {
Expand Down Expand Up @@ -959,6 +964,11 @@ export const darkTheme: ThemeDefinitionProps = {
label: darkColors.dark,
deleteColor: darkColors.dark,
},
grey: {
background: darkColors.disabledBGGrey,
label: darkColors.mainWhite,
deleteColor: darkColors.mainWhite,
},
},
snackbar: {
error: {
Expand Down

0 comments on commit 94284e7

Please sign in to comment.