Skip to content

Commit

Permalink
Merge pull request #54 from Kernel360/common-component-radio
Browse files Browse the repository at this point in the history
공통 컴포넌트: Radio
  • Loading branch information
bottlewook authored Jan 8, 2024
2 parents ead99fc + 1c2d5ef commit 157f611
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
--tertiary: #7A7A7A;
--black: #090A0A;
--white: #FFF;
--white-100: #F3F5F8;
--pink: #F67272;

/* -------------- z-index -------------- */
Expand Down
48 changes: 48 additions & 0 deletions src/components/shared/radio/Radio.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
input[type="radio"] {
display: none;
}

label {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
}

label.gender {
height: 48px;
border-radius: 8px;
}

input[type="radio"] + label.gender {
border: 1px solid var(--gray-100);
background-color: var(--white);
color: var(--gray-300);
}

input[type="radio"]:checked + label.gender {
background-color: var(--primary);
color: var(--white);
}

label.ageGroup {
height: 47px;
border-radius: 30px;
}

label.additionalInfo {
height: 60px;
border-radius: 10px;
}

input[type="radio"] + label.ageGroup,
input[type="radio"] + label.additionalInfo {
background-color: var(--white-100);
color: var(--gray-300);
}

input[type="radio"]:checked + label.ageGroup,
input[type="radio"]:checked + label.additionalInfo {
background-color: var(--primary);
color: var(--white-100);
}
40 changes: 40 additions & 0 deletions src/components/shared/radio/Radio.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { Meta, StoryObj } from '@storybook/react';

import Radio from './Radio';

const meta = {
title: 'Shared/Radio',
component: Radio,
parameters: {
},
tags: ['autodocs'],
argTypes: {
},
} satisfies Meta<typeof Radio>;

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

export const gender: Story = {
args: {
type: 'gender',
label: '남성',
value: 'male',
},
};

export const ageGroup: Story = {
args: {
type: 'ageGroup',
label: '10대',
value: '10',
},
};

export const additionalInfo: Story = {
args: {
type: 'additionalInfo',
label: '소형',
value: 'mini',
},
};
28 changes: 28 additions & 0 deletions src/components/shared/radio/Radio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { InputHTMLAttributes, forwardRef } from 'react';

import classNames from 'classnames/bind';

import styles from './Radio.module.scss';

interface RadioProps extends InputHTMLAttributes<HTMLInputElement> {
type: 'gender' | 'ageGroup' | 'additionalInfo'
label: string
value: string | number
}

const cx = classNames.bind(styles);

const Radio = forwardRef<HTMLInputElement, RadioProps>(({
type, label, value,
}, ref) => {
return (
<>
<input id={label} type="radio" ref={ref} value={value} />
<label className={cx({ [type]: true })} htmlFor={label}>
{label}
</label>
</>
);
});

export default Radio;
1 change: 1 addition & 0 deletions src/styles/colorPalette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const colors = {
tertiary: 'var(--tertiary',
black: 'var(--black)',
white: 'var(--white)',
white100: 'var(--white-100)',
pink: 'var(--pink)',
};

Expand Down

0 comments on commit 157f611

Please sign in to comment.