Chánh Đại

Foldable

Component

About

Folded card that opens like the iPhone Duo, blurring as the cover turns. From chanhdai.com (ncdai), MIT.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Foldable to your project and fits it to your theme.

Code

How Foldable is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import { type ReactNode } from "react"
import { cn } from "@/lib/utils"
import { Foldable, FoldableCover, FoldableInsideLeft, FoldableInsideRight, FoldableSlider, FoldableStage } from "@/components/ui/chanhdai-foldable"

// ---- inlined from src/components/chanhdai-mark.tsx ----
export function ChanhDaiMark(props: React.ComponentProps<"svg">) {
  return (
    <svg
      xmlns="http://www.w3.org/2000/svg"
      fill="none"
      viewBox="0 0 512 256"
      aria-hidden
      {...props}
    >
      <path
        fill="currentColor"
        d="M192 256H64v-64h128v64ZM448 64H320v128h128v64H256V0h192v64ZM64 192H0V64h64v128ZM512 192h-64V64h64v128ZM192 64H64V0h128v64Z"
      />
    </svg>
  )
}

export function getMarkSVG() {
  return `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 256 128"><path fill="currentColor" d="M96 128H32V96h64v32ZM224 32h-64v64h64v32h-96V0h96v32ZM32 96H0V32h32v64ZM256 96h-32V32h32v64ZM96 32H32V0h64v32Z"/></svg>`
}

const PROFILE = {
  displayName: "Chánh Đại",
  jobTitle: "Design Engineer",
  bio: "Creating with code. Small details matter.",
  address: "Ho Chi Minh City, Viet Nam",
  avatar: "https://cdn.21st.dev/assets/mirror/41/4155327cd7a8c22a0c625153237b75435899275c5a5581bb02cc6dbb4d28cb1d.webp",
}

type Post = {
  title: string
  date: string
}

const POSTS: Post[] = [
  { title: "Joining Claude for Open Source Program", date: "22.07.2026" },
  {
    title: "React Wheel Picker joins Vercel Open Source Program",
    date: "24.07.2025",
  },
  { title: "Followed by @shadcn on X", date: "21.06.2025" },
  {
    title: "OrcDev discovered the wildest shadcn component libraries ever",
    date: "27.03.2026",
  },
  {
    title: "OrcDev and Francesco Ciulla reviewed my open source portfolio",
    date: "04.01.2026",
  },
]

export default function FoldableSpreadDemo() {
  return (
    <Foldable className="[--foldable-radius:--spacing(6)]">
      {/* A container one page wide: sizes follow the page, not the screen. */}
      <FoldableStage className="@container/foldable">
        <FoldableInsideRight>
          <SpreadHalf side="right">
            <InnerView />
          </SpreadHalf>
        </FoldableInsideRight>
        <FoldableCover>
          <OuterView />
        </FoldableCover>
        <FoldableInsideLeft>
          <SpreadHalf side="left">
            <InnerView />
          </SpreadHalf>
        </FoldableInsideLeft>
      </FoldableStage>

      <FoldableSlider />
    </Foldable>
  )
}

/** One page's window onto the two-page inner view. */
function SpreadHalf({
  side,
  children,
}: {
  side: "left" | "right"
  children: ReactNode
}) {
  return (
    <div
      className={cn(
        "absolute inset-y-0 w-[200%]",
        side === "left" ? "left-0" : "right-0"
      )}
    >
      {children}
    </div>
  )
}

function OuterView() {
  return (
    <div className="flex size-full flex-col">
      <Cover />
      <Profile className="px-[6.25cqw]">
        <Bio className="@max-xs/foldable:hidden" />
      </Profile>
      <PostList
        posts={POSTS.slice(0, 3)}
        className="mt-auto px-[6.25cqw] pb-[6.25cqw] @max-xs/foldable:pt-3 @max-xs/foldable:[&_li:nth-child(n+2)]:hidden @max-xs/foldable:[&>p]:hidden"
      />
    </div>
  )
}

function InnerView() {
  return (
    <div className="flex size-full flex-col">
      {/* Spans both pages, like a wallpaper across the crease. */}
      <Cover />
      <div className="grid flex-1 grid-cols-2">
        <Profile className="px-[6.25cqw]">
          <Bio />
          <p className="text-sm text-muted-foreground @max-xs/foldable:hidden">
            {PROFILE.address}
          </p>
        </Profile>
        <PostList
          posts={POSTS}
          className="px-[6.25cqw] pt-[6.25cqw] @max-xs/foldable:[&_li:nth-child(n+3)]:hidden"
        />
      </div>
    </div>
  )
}

function Cover() {
  return (
    <div className="flex h-[35cqw] shrink-0 items-center justify-center border-b bg-muted">
      <ChanhDaiMark className="h-[10cqw] w-[20cqw]" />
    </div>
  )
}

function Profile({
  className,
  children,
}: {
  className?: string
  children?: ReactNode
}) {
  return (
    <div
      className={cn("flex flex-col gap-3 @max-xs/foldable:gap-2", className)}
    >
      <img
        className="mt-[calc(max(2.5rem,20cqw)/-2)] size-[max(2.5rem,20cqw)] rounded-full border-4 border-background object-cover @max-xs/foldable:border-2"
        src={PROFILE.avatar}
        alt=""
        draggable={false}
      />
      <div>
        <p className="text-xl font-medium tracking-tight @max-xs/foldable:text-base">
          {PROFILE.displayName}
        </p>
        <p className="text-sm text-muted-foreground @max-xs/foldable:text-xs">
          {PROFILE.jobTitle}
        </p>
      </div>
      {children}
    </div>
  )
}

function Bio({ className }: { className?: string }) {
  return (
    <p
      className={cn("text-sm text-balance @max-xs/foldable:text-xs", className)}
    >
      {PROFILE.bio}
    </p>
  )
}

function PostList({ posts, className }: { posts: Post[]; className?: string }) {
  return (
    <div className={className}>
      <p className="mb-2 font-mono text-xs text-muted-foreground">Blog</p>
      <ul className="border-b">
        {posts.map((post) => (
          <li
            key={post.title}
            className="flex flex-col gap-0.5 border-t py-2 @max-xs/foldable:py-1.5"
          >
            <span className="truncate text-sm font-medium @max-xs/foldable:text-xs">
              {post.title}
            </span>
            <span className="font-mono text-xs text-muted-foreground tabular-nums">
              {post.date}
            </span>
          </li>
        ))}
      </ul>
    </div>
  )
}

Dependencies

More by Chánh Đại

View all
  • Apple Hello Effect

    Apple Hello Effect

    692
  • Theme Switcher

    Theme Switcher

    363
  • Hero Golden Spiral

    Hero Golden Spiral

    121
  • Mobius Loop Icon

    Mobius Loop Icon

    90
  • Wheel Picker

    Wheel Picker

    79
  • Testimonial 2

    Testimonial 2

    50
  • Glow Card Grid

    Glow Card Grid

    49
  • Spinning Circular Text

    Spinning Circular Text

    26