"use client"; import React, { useState } from "react"; import { Button } from "../button"; import { EmailInputBlockProps } from "./types"; const LogoCream = ({ fill = "#FFFEEF" }: { fill?: string }) => { const clipPathId = `logo-cream-clip-${React.useId()}`; return ( ); }; export const EmailInputBlock: React.FC = props => { const { anchorId = "email-input", title, subTitle, emailInputDescription, inputPlaceholder = "Enter your email here", ctaButtonText, ctaText, caption, backgroundColor = "white", successFeedback, onSubmit, themeColor, showPinWheel = true, padding = "large", requiredErrorMessage = "Email is required", validationErrorMessage = "Invalid email address", } = props || {}; const buttonLabel = ctaButtonText || ctaText || "Sign me up"; const backgroundColorClasses: Record = { green: "bg-bg-fill-brand", white: "bg-bg", gray90: "bg-[var(--color-text-secondary)]", }; const themeColorClasses: Record = { green: "bg-bg-fill-brand", blue: "bg-bg-fill-brand-supporting", orange: "bg-orange-500", purple: "bg-bg-fill-brand-tertiary", white: "bg-bg", }; const normalizedBg = ((backgroundColor as string) || "").trim().toLowerCase() || "white"; const outerBgClass = backgroundColorClasses[normalizedBg as keyof typeof backgroundColorClasses] || backgroundColorClasses.white; const captionTextColorClass = normalizedBg === "white" ? "text-text" : "text-white"; const normalizedTheme = ((themeColor as string) || "").trim().toLowerCase() || "green"; const containerBgClass = themeColorClasses[normalizedTheme as keyof typeof themeColorClasses] || themeColorClasses.green; const darkThemeColors = ["green", "blue", "purple"]; const isDarkTheme = darkThemeColors.includes(normalizedTheme); const textColor = isDarkTheme ? "text-white" : "text-text"; const errorTextColor = isDarkTheme ? "text-text-inverse" : "text-text"; const pinwheelFill = normalizedTheme === "white" ? "#E0E0E0" : "#FFFEEF"; const paddingClass = padding === "none" ? "!py-0 md:!py-0" : "!py-8 md:!py-20"; const [email, setEmail] = useState(""); const [formSubmitted, setFormSubmitted] = useState(false); const [emailError, setEmailError] = useState(""); const validateEmail = (email: string) => { const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; return emailRegex.test(email); }; const handleOnSubmit = () => { if (!email.trim()) { setEmailError(requiredErrorMessage); } else if (!validateEmail(email)) { setEmailError(validationErrorMessage); } else { onSubmit({ email }); setEmail(""); setFormSubmitted(true); setEmailError(""); } }; return ( {showPinWheel && ( )} {title && ( {title} )} {subTitle && ( {subTitle} )} {emailInputDescription && ( {emailInputDescription} )} { const value = e.target.value; setEmail(value); if (formSubmitted) setFormSubmitted(false); if (!value.trim()) { setEmailError(requiredErrorMessage); } else if (!validateEmail(value)) { setEmailError(validationErrorMessage); } else { setEmailError(""); } }} className="w-full flex-grow bg-transparent !pl-4 pr-6 py-3 text-[1rem] leading-none md:text-base font-normal text-text outline-none placeholder:input-text-placeholder md:py-4" /> {emailError && ( {emailError} )} {successFeedback && formSubmitted && !emailError && ( {successFeedback} )} {caption && ( {caption} )} ); }; export default EmailInputBlock;
{emailInputDescription}
{emailError}
{successFeedback}