Blocks

Blog 5

Blog Headers
Text Align Left3 ColumnsAuthorDateAvatar ImageMultiple Images
Blog 5

Code

relume-blog5.tsx
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 FeaturedBlogPost = BlogPost;

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

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

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

export const Blog5 = (props: Blog5Props) => {
  const { tagline, heading, description, featuredBlogPost, tabs } = {
    ...Blog5Defaults,
    ...props,
  };
  return (
    <section className="px-[5%] py-16 md:py-24 lg:py-28">
      <div className="container">
        <div className="mb-12 w-full max-w-lg md:mb-18 lg:mb-20">
          <div className="w-full max-w-lg">
            <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>
        <div className="flex flex-col justify-start">
          <div className="mb-12 grid grid-cols-1 items-center gap-6 md:mb-20 md:grid-cols-2 md:gap-12">
            <a href={featuredBlogPost.url} className="w-full">
              <img
                src={featuredBlogPost.image.src}
                alt={featuredBlogPost.image.alt}
                className="aspect-[3/2] size-full rounded-image object-cover"
              />
            </a>
            <div className="flex h-full flex-col items-start justify-center">
              <a
                href={featuredBlogPost.url}
                className="mr-4 mb-2 inline-block max-w-full text-small font-semibold"
              >
                {featuredBlogPost.category}
              </a>
              <div className="flex w-full flex-col items-start justify-start">
                <a className="mb-4 block" href={featuredBlogPost.url}>
                  <h3 className="text-h4 font-bold">{featuredBlogPost.title}</h3>
                </a>
                <p>{featuredBlogPost.description}</p>
                <div className="mt-5 flex items-center md:mt-6">
                  <div className="mr-4 size-12 shrink-0 overflow-hidden rounded-full">
                    <img
                      src={featuredBlogPost.avatar.src}
                      alt={featuredBlogPost.avatar.alt}
                      className="size-full object-cover"
                    />
                  </div>
                  <div>
                    <h6 className="text-small font-semibold">{featuredBlogPost.fullName}</h6>
                    <div className="flex items-center">
                      <p className="text-small">{featuredBlogPost.date}</p>
                      <span className="mx-2">•</span>
                      <p className="text-small">{featuredBlogPost.readTime}</p>
                    </div>
                  </div>
                </div>
              </div>
            </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 overflow-auto pl-[5vw] md:mb-16 md:ml-0 md:w-full 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) => (
                    <div key={index}>
                      <a href={post.url} className="mb-6 inline-block 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 rounded-image object-cover"
                          />
                        </div>
                      </a>
                      <a
                        href={post.url}
                        className="mr-4 mb-2 inline-block max-w-full 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>
                  ))}
                </div>
              </TabsContent>
            ))}
          </Tabs>
        </div>
      </div>
    </section>
  );
};

const blogPost: BlogPost = {
  url: "#",
  image: {
    src: "https://d22po4pjz3o32e.cloudfront.net/placeholder-image-landscape.svg",
    alt: "Relume placeholder image",
  },
  category: "Category",
  readTime: "5 min read",
  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",
};

export const Blog5Defaults: Props = {
  tagline: "Blog",
  heading: "Short heading goes here",
  description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
  featuredBlogPost: blogPost,
  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