Skip to content

Commit

Permalink
Merge pull request #15 from MARU-EGG/feature-#9
Browse files Browse the repository at this point in the history
[FEAT-9,14] Selector 컴포넌트 MenuList로 변경, Chip 컴포넌트 구현
  • Loading branch information
swgvenghy authored Jan 27, 2025
2 parents 4d512cf + f338aa7 commit 4798900
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 154 deletions.
3 changes: 3 additions & 0 deletions src/assets/svg/check-false.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/svg/check-true.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/assets/svg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export { default as TreeIcon } from '@assets/svg/tree.svg?react';
export { default as ReloadIcon } from '@assets/svg/reload.svg?react';
export { default as MaruIcon } from '@assets/svg/maru.svg?react';
export { default as SendIcon } from '@assets/svg/send.svg?react';
export { default as CheckTrueIcon } from '@assets/svg/check-true.svg?react';
export { default as CheckFalseIcon } from '@assets/svg/check-false.svg?react';
13 changes: 6 additions & 7 deletions src/components/bottom-sheet/bottom-sheet.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { useState } from 'react';
import BottomSheet from '@/components/bottom-sheet/bottom-sheet';
import Header from '@/components/header/header';
import Layout from '@/components/layout/layout';
import Selector from '@/components/selector/selector';
import DropdownMenu from '@/components/menu-items/dropdown-menu/dropdown-menu';
import MenuList from '@/components/menu-list/menu-list';
import type { Meta, StoryObj } from '@storybook/react';

const menu = [
Expand Down Expand Up @@ -44,12 +45,10 @@ export const Default: Story = {
<Layout>
<Header />
<div className="flex justify-center">
<Selector>
<Selector.Header>학과(부)를 선택해주세요</Selector.Header>
<Selector.Option style="dropDown" onClick={() => setIsOpen(true)}>
여기를 눌러주세요
</Selector.Option>
</Selector>
<MenuList>
<MenuList.Title title="학과(부)를 선택해주세요"></MenuList.Title>
<DropdownMenu label="여기를 눌러주세요" onClick={() => setIsOpen(true)} />
</MenuList>
</div>

<BottomSheet open={isOpen} onClose={() => setIsOpen(false)}>
Expand Down
26 changes: 26 additions & 0 deletions src/components/chip/chip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Chip from '@/components/chip/chip';
import type { Meta, StoryObj } from '@storybook/react';

const meta = {
title: 'Components/Chip',
component: Chip,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
label: {
controle: 'text',
description: '칩 내부에 들어갈 텍스트',
},
},
} satisfies Meta<typeof Chip>;

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

export const Default: Story = {
args: {
label: '수시 질문중',
},
};
9 changes: 9 additions & 0 deletions src/components/chip/chip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function Chip({ label }: { label: string }) {
return (
<div className="bg-primary-egg rounded-2xl px-2 py-1">
<span className="text-label font-semibold text-primary">{label}</span>
</div>
);
}

export default Chip;
33 changes: 33 additions & 0 deletions src/components/menu-items/check-box/check-box.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useState } from 'react';
import { CheckFalseIcon, CheckTrueIcon } from '@/assets/svg';

interface CheckboxProps {
label: string;
onClick?: (event?: React.MouseEvent<HTMLLabelElement>) => void;
disabled?: boolean;
}

function Checkbox({ label, onClick, disabled = false }: CheckboxProps) {
const [checked, setChecked] = useState<boolean>(false);

const handleClick = (event: React.MouseEvent<HTMLLabelElement>) => {
if (disabled) return;
event.preventDefault();
setChecked(!checked);
onClick?.(event);
};

return (
<label htmlFor={label} onClick={handleClick}>
<div className="relative px-4 py-3 hover:bg-gray-50">
<input id={label} type="checkbox" className="sr-only" disabled={disabled}></input>
<div className="flex items-center gap-2">
{checked ? <CheckTrueIcon /> : <CheckFalseIcon />}
<span className="text-sm">{label}</span>
</div>
</div>
</label>
);
}

export default Checkbox;
22 changes: 22 additions & 0 deletions src/components/menu-items/dropdown-menu/dropdown-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ArrowDownIcon } from '@/assets/svg';

interface DropdownMenuProps {
label: string;
onClick?: (event?: React.MouseEvent<HTMLDivElement>) => void;
}

function DropdownMenu({ label, onClick }: DropdownMenuProps) {
return (
<div className="cursor-pointer px-4 py-3 text-sm">
<div
onClick={onClick}
className="flex items-center justify-between rounded-md border p-2 text-gray-400 transition-colors hover:bg-gray-100"
>
<div>{label}</div>
<ArrowDownIcon />
</div>
</div>
);
}

export default DropdownMenu;
14 changes: 14 additions & 0 deletions src/components/menu-items/text-menu/text-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
interface TextMenuProps {
label: string;
onClick?: (event?: React.MouseEvent<HTMLDivElement>) => void;
}

function TextMenu({ label, onClick }: TextMenuProps) {
return (
<div onClick={onClick} className="cursor-pointer px-4 py-3 text-sm transition-colors hover:bg-gray-100">
{label}
</div>
);
}

export default TextMenu;
5 changes: 5 additions & 0 deletions src/components/menu-list/menu-list-title.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function MenuListTitle({ title }: { title: string }) {
return <div className="bg-image-tree-right rounded-t-lg bg-primary p-4 text-title text-white">{title}</div>;
}

export default MenuListTitle;
57 changes: 57 additions & 0 deletions src/components/menu-list/menu-list.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Checkbox from '@/components/menu-items/check-box/check-box';
import DropdownMenu from '@/components/menu-items/dropdown-menu/dropdown-menu';
import TextMenu from '@/components/menu-items/text-menu/text-menu';
import MenuList from '@/components/menu-list/menu-list';
import type { Meta, StoryObj } from '@storybook/react';

const meta = {
title: 'Components/MenuList',
component: MenuList,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {},
} satisfies Meta<typeof MenuList>;

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

export const Default: Story = {
args: {
children: null,
},
render: () => (
<MenuList>
<MenuList.Title title="모집요강으로 이동" />
<TextMenu label="출처보러 가기" />
<TextMenu label="출처보러 가기" />
<TextMenu label="출처보러 가기" />
</MenuList>
),
};

export const CheckboxMenu: Story = {
args: {
children: null,
},
render: () => (
<MenuList>
<MenuList.Title title="캠퍼스를 선택해주세요" />
<Checkbox label="인문캠퍼스" />
<Checkbox label="자연캠퍼스" />
</MenuList>
),
};

export const DropDown: Story = {
args: {
children: null,
},
render: () => (
<MenuList>
<MenuList.Title title="학과(부)를 선택해주세요" />
<DropdownMenu label="여기를 눌러주세요" />
</MenuList>
),
};
10 changes: 10 additions & 0 deletions src/components/menu-list/menu-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import MenuListTitle from '@/components/menu-list/menu-list-title';

function MenuList({ children }: { children: React.ReactNode }) {
return <div className="w-56 min-w-56 divide-y rounded-lg border border-category_border bg-white">{children}</div>;
}

MenuList.Title = MenuListTitle;

export default MenuList;
7 changes: 0 additions & 7 deletions src/components/selector/select-header.tsx

This file was deleted.

42 changes: 0 additions & 42 deletions src/components/selector/select-option.tsx

This file was deleted.

59 changes: 0 additions & 59 deletions src/components/selector/selector.stories.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/selector/selector.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect } from 'react';
import Selector from '@/components/selector/selector';
import TextMenu from '@/components/menu-items/text-menu/text-menu';
import MenuList from '@/components/menu-list/menu-list';
import systemMessage from '@/constants/message';
import useAdmissionDetail from '@/hooks/querys/useAdmissionDetail';
import useAdmissionStore from '@/stores/store/admission-store';
Expand Down Expand Up @@ -41,14 +42,12 @@ function ChooseAdmissionCategory({ admissionType, changeStep }: Props) {
<div className="mt-2">
<div className="flex w-80 cursor-grab flex-nowrap items-start gap-5 overflow-x-auto">
{data.map((option) => (
<Selector key={option.label}>
<Selector.Header>{`${option.label}전형`}</Selector.Header>
<MenuList key={option.label}>
<MenuList.Title title={`${option.label}전형`} />
{option.children.map((menu) => (
<Selector.Option key={menu} onClick={() => selectCategory(menu)}>
{menu}
</Selector.Option>
<TextMenu label={menu} key={menu} onClick={() => selectCategory(menu)} />
))}
</Selector>
</MenuList>
))}
</div>
</div>
Expand Down
Loading

0 comments on commit 4798900

Please sign in to comment.