Skip to content

Commit

Permalink
add zoomToElement feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisca105 authored and nalves599 committed Feb 19, 2025
1 parent 2923094 commit 797356f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 49 deletions.
114 changes: 66 additions & 48 deletions src/app/(authenticated)/venue/VenueStands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,59 +141,77 @@ const VenueStands: React.FC<VenueStandsProps> = ({ companies }) => {
centerZoomedOut={true}
centerOnInit={true}
>
{({ zoomIn, zoomOut, resetTransform, ...rest }) => (
<React.Fragment>
<div className="absolute top-4 right-4 flex flex-col gap-2 z-10">
<button
onClick={() => zoomIn()}
className="button button-primary !bg-sinfo-primary flex-1 p-2 rounded hover:opacity-90 transition-opacity"
>
+
</button>
<button
onClick={() => zoomOut()}
className="button button-primary !bg-sinfo-primary flex-1 p-2 rounded hover:opacity-90 transition-opacity"
>
-
</button>
{/* <button
{({ zoomIn, zoomOut, resetTransform, zoomToElement, ...rest }) => {
useEffect(() => {
setTimeout(() => {
if (companyParam) {
let element = document.getElementById(
`company-${companyParam}`
);
if (element) {
console.log("Zooming to element", element);
zoomToElement(`company-${companyParam}`, 3);
}
}
}, 300); // Wait for the SVG to render
}, [companyParam]);

return (
<>
<React.Fragment>
<div className="absolute top-4 right-4 flex flex-col gap-2 z-10">
<button
onClick={() => zoomIn()}
className="button button-primary !bg-sinfo-primary flex-1 p-2 rounded hover:opacity-90 transition-opacity"
>
+
</button>
<button
onClick={() => zoomOut()}
className="button button-primary !bg-sinfo-primary flex-1 p-2 rounded hover:opacity-90 transition-opacity"
>
-
</button>
{/* <button
onClick={() => resetTransform()}
className="button button-primary !bg-sinfo-secondary flex-1 p-2 rounded hover:opacity-90 transition-opacity"
>
Reset
</button> */}
</div>
<div className="relative overflow-hidden border border-gray-300 rounded">
<TransformComponent>
<svg
viewBox="0 0 512 380"
className="w-full h-auto max-w-4xl mx-auto"
>
<Entrances />
<SessionsStands />
<FoodZone />
<CoworkingZone />

{/* Company Stands */}
<g id="stands">
{standsForSelectedDay.map((stand) => {
const company = getCompanyAtPosition(stand.standId);
return (
<CompanyStand
key={`stand-${stand.standId}`}
stand={stand}
company={company}
standPositions={standPositions}
isSelected={isStandHighlighted(company)}
/>
);
})}
</g>
</svg>
</TransformComponent>
</div>
</React.Fragment>
)}
</div>
<div className="relative overflow-hidden border border-gray-300 rounded">
<TransformComponent>
<svg
viewBox="0 0 512 380"
className="w-full h-auto max-w-4xl mx-auto"
>
<Entrances />
<SessionsStands />
<FoodZone />
<CoworkingZone />

{/* Company Stands */}
<g id="stands">
{standsForSelectedDay.map((stand) => {
const company = getCompanyAtPosition(stand.standId);
return (
<CompanyStand
key={`stand-${stand.standId}`}
stand={stand}
company={company}
standPositions={standPositions}
isSelected={isStandHighlighted(company)}
/>
);
})}
</g>
</svg>
</TransformComponent>
</div>
</React.Fragment>
</>
);
}}
</TransformWrapper>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/app/(authenticated)/venue/stands/CompanyStand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ const CompanyStand: React.FC<StandProps> = ({
if (!position) return null;

return (
<a href={company ? `/companies/${company.id}` : "#"} className={className}>
<a
href={company ? `/companies/${company.id}` : "#"}
className={className}
id={company?.id ? `company-${company?.id}` : `stand-${standNumber}`}
>
<g
className={`
transition-all duration-200 ease-in-out
Expand Down

0 comments on commit 797356f

Please sign in to comment.