Skip to Content
TelamonJS

BaseFormPage

DRY wrapper for form pages with conditional PageContent wrapping

Base wrapper component for form pages that provides consistent layout with conditional PageContent wrapping.

Dialogs are the default

Generated CRUD modules create, edit and view records in dialogs. BaseFormPage is for the cases that need a standalone form page.

BaseFormPage is the layer under CreatePage and EditPage; most standalone pages should use those instead.


Basic Usage

import { BaseFormPage } from '@telamonjs/ui'
import { UserForm } from './form'

export default function CreateUserPage() {
  return (
    <BaseFormPage
      formComponent={<UserForm />}
      title='Create User'
      variant='card'
    />
  )
}

Props

interface BaseFormPageProps {
  formComponent: React.ReactNode // Form component (required)
  title?: I18nText // Page title — without it, formComponent renders bare
  description?: I18nText // Shown under the title
  variant?: 'card' | 'plain' // PageContent variant (default: 'card')
}

// With a title:
// 'card': PageContent with a card (title in the card header)
// 'plain': PageContent without a card (title above the form)
// Without a title, `variant` is ignored and formComponent renders as is.

Variants

Card Variant (Default)

<BaseFormPage formComponent={<MyForm />} title='Create Item' variant='card' />

Result:

  • Form wrapped in PageContent
  • Card-style container with padding
  • Consistent spacing and borders
  • Best for standard forms

Plain Variant

<BaseFormPage formComponent={<MyForm />} title='Edit Item' variant='plain' />

Result:

  • Form wrapped in PageContent, without a card
  • Title and description above the form
  • Used by EditPage

No Title

<BaseFormPage formComponent={<MyForm />} />

Result:

  • Form rendered directly, no PageContent wrapper
  • Full layout control to the form component
  • Best for custom layouts or multi-step wizards

Examples

With Title and Description

<BaseFormPage
  formComponent={<UserForm />}
  title='Create New User'
  description='Add a new user to the system with role and permissions'
  variant='card'
/>

Custom Layout (No Title)

<BaseFormPage
  formComponent={
    <div className='max-w-4xl mx-auto p-6'>
      <h1>Custom Form Layout</h1>
      <MultiStepForm />
    </div>
  }
/>

Use Cases

✅ When to use BaseFormPage:

  • Building custom page wrappers (like CreatePage, EditPage)
  • Need conditional PageContent wrapping
  • Creating domain-specific form page components

❌ When NOT to use BaseFormPage:

  • Regular form pages → Use CreatePage or EditPage
  • Custom layouts → Use form components directly
  • Multi-step wizards → Use ZustandForm with custom layout

Used By

BaseFormPage is the foundation for these components:

CreatePage

// CreatePage, simplified
export function CreatePage({ title, description, ...formProps }: CreatePageProps) {
  return (
    <BaseFormPage
      formComponent={<CreateForm {...formProps} />}
      title={title}
      description={description}
      variant='card'
    />
  )
}

EditPage

// EditPage, simplified
export function EditPage({ title, description, ...formProps }: EditPageProps) {
  return (
    <BaseFormPage
      formComponent={<EditForm {...formProps} />}
      title={title}
      description={description}
      variant='plain'
    />
  )
}

Complete Example

components/custom-wizard-page.tsx
import { BaseFormPage } from '@telamonjs/ui'
import { MultiStepWizard, type WizardStep } from './wizard'

interface CustomWizardPageProps {
  title: string
  steps: WizardStep[]
}

export function CustomWizardPage({ title, steps }: CustomWizardPageProps) {
  return (
    <BaseFormPage
      formComponent={
        <div className='container max-w-4xl mx-auto py-8'>
          <div className='mb-8'>
            <h1 className='text-3xl font-bold'>{title}</h1>
            <p className='text-muted-foreground'>
              Complete all steps to finish the process
            </p>
          </div>
          <MultiStepWizard steps={steps} />
        </div>
      }
    />
  )
}

// Usage
export default function OnboardingPage() {
  return <CustomWizardPage title='User Onboarding' steps={onboardingSteps} />
}

Best Practices

  1. Prefer high-level wrappers - Use CreatePage/EditPage when possible
  2. Card for standard forms - Use variant="card" for typical CRUD forms
  3. No title for custom layouts - Omit title when the form handles its own layout
  4. Title and description - Add context for users
  5. Reusable wrappers - Create domain-specific wrappers on top of BaseFormPage

Comparison: BaseFormPage vs Higher-Level Wrappers

FeatureBaseFormPageCreatePageEditPage
PurposeBase wrapperCreate formsEdit forms
VariantFlexibleAlways cardAlways plain
Form filterNoneFilters editOnly and crudNone
PropsMinimalCreateForm-specificEditForm-specific
Use whenBuilding custom pagesCreating new recordsEditing existing

Architecture Benefits

DRY principle:

  • Eliminates duplicated PageContent logic
  • Centralized layout handling
  • Consistent page structure

Flexibility:

  • variant prop allows card or plain layouts
  • Works with any form component
  • Extensible for custom wrappers
  • Single source of truth for form page layout


See Also


Status: ✅ Stable

On this page