Vvcare/ui
Documentation menu

Components

Registry

How it works

A registry is a folder of JSON files. The CLI turns them into source files in your project.

The pipeline

Source
src/registry/**
registry.json
manifest
shadcn build
inlines files
public/r/*.json
static host
shadcn add
in your app

Nothing runs at request time. The left half happens on your machine or in CI. The right half happens on your user's machine. In between is a CDN serving static files.

1. The manifest entry

Each component gets one entry in registry.json. This is the real entry for Button:

{
  "name": "button",
  "type": "registry:ui",
  "title": "Button",
  "description": "Displays a button or a component that looks like a button.",
  "dependencies": ["class-variance-authority", "@radix-ui/react-slot"],
  "registryDependencies": ["@vcare/utils"],
  "files": [
    { "path": "src/registry/vcare/ui/button.tsx", "type": "registry:ui" }
  ]
}
  • type decides where the file lands. registry:ui goes to the ui alias, registry:lib to lib, registry:hook to hooks.
  • dependencies are npm packages the CLI installs with the user's package manager.
  • registryDependencies are other registry items, installed first. Here that is the cn helper.
  • files[].path is where the build script reads the source from.

2. The built item

shadcn build reads each file and embeds its text in content, producing a self-contained document:

{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button",
  "type": "registry:ui",
  "dependencies": ["class-variance-authority", "@radix-ui/react-slot"],
  "registryDependencies": ["@vcare/utils"],
  "files": [
    {
      "path": "src/registry/vcare/ui/button.tsx",
      "type": "registry:ui",
      "content": "import * as React from \"react\"\n..."   // the full source
    }
  ]
}

Open /r/button.json on this site to see the real thing.

3. The source file

The source is ordinary React. Note the import: it uses the registry's own path, @/registry/vcare/lib/utils.

src/registry/vcare/ui/button.tsx
import * as React from 'react';
import { cva, type VariantProps } from 'class-variance-authority';
import { cn } from '@/registry/vcare/lib/utils';
import { Slot } from 'radix-ui';
import type { RenderProp } from '@/registry/vcare/lib/render-compat';

const buttonVariants = cva(
  "inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-xl font-semibold leading-none whitespace-nowrap select-none outline-none transition-[scale,background-color,color,box-shadow,opacity] duration-150 ease-power3-out focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary dark:focus-visible:outline-foreground disabled:pointer-events-none disabled:opacity-50 aria-invalid:ring-2 aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
  {
    variants: {
      variant: {
        default: 'bg-primary text-primary-foreground shadow-primary hover:bg-primary-hover',
        secondary: 'bg-secondary text-secondary-foreground shadow-raised ring-1 ring-inset ring-primary/40 hover:bg-primary/10 hover:ring-primary/70 [&_svg]:text-primary dark:ring-foreground/25 dark:hover:bg-primary/20 dark:hover:ring-foreground/45 dark:[&_svg]:text-foreground',
        outline: 'bg-secondary text-secondary-foreground shadow-raised ring-1 ring-inset ring-primary/40 hover:bg-primary/10 hover:ring-primary/70 [&_svg]:text-primary dark:ring-foreground/25 dark:hover:bg-primary/20 dark:hover:ring-foreground/45 dark:[&_svg]:text-foreground',
        destructive: 'bg-destructive text-background hover:bg-destructive/90',
        ghost: 'text-foreground/80 hover:bg-accent hover:text-foreground',
        link: 'rounded-none text-primary underline-offset-4 hover:underline',
      },
      size: {
        default: 'h-control px-3.5 text-[13px]',
        xs: "h-control-sm px-2 text-xs [&_svg:not([class*='size-'])]:size-3",
        sm: 'h-control-sm px-3 text-xs',
        lg: 'h-control-lg px-4 text-sm',
        icon: 'size-(--control-h) p-0',
        'icon-xs': 'size-(--control-h-sm) p-0',
        'icon-sm': 'size-(--control-h-sm) p-0',
        'icon-lg': 'size-(--control-h-lg) p-0',
      },
    },
    // A ghost button with words is still an action: a soft tint of the brand colour so it never reads as plain text.
    // Icon-only ghost buttons (toolbars, row actions) stay plain.
    compoundVariants: [
      {
        variant: 'ghost',
        size: ['default', 'xs', 'sm', 'lg'],
        className: 'bg-primary/10 text-primary hover:bg-primary/15 hover:text-primary dark:bg-primary/30 dark:text-foreground dark:hover:bg-primary/45 dark:hover:text-foreground',
      },
    ],
    defaultVariants: { variant: 'default', size: 'default' },
  },
);

function Button({
  className,
  variant = 'default',
  size = 'default',
  asChild = false,
  static: isStatic = false,
  render,
  children,
  ...props
}: React.ComponentProps<'button'> &
  RenderProp &
  VariantProps<typeof buttonVariants> & {
    asChild?: boolean;
    /** Opt out of the press-scale feedback. */
    static?: boolean;
  }) {
  const Comp = asChild || render ? Slot.Root : 'button';
  const resolved = typeof render === 'function' ? render({}) : render;
  const content = resolved
    ? React.cloneElement(resolved, undefined, children ?? (resolved.props as { children?: React.ReactNode }).children)
    : children;

  return (
    <Comp
      data-slot="button"
      data-variant={variant}
      data-size={size}
      className={cn(buttonVariants({ variant, size }), !isStatic && 'active:not-disabled:scale-[0.96] motion-reduce:active:scale-100', className)}
      {...props}
    >
      {content}
    </Comp>
  );
}

export { Button, buttonVariants };

4. What add does

  1. Resolves the name or URL and downloads the item JSON.
  2. Walks registryDependencies recursively and downloads those too.
  3. Reads the user's components.json and tsconfig for aliases.
  4. Rewrites imports. @/registry/vcare/lib/utils becomes whatever the user's utils alias is, for instance @/lib/utils or ~/lib/utils.
  5. Writes files, installs dependencies, and merges any cssVars into the stylesheet.

Why imports are rewritten

The registry cannot know how your project is laid out. By authoring against a stable fake path and rewriting on install, one source file works in every project.

Registry versus package

npm packageRegistry
You getCompiled code in node_modulesSource files in your repo
CustomizingProps and theme APIEdit the file
UpdatingBump a versionRe-run add, review the diff
PublishingVersioned releaseUpload static JSON