fromis_9/frontend/src/components/Tooltip.jsx
caadiq dff43126c4 feat(schedule): 일정 수정/삭제 기능 구현 및 DB 스키마 개선
- schedule_members 테이블 분리 (members 컬럼 → 별도 테이블)
- schedules 테이블 컬럼 comment 추가 및 순서 정리
- 상세주소(location_detail) 필드 추가
- 장소 검색 UI 개선 (탭 제거 → 입력 필드+검색 버튼 병합)
- 카카오 장소 검색 API 프록시 추가 (/api/admin/kakao/places)
- 백엔드 CRUD API 구현 (GET/PUT/DELETE /schedules/:id)
- 프론트엔드 삭제 기능 및 확인 다이얼로그 추가
- 프론트엔드 수정 모드 지원 (기존 데이터 로드)
2026-01-05 18:11:40 +09:00

70 lines
2.6 KiB
JavaScript

import { useState, useRef } from 'react';
import ReactDOM from 'react-dom';
import { motion, AnimatePresence } from 'framer-motion';
/**
* 커스텀 툴팁 컴포넌트
* 마우스 커서를 따라다니는 방식
* @param {React.ReactNode} children - 툴팁을 표시할 요소
* @param {string|React.ReactNode} text - 툴팁에 표시할 내용 (content prop과 호환)
* @param {string|React.ReactNode} content - 툴팁에 표시할 내용 (text prop과 호환)
*/
const Tooltip = ({ children, text, content, className = "" }) => {
const [isVisible, setIsVisible] = useState(false);
const [position, setPosition] = useState({ bottom: 0, left: 0 });
const triggerRef = useRef(null);
// text 또는 content prop 사용 (문자열 또는 React 노드)
const tooltipContent = text || content;
const handleMouseEnter = (e) => {
// 마우스 커서 위치를 기준으로 툴팁 위치 설정 (커서 위로)
setPosition({
bottom: window.innerHeight - e.clientY + 10,
left: e.clientX
});
setIsVisible(true);
};
const handleMouseMove = (e) => {
// 마우스 이동 시 툴팁 위치 업데이트
setPosition({
bottom: window.innerHeight - e.clientY + 10,
left: e.clientX
});
};
return (
<>
<div
ref={triggerRef}
className={`inline-flex items-center ${className}`}
onMouseEnter={handleMouseEnter}
onMouseMove={handleMouseMove}
onMouseLeave={() => setIsVisible(false)}
>
{children}
</div>
{isVisible && tooltipContent && ReactDOM.createPortal(
<AnimatePresence>
<motion.div
initial={{ opacity: 0, y: 5, scale: 0.95 }}
animate={{ opacity: 1, y: 0, scale: 1 }}
exit={{ opacity: 0, y: 5, scale: 0.95 }}
transition={{ duration: 0.15 }}
style={{
bottom: position.bottom,
left: position.left,
}}
className="fixed z-[9999] -translate-x-1/2 px-3 py-2 bg-gray-800 text-white text-xs font-medium rounded-lg shadow-xl pointer-events-none"
>
{tooltipContent}
</motion.div>
</AnimatePresence>,
document.body
)}
</>
);
};
export default Tooltip;