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] Chip 컴포넌트,스토리북 구현 #52

Merged
merged 8 commits into from
Nov 17, 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
1 change: 0 additions & 1 deletion src/components/common/Button/Button.variants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { cva } from 'class-variance-authority';

// TODO : hover, disable 됐을 경우 색상 추가
export const ButtonVariants = cva(
`flex items-center justify-center whitespace-nowrap select-none rounded-xl`,
{
Expand Down
32 changes: 32 additions & 0 deletions src/components/common/Chip/Chip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable no-restricted-exports */
import type { Meta, StoryObj } from '@storybook/react';

import { Chip } from '.';

const meta = {
title: 'components/common/Chip',
component: Chip,
tags: ['autodocs'],
} satisfies Meta<typeof Chip>;

export default meta;
type Story = StoryObj<typeof Chip>;

export const Basic: Story = {
args: {
variant: 'medium',
children: '카페',
},
argTypes: {
variant: {
control: 'inline-radio',
options: ['small', 'medium', 'large'],
},
children: {
control: 'text',
},
},
render: (args) => {
return <Chip variant={args.variant}>{args.children}</Chip>;
},
};
11 changes: 11 additions & 0 deletions src/components/common/Chip/Chip.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type Props = {
/**
* The variant of the Chip.
* @default 'large'
*/
variant: 'small' | 'medium' | 'large';
/**
* content to be displayed within the Chip component.
*/
children: string;
Comment on lines +7 to +10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

접근성 개선을 위한 aria-label 속성 추가를 권장드립니다.

스크린 리더 사용자를 위해 Chip의 목적을 설명하는 aria-label을 추가하면 좋을 것 같습니다.

   /**
    * content to be displayed within the Chip component.
    */
   children: string;
+  /**
+   * Accessible label for screen readers.
+   * @example '카테고리: JavaScript'
+   */
+  'aria-label'?: string;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* content to be displayed within the Chip component.
*/
children: string;
/**
* content to be displayed within the Chip component.
*/
children: string;
/**
* Accessible label for screen readers.
* @example '카테고리: JavaScript'
*/
'aria-label'?: string;

};
14 changes: 14 additions & 0 deletions src/components/common/Chip/Chip.variants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { cva } from 'class-variance-authority';

export const ChipVariants = cva(`bg-primary rounded-md text-white cursor-default px-3 py-1`, {
variants: {
variant: {
small: 'h-6 min-w-6 text-caption',
medium: 'h-7 min-w-7 text-body4',
large: 'h-8 min-w-8 text-body3',
},
},
defaultVariants: {
variant: 'medium',
},
});
10 changes: 10 additions & 0 deletions src/components/common/Chip/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Props } from './Chip.types';
import { ChipVariants } from './Chip.variants';

export const Chip = ({ variant, children, ...props }: Props) => {
return (
<span className={ChipVariants({ variant })} {...props}>
{children}
</span>
);
};
Comment on lines +4 to +10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

접근성 개선이 필요합니다

다음과 같은 접근성 관련 속성들을 추가하는 것이 좋습니다:

-export const Chip = ({ variant, children, ...props }: Props) => {
+export const Chip = ({ variant, children, role = "status", ...props }: Props) => {
   return (
     <span 
+      role={role}
+      aria-label={typeof children === 'string' ? children : undefined}
       className={ChipVariants({ variant })} 
       {...props}
     >
       {children}
     </span>
   );
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const Chip = ({ variant, children, ...props }: Props) => {
return (
<span className={ChipVariants({ variant })} {...props}>
{children}
</span>
);
};
export const Chip = ({ variant, children, role = "status", ...props }: Props) => {
return (
<span
role={role}
aria-label={typeof children === 'string' ? children : undefined}
className={ChipVariants({ variant })}
{...props}
>
{children}
</span>
);
};

2 changes: 1 addition & 1 deletion src/pages/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const Link = () => {
context={{
state: link.youtubeLink,
setState: (link) => {
dispatch({ type: 'link', payload: { youtubeLink: link } });
dispatch({ type: 'SET_LINK', payload: { youtubeLink: link } });
},
}}
/>
Expand Down
1 change: 1 addition & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
theme: {
colors,
fontFamily: {
sans: ['Pretendard'],
pretendard: ['Pretendard'],
},
extend: {
Expand Down
Loading