ngx-json-render-material
v0.3.19
Published
Angular Material catalog for ngx-json-render: a ready-made component vocabulary for generative UI in Angular.
Maintainers
Readme
ngx-json-render-material
Angular Material catalog for ngx-json-render — a ready-made component vocabulary for generative UI in Angular, which an LLM can generate screens against, so you don't have to write one before your first generated screen.
ngx-json-render gives you the renderer. This gives you the 33 components it renders.
Install
ng add ngx-json-render-materialThat adds the renderer, @json-render/core and zod at the ranges this
package admits, and — when the workspace has no Angular Material yet — adds
Material at your Angular version and runs Material's own ng add, which sets
up the theme, typography and icon font the components need. A workspace that
already has Material keeps its setup as it is.
Or by hand — pin Material to your Angular major (@angular/material@21 on
Angular 21): a bare @angular/material resolves to the newest major, whose
peers reject an older Angular with ERESOLVE.
npm install ngx-json-render-material ngx-json-render @json-render/core zod @angular/material@<your Angular major>Requires Angular ≥ 20 and @json-render/core 0.20 or 0.21. Installed by hand,
your app needs a Material theme and the icon font as usual — see
Angular Material theming.
Bundle size: Angular Material and zod put a new app's initial bundle at
about 1.3 MB raw (≈250 kB transferred), which is over the 1 MB error budget
ng new writes into angular.json. Raise maximumError there, or render
specs in a lazy-loaded route.
Agent skill
Using an AI coding agent (Claude Code, Cursor, Codex, …)? Install the skill that teaches it this catalog — every component, its props, its events and the validation contract — so the specs and overrides it writes match what ships:
npx skills add shteynu/ngx-json-render --skill ngx-json-render-materialThe source is skills/ngx-json-render-material/SKILL.md;
the renderer's skill is --skill ngx-json-render.
Use
import { Component } from '@angular/core';
import { JsonRenderer } from 'ngx-json-render';
import { materialRegistry } from 'ngx-json-render-material';
@Component({
imports: [JsonRenderer],
template: `<json-render [spec]="spec" [registry]="registry" />`,
})
export class AppComponent {
readonly registry = materialRegistry;
readonly spec = {
root: 'card',
elements: {
card: { type: 'Card', props: { title: 'Revenue' }, children: ['total'] },
total: { type: 'Metric', props: { label: 'Q3', value: '$1.2M', delta: '+8%', trend: 'up' }, children: [] },
},
};
}To generate specs, feed the catalog's prompt to the model:
import { materialCatalog } from 'ngx-json-render-material';
const systemPrompt = materialCatalog.prompt();On a server, import it from ngx-json-render-material/catalog instead. That entry point holds the catalog without the components, so it loads no Angular, and plain Node or an edge function can describe the vocabulary to a model and validate what comes back:
import { materialCatalog } from 'ngx-json-render-material/catalog';Components
| Group | Components |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| Layout | Stack, Grid, Card, Toolbar, ExpansionPanel, Tabs, Tab, Stepper, Step, Divider |
| Typography | Heading, Text, Icon, Image |
| Data display | Metric, Chip, List, ListItem, Table |
| Forms | Button, IconButton, Input, Textarea, Select, DatePicker, Checkbox, RadioGroup, ToggleGroup, SlideToggle, Slider |
| Feedback | ProgressBar, Spinner, Callout |
Props are named for what they mean, not for Material's API (variant, not mat-raised-button), so a spec written against this catalog stays portable to the other json-render renderers — and a model that has never seen Angular Material can still target it.
Two-way binding works as it does everywhere else in ngx-json-render: bind value or checked with {"$bindState": "/path"}, or {"$bindItem": "field"} inside a repeat.
{ "type": "Input", "props": { "label": "Name", "value": { "$bindState": "/name" } }, "children": [] }The catalog declares no custom actions — the built-in setState, pushState, removeState, validateForm and submitForm cover it — so materialRegistry renders a spec with nothing else wired up.
Validation
Input, Textarea, Select, DatePicker, Checkbox, RadioGroup and
ToggleGroup take a validation prop. The checks run against the state path the field's value is bound to, so
validation applies only to a bound field — a literal value has no path to
validate and the config is ignored.
{
"type": "Input",
"props": {
"label": "Email",
"value": { "$bindState": "/email" },
"validation": {
"checks": [
{ "type": "required", "message": "Email is required" },
{ "type": "email", "message": "That is not an email address" }
],
"validateOn": "blur"
}
},
"children": []
}Check types: required, requiredIf, email, url, numeric, minLength,
maxLength, pattern, min, max, matches, equalTo, lessThan,
greaterThan. Arguments go in args, and may reference state:
{ "type": "minLength", "args": { "min": 8 }, "message": "At least 8 characters" }
{ "type": "equalTo", "args": { "other": { "$state": "/password" } }, "message": "Passwords must match" }validateOn is "change", "blur" or "submit". It defaults to "blur" for
Input and Textarea — validating on every keystroke is noisy — and to
"change" for Select, DatePicker, Checkbox, RadioGroup and
ToggleGroup, where a change is a deliberate choice. enabled takes a visibility condition and switches the
whole config off when it is false.
The built-in validateForm action validates every bound field at once,
regardless of validateOn, and writes the outcome to /formValidation (or the
statePath you pass):
{ "type": "Button", "props": { "label": "Save" },
"on": { "press": { "action": "validateForm" } }, "children": [] }// /formValidation after a failed submit
{ "valid": false, "errors": { "/email": ["Email is required"] } }submitForm does the same check and then dispatches your own action, but only
if every field passed — one binding instead of a validation the button cannot
act on:
{ "type": "Button", "props": { "label": "Save" },
"on": { "press": { "action": "submitForm", "params": { "action": "saveUser" } } },
"children": [] }Errors appear in the Material form field's subscript (<mat-error>) for
Input, Textarea, Select and DatePicker, and on their own line under
Checkbox, RadioGroup and ToggleGroup, which have no form field to host
one.
Two things worth knowing:
- On
Input, therequiredprop only draws the asterisk. Enforcement comes from arequiredcheck invalidation— which also draws the asterisk, so in practice you only needvalidation. requiredrejectsnull,undefined, empty strings and empty arrays, but notfalse. For a checkbox that must be ticked, use{ "type": "equalTo", "args": { "other": true }, "message": "…" }.
Overriding a component
materialComponents is the plain catalog-name → component map, so swapping one entry keeps the rest:
import { defineRegistry } from 'ngx-json-render';
import { materialCatalog, materialComponents } from 'ngx-json-render-material';
import { BrandedCard } from './branded-card';
export const { registry } = defineRegistry(materialCatalog, {
components: { ...materialComponents, Card: BrandedCard },
actions: {},
});Type the replacement's props with MaterialProps, so they are the ones the catalog declares for that component — every field optional, because the renderer checks them against the schema only when validate is on:
export class BrandedCard {
readonly ctx = injectRenderContext<MaterialProps<'Card'>>();
}Notes
Tabsdiscovers its tabs fromTabchildren in the spec rather than through@ContentChildren, which a spec-driven tree cannot satisfy. EachTabhands its label and body to the parent, which replays them into real<mat-tab>elements.Selectwithmultiple: trueholds an array of the chosen values; start its state as[]. Arequiredcheck fails on an empty array. A lone string reads as a one-item list, and an array in a select withoutmultiplereads as no value.SteppertakesStepchildren the wayTabstakesTabones. Each step but the first gets a Back button and each but the last a Next button (backLabelandnextLabelrename them). Next validates the bound fields inside its step, however deeply nested, and moves on only when they all pass; put the finalsubmitFormbutton in the last step.linear: truestops the headers from skipping to a step not reached through Next.selected, the 0-based index of the open step, can be bound with$bindStateto read or drive it; an index past the last step opens the last one.ToggleGroupis a Material button-toggle group: a row of 2–5 segments with one chosen, bound like aRadioGroup. An option may carry anicon.DatePickerkeeps its date in state as a"YYYY-MM-DD"string, and so dominandmax; clearing the field writes"". ISO dates compare correctly as strings, so an end date after a start date is agreaterThancheck with{ "other": { "$state": "/start" } }. It uses the app'sDateAdapterandMAT_DATE_FORMATSwhen the app provides them (provideLuxonDateAdapter(),provideDateFnsAdapter(), aMAT_DATE_LOCALE), and the nativeDateadapter otherwise, so it needs no provider of its own.Tabletakescolumnsandrowsas props. Bindrowsto a state array with{"$state": "/path"}rather than usingrepeat.Imagerenders only an absolutehttps:URL and nothing for any othersrc—javascript:,data:,http:and relative URLs included. The schema says so too, socheckSpecreports such asrc; the component checks again at render time, because asrcbound to$stateis only known then. It sends no referrer.altis required;""marks a decorative image.ListrequiresListItemchildren, andTabsrequiresTabchildren; the catalog descriptions say so, and the prompt carries them through to the model.
Known issue: the test runner does not exit
ng test ngx-json-render-material runs the suite correctly — 12/12 pass in well
under a second — but the process then stays alive instead of exiting. This is a
defect in the @angular/build:unit-test + Vitest combination, not in the
catalog: the test worker is clean when the suite ends (no pending timers, no
stray handles), and it is the runner process that lingers.
What the bisect actually shows, against Angular 21.2 and Vitest 4.1:
- a spec containing nothing but
expect(1).toBe(1)hangs too, as long as the rest of the project's sources are on disk — so it is not what the tests do; - importing
./form.componentsreproduces it;./layout.components,./content.components,./catalogand./registry's other dependencies do not; - importing all nine Material form modules on their own exits cleanly;
- so does a file of nine plain components that use those modules in their templates;
- so does each of
JrmInput,JrmSelectandJrmSlideron its own — which rules out theeffect()+viewChild()pattern the inputs use, an earlier suspect here; --watch=falseandisolate: truewith either theforksorthreadspool change nothing.
It looks like a threshold in the runner rather than any one API: only the whole
of form.components.ts trips it, and nothing smaller does.
The tests do run in CI. Because the results are complete and written out before
the process hangs, npm run test:material goes through
scripts/run-material-tests.mjs, which
asks Vitest for a JSON report, waits for the report rather than for the
process, kills the runner, and exits on what the report says. A failing test, a
build failure, an empty run and a suite that never finishes all fail the
command.
npm run test:materialLicense
Apache-2.0
