Blocks

Log In 4

Sign up / Log in
Text Align CenterLogo Center1 ColumnButtonsForm
Log In 4

Code

relume-login4.tsx
"use client";

import { useState } from "react";
import { Button, type ButtonProps } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { FacebookLogo, GoogleLogo, AppleLogo } from "relume-icons";

type ImageProps = {
  url?: string;
  src: string;
  alt?: string;
};

type Props = {
  logo: ImageProps;
  signUpText: string;
  signUpLink: {
    text: string;
    url: string;
  };
  title: string;
  description: string;
  inputPlaceholderEmail: string;
  inputPlaceholderPassword: string;
  logInButton: ButtonProps;
  socialLoginButtons: ButtonProps[];
  forgotPassword: {
    text: string;
    url: string;
  };
  footerText: string;
};

export type Login4Props = React.ComponentPropsWithoutRef<"section"> & Partial<Props>;

export const Login4 = (props: Login4Props) => {
  const {
    logo,
    signUpText,
    signUpLink,
    title,
    description,
    inputPlaceholderEmail,
    inputPlaceholderPassword,
    logInButton,
    socialLoginButtons,
    forgotPassword,
    footerText,
  } = {
    ...Login4Defaults,
    ...props,
  };

  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");

  const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
    event.preventDefault();
    console.log({ email, password });
  };

  return (
    <section className="px-[5%]">
      <div className="relative flex min-h-svh flex-col justify-center overflow-auto py-24 lg:py-20">
        <div className="absolute top-0 right-0 left-0 flex h-16 items-center justify-center md:h-18">
          <a href={logo.url}>
            <img src={logo.src} alt={logo.alt} />
          </a>
        </div>
        <Card className="mx-auto w-full max-w-sm px-6 py-8 sm:px-8 md:p-12">
          <div className="mb-6 text-center md:mb-8">
            <h1 className="mb-3 text-h3 font-bold md:mb-4">{title}</h1>
            <p className="text-medium">{description}</p>
          </div>
          <form className="grid gap-4" onSubmit={handleSubmit}>
            <Input
              type="email"
              id="email"
              placeholder={inputPlaceholderEmail}
              value={email}
              onChange={(e) => setEmail(e.target.value)}
            />
            <Input
              type="password"
              id="password"
              placeholder={inputPlaceholderPassword}
              value={password}
              onChange={(e) => setPassword(e.target.value)}
            />
            <Button
              variant={logInButton.variant}
              size={logInButton.size}
              iconLeft={logInButton.iconLeft}
              iconRight={logInButton.iconRight}
            >
              {logInButton.title}
            </Button>
            <div className="my-3 h-px w-full bg-scheme-border md:my-4" />
            {socialLoginButtons.map((button, index) => (
              <Button key={index} {...button} className="gap-x-3">
                {button.title}
              </Button>
            ))}
          </form>
          <div className="mt-5 w-full text-center md:mt-6">
            <a href={forgotPassword.url} className="underline">
              {forgotPassword.text}
            </a>
          </div>
          <div className="mt-3 flex w-full justify-center gap-x-1 text-center md:mt-4">
            <p>{signUpText}</p>
            <a href={signUpLink.url} className="underline">
              {signUpLink.text}
            </a>
          </div>
        </Card>
        <footer className="absolute right-0 bottom-0 left-0 flex h-16 w-full items-center justify-center md:h-18">
          <p className="text-small">{footerText}</p>
        </footer>
      </div>
    </section>
  );
};

export const Login4Defaults: Props = {
  logo: {
    url: "#",
    src: "https://d22po4pjz3o32e.cloudfront.net/logo-image.svg",
    alt: "Logo text",
  },
  signUpText: "Don't have an account?",
  signUpLink: {
    text: "Sign up",
    url: "#",
  },
  title: "Log In",
  description: "Lorem ipsum dolor sit amet adipiscing elit.",
  inputPlaceholderEmail: "Email",
  inputPlaceholderPassword: "Password",
  logInButton: {
    title: "Log in",
  },
  socialLoginButtons: [
    {
      variant: "secondary",
      title: "Log in with Google",
      iconLeft: <GoogleLogo className="size-6 text-scheme-text" />,
    },
    {
      variant: "secondary",
      title: "Log in with Facebook",
      iconLeft: <FacebookLogo className="size-6 text-scheme-text" />,
    },
    {
      variant: "secondary",
      title: "Log in with Apple",
      iconLeft: <AppleLogo className="size-6 text-scheme-text" />,
    },
  ],
  forgotPassword: {
    text: "Forgot your password?",
    url: "#",
  },
  footerText: "© 2024 Relume",
};

npm i @radix-ui/react-dialog @radix-ui/react-label @radix-ui/react-select @radix-ui/react-slot @radix-ui/react-tabs class-variance-authority@0.7.1 clsx@^2.1.1 embla-carousel-autoplay embla-carousel-react@^8.5.2 relume-icons@1.3.0 tailwind-merge@^2.2.2