From 84bcf5c0f908c7096ae01dc78953014a69c207ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EB=8F=99=EC=9C=A8?= Date: Sun, 17 Nov 2024 19:37:31 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[FE][Feat]=20#145=20:=20=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=EB=B6=81=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EA=B5=AC?= =?UTF-8?q?=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/FloatingButton/FloatingButton.tsx | 56 ++++++-------- frontend/src/hooks/useFloatingButton.ts | 23 ++++++ .../FloatingButton/Floatingbutton.stories.tsx | 73 +++++++++++++++++++ 3 files changed, 118 insertions(+), 34 deletions(-) create mode 100644 frontend/src/hooks/useFloatingButton.ts create mode 100644 frontend/src/stories/FloatingButton/Floatingbutton.stories.tsx diff --git a/frontend/src/component/common/FloatingButton/FloatingButton.tsx b/frontend/src/component/common/FloatingButton/FloatingButton.tsx index a4fb5916..127cbd9f 100644 --- a/frontend/src/component/common/FloatingButton/FloatingButton.tsx +++ b/frontend/src/component/common/FloatingButton/FloatingButton.tsx @@ -1,8 +1,19 @@ import classNames from 'classnames'; -import React, { useState } from 'react'; +import React from 'react'; import { ButtonState } from '../enums'; import { IconType, ToolCategory } from '../types'; +interface IFloatingButtonProps { + /** 메뉴가 열려있는지 여부를 나타냅니다. */ + isMenuOpen?: boolean; + /** 메뉴를 토글할 수 있는 함수입니다. */ + toggleMenu?: () => void; + /** 선택된 도구의 버튼 상태를 의미합니다. */ + toolType: ButtonState; + /** 도구를 선택할 수 있는 함수입니다. */ + handleMenuClick?: (type: ButtonState) => void; +} + /** * FloatingButton 컴포넌트는 도구 선택 및 메뉴 토글 기능을 제공하는 플로팅 버튼을 렌더링합니다. * @remarks @@ -12,40 +23,14 @@ import { IconType, ToolCategory } from '../types'; * * ) */ -export const FloatingButton = () => { - const [toolType, setToolType] = useState(ButtonState.CLOSE); - const [isMenuOpen, setIsMenuOpen] = useState(false); - - /** - * @remarks - * - 메뉴를 토글하는 함수입니다. - */ - const toggleMenu = () => { - setIsMenuOpen(prev => !prev); - if (!isMenuOpen) { - setToolType(ButtonState.OPEN); - } else { - setToolType(ButtonState.CLOSE); - } - }; - - /** - * @remarks - * 툴을 선택하고 메뉴를 닫는 함수입니다. - * @param {ButtonState} type - 선택된 툴 타입 - */ - const handleMenuClick = (type: ButtonState) => { - setToolType(type); - setIsMenuOpen(!isMenuOpen); - }; - +export const FloatingButton = (props: IFloatingButtonProps) => { return (
{ToolCategory.map(({ type, description, icon }, index) => (