Skip to content

Commit

Permalink
chore : 토글 컴포넌트 수정 완료 (#136)
Browse files Browse the repository at this point in the history
mmjjaa authored Nov 29, 2024
1 parent 599e521 commit 83070f9
Showing 2 changed files with 29 additions and 10 deletions.
18 changes: 15 additions & 3 deletions src/components/Common/Toggle/Toggle.stories.tsx
Original file line number Diff line number Diff line change
@@ -6,7 +6,15 @@ const meta: Meta<typeof Toggle> = {
title: 'atoms/Toggle',
tags: ['autodocs'],
argTypes: {
onToggle: { action: 'toggled' }
onToggle: { action: 'toggled' },
leftLabel: {
control: 'text',
defaultValue: '전체'
},
rightLabel: {
control: 'text',
defaultValue: '답장'
}
}
};

@@ -16,12 +24,16 @@ type Story = StoryObj<typeof Toggle>;

export const Default: Story = {
args: {
isChecked: false
isChecked: false,
leftLabel: '전체',
rightLabel: '답장'
}
};

export const Checked: Story = {
args: {
isChecked: true
isChecked: true,
leftLabel: '편지지',
rightLabel: '글씨체'
}
};
21 changes: 14 additions & 7 deletions src/components/Common/Toggle/Toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
export type ToggleProps = {
isChecked: boolean;
onToggle: () => void;
leftLabel: string;
rightLabel: string;
};

export const Toggle = ({ isChecked, onToggle }: ToggleProps) => {
export const Toggle = ({
isChecked,
onToggle,
leftLabel,
rightLabel
}: ToggleProps) => {
return (
<div className="relative flex items-center justify-between w-[160px] h-[30px] bg-gray-200 rounded-full p-1">
<div className="relative flex items-center justify-between w-[140px] h-[30px] bg-gray-200 rounded-full p-1">
<div
onClick={onToggle}
className={`absolute w-[78px] h-[30px] bg-gray-100 rounded-full cursor-pointer transition-all duration-200 ease-in-out ${
isChecked ? 'translate-x-[78px]' : 'translate-x-0'
isChecked ? 'translate-x-[60px]' : '-translate-x-2'
}`}
/>
<div
onClick={onToggle}
className={`absolute left-2 font-bold text-sm transform -translate-y-1/2 ${
className={`absolute left-5 font-bold text-sm transform -translate-y-1/2 ${
isChecked ? 'text-gray-400' : 'text-black'
}`}
style={{ top: '50%' }}
>
편지지
{leftLabel}
</div>
<div
onClick={onToggle}
className={`absolute right-2 font-bold text-sm transform -translate-y-1/2 ${
className={`absolute right-5 font-bold text-sm transform -translate-y-1/2 ${
isChecked ? 'text-black' : 'text-gray-400'
}`}
style={{ top: '50%' }}
>
글씨체
{rightLabel}
</div>
</div>
);

0 comments on commit 83070f9

Please sign in to comment.