Skip to Content
gentlemans-stack
ReferenceUI libs

design-system

shadcn components, theme provider and generated design tokens shared by every web app (apps/todo-ui consumes it as a workspace:* dependency).

API

Exported from src/index.ts: Accordion, ArrayField (a list of rows with add, remove and move up/down, plus drag-to-reorder when dragLabel is set; the caller renders each row, keys are internal), ConfirmDialog (a controlled confirm dialog with a pending confirm button and optional typeToConfirm; for a one-click confirm use ActionButton's confirm), EmptyState (title, description, icon and action for an empty list), MultiSelectField (pick several options from a searchable list, chosen ones show as removable chips) and TagsField (free-form tags: Enter or comma adds, Backspace removes; suggestions use a native <datalist>), ActionButton (a Button that runs an async onAction: pending state, onDone/onError, optional confirm dialog, or an external pending for submit buttons; props only, no toast or Query), Badge, Button, Card, the shadcn Field primitives (Field, FieldLabel, FieldDescription, FieldError, FieldGroup, FieldSet, ...), TextField (an Input, or a Textarea when maxLength is above 200 or multiline is set), PasswordField (show/hide toggle), NumberField (value is a number or undefined, never a string), SelectField (radio for 1 to 3 options, a native <select> for 4 to 5, searchable combobox for 6 or more; variant overrides), FormDialog (a dialog around a form: title, description, fields, pending submit; the caller closes it on success), ToggleField (checkbox or switch, optionally a clickable card), DateField (Calendar in a Popover; fromDate/toDate limit the days), DateTimeField (adds a native time input, one combined Date), Combobox, RadioGroup, Checkbox, Calendar, Select, Popover, Command, Input, Textarea, Separator, Sheet, Sidebar (provider, content, groups, menu, trigger, inset, useSidebar), Skeleton, ThemeToggle, Tooltip, TokenShowcase, plus ThemeProvider, cn and the localized-router helpers.

Add components with the shadcn CLI, always pointed at this package: pnpm dlx shadcn@latest add <name> -c ui-libs/design-system. Answer n when it asks to overwrite an existing component.

Forms

@gentlemans-stack/design-system/data-table is a separate entry point too (it loads @tanstack/react-table v8, which the root export never does). DataTable<T> takes columns (ColumnDef<T>[], re-exported with createColumnHelper and SortingState), data, getRowId, an emptyState node and optional filter and pagination (all labels are props). Client mode sorts, filters and pages the rows it is given. Pass manual (pageIndex, total, sorting, onPageChange, onSortingChange) and one page of rows for server mode: the table only reports clicks. Columns opt out of sorting with enableSorting: false.

@gentlemans-stack/design-system/form is a separate entry point, so only apps that import it load @tanstack/react-form; the root export never does. It exports useAppForm (TanStack Form's useForm plus the fields below), withForm, useFieldContext, useFormContext and useFieldError.

const form = useAppForm({ defaultValues, onSubmit: async ({ value }) => save(value), validators: { onChange: schema } });

<form.AppForm>
	<form.Form>
		<form.AppField name="email">{(field) => <field.Text label="Email" type="email" />}</form.AppField>
		<form.SubmitButton>Save</form.SubmitButton>
	</form.Form>
</form.AppForm>;
  • Fields: field.Array (inside <form.AppField name="items" mode="array">; newItem is the value a new row starts with, rows render form.AppField name={items[${index}].email}; object rows work the same), field.Text, field.Password, field.Number, field.Select, field.Toggle, field.Date, field.DateTime. Each is the props-only component of the same name bound to the field's value, change, blur, name and error, so every label, placeholder and hint stays a prop.
  • Validation: pass any Standard Schema (a Zod 4 object works as is, no resolver) as validators. The first error message of a field shows once the field is touched or a submit was attempted. Every field takes an optional showErrors: "blur" (once the field lost focus), "change" (once changed or blurred) or "submit" (only after a submit); every mode also shows errors after a submit attempt, and unset keeps the default. Field-level validators on form.AppField (onBlur, onChange, onSubmit) choose when a single field validates; pair them, for example validators={{ onBlur: z.email() }} with <field.Text showErrors="blur" />.
  • Submit: form.Form runs handleSubmit and turns native validation off. form.SubmitButton is an ActionButton type="submit" that is pending while onSubmit runs, so return its promise.
  • Steps: form.Wizard splits a form into steps inside one useAppForm. Each step lists its fields; Next validates only those (and shows their errors) before moving on, Back keeps every value, the last step submits the whole form. Every string (labels, step titles) is a prop.
  • Dialogs: form.Dialog is a FormDialog wired to the form (submit and pending), so a form dialog is <form.AppForm><form.Dialog ...>fields</form.Dialog></form.AppForm>.
  • Native select: the 4-to-5-option control is shadcn's native-select, not the Radix Select: it works on phones and in jsdom (the Radix one hung a long jsdom test sequence, see docs/learnings.md).

Schema-driven forms

A Zod schema with ui meta feeds useAppForm and an optional defineLayout, and SchemaFields renders the form

Give useAppForm a Zod 4 object and <SchemaFields /> renders the whole form: zod is a peer dependency, and every ui.* helper only attaches typed meta with .meta(), so the schema still validates, parses and infers like any other.

const schema = z.object({
	email: ui.text(email(), { label: () => m.email() }), // z.email() gives type="email", .max() gives maxLength
	name: ui.text(requiredText({ max: 100 }), { autoComplete: "name", label: () => m.name() }),
	role: ui.select(z.enum(["admin", "user"]).default("user"), { label: () => m.role() }), // options come from the enum
});
const layout = defineLayout(schema, { rows: [["name", "email"], "role"] });

const form = useAppForm({ onSubmit, schema }); // derives defaultValues and validators: { onChange: schema }

<form.AppForm>
	<form.Form>
		<SchemaFields labels={schemaFieldsLabels()} layout={layout} />
		<form.SubmitButton>Save</form.SubmitButton>
	</form.Form>
</form.AppForm>;
  • ui.*: text, password, textarea (a field.Text multiline, counter shows the length), number, select, switch, date, datetime, tags, multiSelect, array (an array of objects: add, remove, drag to reorder) and group (a nested object as a titled fieldset, names address.city). Each accepts only the schemas that suit it (ui.number(z.string()) does not compile) and the meta keys label (required), hint, placeholder, autoComplete, showErrors, plus the ones of its widget (options, suggestions, addLabel, counter, step). Text meta are functions (() => m.key()) so they follow the locale; hint is not named description because Zod's own description is a string. Without a ui.* the widget is inferred from the type (string text, number, boolean switch, date, enum select, array of string tags, array of enum multi-select, array of object array, object group) and the label is the key.
  • Put ui.* outermost: .meta(x).optional() loses the meta on the outer schema (Zod keeps it on the inner one); ui.text(z.string().optional(), ...) keeps it where the builder looks. .meta(x).min(3) keeps it. A clone made with .meta() never inherits an id.
  • From the schema: maxLength, min, max (a number's range, an array's size), step, type="email" or url (from the format, also through a .pipe(z.email())), enum options, a .default() (the field's start value; others start "", false, [] or empty). An optional enum or number stores undefined when emptied.
  • labels: the words the meta does not carry (array, date, multi-select, password, tags, wizard chrome). The app builds them once, schemaFieldsLabels() in apps/todo-ui/src/lib/form-labels.ts. Per-field meta (placeholder, addLabel) overrides them.
  • defineLayout(schema, layout): typed against the schema. fields: { path: { visibleWhen: (values) => boolean } } shows a field only while true; hidden, it unmounts and resets to its default, so a "required if" rule stays a .superRefine on the schema and the field .optional(). rows: [["name", "age"], "bio"] puts fields side by side (dotted paths such as "address.city" work inside a group); the others follow in schema order. steps: [{ fields, id, title, description? }] renders the whole wizard (<form> and labels.wizard included) and Next validates a group through its leaf paths.
  • Unions: z.discriminatedUnion("kind", [...]) under a ui.group renders a select for the discriminator and only the active branch's other fields; switching resets them to the new branch's defaults.
  • Models stay portable: never put ui.* in models/*. A form wraps a model rule, ui.text(someModel.shape.name, { label }), which returns a new schema and leaves the model untouched.
  • Limits: SchemaFields reads the form from context (<form.AppForm>) and the schema from useAppForm({ schema }), or from a schema prop. It throws for a type with no widget. A field inside an array row cannot have visibleWhen. useAppForm({ schema }) takes schema, defaultValues and onSubmit only; use the classic call for listeners and async validators.

Storybook

Storybook serves every component at http://localhost:6006 with the real tokens, light and dark, and builds to dist/storybook/design-system. Telemetry is off.

Each component has a *.stories.tsx beside it; add one in the same change as any new component. Stories take props only: no i18n, oRPC or TanStack Query. Docs pages come from the autodocs tag in .storybook/preview.tsx.

In-page navigation

SectionNav switches between the sections of one screen (account, settings). Use it inside the content area, never in the app sidebar: it is text only and marks the current section as a raised plate, so it reads as a different level than the sidebar. It is vertical from lg and a scrolling row below. Keep the current section in the URL (?section=).

Look

The visual direction (matte green-tinted ground, one signal green, matte shadows) is described in DESIGN.md. Change colors, radii and the font in ui-libs/design-tokens/src/tokens.json and run pnpm nx run design-tokens:generate; the shadow tints (--shade-*, --shine) live in src/styles/globals.css.

The sidebar's --sidebar-* variables live in src/styles/globals.css and alias existing tokens (--card, --accent, --border, --primary, --ring), so light and dark follow the generated tokens.css. Never add them to tokens.css; it is generated from ui-libs/design-tokens.

src/components/ui/sidebar.tsx and src/hooks/use-mobile.ts are shadcn output. biome.jsonc switches off a few lint rules for those two files so they stay regenerable.

Tests

Vitest with jsdom runs the specs beside the components. src/test-setup.ts holds the jsdom polyfills Radix and cmdk need (ResizeObserver, scrollIntoView); add one only when a failing test names it.

Commands

pnpm nx run design-system:typecheck         # type-check the package
pnpm nx run design-system:test              # run the Vitest suite
pnpm nx run design-system:storybook         # serve Storybook at http://localhost:6006
pnpm nx run design-system:build-storybook   # build Storybook to dist/storybook/design-system

On this page