Blocks

Blog 3

Blog Headers
Text Align LeftText Align Center3 ColumnsAuthorDateAvatar Image
Blog 3

Code

relume-blog3.tsx
import { Card } from "@/components/ui/card";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";

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

type BlogPost = {
  url: string;
  image: ImageProps;
  category: string;
  readTime: string;
  title: string;
  description: string;
  avatar: ImageProps;
  fullName: string;
  date: string;
};

type Tab = {
  value: string;
  trigger: string;
  content: BlogPost[];
};

type Props = {
  tagline: string;
  heading: string;
  description: string;
  tabs: Tab[];
};

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

export const Blog3 = (props: Blog3Props) => {
  const { tagline, heading, description, tabs } = {
    ...Blog3Defaults,
    ...props,
  };
  return (
    <section className="px-[5%] py-16 md:py-24 lg:py-28">
      <div className="container">
        <div className="mb-12 md:mb-18 lg:mb-20">
          <div className="mx-auto w-full max-w-lg text-center">
            <p className="mb-3 font-semibold md:mb-4">{tagline}</p>
            <h1 className="mb-5 text-h1 font-bold md:mb-6">{heading}</h1>
            <p className="text-medium">{description}</p>
          </div>
        </div>
        <Tabs defaultValue={tabs[0].value} className="flex flex-col justify-start">
          <TabsList className="mb-12 ml-[-5vw] scrollbar-none flex w-screen items-center justify-start overflow-scroll pl-[5vw] md:mb-16 md:ml-0 md:w-full md:justify-center md:overflow-hidden md:pl-0">
            {tabs.map((tab, index) => (
              <TabsTrigger
                key={index}
                value={tab.value}
                className="rounded-button px-4 py-2 data-[state=inactive]:border-transparent"
              >
                {tab.trigger}
              </TabsTrigger>
            ))}
          </TabsList>
          {tabs.map((tab) => (
            <TabsContent
              key={tab.value}
              value={tab.value}
              className="data-[state=active]:animate-tabs"
            >
              <div className="grid grid-cols-1 gap-x-8 gap-y-12 md:grid-cols-2 md:gap-y-16 lg:grid-cols-3">
                {tab.content.map((post, index) => (
                  <Card key={index}>
                    <a href={post.url} className="w-full max-w-full">
                      <div className="w-full overflow-hidden">
                        <img
                          src={post.image.src}
                          alt={post.image.alt}
                          className="aspect-[3/2] size-full object-cover"
                        />
                      </div>
                    </a>
                    <div className="px-5 py-6 md:p-6">
                      <a href={post.url} className="mb-2 flex text-small font-semibold">
                        {post.category}
                      </a>
                      <a href={post.url} className="mb-2 block max-w-full">
                        <h5 className="text-h5 font-bold">{post.title}</h5>
                      </a>
                      <p>{post.description}</p>
                      <div className="mt-5 flex items-center md:mt-6">
                        <div className="mr-4 size-12 min-h-12 min-w-12 shrink-0 overflow-hidden rounded-full">
                          <img
                            src={post.avatar.src}
                            alt={post.avatar.alt}
                            className="size-full object-cover"
                          />
                        </div>
                        <div>
                          <h6 className="text-small font-semibold">{post.fullName}</h6>
                          <div className="flex items-center">
                            <p className="text-small">{post.date}</p>
                            <span className="mx-2">•</span>
                            <p className="text-small">{post.readTime}</p>
                          </div>
                        </div>
                      </div>
                    </div>
                  </Card>
                ))}
              </div>
            </TabsContent>
          ))}
        </Tabs>
      </div>
    </section>
  );
};

const blogPost: BlogPost = {
  url: "#",
  image: {
    src: "https://d22po4pjz3o32e.cloudfront.net/placeholder-image-landscape.svg",
    alt: "Relume placeholder image",
  },
  category: "Category",
  title: "Blog title heading will go here",
  description:
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros.",
  avatar: {
    src: "https://d22po4pjz3o32e.cloudfront.net/placeholder-image.svg",
    alt: "Relume placeholder avatar",
  },
  fullName: "Full name",
  date: "11 Jan 2022",
  readTime: "5 min read",
};

export const Blog3Defaults: Props = {
  tagline: "Blog",
  heading: "Short heading goes here",
  description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
  tabs: [
    {
      value: "view-all",
      trigger: "View all",
      content: [blogPost, blogPost, blogPost, blogPost, blogPost, blogPost],
    },
    {
      value: "category-one",
      trigger: "Category one",
      content: [blogPost, blogPost, blogPost],
    },
    {
      value: "category-two",
      trigger: "Category two",
      content: [blogPost, blogPost, blogPost],
    },
    {
      value: "category-three",
      trigger: "Category three",
      content: [blogPost, blogPost, blogPost],
    },
    {
      value: "category-four",
      trigger: "Category four",
      content: [blogPost, blogPost, blogPost],
    },
  ],
};

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