UiProviderThis is a React component
SourceUiProvider is used to supply the UI library specific widgets, formatters, form components etc that are used throughout the system.
To use with @prestojs/ui-antd
see AntdUiProvider.
import React from 'react';import { UiProvider, getFormatterForField } from '@prestojs/ui';import { Input } from 'antd';const DefaultWidget = ({ input }) => <input {...input} />;const DefaultFormatter = ({ value }) => value;function getWidgetForField(field) {// Add any app specific customisations here, eg// if (field instanceof BooleanField) {// return CustomBooleanWidget;// }// Otherwise return default widget. If you would prefer an error if no explicit widget defined for// a field then don't return anything.return DefaultWidget;}function getFormatterForField(field) {// Add any app specific customisations here, eg// if (field instanceof BooleanField) {// return CustomBooleanFormatter;// }return DefaultFormatter;}function FormItemWrapper({ children, label, help, required }) {return (<div><label>{label} {children}</label>{required ? '(required)' : '(optional)'}{help && <span className="help">{help}</span>}</div>);}export default function Root() {return (<UiProvidergetFormatterForField={getFormatterForField}getWidgetForField={getWidgetForField}formItemComponent={FormItemWrapper}><YourApp /></UiProvider>);}
Parameter | Type | Description | |
---|---|---|---|
* | props.children | any | Children to render |
props.formComponent | React.ComponentType | A component to use to render the form. This is the component that will be rendered by
Form. Defaults to | |
props.formItemComponent | React.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 | |
props.getWidgetForField | Function | A function that is passed an instance of |