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: Badge 구현 #6

Merged
merged 8 commits into from
Oct 1, 2023
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
34 changes: 34 additions & 0 deletions src/components/Badge/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Meta, StoryObj } from '@storybook/react';

import { IcGroundLine } from '@/style';

import { Badge } from './Badge';

const meta: Meta<typeof Badge> = {
title: 'Atoms/Badge',
component: Badge,
parameters: {
layout: 'centered',
},
};
export default meta;

const BadgeStory = ({ ...badgeProps }) => {
return <Badge {...badgeProps} />;
};

type Story = StoryObj<typeof Badge>;
export const withIcon: Story = {
args: {
children: 'Badge',
leftIcon: <IcGroundLine />,
},
render: BadgeStory,
};

export const withoutIcon: Story = {
args: {
children: 'Badge',
},
render: BadgeStory,
};
19 changes: 19 additions & 0 deletions src/components/Badge/Badge.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { styled } from 'styled-components';

import { SemanticColor } from '@/style';

interface StyledBadgeProps {
backgroundColor: SemanticColor;
}
export const StyledBadge = styled.div<StyledBadgeProps>`
display: flex;
gap: 4px;
align-items: center;
width: fit-content;
height: 24px;
padding: 0 var(--padding);
border-radius: 2px;
background-color: ${({ theme, backgroundColor }) => theme.color[backgroundColor]};

${({ theme }) => theme.typo.caption1};
`;
29 changes: 29 additions & 0 deletions src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { IconContext } from '@/style';

import { StyledBadge } from './Badge.style';
import { BadgeProps } from './Badge.type';

function Badge({ color = 'monoItemBG', children = 'Badge', leftIcon }: BadgeProps) {
return (
<StyledBadge
style={{
padding: leftIcon ? '0 8px' : '0 12px',
}}
backgroundColor={color}
>
{leftIcon && (
<IconContext.Provider
value={{
color: '#0f0f0f',
size: '1rem',
}}
>
{leftIcon}
</IconContext.Provider>
)}
{children}
</StyledBadge>
);
}

export { Badge };
7 changes: 7 additions & 0 deletions src/components/Badge/Badge.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { SemanticBGColor } from '@/style';

export interface BadgeProps {
color?: SemanticBGColor;
children?: React.ReactNode;
leftIcon?: React.ReactNode;
}
2 changes: 2 additions & 0 deletions src/components/Badge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Badge } from './Badge';
export type { BadgeProps } from './Badge.type';