Blocks

Layout 497

standard
Text Align Left2 ColumnsTabsButtonsMultiple ImagesImage
Layout 497

Code

relume-layout497.tsx
"use client";

import { useState } from "react";
import { motion } from "motion/react";
import { Button, type ButtonProps } from "@/components/ui/button";
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { ChevronRight, PlayCircle, ProgressActivity, RelumeIcon } from "relume-icons";
import clsx from "clsx";

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

type VideoProps = {
  image: ImageProps;
  url: string;
};

type TabProps = {
  heading: string;
  description: string;
  image?: ImageProps;
  video?: VideoProps;
  value: string;
};

type Props = {
  tagline: string;
  heading: string;
  description: string;
  tabs: TabProps[];
  buttons: ButtonProps[];
};

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

export const Layout497 = (props: Layout497Props) => {
  const { tagline, heading, description, tabs, buttons } = {
    ...Layout497Defaults,
    ...props,
  };
  const [activeValue, setActiveValue] = useState(tabs[0].value);
  const [isIframeLoaded, setIsIframeLoaded] = useState(false);

  return (
    <section className="px-[5%] py-16 md:py-24 lg:py-28">
      <div className="relative container">
        <div className="w-full pr-0 md:w-1/2 md:pr-6 lg:pr-10">
          <div className="mb-8 w-full md:w-auto">
            <p className="mb-3 font-semibold md:mb-4">{tagline}</p>
            <h1 className="mb-5 text-h2 font-bold md:mb-6">{heading}</h1>
            <p className="text-medium">{description}</p>
          </div>
          <div className="static flex flex-col flex-wrap justify-stretch md:block">
            <Tabs defaultValue={tabs[0].value} onValueChange={setActiveValue}>
              <TabsList className="relative mb-8 grid auto-cols-fr grid-cols-1 grid-rows-[auto_auto] items-start md:mb-0 md:items-stretch">
                {tabs.map((tab) => (
                  <TabsTrigger
                    key={tab.value}
                    value={tab.value}
                    className="items-center justify-start gap-4 rounded-none border-0 border-b px-0 py-4 text-left whitespace-normal data-[state=active]:border-scheme-border data-[state=active]:bg-transparent data-[state=inactive]:border-scheme-border data-[state=inactive]:opacity-25"
                  >
                    <div className="flex-none self-start">
                      <RelumeIcon className="size-8 text-scheme-text" />
                    </div>
                    <div>
                      <h2 className="text-h5 font-bold">{tab.heading}</h2>
                      <motion.div
                        initial={false}
                        animate={{
                          height: activeValue === tab.value ? "auto" : 0,
                          opacity: activeValue === tab.value ? 1 : 0,
                        }}
                        transition={{ duration: 0.3, ease: "easeInOut" }}
                        className="overflow-hidden"
                      >
                        <p className="mt-2">{tab.description}</p>
                      </motion.div>
                    </div>
                  </TabsTrigger>
                ))}
              </TabsList>
              <div className="relative top-0 right-0 bottom-0 left-auto flex h-full w-full items-center justify-center md:absolute md:w-1/2 md:pl-6 lg:pl-10">
                {tabs.map((tab) => (
                  <TabsContent
                    key={tab.value}
                    value={tab.value}
                    className="w-full data-[state=active]:animate-tabs"
                  >
                    <motion.div
                      initial={{ opacity: 0 }}
                      animate={{ opacity: 1 }}
                      transition={{ duration: 0.2 }}
                      exit={{ opacity: 0 }}
                    >
                      {tab.image && (
                        <img src={tab.image.src} alt={tab.image.alt} className="rounded-image" />
                      )}
                      {tab.video && (
                        <Dialog>
                          <DialogTrigger className="relative flex w-full items-center justify-center overflow-hidden rounded-image">
                            <img
                              src={tab.video.image.src}
                              alt={tab.video.image.alt}
                              className="size-full object-cover"
                            />
                            <span className="absolute inset-0 z-10 bg-neutral-darkest/50" />
                            <PlayCircle className="absolute z-20 size-20 text-white" />
                          </DialogTrigger>
                          <DialogContent>
                            {!isIframeLoaded && (
                              <ProgressActivity className="mx-auto size-16 animate-spin text-white" />
                            )}
                            <iframe
                              className={clsx(
                                "z-0 mx-auto aspect-video size-full md:w-[738px] lg:w-[940px]",
                                {
                                  visible: isIframeLoaded,
                                  hidden: !isIframeLoaded,
                                },
                              )}
                              src={tab.video.url}
                              allow="autoplay; encrypted-media; picture-in-picture"
                              allowFullScreen
                              onLoad={() => setIsIframeLoaded(true)}
                            />
                          </DialogContent>
                        </Dialog>
                      )}
                    </motion.div>
                  </TabsContent>
                ))}
              </div>
            </Tabs>
          </div>
          <div className="mt-6 flex items-center gap-x-4 md:mt-8">
            {buttons.map((button, index) => (
              <Button key={index} {...button}>
                {button.title}
              </Button>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
};

export const Layout497Defaults: Props = {
  tagline: "Tagline",
  heading: "Medium length section heading goes here",
  description:
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat.",
  tabs: [
    {
      value: "tab-one",
      heading: "Short heading goes here",
      description:
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique.",
      image: {
        src: "https://d22po4pjz3o32e.cloudfront.net/placeholder-image.svg",
        alt: "Relume placeholder image 1",
      },
    },
    {
      value: "tab-two",
      heading: "Short heading goes here",
      description:
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique.",
      video: {
        image: {
          src: "https://d22po4pjz3o32e.cloudfront.net/placeholder-video-thumbnail.svg",
          alt: "Relume placeholder image 2",
        },
        url: "https://www.youtube.com/embed/8DKLYsikxTs?si=Ch9W0KrDWWUiCMMW",
      },
    },
    {
      value: "tab-three",
      heading: "Short heading goes here",
      description:
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique.",
      image: {
        src: "https://d22po4pjz3o32e.cloudfront.net/placeholder-image.svg",
        alt: "Relume placeholder image 3",
      },
    },
  ],
  buttons: [
    { title: "Button", variant: "secondary" },
    {
      title: "Button",
      variant: "link",
      size: "link",
      iconRight: <ChevronRight className="text-scheme-text" />,
    },
  ],
};

npm i @radix-ui/react-dialog @radix-ui/react-slot @radix-ui/react-tabs class-variance-authority@0.7.1 clsx@^2.1.1 motion@^12.15.0 relume-icons@1.3.0 tailwind-merge@^2.2.2