brust 2.0.0-alpha.66
React & libraries / Set up shadcn/ui

Set up shadcn/ui

shadcn/ui copies its components into your project, so brust compiles them like your own code. This guide takes a new brust project to a page with a card, a button and a dialog, with the commands and files exactly as they were run.

1Create the project

You need Bun and a generated brust project. The blank starter already has Tailwind CSS v4 through brust’s own plugin, so there is no separate Tailwind build to configure.

~/
$ bun create @brust/app@latest my-app --yes
$ cd my-app && bun install

2Set up shadcn/ui

One command sets the project up and adds the components you name:

~/my-app
$ bunx brust shadcn init button card dialog
✓ components.json: done (app.css)
✓ tsconfig.json: done (added "@/*": ["./*"] under compilerOptions.paths)
bun add v1.4.4-canary.1 (408c9374b)
Saved lockfile

installed [email protected]
installed [email protected]
installed [email protected]
installed [email protected]

78 packages installed [375.00ms]
✓ dependencies: done ([email protected] [email protected] [email protected] [email protected])
✔ Checking registry.
✔ Installing dependencies.
✔ Created 1 file:
  - lib/utils.ts
✔ Updating app.css
✓ theme: done ([email protected] add index)
✔ Checking registry.
✔ Created 3 files:
  - components/ui/button.tsx
  - components/ui/card.tsx
  - components/ui/dialog.tsx
✓ button: done
✓ card: done
✓ dialog: done

next:
  import the components from './components/ui/<name>' in a page and add the route to routes.tsx
  bun run build

It did, in order:

  • wrote components.json, the file the shadcn CLI reads, pointing at app.css, the CSS file brust’s Tailwind reads;
  • added "@/*": ["./*"] to compilerOptions.paths in tsconfig.json, keeping its comments and layout;
  • installed radix-ui, lucide-react, class-variance-authority and tw-animate-css, each at the exact version the guide was tested with (a package you already have is left as it is);
  • ran the shadcn CLI’s add index (the theme in app.css, and lib/utils.ts) and then add button card dialog.

It pins the shadcn CLI to one tested version instead of @latest, never runs a shell, and does nothing on a second run: every step says skipped. To add another component later, run it again with the new name. --css, --base-color, --force and --shadcn-version are described by bunx brust --help.

Note

A component can also be an https:// registry URL. That installs third-party code from that host into your project, and it runs in your build and in the browser, so read it first. The command prints a warning for each URL, skips a URL whose item is already in components/ on a second run, and will not write through a symbolic tsconfig.json or components.json (it stops and says so).

Note

Before the shadcn CLI runs, brust shadcn init fetches the URL’s item itself (https only, at most 1 MiB, 15 seconds) and checks the files it declares: each must land inside the project and not through a symbolic link, and an item with a key it does not know, or a registry:font or registry:page item, is refused. The CLI is then given that checked copy, not the URL. Two things are not checked. The shadcn components an item names in registryDependencies (plain names, resolved in shadcn’s own registry) and the npm packages it lists in dependencies are installed by the CLI without being read first; the alias directories are still scanned for symbolic links before anything is written. An item that depends on another URL is refused: pass that URL as its own argument so it is checked too.

Note

brust shadcn init needs @brust/core 2.0.0-alpha.11 or later. On an older project, update @brust/core, or follow Doing it by hand.

3Use them in a route

The components are files in components/ui/. Import them like any other component and add the page to routes.tsx.

pages/ShadcnPage.tsx
import { Button } from '../components/ui/button'
import { Card, CardContent, CardHeader, CardTitle } from '../components/ui/card'
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '../components/ui/dialog'

export default function ShadcnPage() {
  return (
    <Card>
      <CardHeader>
        <CardTitle>shadcn/ui in brust</CardTitle>
      </CardHeader>
      <CardContent>
        <Dialog>
          <DialogTrigger asChild>
            <Button>Open</Button>
          </DialogTrigger>
          <DialogContent>
            <DialogHeader>
              <DialogTitle>Hello</DialogTitle>
              <DialogDescription>A Radix dialog, one React island.</DialogDescription>
            </DialogHeader>
          </DialogContent>
        </Dialog>
      </CardContent>
    </Card>
  )
}
routes.tsx
import ShadcnPage from './pages/ShadcnPage'
// in the children array, next to the home page:
{ path: '/ui', Component: ShadcnPage },

4Build and read the result

brust build names every Radix part that renders as a React island. These are warnings, not errors: the component works as it does in React. The card and the button are static markup: a page with only those loads no JavaScript of its own. The dialog is where React comes in, one island per Radix part, and in the browser the Open button shows the dialog.

~/my-app
$ bun run build
warning external-component components/ui/dialog.tsx:11:10 <DialogPrimitive.Root> comes from the package radix-ui (Dialog.Root); it renders as a React island (package source: .brust/pkg-src/p-4ba0125d4d233615/src/dialog.tsx renders as React in its source: export is not a function declaration)
warning spread-props components/ui/dialog.tsx:11:10 props are spread into the React island <DialogPrimitive.Root>
…
[brust] built dist in 1208ms

Run it with brust start, or work on it with dev mode. shadcn/ui and React libraries says which components compile and which stay islands, with the numbers from the build.

5Dark mode

add index writes the variables twice: the light values under :root and the dark values under .dark, and the dark: variant applies below an element with the dark class. Put that class on <html> to switch the whole page.

6Doing it by hand

brust shadcn init does the steps below, so you normally skip them. They are here for projects that cannot run it.

The shadcn CLI’s init does not recognise brust as a framework, so it stops there. Skip it: add only needs two files.

~/my-app
$ bunx shadcn@latest init
We could not detect a supported framework at /home/you/my-app.
Visit https://ui.shadcn.com/docs/installation/manual to manually configure your project.

components.json at the project root says where things go: the style, the CSS file (app.css, the one brust’s Tailwind reads) and the aliases.

components.json
{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "new-york",
  "rsc": false,
  "tsx": true,
  "tailwind": { "config": "", "css": "app.css", "baseColor": "neutral", "cssVariables": true, "prefix": "" },
  "iconLibrary": "lucide",
  "aliases": { "components": "@/components", "utils": "@/lib/utils", "ui": "@/components/ui", "lib": "@/lib", "hooks": "@/hooks" }
}

The aliases start with @/, and the CLI resolves them through tsconfig.json. Add one line to its compilerOptions; no baseUrl is needed:

tsconfig.json (inside "compilerOptions")
"paths": { "@/*": ["./*"] },
Note

The imports the CLI writes into the components it adds (@/components/ui/button in the dialog) build as they are, with this one line.

add index is the part of init you need: it adds the Tailwind imports, the light and dark colour variables and the @theme block to app.css, creates lib/utils.ts and installs shadcn and tw-animate-css. Then add the components. The CLI installs cn, the class-name helper the components import, as a package; there is no helper to write yourself.

~/my-app
$ bun add radix-ui lucide-react class-variance-authority tw-animate-css
$ bunx shadcn@latest add index -y
$ bunx shadcn@latest add button card dialog -y
app.css (what `add index` put at the top; the variables follow)
@import "tailwindcss";
@import "tw-animate-css";
@import "shadcn/tailwind.css";

@custom-variant dark (&:is(.dark *));