Skip to content

Commit 10b9829

Browse files
committed
WIP
1 parent 1486a0d commit 10b9829

File tree

1 file changed

+47
-14
lines changed

1 file changed

+47
-14
lines changed

src/app/course/call-to-action.tsx

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function SignUpForm() {
2525
}
2626

2727
export function HeroActions() {
28-
let [isExpanded, setIsExpanded] = useState(false);
28+
let [signUpState, setSignUpState] = useState<"closed" | "open" | "subscribed">("closed");
2929
let input = useRef<HTMLInputElement>(null);
3030
let getCourseButton = useRef(null);
3131
let containerRef = useRef<HTMLInputElement>(null);
@@ -35,7 +35,7 @@ export function HeroActions() {
3535

3636
// Check if the related target (where focus is going) is within our container
3737
if (input.current.value.length === 0 && !containerRef.current?.contains(e.relatedTarget)) {
38-
setIsExpanded(false);
38+
setSignUpState("closed");
3939
}
4040
};
4141

@@ -45,20 +45,22 @@ export function HeroActions() {
4545
<motion.div
4646
ref={containerRef}
4747
layout
48-
transition={{ duration: isExpanded ? 0.1 : 0.2, ease: "circOut" }}
49-
className="relative flex items-center bg-white data-expanded:overflow-hidden"
48+
transition={{ duration: signUpState === "open" ? 0.1 : 0.2, ease: "circOut" }}
49+
className="relative flex items-center bg-white data-[state=open]:overflow-hidden data-[state=subscribed]:bg-gray-950"
5050
style={{ borderRadius: 20 }}
51-
data-expanded={isExpanded || undefined}
51+
data-state={signUpState}
5252
>
5353
<AnimatePresence mode="popLayout" initial={false}>
54-
{isExpanded ? (
55-
<motion.div
54+
{signUpState === "open" && (
55+
<motion.form
56+
action="https://app.kit.com/forms/7712177/subscriptions"
57+
method="POST"
5658
className="flex items-center"
5759
layout
5860
onKeyDown={(e) => {
5961
if (e.key === "Escape" && input.current) {
6062
input.current.value = "";
61-
setIsExpanded(false);
63+
setSignUpState("closed");
6264
}
6365
}}
6466
exit={{
@@ -80,22 +82,26 @@ export function HeroActions() {
8082
ref={input}
8183
onBlur={handleBlur}
8284
type="email"
83-
id="email"
85+
name="email_address"
8486
className="w-3xs rounded-full bg-transparent px-4 py-2 text-sm/6 text-gray-950 focus:outline-none"
8587
placeholder="Enter your email"
8688
aria-label="Email address"
8789
/>
88-
<button className="mr-0.5 shrink-0 overflow-hidden rounded-full bg-gray-950 px-3 py-1.5 text-sm/6 font-semibold text-nowrap text-white hover:bg-gray-950/85">
90+
<button
91+
type="submit"
92+
className="mr-0.5 shrink-0 overflow-hidden rounded-full bg-gray-950 px-3 py-1.5 text-sm/6 font-semibold text-nowrap text-white hover:bg-gray-950/85"
93+
>
8994
Sign up
9095
</button>
91-
</motion.div>
92-
) : (
96+
</motion.form>
97+
)}
98+
{signUpState === "closed" && (
9399
<motion.button
94100
layout
95101
ref={getCourseButton}
96102
key="get-course-button"
97103
onClick={() => {
98-
setIsExpanded(true);
104+
setSignUpState("open");
99105
}}
100106
type="button"
101107
className="inline-flex rounded-full bg-transparent px-4 py-2 text-sm/6 font-semibold text-gray-950 hover:bg-gray-100 focus:outline-none focus-visible:outline focus-visible:outline-offset-2 focus-visible:outline-white focus-visible:outline-solid"
@@ -116,11 +122,38 @@ export function HeroActions() {
116122
Get the free course &rarr;
117123
</motion.button>
118124
)}
125+
{signUpState === "subscribed" && (
126+
<motion.button
127+
onClick={() => setSignUpState("closed")}
128+
layout
129+
transition={{ duration: 0.3 }}
130+
className="inline-flex flex-nowrap items-baseline gap-1.5 self-center rounded-full bg-white/25 px-4 py-2 pl-3 text-sm/6 font-semibold whitespace-nowrap text-white hover:bg-white/30"
131+
initial={{
132+
opacity: 0,
133+
}}
134+
animate={{
135+
opacity: 1,
136+
}}
137+
exit={{
138+
opacity: 0,
139+
}}
140+
>
141+
<svg width={20} height={20} fill="none" className="self-center stroke-white">
142+
<path d="M19 10a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
143+
<path
144+
d="M13.91 9.67a.37.37 0 0 1 0 .66l-5.6 3.11a.38.38 0 0 1-.56-.33V6.9c0-.29.3-.47.56-.33l5.6 3.11Z"
145+
strokeLinecap="round"
146+
strokeLinejoin="round"
147+
/>
148+
</svg>
149+
You're in
150+
</motion.button>
151+
)}
119152
</AnimatePresence>
120153
</motion.div>
121154
</div>
122155
<AnimatePresence initial={false}>
123-
{!isExpanded && (
156+
{signUpState === "closed" && (
124157
<motion.button
125158
layout
126159
transition={{ duration: 0.3 }}

0 commit comments

Comments
 (0)