Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE][FEAT] #145 - 플로팅 버튼 구현 #150

Merged
merged 16 commits into from
Nov 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions frontend/src/component/common/FloatingButton/FloatingButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import classNames from 'classnames';
import React, { useState } from 'react';
import { IconType, ButtonType, ToolCategory } from './enumTypes';

export const FloatingButton = () => {
const [toolType, setToolType] = useState<ButtonType>(ButtonType.CLOSE);
leedongyull marked this conversation as resolved.
Show resolved Hide resolved
const [isMenuOpen, setIsMenuOpen] = useState<boolean>(false);

// 메뉴 열기/닫기
const toggleMenu = () => {
setIsMenuOpen(prev => !prev);
if (!isMenuOpen) {
setToolType(ButtonType.OPEN);
} else {
setToolType(ButtonType.CLOSE);
}
};

// 메뉴 아이콘 클릭 시 툴 변경
const handleMenuClick = (type: ButtonType) => {
setIsMenuOpen(false);
leedongyull marked this conversation as resolved.
Show resolved Hide resolved
setToolType(type);
};

return (
<div
className={classNames('absolute', 'bottom-5', 'right-10', 'flex', 'flex-col', 'items-center')}
leedongyull marked this conversation as resolved.
Show resolved Hide resolved
>
<button
type="button"
onClick={toggleMenu}
className={classNames(
'absolute',
'bottom-0',
'bg-blueGray-800',
'w-[50px]',
'h-[50px]',
'rounded-full',
'flex',
'justify-center',
'items-center',
'text-white',
'z-10',
)}
>
{React.createElement(IconType[toolType], { className: 'w-[24px] h-[24px]' })}
</button>

{ToolCategory.map(({ type, description, icon }, index) => (
<button
type="button"
onClick={() => handleMenuClick(type)}
key={type}
className={classNames(
'w-[40px]',
'h-[40px]',
'bg-blueGray-200',
'text-white',
'rounded-full',
'flex',
'items-center',
'justify-center',
'absolute',
'transition-all',
'duration-300',
)}
style={{ bottom: isMenuOpen ? `${(index + 1) * 60}px` : '0px' }}
leedongyull marked this conversation as resolved.
Show resolved Hide resolved
>
<div className={classNames('flex', 'items-center')}>
{React.createElement(icon, { className: 'w-[20px] h-[20px]' })}
{isMenuOpen && (
<div
className={classNames(
'w-[78px]',
leedongyull marked this conversation as resolved.
Show resolved Hide resolved
'h-[30px]',
'bg-blueGray-200',
'absolute',
'right-12',
'text-white',
'text-xs',
'flex',
'items-center',
'justify-center',
'rounded-md',
'opacity-[0.5]',
)}
>
{description}
</div>
)}
</div>
</button>
))}
</div>
);
};