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

feat(ui) Tag 컴포넌트에 className prop을 추가합니다. #232

Merged
merged 2 commits into from
Dec 26, 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
5 changes: 5 additions & 0 deletions .changeset/short-hats-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sopt-makers/ui': patch
---

Tag 컴포넌트에 ClassName Prop을 추가해 커스텀 스타일이 가능케 합니다.
35 changes: 12 additions & 23 deletions apps/docs/src/stories/Tag.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
import { Meta, StoryObj } from "@storybook/react";
import { Meta, StoryObj } from '@storybook/react';

import { type HTMLAttributes } from "react";
import { Tag } from "@sopt-makers/ui";

interface TagOwnProps extends HTMLAttributes<HTMLSpanElement> {
children?: string;
size?: "sm" | "md" | "lg";
shape?: "rect" | "pill";
variant?: "default" | "primary" | "secondary";
type?: "solid" | "line";
}

type TagStoryProps = TagOwnProps & { children: string };
import { Tag, TagProps } from '@sopt-makers/ui';

export default {
title: "Components/Tag",
title: 'Components/Tag',
component: Tag,
tags: ["autodocs"],
tags: ['autodocs'],
argTypes: {
size: { control: 'radio', options: ['sm', 'md', 'lg'] },
shape: { control: 'radio', options: ['rect', 'pill'] },
variant: { control: 'radio', options: ['default', 'primary', 'secondary'] },
type: { control: 'radio', options: ['solid', 'line'] },
}
} as Meta<TagStoryProps>;
},
} as Meta<TagProps>;

// 기본 태그 스토리
export const Default: StoryObj<TagStoryProps> = {
export const Default: StoryObj<TagProps> = {
args: {
children: "Default Tag",
size: "sm",
shape: "rect",
variant: "default",
type: "solid",
children: 'Default Tag',
size: 'sm',
shape: 'rect',
variant: 'default',
type: 'solid',
},
};
5 changes: 3 additions & 2 deletions packages/ui/Tag/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import createTagStyle from './utils';

export interface TagProps extends HTMLAttributes<HTMLDivElement> {
children?: React.ReactNode;
className?: string;
size?: 'sm' | 'md' | 'lg';
shape?: 'rect' | 'pill';
variant?: 'default' | 'primary' | 'secondary';
type?: 'solid' | 'line';
}

export const Tag = forwardRef<HTMLDivElement, TagProps>((props, forwardedRef) => {
const { children, size = 'sm', shape = 'rect', variant = 'default', type = 'solid', ...restProps } = props;
const { children, className, size = 'sm', shape = 'rect', variant = 'default', type = 'solid', ...restProps } = props;
const style = createTagStyle(type, variant, shape, size);

return (
<div className={`${S.root} ${style}`} ref={forwardedRef} {...restProps}>
<div className={`${S.root} ${style} ${className}`} ref={forwardedRef} {...restProps}>
{children}
</div>
);
Expand Down
11 changes: 3 additions & 8 deletions packages/ui/Tag/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import type {
TagShapeTheme,
TagSizeTheme,
TagTypeTheme,
TagVariantTheme,
} from "./types";
import { sprinkles } from "./style.css";
import type { TagShapeTheme, TagSizeTheme, TagTypeTheme, TagVariantTheme } from './types';
import { sprinkles } from './style.css';

function createTagStyle(
typeTheme: TagTypeTheme,
variantTheme: TagVariantTheme,
shapeTheme: TagShapeTheme,
sizeTheme: TagSizeTheme
sizeTheme: TagSizeTheme,
) {
return sprinkles({
backgroundColor: `${variantTheme}-${typeTheme}`,
Expand Down
Loading