Skip to content

Commit

Permalink
animate headlines and add highlight briefs
Browse files Browse the repository at this point in the history
  • Loading branch information
khanghy2130 committed Oct 5, 2024
1 parent fab723b commit 9b67aa7
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function Footer() {
return (
<div className="flex w-full flex-grow items-end pt-10">
<div className="z-10 flex w-full flex-grow items-end pt-10">
<div className="text-md flex w-full flex-col items-center bg-black px-2 py-3 text-center text-gray-200 sm:px-20 sm:text-lg">
<h2>&copy; {new Date().getFullYear()} TOYSHOP</h2>
<h2>
Expand Down
36 changes: 36 additions & 0 deletions app/routes/_index/BriefCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useInView } from "react-intersection-observer";
import { HighlightInfo } from ".";

type Props = {
highlight: HighlightInfo;
};

export default function BriefCard({ highlight }: Props) {
const { ref: briefRef, inView: briefInView } = useInView({
threshold: 0.5, // How much visible to trigger
triggerOnce: true,
});

return (
<div ref={briefRef} className="flex w-full p-1 sm:w-1/2 sm:p-2">
<div className="flex flex-col px-0 py-4 sm:px-4">
<h1 className="-mb-2 ms-4 text-4xl font-bold text-primaryColor sm:text-5xl">
{highlight.headline}
</h1>
<p className="w-full flex-grow rounded-lg bg-primaryColor px-2 py-4 text-2xl text-primaryTextColor shadow-md sm:rounded-xl sm:text-3xl">
{highlight.brief.split(" ").map((word, index) => (
<span
key={index}
className={`${briefInView ? "opacity-100" : "opacity-0"} inline-block transition-opacity duration-500`}
style={{
transitionDelay: `${index * 0.1}s`,
}}
>
&nbsp;{word}
</span>
))}
</p>
</div>
</div>
);
}
54 changes: 54 additions & 0 deletions app/routes/_index/Headlines.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { HighlightInfo } from ".";
import { useEffect, useRef, useState } from "react";

type Props = {
highlight: HighlightInfo;
};

export default function Headlines({ highlight }: Props) {
const containerRef = useRef<HTMLDivElement>(null);
const [headlineWidth, setHeadlineWidth] = useState<number>(0);

// Update scrollY on scroll
useEffect(() => {
const handleScroll = () => {
if (!containerRef.current) return;
const clientRect = containerRef.current.getBoundingClientRect();
const percentage =
(100 / clientRect.height) *
(clientRect.height - clientRect.bottom);
// add 5% to fill up sooner
setHeadlineWidth(Math.min(Math.max(percentage + 5, 0), 100));
};

window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
}, []);

return (
<div ref={containerRef} className="flex h-[1000px] flex-col">
{/* Headline image */}
<div className="sticky top-0 -z-10 flex justify-center">
<div className="relative flex justify-start">
<img
className="w-screen max-w-[800px]"
src={highlight.headlineImages[0]}
/>
<div
className="absolute left-0 top-0 overflow-x-hidden"
style={{
width: headlineWidth + "%",
}}
>
<img
className="w-screen max-w-[800px]"
src={highlight.headlineImages[1]}
/>
</div>
</div>
</div>
</div>
);
}
73 changes: 35 additions & 38 deletions app/routes/_index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import save_outline from "~/assets/landing_page/headlines/save_outline.png";
import save_fill from "~/assets/landing_page/headlines/save_fill.png";
import share_outline from "~/assets/landing_page/headlines/share_outline.png";
import share_fill from "~/assets/landing_page/headlines/share_fill.png";
import Headlines from "./Headlines";
import BriefCard from "./BriefCard";

export const meta: MetaFunction = () => {
return [
Expand All @@ -17,62 +19,57 @@ export const meta: MetaFunction = () => {
];
};

export default function Index() {
const highlights: {
headline: [string, string]; // [outline, fill]
brief: string;
}[] = [
export type HighlightInfo = {
headline: string;
headlineImages: [string, string]; // [outline, fill]
brief: string;
};

export default function LandingPage() {
const highlights: HighlightInfo[] = [
{
// EXPLORE
headline: [explore_outline, explore_fill],
brief: "exploreeee",
headline: "Explore",
headlineImages: [explore_outline, explore_fill],
brief: "Browse our huge selection of unique and exciting toys, from futuristic vehicles to powerful battle machines, all waiting to be explored.",
},
{
// COLLECT
headline: [collect_outline, collect_fill],
brief: "colllecettt",
headline: "Collect",
headlineImages: [collect_outline, collect_fill],
brief: "Build your ultimate collection with limited editions and series designed for true enthusiasts and collectors alike.",
},
{
// SAVE
headline: [save_outline, save_fill],
brief: "sassavavee",
headline: "Save",
headlineImages: [save_outline, save_fill],
brief: "Save big on every purchase! We offer unbeatable deals and exclusive discounts. Don't miss our regular flash sales for your favorite toys!",
},
{
// SHARE
headline: [share_outline, share_fill],
brief: "shharrree",
headline: "Share",
headlineImages: [share_outline, share_fill],
brief: "Join the conversation! Share your experience, rate your favorites, and help others find the perfect toy by leaving your feedback and reviews.",
},
];

return (
<div className="relative h-full w-full">
<ThreeCanvas />
{/* Hero section */}
<div className="relative z-10 h-96 w-full bg-bgColor2">
<div className="relative z-10 mb-20 h-96 w-full bg-bgColor2">
<h1>Welcome</h1>
</div>

{/* Headlines scrollzone */}
{highlights.map((highlight, i) => (
<div key={i} className="h-screen">
<div className="sticky top-0 -z-10 flex justify-center pt-16">
<div className="relative flex justify-start">
<img
className="w-screen max-w-[800px]"
src={highlight.headline[0]}
/>
<div className="absolute left-0 top-0 w-[50%] overflow-x-hidden bg-bgColor2">
<img
className="w-screen max-w-[800px]"
src={highlight.headline[1]}
/>
</div>
</div>
</div>
<p className="relative z-10">
{highlight.brief} Online store for toys. Online store
for toys. Online store for toys. Online store for toys.
</p>
</div>
<Headlines key={i} highlight={highlight} />
))}

{/* Highlight briefs */}
<div className="relative z-10 -mb-10 py-40 backdrop-blur-md">
<div className="mx-auto flex w-full max-w-[400px] flex-wrap px-2 sm:max-w-[800px]">
{highlights.map((highlight, i) => (
<BriefCard key={i} highlight={highlight} />
))}
</div>
</div>
</div>
);
}
2 changes: 1 addition & 1 deletion app/routes/pay._index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function PayPageDefault() {
<p className="mb-4 bg-yellow-500 bg-opacity-30 px-2 text-lg">
<span className="font-bold">Note: </span>
this is a demo project, do not enter real information. To
test payment, please enter card number: 4242 4242 4242 4242.
test payment, please enter card number 4242 4242 4242 4242 and any valid value for the rest.
</p>
<PaymentElement />
<div className="mt-6 flex w-full justify-center">
Expand Down
2 changes: 1 addition & 1 deletion app/routes/store/TagsFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function TagsFilter({
<>
<div className="flex flex-wrap items-center gap-x-1 gap-y-2">
<button
className="text-md mr-2 flex flex-row rounded-md bg-primaryColor px-2 py-2 font-medium text-primaryTextColor hover:bg-primaryColorMuted"
className="text-md mr-2 flex flex-row rounded-md bg-bgColor2 px-2 py-2 font-medium text-textColor1 hover:bg-bgColor3"
onClick={() => setShowTagsModal(!showTagsModal)}
>
<svg
Expand Down
10 changes: 7 additions & 3 deletions app/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
--primaryTextColor: #f6f6f6;
}
html {
--bgColor1: #f8d6eb;
--bgColor2: #f8f6d9;
--bgColor3: #f7f1bc;
--bgColor1: #faf9ee;
--bgColor2: #f3f0d6;
--bgColor3: #f3edb8;
--textColor1: #373737;
--textColor2: #6b6b6b;
}
Expand Down Expand Up @@ -44,6 +44,10 @@
@apply transition-[transform] active:scale-90;
}

.custom-text-shadow {
text-shadow: 0 0 0.15em black;
}

.auth-form {
@apply absolute top-1/2 flex w-full -translate-y-1/2 flex-col items-center p-2 text-left transition-transform duration-200;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"isbot": "^5.1.17",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-intersection-observer": "^9.13.1",
"stripe": "^16.8.0",
"supabase": "^1.191.3",
"three": "^0.169.0"
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5899,6 +5899,11 @@ react-dom@^18.3.1:
loose-envify "^1.1.0"
scheduler "^0.23.2"

react-intersection-observer@^9.13.1:
version "9.13.1"
resolved "https://registry.yarnpkg.com/react-intersection-observer/-/react-intersection-observer-9.13.1.tgz#6c61a75801162491c6348bad09967f2caf445584"
integrity sha512-tSzDaTy0qwNPLJHg8XZhlyHTgGW6drFKTtvjdL+p6um12rcnp8Z5XstE+QNBJ7c64n5o0Lj4ilUleA41bmDoMw==

react-is@^16.13.1:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
Expand Down

0 comments on commit 9b67aa7

Please sign in to comment.