Blocks

Comparison 1

standard
2 ColumnsText Align CenterIconsButtonsListComparison Section
Comparison 1

Code

relume-comparison1.tsx
import React from "react";
import clsx from "clsx";
import { Button, type ButtonProps } from "@/components/ui/button";
import { Check, ChevronRight, Close, RelumeIcon } from "relume-icons";

type Feature = {
  text: string;
  items: React.ReactNode[];
};

type ComparisonProducts = {
  title?: string;
  products: Product[];
};

type Product = {
  productName: string;
  description: string;
};

type Props = {
  tagline: string;
  heading: string;
  description: string;
  comparisonProducts: ComparisonProducts[];
  features: Feature[];
  buttons: ButtonProps[];
};

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

export const Comparison1 = (props: Comparison1Props) => {
  const { tagline, heading, description, buttons, comparisonProducts, features } = {
    ...Comparison1Defaults,
    ...props,
  };
  return (
    <section className="px-[5%] py-16 md:py-24 lg:py-28">
      <div className="container">
        <div className="mx-auto mb-12 max-w-lg text-center md:mb-18 lg:mb-20">
          <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="mx-auto max-w-xl">
          <div className="grid grid-cols-2 border-b border-scheme-border md:grid-cols-[1.5fr_1fr_1fr]">
            {comparisonProducts.map((comparison, index) => (
              <React.Fragment key={index}>
                <div className="hidden h-full flex-col items-start justify-end py-4 pr-4 sm:py-6 sm:pr-6 md:flex lg:py-6 lg:pr-6">
                  <h2 className="text-h6 font-bold">{comparison.title}</h2>
                </div>
                {comparison.products.map((plan, index) => (
                  <ProductPlan key={index} index={index} {...plan} />
                ))}
              </React.Fragment>
            ))}
          </div>
          <FeaturesSection features={features} />
          <div className="mt-12 flex flex-wrap items-center justify-center gap-4 md:mt-18 lg:mt-20">
            {buttons.map((button, index) => (
              <Button key={index} {...button}>
                {button.title}
              </Button>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
};
const ProductPlan = ({ index, ...product }: Product & { index: number }) => {
  return (
    <div
      className={clsx("flex h-full flex-col justify-between px-2 py-4 sm:px-4 sm:py-6 lg:p-6", {
        "bg-scheme-foreground": index === 0,
      })}
    >
      <div className="flex flex-col items-center gap-2 text-center">
        <RelumeIcon className="size-12 text-scheme-text" />
        <h2 className="text-h6 font-bold">{product.productName}</h2>
        <p>{product.description}</p>
      </div>
    </div>
  );
};

const FeaturesSection = ({ features }: { features: Feature[] }) => {
  return (
    <div>
      {features.map((feature, index) => (
        <div key={index}>
          <div
            key={index}
            className="grid grid-cols-2 border-b border-scheme-border md:grid-cols-[1.5fr_1fr_1fr]"
          >
            <p className="col-span-3 row-span-1 border-b border-scheme-border py-4 pr-4 md:col-span-1 md:border-none md:pr-6">
              {feature.text}
            </p>
            {feature.items.map((item, index) => (
              <div
                key={index}
                className={clsx(
                  "flex items-center justify-center px-4 py-4 text-center font-semibold md:px-6",
                  {
                    "bg-scheme-foreground": index === 0,
                  },
                )}
              >
                <span>{item}</span>
              </div>
            ))}
          </div>
        </div>
      ))}
    </div>
  );
};

export const Comparison1Defaults: Props = {
  tagline: "Tagline",
  heading: "Short heading goes here",
  description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
  comparisonProducts: [
    {
      title: "Product comparison",
      products: [
        {
          productName: "Product name",
          description: "Lorem ipsum dolor sit amet",
        },
        {
          productName: "Product name",
          description: "Lorem ipsum dolor sit amet",
        },
      ],
    },
  ],
  features: [
    {
      text: "Feature text goes here",
      items: ["Unlimited", "10"],
    },
    {
      text: "Feature text goes here",
      items: [
        <Check className="size-6 text-scheme-text" />,
        <Check className="size-6 text-scheme-text" />,
      ],
    },
    {
      text: "Feature text goes here",
      items: [
        <Check className="size-6 text-scheme-text" />,
        <Check className="size-6 text-scheme-text" />,
      ],
    },
    {
      text: "Feature text goes here",
      items: [<Check className="size-6 text-scheme-text" />, <Close className="size-6" />],
    },
    {
      text: "Feature text goes here",
      items: [<Check className="size-6 text-scheme-text" />, <Close className="size-6" />],
    },
  ],
  buttons: [
    {
      title: "Button",
      variant: "secondary",
    },
    {
      title: "Button",
      variant: "link",
      size: "link",
      iconRight: <ChevronRight className="text-scheme-text" />,
    },
  ],
};

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