@rjsf/core
Version:
A simple React component capable of building HTML forms out of a JSON schema.
21 lines (20 loc) • 1.14 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import IconButton from './ButtonTemplates/IconButton.js';
/** The OptionalDataControlsTemplate renders one of three different states. If
* there is an `onAddClick()` function, it renders the "Add" button. If there is
* an `onRemoveClick()` function, it renders the "Remove" button. Otherwise it
* renders the "No data found" section. All of them use the `label` as either
* the `title` of buttons or simply outputting it.
*
* @param props - The `OptionalDataControlsTemplateProps` for the template
*/
export default function OptionalDataControlsTemplate(props) {
const { id, registry, label, onAddClick, onRemoveClick } = props;
if (onAddClick) {
return (_jsx(IconButton, { id: id, registry: registry, icon: 'plus', className: 'rjsf-add-optional-data btn-sm', onClick: onAddClick, title: label }));
}
else if (onRemoveClick) {
return (_jsx(IconButton, { id: id, registry: registry, icon: 'remove', className: 'rjsf-remove-optional-data btn-sm', onClick: onRemoveClick, title: label }));
}
return _jsx("em", { id: id, children: label });
}