Skip to main content

@canard/schema-form-antd-mobile-plugin

@canard/schema-form-antd-mobile-plugin npm versionlicense
yarn add @canard/schema-form-antd-mobile-plugin

Ant Design Mobile UI plugin for @canard/schema-form. Provides 10 touch-optimized form input components built on antd-mobile ^5.0.0. Designed for mobile web applications — switches and sliders are preferred over desktop-style inputs.

Component Catalog

Preview

Full Catalog

See all 10 components in the Component Catalog page.

Installation

yarn add @canard/schema-form-antd-mobile-plugin antd-mobile@>=5.0.0

Peer Dependencies

yarn add dayjs@>=1 react@>=18 react-dom@>=18

Note: antd-mobile is a direct dependency of this plugin, not a peer dependency.

Quick Setup

import { registerPlugin } from '@canard/schema-form';
import { plugin } from '@canard/schema-form-antd-mobile-plugin';

registerPlugin(plugin);

Component Mapping

Components are selected automatically based on JSON Schema properties. Priority order matches the list below (top = highest priority).

ComponenttypeformatformTypeenumNotes
FormTypeInputBooleanSwitchboolean"switch"Switch toggle with custom labels
FormTypeInputStringCheckboxarray"checkbox"items.enumCheckbox group; items must be string schema
FormTypeInputStringSwitchstring"switch"2 valuesToggle between two enum values
FormTypeInputRadioGroupstring | number | integer"radio" or "radiogroup"requiredRadio group
FormTypeInputArrayarrayDynamic list with add/remove
FormTypeInputSlidernumber | integer"slider"Slider; also supports range slider for numeric-item arrays
FormTypeInputTextareastring"textarea" or formType "textarea"Multi-line textarea
FormTypeInputStringstringDefault text input (password supported via format: "password")
FormTypeInputNumbernumber | integerStepper component
FormTypeInputBooleanbooleanCheckbox with indeterminate state

Slider Range Support

FormTypeInputSlider activates for numeric range arrays:

// Single value slider
{ type: 'number', format: 'slider' }

// Range slider (array of two numbers)
{
type: 'array',
format: 'slider', // or: items with numeric type + format:'slider'
items: { type: 'number' }
}

Schema Extension Properties

{
formType?: 'switch' | 'radio' | 'radiogroup' | 'checkbox' | 'textarea',
format?: 'slider' | 'textarea' | 'password',
}

Usage Example

import { Form } from '@canard/schema-form';

const schema = {
type: 'object',
properties: {
name: { type: 'string' },
count: { type: 'integer' },
active: { type: 'boolean', formType: 'switch' },
rating: { type: 'number', format: 'slider', minimum: 0, maximum: 5 },
tags: {
type: 'array',
formType: 'checkbox',
items: { type: 'string', enum: ['js', 'ts', 'react'] },
},
},
};

<Form jsonSchema={schema} onChange={setValue} />

Context: Custom Switch Labels

// Pass checkboxLabels through context for BooleanSwitch
<Form
jsonSchema={schema}
context={{ checkboxLabels: { active: { true: 'On', false: 'Off' } } }}
/>
AI Agent Reference

AI Reference

Package: @canard/schema-form-antd-mobile-plugin v0.10.0 Purpose: Ant Design Mobile UI plugin — 10 touch-optimized form components for mobile web.

Exports

import { plugin } from '@canard/schema-form-antd-mobile-plugin';

Peer dependencies

antd-mobile@>=5.0.0 (direct dep), dayjs@>=1, react@>=18

Component mapping (priority order, high → low)

ComponentTrigger
BooleanSwitchboolean + formType: "switch"
StringCheckboxarray + formType: "checkbox" + items.enum
StringSwitchstring + formType: "switch" + 2 enum values
RadioGroupstring|number + formType: "radio" + enum
Arrayarray (dynamic list)
Slidernumber + format: "slider" (also supports range arrays)
Textareastring + format: "textarea"
Stringstring (default)
Numbernumber|integer (Stepper component)
Booleanboolean (default checkbox with indeterminate)

Context: custom switch labels

context={{ checkboxLabels: { fieldName: { true: 'On', false: 'Off' } } }}

Key differences from antd5/antd6

  • No Date/Time/Month/URI pickers (mobile-specific)
  • Number uses Stepper component (not text input)
  • Slider supports range arrays: { type: 'array', format: 'slider', items: { type: 'number' } }