Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

HomeIntro.tsx

182 lines5.3 KB

1import { useNavigate } from "@tanstack/react-router";
2import { ArrowRightIcon, DatabaseZap } from "lucide-react";
3import { AnimatePresence, motion, stagger, Variants } from "motion/react";
4import { type ReactNode, useCallback, useState } from "react";
5import { cn } from "@/lib/utils";
6import { Button } from "./ui/button";
7import {
8 Card,
9 CardContent,
10 CardDescription,
11 CardFooter,
12 CardHeader,
13 CardTitle,
14} from "./ui/card";
15​
16const container = {
17 hidden: { opacity: 0 },
18 show: {
19 opacity: 1,
20 transition: {
21 when: "beforeChildren",
22 delayChildren: stagger(0.2),
23 },
24 },
25} satisfies Variants;
26​
27const item = {
28 hidden: { opacity: 0, translateY: 20 },
29 show: {
30 opacity: 1,
31 translateY: 0,
32 transition: { duration: 0.4 },
33 },
34} satisfies Variants;
35​
36function FeatureItem({
37 children,
38 title,
39 emoji,
40}: {
41 title: string;
42 children: ReactNode;
43 emoji: string;
44}) {
45 return (
46 <motion.li className="text-muted-foreground h-50 w-50" variants={item}>
47 <Card className="gap-3 h-full">
48 <CardHeader className="font-bold text-pretty">
49 {emoji} {title}
50 </CardHeader>
51 <CardContent>
52 <CardDescription>{children}</CardDescription>
53 </CardContent>
54 </Card>
55 </motion.li>
56 );
58​
59function WavyLine() {
60 return <div className="text-muted-foreground text-center">〰〰 ★ 〰〰</div>;
62​
63export function HomeIntro({
64 activeStep,
65 intro,
66}: {
67 activeStep: string | null;
68 intro: "true" | "false" | undefined;
69}) {
70 const [open, setOpen] = useState(
71 activeStep === null ||
72 // used for debugging
73 intro === "true",
74 );
75​
76 const navigate = useNavigate();
77​
78 const startTutorial = useCallback(() => {
79 setOpen(false);
80 navigate({
81 to: ".",
82 search: (o) => ({
83 ...o,
84 intro: "false",
85 }),
86 });
87 }, [navigate]);
88​
89 return (
90 <AnimatePresence initial={true}>
91 {open && (
92 <motion.div
93 initial="hidden"
94 animate="show"
95 variants={container}
96 exit={{
97 opacity: 0,
98 transition: { duration: 0.2 },
99 }}
100 className={cn(
101 "fixed top-0 left-0 right-0 p-6 bottom-0 bg-black/80 z-52 flex items-center justify-center backdrop-blur-xs",
102 )}
103 >
104 <Card className="w-3xl p-6 gap-10 max-h-full overflow-y-auto bg-background">
105 <CardHeader>
106 <CardTitle className="flex justify-center">
107 <div className="text-sm flex gap-2 items-center px-4 py-1 rounded-full">
108 <DatabaseZap className="h-4 text-primary" /> trytanstackdb.com{" "}
109 <span className="text-muted-foreground">BETA</span>
110 </div>
111 </CardTitle>
112 </CardHeader>
113 <CardContent className="space-y-6 flex justify-center flex-col items-center">
114 <motion.p
115 initial={{ opacity: 0 }}
116 animate={{ opacity: 1 }}
117 className="text-xl font-bold max-w-md text-pretty text-center"
118 >
119 <a
120 className="text-primary hover:underline hover:cursor-pointer"
121 target="_blank"
122 rel="noreferrer"
123 href="https://tanstack.com/db"
124 >
125 TanStack DB
126 </a>{" "}
127 is a library that makes it really easy to build ⚡blazing fast⚡
128 front-ends.
129 </motion.p>
130 <WavyLine />
131 <ul className="flex flex-wrap gap-4">
132 <FeatureItem emoji={"🚀"} title="User actions feel instant">
133 Updates show immediately while sync happens in the background.
134 </FeatureItem>
135 <FeatureItem
136 emoji={"🔄"}
137 title="Fetch data once, use everywhere"
138 >
139 Tanstack DB keeps it up to date!
140 </FeatureItem>
141 <FeatureItem
142 emoji={"🤝"}
143 title="Use any database and language on the backend"
144 >
145 No new libs needed.
146 </FeatureItem>
147 </ul>
148 <p className="max-w-sm text-center">
149 Sounds amazing, right? Learn the basics with this interactive
150 tutorial in 6-7 minutes!
151 </p>
152 </CardContent>
153 <CardFooter className="flex justify-center items-center flex-col gap-10">
154 <Button
155 onClick={startTutorial}
156 className="bg-primary cursor-pointer"
157 >
158 Get started <ArrowRightIcon />
159 </Button>
160 <div className="flex items-center gap-2 text-muted-foreground text-sm">
161 by{" "}
162 <a
163 className="flex items-center gap-2"
164 target="_blank"
165 rel="noreferrer"
166 href="https://fulop.dev"
167 >
168 <img
169 alt="fuko"
170 src="https://avatars.githubusercontent.com/u/43729152?s=96&v=4"
171 className="inline h-10 w-10 rounded-full border"
172 />
173 fuko
174 </a>
175 </div>
176 </CardFooter>
177 </Card>
178 </motion.div>
179 )}
180 </AnimatePresence>
181 );