For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
FrakmentFrakment

November 6, 2026

Dialog and Sheet primitives, full-demo registry blocks, and a unified Motion animation system.

This release adds two modal primitives, ships full-demo registry blocks for AI-heavy examples, and moves every state transition onto Motion.

  • Dialog: Modal window built on Radix with a close button toggle.
  • Sheet: Modal panel that slides in from any edge.
  • Trace demos: Six full-demo blocks for trace and AI examples.
  • Animation system: Accordion, collapsible, and shimmer now run on Motion.

Dialog

dialog.tsx
"use client";

import { XIcon } from "lucide-react";
import * as React from "react";
import { createPortal } from "react-dom";

import { getTransition, parseMotion, useReducedMotion } from "@/lib/motion";
import { cn } from "@/lib/utils";

interface DialogContextValue {
  contentRef: React.RefObject<HTMLDivElement | null>;
  descriptionId: string | null;
  open: boolean;
  setDescriptionId: (id: string | null) => void;
  setOpen: (open: boolean) => void;
  setTitleId: (id: string | null) => void;
  titleId: string | null;
  triggerRef: React.RefObject<HTMLElement | null>;
}

const DialogContext = React.createContext<DialogContextValue | null>(null);

function useDialogContext(): DialogContextValue {
  const ctx = React.useContext(DialogContext);
  if (!ctx) {
    throw new Error("Dialog components must be used within <Dialog>.");
  }
  return ctx;
}

const FOCUSABLE_SELECTOR =
  'a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])';

function getFocusable(root: HTMLElement | null): HTMLElement[] {
  if (!root) {
    return [];
  }
  return Array.from(
    root.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)
  ).filter((el) => !el.hasAttribute("disabled") && el.offsetParent !== null);
}

interface DialogProps {
  children?: React.ReactNode;
  defaultOpen?: boolean;
  onOpenChange?: (open: boolean) => void;
  open?: boolean;
}

function Dialog({
  children,
  open: openProp,
  defaultOpen = false,
  onOpenChange,
}: DialogProps) {
  const isControlled = openProp !== undefined;
  const [uncontrolled, setUncontrolled] = React.useState(defaultOpen);
  const open = isControlled ? openProp : uncontrolled;
  const triggerRef = React.useRef<HTMLElement | null>(null);
  const contentRef = React.useRef<HTMLDivElement | null>(null);
  const [titleId, setTitleId] = React.useState<string | null>(null);
  const [descriptionId, setDescriptionId] = React.useState<string | null>(null);
  const setOpen = React.useCallback(
    (next: boolean) => {
      if (!isControlled) {
        setUncontrolled(next);
      }
      onOpenChange?.(next);
    },
    [isControlled, onOpenChange]
  );
  const ctx = React.useMemo<DialogContextValue>(
    () => ({
      contentRef,
      descriptionId,
      open,
      setDescriptionId,
      setOpen,
      setTitleId,
      titleId,
      triggerRef,
    }),
    [open, setOpen, titleId, descriptionId]
  );
  return (
    <DialogContext.Provider value={ctx}>
      <div data-slot="dialog" data-state={open ? "open" : "closed"}>
        {children}
      </div>
    </DialogContext.Provider>
  );
}

type DialogTriggerProps = Omit<
  React.ComponentPropsWithoutRef<"button">,
  "ref"
> &
  Record<string, unknown> & {
    as?: React.ElementType;
    asChild?: boolean;
    ref?: React.Ref<HTMLElement>;
  };

function DialogTrigger({
  as,
  asChild,
  children,
  onClick,
  ref,
  ...props
}: DialogTriggerProps) {
  const ctx = useDialogContext();
  const setRef = React.useCallback(
    (node: HTMLElement | null) => {
      ctx.triggerRef.current = node;
      if (typeof ref === "function") {
        ref(node);
      } else if (ref) {
        (ref as React.MutableRefObject<HTMLElement | null>).current = node;
      }
    },
    [ctx.triggerRef, ref]
  );
  const handleClick = (event: React.MouseEvent<HTMLElement>) => {
    onClick?.(event as never);
    if (event.defaultPrevented) {
      return;
    }
    ctx.setOpen(true);
  };
  if (asChild && React.isValidElement(children)) {
    const child = children as React.ReactElement<{
      onClick?: (e: React.MouseEvent<HTMLElement>) => void;
      ref?: React.Ref<HTMLElement>;
    }>;
    return React.cloneElement(child, {
      ...props,
      onClick: (event: React.MouseEvent<HTMLElement>) => {
        child.props.onClick?.(event);
        handleClick(event);
      },
      ref: setRef,
    } as never);
  }
  const Component = (as ?? "button") as React.ElementType;
  const isNativeButton = !as;
  return (
    <Component
      data-slot="dialog-trigger"
      {...props}
      {...(isNativeButton ? { type: "button" as const } : {})}
      onClick={handleClick}
      ref={setRef}
    >
      {children}
    </Component>
  );
}

function DialogPortal({ children }: { children?: React.ReactNode }) {
  return <>{children}</>;
}

type DialogCloseProps = Omit<React.ComponentPropsWithoutRef<"button">, "ref"> &
  Record<string, unknown> & {
    as?: React.ElementType;
    asChild?: boolean;
    ref?: React.Ref<HTMLElement>;
  };

function DialogClose({
  as,
  asChild,
  children,
  onClick,
  ref,
  ...props
}: DialogCloseProps) {
  const ctx = useDialogContext();
  const setRef = React.useCallback(
    (node: HTMLElement | null) => {
      if (typeof ref === "function") {
        ref(node);
      } else if (ref) {
        (ref as React.MutableRefObject<HTMLElement | null>).current = node;
      }
    },
    [ref]
  );
  const handleClick = (event: React.MouseEvent<HTMLElement>) => {
    onClick?.(event as never);
    if (event.defaultPrevented) {
      return;
    }
    ctx.setOpen(false);
  };
  if (asChild && React.isValidElement(children)) {
    const child = children as React.ReactElement<{
      onClick?: (e: React.MouseEvent<HTMLElement>) => void;
      ref?: React.Ref<HTMLElement>;
    }>;
    return React.cloneElement(child, {
      ...props,
      onClick: (event: React.MouseEvent<HTMLElement>) => {
        child.props.onClick?.(event);
        handleClick(event);
      },
      ref: setRef,
    } as never);
  }
  const Component = (as ?? "button") as React.ElementType;
  const isNativeButton = !as;
  return (
    <Component
      data-slot="dialog-close"
      {...props}
      {...(isNativeButton ? { type: "button" as const } : {})}
      onClick={handleClick}
      ref={setRef}
    >
      {children}
    </Component>
  );
}

type DialogOverlayProps = React.ComponentPropsWithoutRef<"div"> & {
  motion?: string;
};

function DialogOverlay({
  className,
  motion,
  style,
  ...props
}: DialogOverlayProps) {
  const ctx = useDialogContext();
  const reduce = useReducedMotion();
  const transition = reduce
    ? "none"
    : (getTransition(parseMotion(motion)) ?? "opacity 150ms ease-out");
  return (
    <div
      aria-hidden="true"
      className={className}
      data-slot="dialog-overlay"
      data-state={ctx.open ? "open" : "closed"}
      {...props}
      onClick={(event) => {
        if (event.target === event.currentTarget) {
          ctx.setOpen(false);
        }
      }}
      style={{
        background: "rgba(0,0,0,0.5)",
        inset: 0,
        opacity: ctx.open ? 1 : 0,
        position: "fixed",
        transition,
        zIndex: 50,
        ...style,
      }}
    />
  );
}

type DialogContentProps = React.ComponentPropsWithoutRef<"div"> & {
  showCloseButton?: boolean;
  motion?: string;
};

function DialogContent({
  children,
  className,
  motion,
  showCloseButton = true,
  style,
  ...props
}: DialogContentProps) {
  const ctx = useDialogContext();
  const { open, setOpen, contentRef, triggerRef, titleId, descriptionId } = ctx;
  const reduce = useReducedMotion();
  const [mounted, setMounted] = React.useState(false);
  const [entered, setEntered] = React.useState(false);
  const transition = reduce
    ? "none"
    : (getTransition(parseMotion(motion)) ??
      "opacity 150ms ease-out, transform 150ms ease-out");
  React.useEffect(() => {
    if (open) {
      setMounted(true);
      const r1 = requestAnimationFrame(() => {
        const r2 = requestAnimationFrame(() => setEntered(true));
        return () => cancelAnimationFrame(r2);
      });
      return () => cancelAnimationFrame(r1);
    }
    setEntered(false);
    const t = setTimeout(() => setMounted(false), 150);
    return () => clearTimeout(t);
  }, [open]);
  React.useEffect(() => {
    if (!(open && mounted)) {
      return;
    }
    const prev = document.activeElement as HTMLElement | null;
    const root = contentRef.current;
    if (root) {
      const f = getFocusable(root);
      (f[0] ?? root).focus();
    }
    return () => {
      if (prev && typeof prev.focus === "function") {
        prev.focus();
      } else {
        triggerRef.current?.focus?.();
      }
    };
  }, [open, mounted, contentRef, triggerRef]);
  React.useEffect(() => {
    if (!open) {
      return;
    }
    const onKey = (event: KeyboardEvent) => {
      if (event.key === "Escape") {
        event.stopPropagation();
        setOpen(false);
        return;
      }
      if (event.key !== "Tab") {
        return;
      }
      const root = contentRef.current;
      if (!root) {
        return;
      }
      const f = getFocusable(root);
      if (f.length === 0) {
        event.preventDefault();
        root.focus();
        return;
      }
      const first = f[0];
      const last = f.at(-1);
      if (!last) {
        return;
      }
      const active = document.activeElement as HTMLElement | null;
      if (event.shiftKey && active === first) {
        event.preventDefault();
        last.focus();
      } else if (!event.shiftKey && active === last) {
        event.preventDefault();
        first.focus();
      }
    };
    document.addEventListener("keydown", onKey);
    return () => document.removeEventListener("keydown", onKey);
  }, [open, setOpen, contentRef]);
  if (!mounted) {
    return null;
  }
  if (typeof document === "undefined") {
    return null;
  }
  const content = (
    <>
      <DialogOverlay motion={motion} />
      <div
        aria-describedby={descriptionId ?? undefined}
        aria-labelledby={titleId ?? undefined}
        aria-modal="true"
        className={cn(
          "bg-background fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] gap-4 rounded-lg border p-6 shadow-lg sm:max-w-lg",
          className
        )}
        data-slot="dialog-content"
        data-state={open ? "open" : "closed"}
        ref={contentRef}
        role="dialog"
        tabIndex={-1}
        {...props}
        style={{
          opacity: entered ? 1 : 0,
          overscrollBehavior: "contain",
          transform: `translate(-50%, -50%) scale(${entered ? 1 : 0.95})`,
          transition,
          ...style,
        }}
      >
        {children}
        {showCloseButton && (
          <DialogClose className="ring-offset-background focus:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*=size-])]:size-4">
            <XIcon />
            <span className="sr-only">Close</span>
          </DialogClose>
        )}
      </div>
    </>
  );
  return createPortal(content, document.body);
}

const DialogHeader = ({ className, ...props }: React.ComponentProps<"div">) => (
  <div
    className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
    data-slot="dialog-header"
    {...props}
  />
);

const DialogFooter = ({ className, ...props }: React.ComponentProps<"div">) => (
  <div
    className={cn(
      "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
      className
    )}
    data-slot="dialog-footer"
    {...props}
  />
);

const DialogTitle = ({
  className,
  id,
  ...props
}: React.ComponentProps<"h2">) => {
  const ctx = useDialogContext();
  const generatedId = React.useId();
  const titleId = id ?? generatedId;
  React.useEffect(() => {
    ctx.setTitleId(titleId);
    return () => ctx.setTitleId(null);
  }, [ctx, titleId]);
  return (
    <h2
      className={cn("text-lg leading-none font-semibold", className)}
      data-slot="dialog-title"
      id={titleId}
      {...props}
    />
  );
};

const DialogDescription = ({
  className,
  id,
  ...props
}: React.ComponentProps<"p">) => {
  const ctx = useDialogContext();
  const generatedId = React.useId();
  const descId = id ?? generatedId;
  React.useEffect(() => {
    ctx.setDescriptionId(descId);
    return () => ctx.setDescriptionId(null);
  }, [ctx, descId]);
  return (
    <p
      className={cn("text-muted-foreground text-sm", className)}
      data-slot="dialog-description"
      id={descId}
      {...props}
    />
  );
};

export {
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogOverlay,
  DialogPortal,
  DialogTitle,
  DialogTrigger,
};

Dialog renders a modal window that traps focus and dismisses on Escape or backdrop click. Built on Radix Dialog.

DialogContent accepts showCloseButton (default true) to toggle the top-right close button. Use asChild on DialogTrigger and DialogClose to render your own Button.

Installation

Install the primitive

$ npx frakment add dialog

See the Dialog docs for the full API reference.


Sheet

sheet.tsx
"use client";

import { XIcon } from "lucide-react";
import * as React from "react";
import { createPortal } from "react-dom";

import { cn } from "@/lib/utils";

type SheetSide = "top" | "right" | "bottom" | "left";

interface SheetContextValue {
  contentRef: React.RefObject<HTMLDivElement | null>;
  descriptionId: string | null;
  open: boolean;
  setDescriptionId: (id: string | null) => void;
  setOpen: (open: boolean) => void;
  setTitleId: (id: string | null) => void;
  titleId: string | null;
  triggerRef: React.RefObject<HTMLElement | null>;
}

const SheetContext = React.createContext<SheetContextValue | null>(null);

function useSheetContext(): SheetContextValue {
  const ctx = React.useContext(SheetContext);
  if (!ctx) {
    throw new Error("Sheet components must be used within <Sheet>.");
  }
  return ctx;
}

const FOCUSABLE_SELECTOR =
  'a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])';

function getFocusable(root: HTMLElement | null): HTMLElement[] {
  if (!root) {
    return [];
  }
  return Array.from(
    root.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)
  ).filter((el) => !el.hasAttribute("disabled") && el.offsetParent !== null);
}

interface SheetProps {
  children?: React.ReactNode;
  defaultOpen?: boolean;
  onOpenChange?: (open: boolean) => void;
  open?: boolean;
}

function Sheet({
  children,
  open: openProp,
  defaultOpen = false,
  onOpenChange,
}: SheetProps) {
  const isControlled = openProp !== undefined;
  const [uncontrolled, setUncontrolled] = React.useState(defaultOpen);
  const open = isControlled ? openProp : uncontrolled;
  const triggerRef = React.useRef<HTMLElement | null>(null);
  const contentRef = React.useRef<HTMLDivElement | null>(null);
  const [titleId, setTitleId] = React.useState<string | null>(null);
  const [descriptionId, setDescriptionId] = React.useState<string | null>(null);
  const setOpen = React.useCallback(
    (next: boolean) => {
      if (!isControlled) {
        setUncontrolled(next);
      }
      onOpenChange?.(next);
    },
    [isControlled, onOpenChange]
  );
  const ctx = React.useMemo<SheetContextValue>(
    () => ({
      contentRef,
      descriptionId,
      open,
      setDescriptionId,
      setOpen,
      setTitleId,
      titleId,
      triggerRef,
    }),
    [
      contentRef,
      descriptionId,
      open,
      setDescriptionId,
      setOpen,
      setTitleId,
      titleId,
      triggerRef,
    ]
  );
  return (
    <SheetContext.Provider value={ctx}>
      <div data-slot="sheet" data-state={open ? "open" : "closed"}>
        {children}
      </div>
    </SheetContext.Provider>
  );
}

type SheetTriggerProps = Omit<React.ComponentPropsWithoutRef<"button">, "ref"> &
  Record<string, unknown> & {
    as?: React.ElementType;
    asChild?: boolean;
    ref?: React.Ref<HTMLElement>;
  };

function SheetTrigger({
  as,
  asChild,
  children,
  onClick,
  ref,
  ...props
}: SheetTriggerProps) {
  const ctx = useSheetContext();
  const setRef = React.useCallback(
    (node: HTMLElement | null) => {
      ctx.triggerRef.current = node;
      if (typeof ref === "function") {
        ref(node);
      } else if (ref) {
        (ref as React.MutableRefObject<HTMLElement | null>).current = node;
      }
    },
    [ctx.triggerRef, ref]
  );
  const handleClick = (event: React.MouseEvent<HTMLElement>) => {
    onClick?.(event as never);
    if (event.defaultPrevented) {
      return;
    }
    ctx.setOpen(true);
  };
  if (asChild && React.isValidElement(children)) {
    const child = children as React.ReactElement<{
      onClick?: (e: React.MouseEvent<HTMLElement>) => void;
      ref?: React.Ref<HTMLElement>;
    }>;
    return React.cloneElement(child, {
      ...props,
      onClick: (event: React.MouseEvent<HTMLElement>) => {
        child.props.onClick?.(event);
        handleClick(event);
      },
      ref: setRef,
    } as never);
  }
  const Component = (as ?? "button") as React.ElementType;
  const isNativeButton = !as;
  return (
    <Component
      data-slot="sheet-trigger"
      {...props}
      {...(isNativeButton ? { type: "button" as const } : {})}
      onClick={handleClick}
      ref={setRef}
    >
      {children}
    </Component>
  );
}

type SheetCloseProps = Omit<React.ComponentPropsWithoutRef<"button">, "ref"> &
  Record<string, unknown> & {
    as?: React.ElementType;
    asChild?: boolean;
    ref?: React.Ref<HTMLElement>;
  };

function SheetClose({
  as,
  asChild,
  children,
  onClick,
  ref,
  ...props
}: SheetCloseProps) {
  const ctx = useSheetContext();
  const setRef = React.useCallback(
    (node: HTMLElement | null) => {
      if (typeof ref === "function") {
        ref(node);
      } else if (ref) {
        (ref as React.MutableRefObject<HTMLElement | null>).current = node;
      }
    },
    [ref]
  );
  const handleClick = (event: React.MouseEvent<HTMLElement>) => {
    onClick?.(event as never);
    if (event.defaultPrevented) {
      return;
    }
    ctx.setOpen(false);
  };
  if (asChild && React.isValidElement(children)) {
    const child = children as React.ReactElement<{
      onClick?: (e: React.MouseEvent<HTMLElement>) => void;
      ref?: React.Ref<HTMLElement>;
    }>;
    return React.cloneElement(child, {
      ...props,
      onClick: (event: React.MouseEvent<HTMLElement>) => {
        child.props.onClick?.(event);
        handleClick(event);
      },
      ref: setRef,
    } as never);
  }
  const Component = (as ?? "button") as React.ElementType;
  const isNativeButton = !as;
  return (
    <Component
      data-slot="sheet-close"
      {...props}
      {...(isNativeButton ? { type: "button" as const } : {})}
      onClick={handleClick}
      ref={setRef}
    >
      {children}
    </Component>
  );
}

function _SheetPortal({ children }: { children?: React.ReactNode }) {
  return <>{children}</>;
}

type SheetOverlayProps = React.ComponentPropsWithoutRef<"div">;

function SheetOverlay({ className, style, ...props }: SheetOverlayProps) {
  const ctx = useSheetContext();
  return (
    <div
      aria-hidden="true"
      data-slot="sheet-overlay"
      data-state={ctx.open ? "open" : "closed"}
      {...props}
      className={className}
      onClick={(event) => {
        if (event.target === event.currentTarget) {
          ctx.setOpen(false);
        }
      }}
      style={{
        background: "rgba(0,0,0,0.5)",
        inset: 0,
        opacity: ctx.open ? 1 : 0,
        position: "fixed",
        transition: "opacity 200ms ease-out",
        zIndex: 50,
        ...style,
      }}
    />
  );
}

const sideStyles: Record<SheetSide, string> = {
  bottom: "inset-x-0 bottom-0 h-auto border-t",
  left: "inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",
  right: "inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",
  top: "inset-x-0 top-0 h-auto border-b",
};

const sideTransform: Record<SheetSide, string> = {
  bottom: "translateY(100%)",
  left: "translateX(-100%)",
  right: "translateX(100%)",
  top: "translateY(-100%)",
};

type SheetContentProps = Omit<React.ComponentPropsWithoutRef<"div">, "ref"> & {
  side?: SheetSide;
  showCloseButton?: boolean;
  ref?: React.Ref<HTMLDivElement>;
};

function SheetContent({
  children,
  className,
  ref,
  showCloseButton = true,
  side = "right",
  style,
  ...props
}: SheetContentProps) {
  const ctx = useSheetContext();
  const { contentRef, descriptionId, open, setOpen, titleId, triggerRef } = ctx;
  const [mounted, setMounted] = React.useState(false);
  const [entered, setEntered] = React.useState(false);

  React.useEffect(() => {
    if (open) {
      setMounted(true);
    }
  }, [open]);

  React.useEffect(() => {
    if (!(open && mounted)) {
      return;
    }
    const el = contentRef.current;
    if (el) {
      el.getBoundingClientRect();
    }
    const raf = requestAnimationFrame(() => setEntered(true));
    return () => cancelAnimationFrame(raf);
  }, [open, mounted, contentRef]);

  React.useEffect(() => {
    if (open) {
      return;
    }
    setEntered(false);
    const timer = window.setTimeout(() => setMounted(false), 200);
    return () => window.clearTimeout(timer);
  }, [open]);

  const setRef = React.useCallback(
    (node: HTMLDivElement | null) => {
      contentRef.current = node;
      if (typeof ref === "function") {
        ref(node);
      } else if (ref) {
        (ref as React.MutableRefObject<HTMLDivElement | null>).current = node;
      }
    },
    [contentRef, ref]
  );

  React.useEffect(() => {
    if (!(open && mounted)) {
      return;
    }
    const prev = document.activeElement as HTMLElement | null;
    const root = contentRef.current;
    if (root) {
      const f = getFocusable(root);
      (f[0] ?? root).focus();
    }
    return () => {
      if (prev && typeof prev.focus === "function") {
        prev.focus();
      } else {
        triggerRef.current?.focus?.();
      }
    };
  }, [open, mounted, contentRef, triggerRef]);

  React.useEffect(() => {
    if (!open) {
      return;
    }
    const onKey = (event: KeyboardEvent) => {
      if (event.key === "Escape") {
        event.stopPropagation();
        setOpen(false);
        return;
      }
      if (event.key !== "Tab") {
        return;
      }
      const root = contentRef.current;
      if (!root) {
        return;
      }
      const f = getFocusable(root);
      if (f.length === 0) {
        event.preventDefault();
        root.focus();
        return;
      }
      const first = f[0];
      const last = f.at(-1);
      if (!last) {
        return;
      }
      const active = document.activeElement as HTMLElement | null;
      if (event.shiftKey && active === first) {
        event.preventDefault();
        last.focus();
      } else if (!event.shiftKey && active === last) {
        event.preventDefault();
        first.focus();
      }
    };
    document.addEventListener("keydown", onKey);
    return () => document.removeEventListener("keydown", onKey);
  }, [open, setOpen, contentRef]);

  if (!mounted || typeof document === "undefined") {
    return null;
  }

  return createPortal(
    <>
      <SheetOverlay />
      <div
        {...props}
        aria-describedby={descriptionId ?? undefined}
        aria-labelledby={titleId ?? undefined}
        aria-modal="true"
        className={cn(
          "bg-background fixed z-50 flex flex-col gap-4 shadow-lg",
          sideStyles[side],
          className
        )}
        data-side={side}
        data-slot="sheet-content"
        data-state={open ? "open" : "closed"}
        ref={setRef}
        role="dialog"
        style={{
          opacity: entered ? 1 : 0,
          transform: entered ? "translate3d(0,0,0)" : sideTransform[side],
          transition:
            "opacity 200ms ease-out, transform 300ms cubic-bezier(0.32, 0.72, 0, 1)",
          ...style,
        }}
        tabIndex={-1}
      >
        {children}
        {showCloseButton && (
          <button
            aria-label="Close"
            className="ring-offset-background focus:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none"
            data-slot="sheet-close"
            onClick={() => setOpen(false)}
            type="button"
          >
            <XIcon className="size-4" />
            <span className="sr-only">Close</span>
          </button>
        )}
      </div>
    </>,
    document.body
  );
}

const SheetHeader = ({ className, ...props }: React.ComponentProps<"div">) => (
  <div
    className={cn("flex flex-col gap-1.5 p-4", className)}
    data-slot="sheet-header"
    {...props}
  />
);

const SheetFooter = ({ className, ...props }: React.ComponentProps<"div">) => (
  <div
    className={cn("mt-auto flex flex-col gap-2 p-4", className)}
    data-slot="sheet-footer"
    {...props}
  />
);

const SheetTitle = ({
  className,
  id,
  ...props
}: React.ComponentProps<"h2">) => {
  const ctx = useSheetContext();
  const generatedId = React.useId();
  const titleId = id ?? generatedId;
  React.useEffect(() => {
    ctx.setTitleId(titleId);
    return () => ctx.setTitleId(null);
  }, [ctx, titleId]);
  return (
    <h2
      className={cn("text-foreground font-semibold", className)}
      data-slot="sheet-title"
      id={titleId}
      {...props}
    />
  );
};

const SheetDescription = ({
  className,
  id,
  ...props
}: React.ComponentProps<"p">) => {
  const ctx = useSheetContext();
  const generatedId = React.useId();
  const descId = id ?? generatedId;
  React.useEffect(() => {
    ctx.setDescriptionId(descId);
    return () => ctx.setDescriptionId(null);
  }, [ctx, descId]);
  return (
    <p
      className={cn("text-muted-foreground text-sm", className)}
      data-slot="sheet-description"
      id={descId}
      {...props}
    />
  );
};

export {
  Sheet,
  SheetClose,
  SheetContent,
  SheetDescription,
  SheetFooter,
  SheetHeader,
  SheetTitle,
  SheetTrigger,
};

Sheet is a modal panel that slides in from the edge of the screen. It shares the Radix Dialog foundation, so focus is trapped and Escape dismisses.

SheetContent accepts side (top | right | bottom | left) and showCloseButton (default true).

Installation

Install the primitive

$ npx frakment add sheet

See the Sheet docs for the full API reference.


Trace demos

Why does pnpm install fail in CI?
CI installs with a frozen lockfile, so the install stops when package.json and pnpm-lock.yaml disagree. I should check what the last commit changed, then reproduce the install.
10.18.0
 package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ERR_PNPM_OUTDATED_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is not up to date with package.json

The last commit bumped a version in package.json without updating pnpm-lock.yaml, so the frozen install fails. Run pnpm install locally and commit the lockfile.

trace.tsx
"use client";

import { ChevronRightIcon } from "lucide-react";
import * as React from "react";

import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible";
import { Shimmer } from "@/components/ui/shimmer";
import { cn } from "@/lib/utils";

const defaultTraceMotion = "450 cubic-bezier(0.32, 0.72, 0, 1)";

interface TraceCollapsibleContextValue {
  motion: string;
  open: boolean;
}

const TraceCollapsibleContext =
  React.createContext<TraceCollapsibleContextValue>({
    motion: defaultTraceMotion,
    open: false,
  });

const TraceLineContext = React.createContext<{
  status?: "running" | "error" | "pending";
}>({});

function resolveTraceMotion(
  motion: string | undefined,
  animation: false | string | undefined,
  fallback: string
): string {
  if (motion !== undefined) {
    return motion;
  }
  if (animation === false) {
    return "off";
  }
  if (typeof animation === "string") {
    if (/^(spring|inertia|keyframes)/u.test(animation)) {
      console.warn(
        `[trace] animation="${animation}" uses a motion DSL that is not supported in CSS. Falling back to default. Prefer motion="150 ease-out" instead.`
      );
      return fallback;
    }
    return animation;
  }
  return fallback;
}

function Trace({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      className={cn("flex w-full min-w-0 flex-col gap-1", className)}
      data-slot="trace"
      {...props}
    />
  );
}

function TraceLine({
  className,
  status,
  ...props
}: React.ComponentProps<"span"> & {
  status?: "running" | "error" | "pending";
}) {
  return (
    <TraceLineContext.Provider value={{ status }}>
      <span
        className={cn(
          "text-muted-foreground flex w-fit max-w-full min-w-0 items-center gap-2",
          "data-[status=error]:text-destructive",
          "data-[status=pending]:opacity-60",
          "data-[status=running]:text-foreground",
          className
        )}
        data-slot="trace-line"
        data-status={status}
        {...props}
      />
    </TraceLineContext.Provider>
  );
}

function TraceIcon({ className, ...props }: React.ComponentProps<"span">) {
  return (
    <span
      aria-hidden="true"
      className={cn(
        "flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:size-4",
        className
      )}
      data-slot="trace-icon"
      {...props}
    />
  );
}

function TraceTitle({
  className,
  children,
  ...props
}: React.ComponentProps<"span">) {
  const { status } = React.useContext(TraceLineContext);
  const content =
    status === "running" ? <Shimmer>{children}</Shimmer> : children;
  return (
    <span
      className={cn("min-w-0 truncate", className)}
      data-slot="trace-title"
      {...props}
    >
      {content}
    </span>
  );
}

function TraceDescription({
  className,
  ...props
}: React.ComponentProps<"span">) {
  return (
    <span
      className={cn(
        "text-muted-foreground/70 shrink-0 text-xs tabular-nums",
        className
      )}
      data-slot="trace-description"
      {...props}
    />
  );
}

type TraceCollapsibleProps = Omit<React.ComponentProps<"div">, "onChange"> & {
  animation?: false | string;
  defaultOpen?: boolean;
  disabled?: boolean;
  motion?: string;
  onOpenChange?: (open: boolean) => void;
  open?: boolean;
};

function TraceCollapsible({
  animation,
  children,
  className,
  defaultOpen,
  disabled,
  motion,
  onOpenChange,
  open: openProp,
  ...props
}: TraceCollapsibleProps) {
  const [internalOpen, setInternalOpen] = React.useState(defaultOpen ?? false);
  const isControlled = openProp !== undefined;
  const currentOpen = isControlled ? openProp : internalOpen;
  const resolvedMotion = resolveTraceMotion(
    motion,
    animation,
    defaultTraceMotion
  );

  const handleOpenChange = React.useCallback(
    (next: boolean) => {
      if (!isControlled) {
        setInternalOpen(next);
      }
      onOpenChange?.(next);
    },
    [isControlled, onOpenChange]
  );

  return (
    <TraceCollapsibleContext.Provider
      value={{ motion: resolvedMotion, open: currentOpen }}
    >
      <Collapsible
        className={cn("flex w-full min-w-0 flex-col", className)}
        data-slot="trace-collapsible"
        disabled={disabled}
        motion={resolvedMotion}
        onOpenChange={handleOpenChange}
        open={currentOpen}
        {...props}
      >
        {children}
      </Collapsible>
    </TraceCollapsibleContext.Provider>
  );
}

function TraceCollapsibleTrigger({
  className,
  children,
  onClick,
  ...props
}: React.ComponentProps<"button">) {
  const { open } = React.useContext(TraceCollapsibleContext);
  return (
    <CollapsibleTrigger
      className={cn(
        "group/trace-collapsible-trigger text-muted-foreground flex w-fit max-w-full min-w-0 cursor-pointer items-center gap-2 text-left outline-none",
        "has-[[data-status=error]]:text-destructive",
        className
      )}
      data-slot="trace-collapsible-trigger"
      onClick={onClick}
      {...props}
    >
      <span className="inline-flex items-center gap-2 transition-transform duration-200 hover:translate-x-px motion-reduce:transition-none motion-reduce:hover:translate-x-0">
        {children}
      </span>
      <span
        aria-hidden="true"
        className="flex shrink-0 items-center justify-center transition-transform duration-200 data-[state=open]:rotate-90 motion-reduce:transition-none"
        data-state={open ? "open" : "closed"}
      >
        <ChevronRightIcon className="text-muted-foreground size-3.5" />
      </span>
    </CollapsibleTrigger>
  );
}

type TraceCollapsibleContentProps = React.ComponentProps<"div"> & {
  animation?: false | string;
  animateHeight?: boolean;
  keepMounted?: boolean;
  motion?: string;
};

function TraceCollapsibleContent({
  animateHeight = true,
  animation,
  children,
  className,
  keepMounted: _keepMounted,
  motion,
  ...props
}: TraceCollapsibleContentProps) {
  const { motion: contextMotion } = React.useContext(TraceCollapsibleContext);
  const resolvedMotion = resolveTraceMotion(motion, animation, contextMotion);
  return (
    <CollapsibleContent
      motion={animateHeight ? resolvedMotion : false}
      {...props}
    >
      <div
        className={cn("border-border mt-1 ml-2 border-l pb-1 pl-4", className)}
        data-slot="trace-collapsible-content"
      >
        {children}
      </div>
    </CollapsibleContent>
  );
}

export {
  Trace,
  TraceCollapsible,
  TraceCollapsibleContent,
  TraceCollapsibleTrigger,
  TraceDescription,
  TraceIcon,
  TraceLine,
  TraceTitle,
};

Six full-demo blocks ship as registry items: trace-demo, trace-commit, trace-dialog, trace-sheet, trace-thinking, and trace-tool-calls. Each pulls its own @ai-sdk/react, ai, and UI dependencies so the source is copy-pasteable.

$ npx frakment add trace-demo

The preview above is the exact code you get from the install command.

Animation system

Accordion and Collapsible now animate height through Motion instead of CSS keyframes. Shimmer is a Motion component. TraceCollapsibleContent uses ResizeObserver so streaming content updates the spring target instead of stalling on auto.

lib/animation.ts ships with npx frakment init and exports SPRING_SMOOTH, EASE_OUT, EASE_SMOOTH, EASE_IN_OUT, DURATION_FAST, DURATION_SMOOTH. Import from it when you build animated components so timing matches the library.

ts
import { SPRING_SMOOTH } from "@/lib/animation";

See the Animations guide for the two-engine model.