Skip to content

Commit

Permalink
feat(tag): introduce size prop to Tag component (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmatrhd authored Jun 25, 2024
1 parent 2be0106 commit ff46faa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/apsara-ui/src/Tag/Tag.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export const Profile = Icons["profile"];
type: { summary: "ReactNode" },
},
},
size: {
description: "Size of the tag",
control: { type: "select", options: ["small", "medium", "large"] },
table: {
type: { summary: ["small", "medium", "large"] },
defaultValue: { summary: "medium" },
},
}
}}
/>

Expand Down
17 changes: 15 additions & 2 deletions packages/apsara-ui/src/Tag/Tag.styles.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import styled from "styled-components";
import { textStyles } from "../mixin";
import { TagSize } from "./Tag";

export const StyledTag = styled("div")<{ type: "round" | "rect"; color: string; closable: boolean; icon: boolean }>`
const fontSizeMap: Record<TagSize, string> = {
small: "9px",
medium: "11px",
large: "14px",
};

export const StyledTag = styled("div") <{
type: "round" | "rect";
color: string;
closable: boolean;
icon: boolean;
size: TagSize;
}>`
box-sizing: border-box;
display: inline-flex;
align-items: center;
${({ theme }) => textStyles("11px", theme?.tag?.text, "0.11px", "normal")}
${({ theme, size }) => textStyles(fontSizeMap[size], theme?.tag?.text, "0.11px", "normal")}
border-radius: ${({ type }) => (type === "round" ? "10.5px" : "2px")};
border-color: ${({ color }) => color};
border-width: 1px;
Expand Down
6 changes: 5 additions & 1 deletion packages/apsara-ui/src/Tag/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Colors from "../Colors";

const Cross = Icons["cross"];

export type TagSize = "small" | "medium" | "large";

type TagProps = {
children?: ReactNode;
type?: "round" | "rect";
Expand All @@ -14,6 +16,7 @@ type TagProps = {
icon?: ReactNode;
className?: string;
style?: React.CSSProperties;
size: TagSize;
};

const Tag = ({
Expand All @@ -23,13 +26,14 @@ const Tag = ({
closable = false,
closeIcon,
icon,
size = "medium",
...props
}: TagProps) => {
const [visible, setVisible] = useState(true);
if (!visible) return null;
return (
<TagWrapper>
<StyledTag {...props} type={type} color={color} closable={closable} icon={icon ? true : false}>
<StyledTag {...props} type={type} color={color} closable={closable} icon={icon ? true : false} size={size}>
<span className="tag_icon">{icon}</span>
<span className="tag_content">{children}</span>
{closable && (
Expand Down

0 comments on commit ff46faa

Please sign in to comment.