Skip to content

Commit

Permalink
update component
Browse files Browse the repository at this point in the history
  • Loading branch information
johnchourajr committed Jan 13, 2025
1 parent 0c02ac8 commit aacd267
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 60 deletions.
44 changes: 3 additions & 41 deletions example/src/components/SliceHero/SliceHero.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
"use client";

import { useEffect, useRef, useState } from "react";
import { useRef } from "react";
import { GenThreeShader } from "../GenThreeShader";
import { wavesShader } from "../GenThreeShader/shaders/wavesShader";
import { logotype } from "../SvgHeader/logotype";
import { SvgHeader } from "../SvgHeader";

export function SliceHero() {
const containerRef = useRef<HTMLDivElement>(null);
const [scale, setScale] = useState(1);

useEffect(() => {
const updateScale = () => {
if (!containerRef.current) return;
const { width } = containerRef.current.getBoundingClientRect();
// Adjust these values to control how the logo scales
const baseWidth = 208; // Original SVG width
const newScale = width / baseWidth;
setScale(newScale);
};

updateScale();
window.addEventListener("resize", updateScale);
return () => window.removeEventListener("resize", updateScale);
}, []);

return (
<section
Expand All @@ -47,29 +31,7 @@ export function SliceHero() {
}}
/>
</div>
<svg
className="absolute bottom-0 w-full aspect-[23.6/9]"
viewBox="0 0 208 79"
preserveAspectRatio="xMidYMid meet"
vectorEffect={"non-scaling-stroke"}
>
<defs>
<mask id="logotypeMask">
<g transform={`translate(0, ${20 * scale}) scale(${scale})`}>
<path d={logotype} fill="white" transform="translate(0, -10)" />
</g>
</mask>
</defs>
<path
fillRule="evenodd"
clipRule="evenodd"
d={logotype}
fill="none"
stroke="currentColor"
strokeWidth={0.2}
strokeDasharray={0.75}
/>
</svg>
<SvgHeader containerRef={containerRef} />
</section>
);
}
65 changes: 46 additions & 19 deletions example/src/components/SvgHeader/SvgHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
"use client";

import { motion } from "framer-motion";
import clsx from "clsx";
import { RefObject, useEffect, useState } from "react";
import { logotype } from "./logotype";

type SvgHeaderProps = {
className?: string;
containerRef: RefObject<HTMLDivElement>;
};

const SvgHeader = ({ className }: SvgHeaderProps) => (
<motion.svg
viewBox="0 0 208 79"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className={className}
>
<path
fillRule="evenodd"
clipRule="evenodd"
d={logotype}
fill="none"
stroke="currentColor"
strokeWidth={0.5}
strokeDasharray={1}
/>
</motion.svg>
);
const SvgHeader = ({ className, containerRef }: SvgHeaderProps) => {
const [scale, setScale] = useState(1);

useEffect(() => {
const updateScale = () => {
if (!containerRef.current) return;
const { width } = containerRef.current.getBoundingClientRect();
// Adjust these values to control how the logo scales
const baseWidth = 208; // Original SVG width
const newScale = width / baseWidth;
setScale(newScale);
};

updateScale();
window.addEventListener("resize", updateScale);
return () => window.removeEventListener("resize", updateScale);
}, []);
return (
<svg
className={clsx("absolute bottom-0 w-full aspect-[23.6/9]", className)}
viewBox="0 0 208 79"
preserveAspectRatio="xMidYMid meet"
vectorEffect={"non-scaling-stroke"}
>
<defs>
<mask id="logotypeMask">
<g transform={`translate(0, ${20 * scale}) scale(${scale})`}>
<path d={logotype} fill="white" transform="translate(0, -10)" />
</g>
</mask>
</defs>
<path
fillRule="evenodd"
clipRule="evenodd"
d={logotype}
fill="none"
stroke="currentColor"
strokeWidth={0.2}
strokeDasharray={0.75}
/>
</svg>
);
};
export default SvgHeader;

0 comments on commit aacd267

Please sign in to comment.