From f0a04b0417b2bc544ed5a01fe753260cd1ab2bf1 Mon Sep 17 00:00:00 2001 From: eeseung Date: Fri, 10 Nov 2023 17:11:54 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20#63=20-=20Dropdown=20=EC=BB=B4?= =?UTF-8?q?=ED=8F=AC=EB=84=8C=ED=8A=B8=20defaultIndex=20prop=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/Dropdown/Dropdown.tsx | 4 ++++ src/components/common/Dropdown/hooks/useDropdown.ts | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/common/Dropdown/Dropdown.tsx b/src/components/common/Dropdown/Dropdown.tsx index d456b868..cb7010e2 100644 --- a/src/components/common/Dropdown/Dropdown.tsx +++ b/src/components/common/Dropdown/Dropdown.tsx @@ -3,6 +3,7 @@ import { useRef } from 'react' import { cls } from '@/utils' import { ChevronDownIcon } from '@heroicons/react/20/solid' +import { useSearchParams } from 'next/navigation' import DropdownItem from './DropdownItem' import { DROPDOWN_OPTIONS, PLACEMENTS, VERTICAL_PADDING } from './constants' import useDropdown from './hooks/useDropdown' @@ -11,6 +12,7 @@ export interface DropdownProps { type: 'space' | 'link' | 'search' | 'user_edit' | 'user_invite' | 'tag' size?: 'large' | 'medium' | 'small' placement?: 'left' | 'right' + defaultIndex?: number tags?: string[] onChange: (e: React.MouseEvent) => void } @@ -19,6 +21,7 @@ const Dropdown = ({ type, size = 'medium', placement = 'left', + defaultIndex, tags, onChange, }: DropdownProps) => { @@ -32,6 +35,7 @@ const Dropdown = ({ : tags && ['전체', ...tags] const dropdownRef = useRef(null) const { isOpen, setIsOpen, index, handleClick } = useDropdown({ + defaultIndex, el: dropdownRef, onChange, }) diff --git a/src/components/common/Dropdown/hooks/useDropdown.ts b/src/components/common/Dropdown/hooks/useDropdown.ts index aad00161..8c56f681 100644 --- a/src/components/common/Dropdown/hooks/useDropdown.ts +++ b/src/components/common/Dropdown/hooks/useDropdown.ts @@ -9,11 +9,13 @@ import { } from 'react' export interface useDropdownProps { + defaultIndex?: number el: React.RefObject onChange: (e: React.MouseEvent) => void } const useDropdown = ({ + defaultIndex, el, onChange, }: useDropdownProps): { @@ -23,7 +25,7 @@ const useDropdown = ({ handleClick: (e: React.MouseEvent, i: number) => void } => { const [isOpen, setIsOpen] = useState(false) - const [index, setIndex] = useState(0) + const [index, setIndex] = useState(defaultIndex ?? 0) useEffect(() => { const handleOutsideClose = (e: { target: any }) => { From a62102dd1f334b136d4bd210dd97382974c7db9d Mon Sep 17 00:00:00 2001 From: eeseung Date: Sat, 11 Nov 2023 11:06:41 +0900 Subject: [PATCH 2/8] =?UTF-8?q?refactor:=20#63=20-=20CategoryList=20prop?= =?UTF-8?q?=20defaultIndex=20=ED=9B=85=EC=9C=BC=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/CategoryList/CategoryList.tsx | 10 ++++------ .../common/CategoryList/hooks/useCategoryList.ts | 5 +++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/common/CategoryList/CategoryList.tsx b/src/components/common/CategoryList/CategoryList.tsx index 5b059add..e7bf0344 100644 --- a/src/components/common/CategoryList/CategoryList.tsx +++ b/src/components/common/CategoryList/CategoryList.tsx @@ -1,6 +1,5 @@ 'use client' -import { useEffect } from 'react' import { cls } from '@/utils' import CategoryListItem from './CategoryListItem' import { CATEGORIES } from './constants' @@ -19,11 +18,10 @@ const CategoryList = ({ defaultIndex, onChange, }: CategoryListProps) => { - const { index, setIndex, handleClick } = useCategoryList({ onChange }) - - useEffect(() => { - defaultIndex && setIndex(defaultIndex) - }, [defaultIndex, setIndex]) + const { index, handleClick } = useCategoryList({ + defaultIndex, + onChange, + }) return (
    ) => void } -const useCategoryList = ({ onChange }: useCategoryListProps) => { - const [index, setIndex] = useState(0) +const useCategoryList = ({ defaultIndex, onChange }: useCategoryListProps) => { + const [index, setIndex] = useState(defaultIndex ?? 0) const handleClick = (e: React.MouseEvent, i: number) => { setIndex(i) From 07532fad5d8b953d62ff7f3c9c4a3704c00870a3 Mon Sep 17 00:00:00 2001 From: eeseung Date: Sun, 12 Nov 2023 05:29:13 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20#63=20-=20Dropdown=20=EC=BB=B4?= =?UTF-8?q?=ED=8F=AC=EB=84=8C=ED=8A=B8=20=EC=83=81=EC=88=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/Dropdown/constants/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/common/Dropdown/constants/index.ts b/src/components/common/Dropdown/constants/index.ts index d1fbddcd..282aa67d 100644 --- a/src/components/common/Dropdown/constants/index.ts +++ b/src/components/common/Dropdown/constants/index.ts @@ -4,15 +4,15 @@ export const DROPDOWN_OPTIONS = { search: { 스페이스: 'space', 유저: 'user' }, user_edit: { '편집 허용': 'edit', '읽기 허용': 'view', 제거: 'remove' }, user_invite: { '편집 허용': 'eidt', '읽기 허용': 'view' }, -} as const +} export const VERTICAL_PADDING = { large: 'py-2.5', medium: 'py-1.5', small: 'py-0.5', -} as const +} export const PLACEMENTS = { left: 'left-0', right: 'right-0', -} as const +} From f6e2bfb7ed51b75e89837e8d9a1a9251f4f26c34 Mon Sep 17 00:00:00 2001 From: eeseung Date: Sun, 12 Nov 2023 06:21:13 +0900 Subject: [PATCH 4/8] =?UTF-8?q?feat:=20#63=20-=20Input=20=EC=BB=B4?= =?UTF-8?q?=ED=8F=AC=EB=84=8C=ED=8A=B8=20buttonType=20prop=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/Input/Input.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/common/Input/Input.tsx b/src/components/common/Input/Input.tsx index 982236b0..da042aaf 100644 --- a/src/components/common/Input/Input.tsx +++ b/src/components/common/Input/Input.tsx @@ -7,6 +7,7 @@ export interface InputProps { placeholder?: string inputButton?: boolean buttonText?: string + buttonType?: 'button' | 'submit' | 'reset' buttonColor?: 'green' | 'gray' validation?: string disabled?: boolean @@ -21,6 +22,7 @@ const Input = forwardRef( placeholder, inputButton, buttonText = '추가', + buttonType = 'button', buttonColor = 'green', validation, disabled, @@ -52,7 +54,7 @@ const Input = forwardRef( /> {inputButton && (