SchemaDrivenView

Generate a List, Edit, or Show view automatically from a flat JSON Schema.

Installation

pnpm dlx shadcn@latest add @shadmin/schema-driven-view
  • format + enum to admin field / input components.

Usage

import { SchemaDrivenView } from '@/components/admin';
 
const SCHEMA = {
  type: 'object',
  properties: {
    title: { type: 'string' },
    email: { type: 'string', format: 'email' },
    publishedAt: { type: 'string', format: 'date' },
    status: { type: 'string', enum: ['draft', 'review', 'published'] },
    views: { type: 'integer' },
  },
};
 
<SchemaDrivenView schema={SCHEMA} mode="show" />
<SchemaDrivenView schema={SCHEMA} mode="edit" />
<SchemaDrivenView schema={SCHEMA} mode="list" />

Props

PropRequiredTypeDefaultDescription
schemaRequiredJsonSchema-Flat object schema
modeRequired"list" | "edit" | "show"-View kind
overridesOptionalRecord<string, ReactNode>-Property-key → custom rendering

Mapping table

PropertyShow fieldEdit input
type: 'string'TextFieldTextInput
type: 'string', format: 'email'EmailFieldTextInput
type: 'string', format: 'date'DateFieldDateInput
type: 'number' | 'integer'NumberFieldNumberInput
type: 'boolean'BooleanFieldBooleanInput
enum: [...]SelectFieldSelectInput

Limitations

  • Flat schemas only. Nested object and array-of-object schemas are deferred.
  • $ref, allOf, oneOf are not supported.