-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPortfolioModal.tsx
More file actions
181 lines (167 loc) · 5.71 KB
/
Copy pathPortfolioModal.tsx
File metadata and controls
181 lines (167 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
'use client'
import React, { useEffect, useId, useRef, useState } from 'react'
import Image from 'next/image'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faCheck, faTimes } from '@fortawesome/free-solid-svg-icons'
import { Raleway } from '@/app/fonts'
interface AccordionItem {
title: string
body: string
}
interface PortfolioModalProps {
isOpen: boolean
onClose: () => void
title: string
imageSrc: string
imageAlt: string
founded: string
clientSince: string
description: string
link?: { href: string; label: string }
projects: AccordionItem[]
}
const PortfolioModal: React.FC<PortfolioModalProps> = ({
isOpen,
onClose,
title,
imageSrc,
imageAlt,
founded,
clientSince,
description,
link,
projects,
}) => {
const [openAccordion, setOpenAccordion] = useState<number | null>(null)
const backdropRef = useRef<HTMLDivElement>(null)
const generatedId = useId()
const titleId = `portfolio-modal-title-${generatedId}`
useEffect(() => {
if (isOpen) {
const previousOverflow = document.body.style.overflow
document.body.style.overflow = 'hidden'
setOpenAccordion(null)
return () => {
document.body.style.overflow = previousOverflow
}
}
}, [isOpen])
useEffect(() => {
const handleEsc = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose()
}
if (isOpen) window.addEventListener('keydown', handleEsc)
return () => window.removeEventListener('keydown', handleEsc)
}, [isOpen, onClose])
if (!isOpen) return null
const handleBackdropClick = (e: React.MouseEvent) => {
if (e.target === backdropRef.current) onClose()
}
// Safely render description with optional inline links for all occurrences of link.label
const renderDescription = () => {
if (!link || !description.includes(link.label)) {
return description
}
const parts = description.split(link.label)
return (
<>
{parts.map((part, i) => (
<React.Fragment key={i}>
{part}
{i < parts.length - 1 && (
<a href={link.href} target="_blank" rel="noopener noreferrer" className="text-[#09afdf] hover:underline">
{link.label}
</a>
)}
</React.Fragment>
))}
</>
)
}
return (
<div
ref={backdropRef}
role="dialog"
aria-modal="true"
aria-labelledby={titleId}
className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 animate-fadeIn"
onClick={handleBackdropClick}
>
<div
className={`${Raleway.className} relative bg-white rounded-md shadow-2xl w-[90%] max-w-[600px] max-h-[85vh] overflow-y-auto animate-slideUp`}
>
{/* Modal Header */}
<div className="flex items-center justify-between px-5 py-3 border-b border-gray-200">
<h4 id={titleId} className="text-lg font-semibold text-[#333]">
{title}
</h4>
<button
onClick={onClose}
className="text-gray-400 hover:text-gray-700 transition-colors text-xl leading-none p-1"
aria-label="Close"
>
<FontAwesomeIcon icon={faTimes} />
</button>
</div>
{/* Modal Body */}
<div className="px-5 py-4">
{/* Client Info Row */}
<div className="flex flex-col md:flex-row gap-4 mb-4">
<div className="md:w-1/6 flex-shrink-0">
<Image
src={imageSrc}
alt={imageAlt}
width={100}
height={100}
className="max-h-[100px] w-auto object-contain relative"
unoptimized
/>
</div>
<div className="md:w-5/6">
<p className="text-sm text-[#666] mb-1">
<strong>Founded</strong> - {founded} · <strong>Client Since</strong> - {clientSince}
</p>
<p className="text-sm text-[#666]">{renderDescription()}</p>
</div>
</div>
{/* Projects Accordion */}
<h3 className="text-xl font-semibold text-[#333] mb-3">Projects</h3>
<div className="border border-gray-200 rounded">
{projects.map((project, index) => (
<div key={index} className="border-b border-gray-200 last:border-b-0">
<button
onClick={() => setOpenAccordion(openAccordion === index ? null : index)}
className={`w-full text-left px-4 py-3 flex items-center gap-2 text-sm font-medium transition-colors duration-200 ${
openAccordion === index ? 'bg-[#09afdf] text-white' : 'text-[#09afdf] hover:bg-gray-50'
}`}
>
<FontAwesomeIcon icon={faCheck} className="text-xs" />
{project.title}
</button>
<div
className={`overflow-hidden transition-all duration-300 ease-in-out ${
openAccordion === index ? 'max-h-96 opacity-100' : 'max-h-0 opacity-0'
}`}
>
<div className="px-4 py-3 text-sm text-[#666] bg-gray-50 border-t border-gray-100">
{project.body}
</div>
</div>
</div>
))}
</div>
</div>
{/* Modal Footer */}
<div className="flex justify-end px-5 py-3 border-t border-gray-200">
<button
onClick={onClose}
className="px-4 py-2 text-sm bg-white border border-gray-300 rounded text-[#333] hover:bg-gray-50 transition-colors"
>
Close
</button>
</div>
</div>
</div>
)
}
export default PortfolioModal