Docs

Getting started

Bollard UI is an independent open-source React component library for preventing user input mistakes, unrelated to physical bollards or other products with a similar name. Each component is a source file the shadcn CLI copies into your project.

Prerequisites

  • React 19 or later. Components take ref as a plain prop, so React 18 is not supported.
  • Tailwind CSS v4 with the shadcn theme variables. Tailwind v3 is not targeted.
  • A shadcn/ui setup: a components.json, the theme tokens and the cn() helper in @/lib/utils. You don't need any of shadcn's own components.
  • TypeScript is recommended; every component is written in strict TypeScript.

If the project doesn't have a shadcn setup yet, run this once:

pnpm dlx shadcn@latest init

Add a component

Requires React 19 and Tailwind CSS v4. @bollard is in the official shadcn registry index, so this works in a shadcn project without editing components.json.

pnpm dlx shadcn@latest add @bollard/amount-input

The CLI reads your components.json aliases, then:

  1. writes the component to your ui folder, for example components/ui/amount-input.tsx (a few components also bring a helper .ts file that lands next to it);
  2. installs the npm packages the component lists, such as lucide-react or motion;
  3. adds any other Bollard UI component it builds on.

Every component page shows its exact command, its dependencies and the files it adds. The whole registry is at /r/registry.json.

project
components/
  ui/
    amount-input.tsx   ← written by the CLI, yours to edit
lib/
  utils.ts             ← cn(), from shadcn init

Fallback: add the namespace by hand

Only if npx shadcn@latest add @bollard/… cannot resolve the namespace. Merge this into components.json, then run the same add command. The official shadcn registry index already lists @bollard.

{
  "registries": {
    "@bollard": "https://bollard-ui.vercel.app/r/{name}.json"
  }
}

Add by hand

  1. Install the npm packages listed under Dependencies on the component's page.
  2. Open the Manual tab on the component's page, copy each file into components/ui, keeping the file names.
  3. Fix the imports if your aliases differ: @/lib/utils for cn(), and @/components/ui/… for any other Bollard UI component it imports.

Import and use

Import from where the file landed. Snippets on this site always use @/components/ui/<name>, which is what the CLI writes with the default aliases.

rent-field.tsx
import { AmountInput } from "@/components/ui/amount-input"

export function RentField() {
  return <AmountInput label="Monthly rent" locale="en-IN" currency="INR" typical={24000} />
}

Value-holding components work controlled (value + onValueChange) or uncontrolled (defaultValue). Most user-facing strings are props with English defaults; the Props table on each page lists them.

Keep your existing controls

Want to keep your existing controls? Add the optional useBollardField hook. It owns field value, touched/error state and async-safe validation; you keep the markup, styles and submit flow. Its only runtime dependency is React. The registry installs it in your configured hooks folder.

The ready-made UI components use Bollard's shadcn-compatible styling and Tailwind v4 theme tokens. For HeroUI or a different design system, use the hook and keep that library's control as the only visual input. The catalog labels these two integration paths and lists extra npm packages before you install.

For current HeroUI React, connect the hook to its TextField value and error state. The snippet keeps HeroUI's label, input and error slots; see the HeroUI TextField docs for the API details.

hero-ui-field.tsx
import { FieldError, Input, Label, TextField } from "@heroui/react"
import { useBollardField } from "@/components/ui/use-bollard-field"

export function UsernameField() {
  const username = useBollardField({
    initialValue: "",
    validate: (value) => value.length >= 3 ? undefined : "Use at least three characters.",
  })

  return (
    <TextField
      name="username"
      value={username.value}
      onChange={username.setValue}
      onBlur={username.onBlur}
      isInvalid={username.invalid}
      validationBehavior="aria"
    >
      <Label>Username</Label>
      <Input autoComplete="username" />
      {username.error && <FieldError>{username.error}</FieldError>}
    </TextField>
  )
}

For a custom control, merge Bollard's error ID with your existing hint IDs and keep your own visual states:

custom-field.tsx
import { useBollardField } from "@/components/ui/use-bollard-field"

export function UsernameField() {
const username = useBollardField({
  initialValue: "",
  validate: (value) => value.length >= 3 ? undefined : "Use at least three characters.",
})

return (
  <div>
    <label htmlFor="username">Username</label>
    <input
      id="username"
      value={username.value}
      onChange={(event) => username.setValue(event.target.value)}
      onBlur={username.onBlur}
      {...username.ariaPropsFor("username-hint")}
    />
    <p id="username-hint">Shown on your public profile.</p>
    {username.error && <p id={username.errorId} role="alert">{username.error}</p>}
  </div>
)
}
pnpm dlx shadcn@latest add @bollard/use-bollard-field
email-field.tsx
import { useBollardField } from "@/components/ui/use-bollard-field"
import { Input } from "@/components/ui/input"

export function EmailField() {
  const email = useBollardField({
    initialValue: "",
    validate: (value) => /.+@.+\..+/.test(value) ? undefined : "Enter a valid email address.",
  })

  return (
    <div className="space-y-2">
      <label htmlFor="email">Email</label>
      <Input
        id="email"
        value={email.value}
        onChange={(event) => email.setValue(event.target.value)}
        onBlur={email.onBlur}
        {...email.ariaProps}
      />
      {email.error && <p id={email.errorId} role="alert">{email.error}</p>}
    </div>
  )
}

Connect a Select, Date Picker, Checkbox, HeroUI control or custom component through the value callback it already exposes. Text inputs useonChange; value-based controls use onValueChange; checkboxes use checked and onCheckedChange. The value type is inferred, including strings, booleans and custom objects.

Keep the host control's appearance and behavior. Pass its invalid state and the hook's error ID through aria-invalid and aria-describedby, then render the message beside it withrole="alert" or a polite live region.

Validation runs on blur and after edits. Call validate() before submitting. Map a field error returned by your server with setError(); editing clears that server error so the user can recover. The server must still validate and authorize every request.

server-errors.ts
if (!(await email.validate())) return
const result = await saveProfile({ email: email.value })
const message = result.fieldErrors?.email?.[0] ?? result.message
if (message) email.setError(message)

If a schema library owns your rules, delegate to it from validate rather than duplicating them. With Zod, callsafeParse(value) and return the first issue message. When React Hook Form already owns the field value, keep it as the single state owner: use Controller and fieldState.error for the accessible state instead of adding this hook as a second owner.

zod-validation.ts
validate: (value) => {
  const result = emailSchema.safeParse(value)
  return result.success ? undefined : result.error.issues[0]?.message
}

The existing Error Summary and useFormErrors remain available for DOM-registered forms.

Custom aliases

If your components.json points aliases.ui or aliases.utils somewhere else (say ~/ui), the CLI rewrites the imports in the copied files to match. When you copy by hand, change those imports yourself. Check that the alias also exists in tsconfig.json (and in your bundler config for Vite).

Updating a component

Copied code doesn't update itself. Fixes and rule changes are listed in the changelog. To pick one up, either re-run the add command with --overwrite, which replaces your file (commit first so you can see and keep your own edits):

pnpm dlx shadcn@latest add @bollard/amount-input --overwrite

or compare your copy with the published source in /r/<name>.json and merge by hand:

terminal
# Fetch the current source and compare it with your copy
curl -s https://bollard-ui.vercel.app/r/amount-input.json | jq -r '.files[0].content' > /tmp/amount-input.tsx
git diff --no-index components/ui/amount-input.tsx /tmp/amount-input.tsx

Next.js

  • App Router works as is. Components that use hooks start with "use client", so you can render them from Server Components.
  • They never touch window, document or localStorage during render, so server rendering is safe.
  • create-next-app already sets the @/* alias; run shadcn init and add components.

Vite

Set up Tailwind v4 with @tailwindcss/vite and the @ alias before running shadcn init, as the shadcn Vite guide describes. The "use client" lines are harmless outside Next.js.

// vite.config.ts
import path from "node:path"
import tailwindcss from "@tailwindcss/vite"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"

export default defineConfig({
  plugins: [react(), tailwindcss()],
  resolve: { alias: { "@": path.resolve(__dirname, "./src") } },
})

Technical facts & specifications

Key architectural facts, licensing, runtime requirements, and boundaries for Bollard UI:

Technical specifications, licensing, and limitations
PropertySpecification
Distribution modelshadcn registry (source code copied directly to your app)
Install commandnpx shadcn@latest add @bollard/<name>
Current version0.1.0
React supportReact 19+ (ref is a normal prop; React 18 is not supported)
Styling engineTailwind CSS v4 (shadcn color tokens & CSS variables)
SSR & Server ComponentsFully compatible (SSR & Server Components safe, client-hydrated controls)
LicenseMIT License (free, commercial-friendly)
Primary limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Guard rails, not enforcement

Bollard UI components catch honest mistakes in the browser. They don't replace server-side validation, authorization, rate limits, idempotency keys or database constraints, and anyone can bypass client code. Pages for security, payment and destructive components say what the server still has to enforce. See also Security.

Not sure where to begin? Start here has the essentials, or browse every component.

About Bollard UI

Bollard UI is an independent open-source React component library for preventing user input mistakes, unrelated to physical bollards or other products with a similar name. Built by Tushar Khadde (@devtushark) to stop expensive user mistakes in forms and risky actions. Unlike schema validation libraries like Zod that enforce types on submit or blur, and unlike generic modal dialogs that people dismiss on autopilot, Bollard UI provides proactive, inline UX guardrails—catching extra zeros in currency fields, detecting mistyped email domains, and requiring typed confirmations for destructive actions—right inside your existing shadcn and Tailwind setup. Read more on the dedicated About page.