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

HomeIntro.tsx

185 lines5.7 KB

1import { ArrowRightIcon, DatabaseZap } from "lucide-react";
2import { AnimatePresence, motion, stagger, type Variants } from "motion/react";
3import { type ReactNode, useCallback, useMemo, useState } from "react";
4import { cn } from "@/lib/utils";
5import { getShowIntro } from "@/utils/getShowIntro";
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 showIntro,
66 isMobile = false,
67}: {
68 activeStep: string | null;
69 showIntro: boolean;
70 isMobile?: boolean;
71}) {
72 const [open, setOpen] = useState(
73 activeStep === null ||
74 // used for debugging
75 showIntro,
76 );
77​
78 const { updateShowIntro } = useMemo(() => getShowIntro(), []);
79​
80 const startTutorial = useCallback(() => {
81 setOpen(false);
82 updateShowIntro("hidden");
83 }, [updateShowIntro]);
84​
85 return (
86 <AnimatePresence initial={true}>
87 {open && (
88 <motion.div
89 initial="hidden"
90 animate="show"
91 variants={container}
92 exit={{
93 opacity: 0,
94 transition: { duration: 0.2 },
95 }}
96 className={cn(
97 "fixed top-0 left-0 right-0 p-6 bottom-0 bg-black/80 z-52 flex items-center justify-center backdrop-blur-xs",
98 )}
99 >
100 <Card className="w-3xl p-6 gap-10 max-h-full overflow-y-auto bg-background">
101 <CardHeader>
102 <CardTitle className="flex justify-center">
103 <div className="text-sm flex gap-2 items-center px-4 py-1 rounded-full">
104 <DatabaseZap className="h-4 text-primary" /> trytanstackdb.com{" "}
105 <span className="text-muted-foreground">BETA</span>
106 </div>
107 </CardTitle>
108 </CardHeader>
109 <CardContent className="space-y-6 flex justify-center flex-col items-center">
110 <motion.p
111 initial={{ opacity: 0 }}
112 animate={{ opacity: 1 }}
113 className="text-xl font-bold max-w-md text-pretty text-center"
114 >
115 <a
116 className="text-primary hover:underline hover:cursor-pointer"
117 target="_blank"
118 rel="noreferrer"
119 href="https://tanstack.com/db"
120 >
121 TanStack DB
122 </a>{" "}
123 is a library that makes it really easy to build ⚡blazing fast⚡
124 front-ends.
125 </motion.p>
126 <WavyLine />
127 <ul className="flex flex-wrap gap-4 justify-center">
128 <FeatureItem emoji={"🚀"} title="User actions feel instant">
129 Updates show immediately while sync happens in the background.
130 </FeatureItem>
131 <FeatureItem
132 emoji={"🔄"}
133 title="Fetch data once, use everywhere"
134 >
135 Tanstack DB keeps it up to date!
136 </FeatureItem>
137 <FeatureItem
138 emoji={"🤝"}
139 title="Use any database and language on the backend"
140 >
141 No new libs needed.
142 </FeatureItem>
143 </ul>
144 <p className="max-w-sm text-center">
145 Sounds amazing, right? Learn the basics with this interactive
146 tutorial in 6-7 minutes!
147 </p>
148 {isMobile && (
149 <p className="max-w-sm text-destructive text-center font-bold text-sm">
150 This interactive tutorial requires features not available on
151 mobile browsers. Please visit on a desktop computer.
152 </p>
153 )}
154 </CardContent>
155 <CardFooter className="flex justify-center items-center flex-col gap-10">
156 <Button
157 onClick={startTutorial}
158 className="bg-primary cursor-pointer"
159 disabled={isMobile}
160 >
161 Get started <ArrowRightIcon />
162 </Button>
163 <div className="flex items-center gap-2 text-muted-foreground text-sm">
164 by{" "}
165 <a
166 className="flex items-center gap-2"
167 target="_blank"
168 rel="noreferrer"
169 href="https://fulop.dev"
170 >
171 <img
172 alt="fuko"
173 src="https://avatars.githubusercontent.com/u/43729152?s=96&v=4"
174 className="inline h-10 w-10 rounded-full border"
175 />
176 fuko
177 </a>
178 </div>
179 </CardFooter>
180 </Card>
181 </motion.div>
182 )}
183 </AnimatePresence>
184 );