From 076be34ef747fc30134fdc00845b7cf274966790 Mon Sep 17 00:00:00 2001 From: dan1M Date: Thu, 24 Oct 2024 15:51:42 +0200 Subject: [PATCH] feat: handled rounded body using circles bodies, fixed link click, fixed jumbotron images over second section --- .../landing/EllipsePositionnedImages.tsx | 1 + .../landing/PartnerSectionWithPhysics.tsx | 76 +++++++++++++------ 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/webapp/src/components/landing/EllipsePositionnedImages.tsx b/webapp/src/components/landing/EllipsePositionnedImages.tsx index a57f2d58..fd343e67 100644 --- a/webapp/src/components/landing/EllipsePositionnedImages.tsx +++ b/webapp/src/components/landing/EllipsePositionnedImages.tsx @@ -73,6 +73,7 @@ const EllipsePositionnedImages = ({ left: "50%", top: "50%", rotate: index % 2 === 0 ? 5 : -7.5, + zIndex: 2, }} > { const partnerElements = document.getElementsByClassName(partnerItemClassName); + + const bodyProps: IBodyDefinition = { + restitution: 0.5, + friction: 0.3, + slop: 0.01, + density: 0.01, + render: { + visible: false, + }, + }; // Creates Matter.js bodies dynamically for each partner element const partnerBodies = Array.from(partnerElements).map((element, index) => { const html_element = element as HTMLElement; @@ -84,17 +96,30 @@ const PartnerSectionWithPhysics = ({}: PartnerSectionProps) => { const height = html_element.offsetHeight; const x = html_element.offsetLeft + width / 2; const y = html_element.offsetTop + height / 2; + const isSquare = width === height; + + let body; + if (isSquare) { + body = Bodies.circle(x, y, width / 2, bodyProps); + } else { + const rectangle = Bodies.rectangle(x, y, width - height, height); + const leftCircle = Bodies.circle( + x - (width - height) / 2, + y, + height / 2 + ); + const rightCircle = Bodies.circle( + x + (width - height) / 2, + y, + height / 2 + ); + + body = Body.create({ + ...bodyProps, + parts: [rectangle, leftCircle, rightCircle], + }); + } - const body = Bodies.rectangle(x, y, width, height, { - restitution: 0.5, // Bounciness - friction: 0.3, - slop: 0.01, - density: 0.01, - render: { - // remove border - visible: false, - }, - }); World.add(engine.world, body); return { body, element: html_element }; // Returns the body and the DOM element }); @@ -174,10 +199,7 @@ const PartnerSectionWithPhysics = ({}: PartnerSectionProps) => { }; }, [arePhysicsTriggered]); - // TODO: Make rounded border rectangles // TODO: Handle scroll when in canvas - // TODO: Handle link click when in canvas - // TODO: Fix image hitboxes return ( { fontWeight={"bold"} fontSize={{ lg: "lg" }} passHref + w={"fit-content"} + zIndex={10} > Voir toutes les entreprises engagées → @@ -227,9 +251,10 @@ const PartnerSectionWithPhysics = ({}: PartnerSectionProps) => { { justifyContent="center" bg="white" rounded="full" - h={14} - w={"fit-content"} - p={4} + h={{ base: 12, lg: 20 }} + p={2} className={partnerItemClassName} pointerEvents={"none"} + userSelect={"none"} > - {`Logo + {`Logo {partner.promo_label}