AntdUiProvider
This is a React component

Source
import { AntdUiProvider } from "@prestojs/ui-antd";
AntdUiProvider(props)

Version of UiProvider that supports some extra options specific to antd.

If you use date or time widgets in the system you should pass through the datePickerComponent and timePickerComponent props. Without this when DateWidget, TimeWidget or other date/time based components are used they will throw an error. The reason for this is to configure how you want dates to be handled. The default DatePicker and TimePicker components provided by antd use momentjs but it is recommended you use date-fns or dayjs instead.

Recommended Setup

To setup form components, widgets and formatters with sensible defaults we recommend the following:

import React from 'react';
import { AntdUiProvider } from '@prestojs/ui-antd';
import { getFormatterForField as defaultGetFormatterForField } from '@prestojs/ui';
import { getWidgetForField as defaultGetWidgetForField } from '@prestojs/ui-antd';
const DatePicker = React.lazy(() => import('./DatePicker'));
const TimePicker = React.lazy(() => import('./TimePicker'));
const FormItemWrapper = React.lazy(() => import('@prestojs/ui-antd/FormItemWrapper'));
const FormWrapper = React.lazy(() => import('@prestojs/ui-antd/FormWrapper'));
function getWidgetForField(field) {
// Add any app specific customisations here, eg
// if (field instanceof BooleanField) {
// return CustomBooleanWidget;
// }
// Otherwise fall back to specific UI library defaults
let widget;
if ((widget = getAntdWidget(field))) return widget;
// ... if integrating any other libraries add them here ...
// Fall through to any parent UiProvider. If there is none or they
// don't provide a widget for this field then an error will be thrown
}
function getFormatterForField(field) {
// Add any app specific customisations here, eg
// if (field instanceof BooleanField) {
// return CustomBooleanFormatter;
// }
// Otherwise fall back to specific UI library defaults
let formatter;
if ((formatter = defaultGetFormatterForField(field))) return formatter;
// ... if integrating any other libraries add them here ...
// Fall through to any parent UiProvider. If there is none or they
// don't provide a formatter for this field then an error will be thrown
}
export default function Root() {
return (
<AntdUiProvider
datePickerComponent={datePickerComponent}
timePickerComponent={timePickerComponent}
getFormatterForField={getFormatterForField}
getWidgetForField={getWidgetForField}
formItemComponent={FormItemWrapper}
formComponent={FormWrapper}
>
<YourApp />
</AntdUiProvider>
);
}

This recommended setup sets:

NOTE The components here are loaded using React.lazy. Your build must support this otherwise it is recommended to implement your own version of getWidgetForField and getFormatterForField.

ParameterTypeDescription
props.datePickerComponentDatePickerComponent

The DatePicker component to use for components like DateWidget. If you don't use any of these components you don't have to provide this option.

You can pass the antd DatePicker directly or create your own version

props.timePickerComponentTimePickerComponent

The TimePicker component to use for components like TimeWidget. If you don't use any of these components you don't have to provide this option.

You can pass the antd TimePicker directly or create your own version

*props.childrenany

Children to render

props.formComponentReact.ComponentType

A component to use to render the form. This is the component that will be rendered by Form. Defaults to form.

props.formItemComponentReact.ComponentType

A component to use to render items in a form. This is the component that will be rendered by Form.Item.

props.getFormatterForField
Function

A function that is passed an instance of Field and should return the formatter to use for this field. If falsey is returned then it will fall back to a parent UiProvider (if any) or if no parent UiProvider an error will be thrown.

props.getWidgetForField
Function

A function that is passed an instance of Field and should return the widget component to use for this field. If falsey is returned then it will fall back to a parent UiProvider (if any) or if no parent UiProvider an error will be thrown.