@rjsf/react-bootstrap
Version:
React Bootstrap theme, fields and widgets for react-jsonschema-form, powered by react-bootstrap
1,035 lines (1,006 loc) • 32.6 kB
JavaScript
// src/Form/Form.tsx
import { withTheme } from "@rjsf/core";
// src/AddButton/AddButton.tsx
import { TranslatableString } from "@rjsf/utils";
import Button from "react-bootstrap/Button";
import { BsPlus } from "@react-icons/all-files/bs/BsPlus";
import { jsx } from "react/jsx-runtime";
function AddButton({
uiSchema,
registry,
...props
}) {
const { translateString } = registry;
return /* @__PURE__ */ jsx(
Button,
{
title: translateString(TranslatableString.AddItemButton),
...props,
style: { width: "100%" },
className: `ml-1 ${props.className}`,
children: /* @__PURE__ */ jsx(BsPlus, {})
}
);
}
// src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import {
getTemplate,
getUiOptions
} from "@rjsf/utils";
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
function ArrayFieldItemTemplate(props) {
const { children, buttonsProps, displayLabel, hasDescription, hasToolbar, uiSchema, registry } = props;
const uiOptions = getUiOptions(uiSchema);
const ArrayFieldItemButtonsTemplate = getTemplate(
"ArrayFieldItemButtonsTemplate",
registry,
uiOptions
);
const btnStyle = {
flex: 1,
paddingLeft: 6,
paddingRight: 6,
fontWeight: "bold"
};
const padding = hasDescription ? "pb-1" : "pt-4 mt-2";
return /* @__PURE__ */ jsx2("div", { children: /* @__PURE__ */ jsxs(Row, { className: "mb-2 d-flex align-items-center", children: [
/* @__PURE__ */ jsx2(Col, { xs: "8", md: "9", lg: "10", children }),
/* @__PURE__ */ jsx2(Col, { xs: "4", md: "3", lg: "2", className: displayLabel ? padding : "py-4", children: hasToolbar && /* @__PURE__ */ jsx2("div", { className: "d-flex flex-row", children: /* @__PURE__ */ jsx2(ArrayFieldItemButtonsTemplate, { ...buttonsProps, style: btnStyle }) }) })
] }) });
}
// src/ArrayFieldTemplate/ArrayFieldTemplate.tsx
import Row2 from "react-bootstrap/Row";
import Col2 from "react-bootstrap/Col";
import Container from "react-bootstrap/Container";
import {
buttonId,
getTemplate as getTemplate2,
getUiOptions as getUiOptions2
} from "@rjsf/utils";
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
function ArrayFieldTemplate(props) {
const {
canAdd,
disabled,
fieldPathId,
uiSchema,
items,
optionalDataControl,
onAddClick,
readonly,
registry,
required,
schema,
title
} = props;
const uiOptions = getUiOptions2(uiSchema);
const ArrayFieldDescriptionTemplate = getTemplate2(
"ArrayFieldDescriptionTemplate",
registry,
uiOptions
);
const ArrayFieldTitleTemplate = getTemplate2(
"ArrayFieldTitleTemplate",
registry,
uiOptions
);
const showOptionalDataControlInTitle = !readonly && !disabled;
const {
ButtonTemplates: { AddButton: AddButton2 }
} = registry.templates;
return /* @__PURE__ */ jsx3("div", { children: /* @__PURE__ */ jsx3(Row2, { className: "p-0 m-0", children: /* @__PURE__ */ jsxs2(Col2, { className: "p-0 m-0", children: [
/* @__PURE__ */ jsx3(
ArrayFieldTitleTemplate,
{
fieldPathId,
title: uiOptions.title || title,
schema,
uiSchema,
required,
registry,
optionalDataControl: showOptionalDataControlInTitle ? optionalDataControl : void 0
}
),
/* @__PURE__ */ jsx3(
ArrayFieldDescriptionTemplate,
{
fieldPathId,
description: uiOptions.description || schema.description,
schema,
uiSchema,
registry
}
),
/* @__PURE__ */ jsxs2(Container, { fluid: true, className: "p-0 m-0", children: [
!showOptionalDataControlInTitle ? optionalDataControl : void 0,
items,
canAdd && /* @__PURE__ */ jsx3(Container, { className: "", children: /* @__PURE__ */ jsxs2(Row2, { className: "mt-2", children: [
/* @__PURE__ */ jsx3(Col2, { xs: 9, md: 10, lg: 11 }),
/* @__PURE__ */ jsx3(Col2, { xs: 3, md: 2, lg: 1, className: "py-4", children: /* @__PURE__ */ jsx3(
AddButton2,
{
id: buttonId(fieldPathId, "add"),
className: "rjsf-array-item-add",
onClick: onAddClick,
disabled: disabled || readonly,
uiSchema,
registry
}
) })
] }) })
] }, `array-item-list-${fieldPathId.$id}`)
] }) }) });
}
// src/BaseInputTemplate/BaseInputTemplate.tsx
import { useCallback } from "react";
import Form from "react-bootstrap/Form";
import {
ariaDescribedByIds,
examplesId,
getInputProps
} from "@rjsf/utils";
import { SchemaExamples } from "@rjsf/core";
import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
function BaseInputTemplate({
id,
htmlName,
placeholder,
required,
readonly,
disabled,
type,
value,
onChange,
onChangeOverride,
onBlur,
onFocus,
autofocus,
options,
schema,
rawErrors = [],
children,
extraProps,
registry
}) {
const { ClearButton: ClearButton2 } = registry.templates.ButtonTemplates;
const inputProps = {
...extraProps,
...getInputProps(schema, type, options)
};
const _onChange = ({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2);
const _onBlur = ({ target }) => onBlur(id, target && target.value);
const _onFocus = ({ target }) => onFocus(id, target && target.value);
const _onClear = useCallback(
(e) => {
e.preventDefault();
e.stopPropagation();
onChange(options.emptyValue ?? "");
},
[onChange, options.emptyValue]
);
return /* @__PURE__ */ jsxs3(Fragment, { children: [
/* @__PURE__ */ jsx4(
Form.Control,
{
id,
name: htmlName || id,
placeholder,
autoFocus: autofocus,
required,
disabled,
readOnly: readonly,
className: rawErrors.length > 0 ? "is-invalid" : "",
list: schema.examples ? examplesId(id) : void 0,
...inputProps,
value: value || value === 0 ? value : "",
onChange: onChangeOverride || _onChange,
onBlur: _onBlur,
onFocus: _onFocus,
"aria-describedby": ariaDescribedByIds(id, !!schema.examples)
}
),
options.allowClearTextInputs && !readonly && !disabled && value && /* @__PURE__ */ jsx4(ClearButton2, { registry, onClick: _onClear }),
children,
/* @__PURE__ */ jsx4(SchemaExamples, { id, schema })
] });
}
// src/DescriptionField/DescriptionField.tsx
import { RichDescription } from "@rjsf/core";
import { jsx as jsx5 } from "react/jsx-runtime";
function DescriptionField({ id, description, registry, uiSchema }) {
if (!description) {
return null;
}
return /* @__PURE__ */ jsx5("div", { children: /* @__PURE__ */ jsx5("div", { id, className: "mb-3", children: /* @__PURE__ */ jsx5(RichDescription, { description, registry, uiSchema }) }) });
}
// src/ErrorList/ErrorList.tsx
import Card from "react-bootstrap/Card";
import ListGroup from "react-bootstrap/ListGroup";
import { TranslatableString as TranslatableString2 } from "@rjsf/utils";
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
function ErrorList({
errors,
registry
}) {
const { translateString } = registry;
return /* @__PURE__ */ jsxs4(Card, { border: "danger", className: "mb-4", children: [
/* @__PURE__ */ jsx6(Card.Header, { className: "alert-danger", children: translateString(TranslatableString2.ErrorsLabel) }),
/* @__PURE__ */ jsx6(Card.Body, { className: "p-0", children: /* @__PURE__ */ jsx6(ListGroup, { children: errors.map((error, i) => {
return /* @__PURE__ */ jsx6(ListGroup.Item, { className: "border-0", children: /* @__PURE__ */ jsx6("span", { children: error.stack }) }, i);
}) }) })
] });
}
// src/IconButton/IconButton.tsx
import { TranslatableString as TranslatableString3 } from "@rjsf/utils";
import Button2 from "react-bootstrap/Button";
import { IoIosCopy } from "@react-icons/all-files/io/IoIosCopy";
import { IoIosRemove } from "@react-icons/all-files/io/IoIosRemove";
import { AiOutlineArrowUp } from "@react-icons/all-files/ai/AiOutlineArrowUp";
import { AiOutlineArrowDown } from "@react-icons/all-files/ai/AiOutlineArrowDown";
import { IoMdClose } from "@react-icons/all-files/io/IoMdClose";
import { jsx as jsx7 } from "react/jsx-runtime";
function IconButton(props) {
const { icon, iconType, className, uiSchema, registry, ...otherProps } = props;
return /* @__PURE__ */ jsx7(Button2, { ...otherProps, variant: props.variant || "light", size: "sm", children: icon });
}
function CopyButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsx7(IconButton, { title: translateString(TranslatableString3.CopyButton), ...props, icon: /* @__PURE__ */ jsx7(IoIosCopy, {}) });
}
function MoveDownButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsx7(IconButton, { title: translateString(TranslatableString3.MoveDownButton), ...props, icon: /* @__PURE__ */ jsx7(AiOutlineArrowDown, {}) });
}
function MoveUpButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsx7(IconButton, { title: translateString(TranslatableString3.MoveUpButton), ...props, icon: /* @__PURE__ */ jsx7(AiOutlineArrowUp, {}) });
}
function RemoveButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsx7(
IconButton,
{
title: translateString(TranslatableString3.RemoveButton),
variant: "danger",
...props,
icon: /* @__PURE__ */ jsx7(IoIosRemove, {})
}
);
}
function ClearButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsx7(IconButton, { title: translateString(TranslatableString3.ClearButton), ...props, icon: /* @__PURE__ */ jsx7(IoMdClose, {}) });
}
// src/FieldErrorTemplate/FieldErrorTemplate.tsx
import { errorId } from "@rjsf/utils";
import ListGroup2 from "react-bootstrap/ListGroup";
import { jsx as jsx8 } from "react/jsx-runtime";
function FieldErrorTemplate(props) {
const { errors = [], fieldPathId } = props;
if (errors.length === 0) {
return null;
}
const id = errorId(fieldPathId);
return /* @__PURE__ */ jsx8(ListGroup2, { as: "ul", id, children: errors.map((error, i) => {
return /* @__PURE__ */ jsx8(ListGroup2.Item, { as: "li", className: "border-0 m-0 p-0", children: /* @__PURE__ */ jsx8("small", { className: "m-0 text-danger", children: error }) }, i);
}) });
}
// src/FieldHelpTemplate/FieldHelpTemplate.tsx
import { helpId } from "@rjsf/utils";
import { RichHelp } from "@rjsf/core";
import Form2 from "react-bootstrap/Form";
import { jsx as jsx9 } from "react/jsx-runtime";
function FieldHelpTemplate(props) {
const { fieldPathId, help, uiSchema, registry, hasErrors } = props;
if (!help) {
return null;
}
return /* @__PURE__ */ jsx9(Form2.Text, { id: helpId(fieldPathId), className: hasErrors ? "text-danger" : "text-muted", children: /* @__PURE__ */ jsx9(RichHelp, { help, registry, uiSchema }) });
}
// src/FieldTemplate/FieldTemplate.tsx
import {
getTemplate as getTemplate3,
getUiOptions as getUiOptions3
} from "@rjsf/utils";
import Form3 from "react-bootstrap/Form";
import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
function FieldTemplate({
id,
children,
displayLabel,
rawErrors = [],
errors,
help,
description,
rawDescription,
classNames,
style,
disabled,
label,
hidden,
onKeyRename,
onKeyRenameBlur,
onRemoveProperty,
readonly,
required,
schema,
uiSchema,
registry
}) {
const uiOptions = getUiOptions3(uiSchema);
const WrapIfAdditionalTemplate2 = getTemplate3(
"WrapIfAdditionalTemplate",
registry,
uiOptions
);
if (hidden) {
return /* @__PURE__ */ jsx10("div", { className: "hidden", children });
}
const isCheckbox = uiOptions.widget === "checkbox";
return /* @__PURE__ */ jsx10(
WrapIfAdditionalTemplate2,
{
classNames,
style,
disabled,
id,
label,
displayLabel,
rawDescription,
onKeyRename,
onKeyRenameBlur,
onRemoveProperty,
readonly,
required,
schema,
uiSchema,
registry,
children: /* @__PURE__ */ jsxs5(Form3.Group, { children: [
displayLabel && !isCheckbox && /* @__PURE__ */ jsxs5(Form3.Label, { htmlFor: id, className: rawErrors.length > 0 ? "text-danger" : "", children: [
label,
required ? "*" : null
] }),
children,
displayLabel && rawDescription && !isCheckbox && /* @__PURE__ */ jsx10(Form3.Text, { className: rawErrors.length > 0 ? "text-danger" : "text-muted", children: description }),
errors,
help
] })
}
);
}
// src/GridTemplate/GridTemplate.tsx
import Row3 from "react-bootstrap/Row";
import Col3 from "react-bootstrap/Col";
import { jsx as jsx11 } from "react/jsx-runtime";
function GridTemplate(props) {
const { children, column, ...rest } = props;
if (column) {
return /* @__PURE__ */ jsx11(Col3, { ...rest, children });
}
return /* @__PURE__ */ jsx11(Row3, { ...rest, children });
}
// src/MultiSchemaFieldTemplate/MultiSchemaFieldTemplate.tsx
import Card2 from "react-bootstrap/Card";
import { jsx as jsx12, jsxs as jsxs6 } from "react/jsx-runtime";
function MultiSchemaFieldTemplate({ selector, optionSchemaField }) {
return /* @__PURE__ */ jsxs6(Card2, { style: { marginBottom: "1rem" }, children: [
/* @__PURE__ */ jsx12(Card2.Body, { children: selector }),
/* @__PURE__ */ jsx12(Card2.Body, { children: optionSchemaField })
] });
}
// src/ObjectFieldTemplate/ObjectFieldTemplate.tsx
import Row4 from "react-bootstrap/Row";
import Col4 from "react-bootstrap/Col";
import Container2 from "react-bootstrap/Container";
import {
buttonId as buttonId2,
canExpand,
descriptionId,
getTemplate as getTemplate4,
getUiOptions as getUiOptions4,
titleId
} from "@rjsf/utils";
import { Fragment as Fragment2, jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
function ObjectFieldTemplate({
description,
title,
properties,
required,
uiSchema,
fieldPathId,
schema,
formData,
optionalDataControl,
onAddProperty,
disabled,
readonly,
registry
}) {
const uiOptions = getUiOptions4(uiSchema);
const TitleFieldTemplate = getTemplate4("TitleFieldTemplate", registry, uiOptions);
const DescriptionFieldTemplate = getTemplate4(
"DescriptionFieldTemplate",
registry,
uiOptions
);
const showOptionalDataControlInTitle = !readonly && !disabled;
const {
ButtonTemplates: { AddButton: AddButton2 }
} = registry.templates;
return /* @__PURE__ */ jsxs7(Fragment2, { children: [
title && /* @__PURE__ */ jsx13(
TitleFieldTemplate,
{
id: titleId(fieldPathId),
title,
required,
schema,
uiSchema,
registry,
optionalDataControl: showOptionalDataControlInTitle ? optionalDataControl : void 0
}
),
description && /* @__PURE__ */ jsx13(
DescriptionFieldTemplate,
{
id: descriptionId(fieldPathId),
description,
schema,
uiSchema,
registry
}
),
/* @__PURE__ */ jsxs7(Container2, { fluid: true, className: "p-0", children: [
!showOptionalDataControlInTitle ? optionalDataControl : void 0,
properties.map((element, index) => /* @__PURE__ */ jsx13(Row4, { style: { marginBottom: "10px" }, className: element.hidden ? "d-none" : void 0, children: /* @__PURE__ */ jsxs7(Col4, { xs: 12, children: [
" ",
element.content
] }) }, index)),
canExpand(schema, uiSchema, formData) ? /* @__PURE__ */ jsx13(Row4, { children: /* @__PURE__ */ jsx13(Col4, { xs: { offset: 11, span: 1 }, className: "py-0.5", children: /* @__PURE__ */ jsx13(
AddButton2,
{
id: buttonId2(fieldPathId, "add"),
onClick: onAddProperty,
disabled: disabled || readonly,
className: "rjsf-object-property-expand",
uiSchema,
registry
}
) }) }) : null
] })
] });
}
// src/OptionalDataControlsTemplate/OptionalDataControlsTemplate.tsx
import { BsPlus as BsPlus2 } from "@react-icons/all-files/bs/BsPlus";
import { jsx as jsx14 } from "react/jsx-runtime";
function OptionalDataControlsTemplate(props) {
const { id, registry, label, onAddClick, onRemoveClick } = props;
if (onAddClick) {
return /* @__PURE__ */ jsx14(
IconButton,
{
id,
registry,
className: "rjsf-add-optional-data",
icon: /* @__PURE__ */ jsx14(BsPlus2, {}),
onClick: onAddClick,
title: label,
size: "sm",
variant: "secondary"
}
);
} else if (onRemoveClick) {
return /* @__PURE__ */ jsx14(
RemoveButton,
{
id,
registry,
className: "rjsf-remove-optional-data",
onClick: onRemoveClick,
title: label,
size: "sm",
variant: "secondary"
}
);
}
return /* @__PURE__ */ jsx14("em", { id, children: label });
}
// src/SubmitButton/SubmitButton.tsx
import Button3 from "react-bootstrap/Button";
import { getSubmitButtonOptions } from "@rjsf/utils";
import { jsx as jsx15 } from "react/jsx-runtime";
function SubmitButton(props) {
const { submitText, norender, props: submitButtonProps } = getSubmitButtonOptions(props.uiSchema);
if (norender) {
return null;
}
return /* @__PURE__ */ jsx15("div", { children: /* @__PURE__ */ jsx15(Button3, { variant: "primary", type: "submit", ...submitButtonProps, children: submitText }) });
}
// src/TitleField/TitleField.tsx
import { getUiOptions as getUiOptions5 } from "@rjsf/utils";
import Row5 from "react-bootstrap/Row";
import Col5 from "react-bootstrap/Col";
import Container3 from "react-bootstrap/Container";
import { jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
function TitleField({
id,
title,
uiSchema,
optionalDataControl
}) {
const uiOptions = getUiOptions5(uiSchema);
let heading = /* @__PURE__ */ jsx16("h5", { children: uiOptions.title || title });
if (optionalDataControl) {
heading = /* @__PURE__ */ jsx16(Container3, { fluid: true, className: "p-0", children: /* @__PURE__ */ jsxs8(Row5, { children: [
/* @__PURE__ */ jsx16(Col5, { xs: "11", children: heading }),
/* @__PURE__ */ jsx16(Col5, { xs: "1", style: { marginLeft: "-5px" }, children: optionalDataControl })
] }) });
}
return /* @__PURE__ */ jsxs8("div", { id, className: "my-1", children: [
heading,
/* @__PURE__ */ jsx16("hr", { className: "border-0 bg-secondary mt-0", style: { height: "1px" } })
] });
}
// src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx
import {
ADDITIONAL_PROPERTY_FLAG,
buttonId as buttonId3,
TranslatableString as TranslatableString4
} from "@rjsf/utils";
import Row6 from "react-bootstrap/Row";
import Col6 from "react-bootstrap/Col";
import Form4 from "react-bootstrap/Form";
import { jsx as jsx17, jsxs as jsxs9 } from "react/jsx-runtime";
function WrapIfAdditionalTemplate({
classNames,
style,
children,
disabled,
id,
label,
displayLabel,
onRemoveProperty,
onKeyRenameBlur,
rawDescription,
readonly,
required,
schema,
uiSchema,
registry
}) {
const { templates, translateString } = registry;
const { RemoveButton: RemoveButton2 } = templates.ButtonTemplates;
const keyLabel = translateString(TranslatableString4.KeyLabel, [label]);
const additional = ADDITIONAL_PROPERTY_FLAG in schema;
const descPadding = rawDescription ? 1 : 0;
const descMargin = rawDescription ? -24 : 0;
if (!additional) {
return /* @__PURE__ */ jsx17("div", { className: classNames, style, children });
}
const keyId = `${id}-key`;
const margin = displayLabel ? 12 + descMargin : 0;
const padding = displayLabel ? 4 + descPadding : 1;
return /* @__PURE__ */ jsxs9(Row6, { className: classNames, style, children: [
/* @__PURE__ */ jsx17(Col6, { xs: 5, children: /* @__PURE__ */ jsxs9(Form4.Group, { children: [
displayLabel && /* @__PURE__ */ jsx17(Form4.Label, { htmlFor: keyId, children: keyLabel }),
/* @__PURE__ */ jsx17(
Form4.Control,
{
required,
defaultValue: label,
disabled: disabled || readonly,
id: keyId,
name: keyId,
onBlur: !readonly ? onKeyRenameBlur : void 0,
type: "text"
}
)
] }) }),
/* @__PURE__ */ jsx17(Col6, { xs: 6, children }),
/* @__PURE__ */ jsx17(Col6, { xs: 1, className: `py-${padding} d-grid gap-2`, style: { marginTop: `${margin}px`, maxHeight: `2.5rem` }, children: /* @__PURE__ */ jsx17(
RemoveButton2,
{
id: buttonId3(id, "remove"),
className: "rjsf-object-property-remove w-100",
disabled: disabled || readonly,
onClick: onRemoveProperty,
uiSchema,
registry
}
) })
] }, keyId);
}
// src/Templates/Templates.ts
function generateTemplates() {
return {
ArrayFieldItemTemplate,
ArrayFieldTemplate,
BaseInputTemplate,
ButtonTemplates: {
AddButton,
CopyButton,
MoveDownButton,
MoveUpButton,
RemoveButton,
SubmitButton,
ClearButton
},
DescriptionFieldTemplate: DescriptionField,
ErrorListTemplate: ErrorList,
FieldErrorTemplate,
FieldHelpTemplate,
FieldTemplate,
GridTemplate,
MultiSchemaFieldTemplate,
ObjectFieldTemplate,
OptionalDataControlsTemplate,
TitleFieldTemplate: TitleField,
WrapIfAdditionalTemplate
};
}
var Templates_default = generateTemplates();
// src/CheckboxWidget/CheckboxWidget.tsx
import {
ariaDescribedByIds as ariaDescribedByIds2,
descriptionId as descriptionId2,
getTemplate as getTemplate5,
labelValue,
schemaRequiresTrueValue
} from "@rjsf/utils";
import Form5 from "react-bootstrap/Form";
import { jsx as jsx18, jsxs as jsxs10 } from "react/jsx-runtime";
function CheckboxWidget(props) {
const {
id,
htmlName,
value,
disabled,
readonly,
label,
hideLabel,
schema,
autofocus,
options,
onChange,
onBlur,
onFocus,
registry,
uiSchema
} = props;
const required = schemaRequiresTrueValue(schema);
const DescriptionFieldTemplate = getTemplate5(
"DescriptionFieldTemplate",
registry,
options
);
const _onChange = ({ target: { checked } }) => onChange(checked);
const _onBlur = ({ target }) => onBlur(id, target && target.checked);
const _onFocus = ({ target }) => onFocus(id, target && target.checked);
const description = options.description || schema.description;
return /* @__PURE__ */ jsxs10(Form5.Group, { className: disabled || readonly ? "disabled" : "", "aria-describedby": ariaDescribedByIds2(id), children: [
!hideLabel && description && /* @__PURE__ */ jsx18(
DescriptionFieldTemplate,
{
id: descriptionId2(id),
description,
schema,
uiSchema,
registry
}
),
/* @__PURE__ */ jsx18(
Form5.Check,
{
id,
name: htmlName || id,
label: labelValue(label, hideLabel || !label),
checked: typeof value === "undefined" ? false : value,
required,
disabled: disabled || readonly,
autoFocus: autofocus,
onChange: _onChange,
type: "checkbox",
onBlur: _onBlur,
onFocus: _onFocus
}
)
] });
}
// src/CheckboxesWidget/CheckboxesWidget.tsx
import Form6 from "react-bootstrap/Form";
import {
ariaDescribedByIds as ariaDescribedByIds3,
enumOptionsDeselectValue,
enumOptionsIsSelected,
enumOptionsSelectValue,
enumOptionsValueForIndex,
optionId
} from "@rjsf/utils";
import { jsx as jsx19 } from "react/jsx-runtime";
function CheckboxesWidget({
id,
htmlName,
disabled,
options,
value,
autofocus,
readonly,
required,
onChange,
onBlur,
onFocus
}) {
const { enumOptions, enumDisabled, inline, emptyValue } = options;
const checkboxesValues = Array.isArray(value) ? value : [value];
const _onChange = (index) => ({ target: { checked } }) => {
if (checked) {
onChange(enumOptionsSelectValue(index, checkboxesValues, enumOptions));
} else {
onChange(enumOptionsDeselectValue(index, checkboxesValues, enumOptions));
}
};
const _onBlur = ({ target }) => onBlur(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue));
const _onFocus = ({ target }) => onFocus(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue));
return /* @__PURE__ */ jsx19(Form6.Group, { children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
const checked = enumOptionsIsSelected(option.value, checkboxesValues);
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
return /* @__PURE__ */ jsx19(
Form6.Check,
{
inline,
required,
checked,
className: "bg-transparent border-0",
type: "checkbox",
id: optionId(id, index),
name: htmlName || id,
label: option.label,
autoFocus: autofocus && index === 0,
onChange: _onChange(index),
onBlur: _onBlur,
onFocus: _onFocus,
disabled: disabled || itemDisabled || readonly,
"aria-describedby": ariaDescribedByIds3(id)
},
option.value
);
}) });
}
// src/RadioWidget/RadioWidget.tsx
import Form7 from "react-bootstrap/Form";
import {
ariaDescribedByIds as ariaDescribedByIds4,
enumOptionsIsSelected as enumOptionsIsSelected2,
enumOptionsValueForIndex as enumOptionsValueForIndex2,
optionId as optionId2
} from "@rjsf/utils";
import { jsx as jsx20 } from "react/jsx-runtime";
function RadioWidget({
id,
htmlName,
options,
value,
required,
disabled,
readonly,
onChange,
onBlur,
onFocus
}) {
const { enumOptions, enumDisabled, emptyValue } = options;
const _onChange = ({ target: { value: value2 } }) => onChange(enumOptionsValueForIndex2(value2, enumOptions, emptyValue));
const _onBlur = ({ target }) => onBlur(id, enumOptionsValueForIndex2(target && target.value, enumOptions, emptyValue));
const _onFocus = ({ target }) => onFocus(id, enumOptionsValueForIndex2(target && target.value, enumOptions, emptyValue));
const inline = Boolean(options && options.inline);
return /* @__PURE__ */ jsx20(Form7.Group, { className: "mb-0", children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
const checked = enumOptionsIsSelected2(option.value, value);
const radio = /* @__PURE__ */ jsx20(
Form7.Check,
{
inline,
label: option.label,
id: optionId2(id, index),
name: htmlName || id,
type: "radio",
disabled: disabled || itemDisabled || readonly,
checked,
required,
value: String(index),
onChange: _onChange,
onBlur: _onBlur,
onFocus: _onFocus,
"aria-describedby": ariaDescribedByIds4(id)
},
index
);
return radio;
}) });
}
// src/RangeWidget/RangeWidget.tsx
import { rangeSpec } from "@rjsf/utils";
import FormRange from "react-bootstrap/FormRange";
import { Fragment as Fragment3, jsx as jsx21, jsxs as jsxs11 } from "react/jsx-runtime";
function RangeWidget(props) {
const { id, value, disabled, onChange, onBlur, onFocus, schema } = props;
const _onChange = ({ target: { value: value2 } }) => onChange(value2);
const _onBlur = ({ target: { value: value2 } }) => onBlur(id, value2);
const _onFocus = ({ target: { value: value2 } }) => onFocus(id, value2);
const rangeProps = {
value,
id,
name: id,
disabled,
onChange: _onChange,
onBlur: _onBlur,
onFocus: _onFocus,
...rangeSpec(schema)
};
return /* @__PURE__ */ jsxs11(Fragment3, { children: [
/* @__PURE__ */ jsx21(FormRange, { ...rangeProps }),
/* @__PURE__ */ jsx21("span", { className: "range-view", children: value })
] });
}
// src/SelectWidget/SelectWidget.tsx
import FormSelect from "react-bootstrap/FormSelect";
import {
ariaDescribedByIds as ariaDescribedByIds5,
enumOptionsIndexForValue,
enumOptionsValueForIndex as enumOptionsValueForIndex3
} from "@rjsf/utils";
import { jsx as jsx22, jsxs as jsxs12 } from "react/jsx-runtime";
function SelectWidget({
schema,
id,
htmlName,
options,
required,
disabled,
readonly,
value,
multiple,
autofocus,
onChange,
onBlur,
onFocus,
placeholder,
rawErrors = []
}) {
const { enumOptions, enumDisabled, emptyValue: optEmptyValue } = options;
const emptyValue = multiple ? [] : "";
function getValue(event, multiple2) {
if (multiple2) {
return [].slice.call(event.target.options).filter((o) => o.selected).map((o) => o.value);
} else {
return event.target.value;
}
}
const selectedIndexes = enumOptionsIndexForValue(value, enumOptions, multiple);
const showPlaceholderOption = !multiple && schema.default === void 0;
return /* @__PURE__ */ jsxs12(
FormSelect,
{
id,
name: htmlName || id,
value: typeof selectedIndexes === "undefined" ? emptyValue : selectedIndexes,
required,
multiple,
disabled: disabled || readonly,
autoFocus: autofocus,
className: rawErrors.length > 0 ? "is-invalid" : "",
onBlur: onBlur && ((event) => {
const newValue = getValue(event, multiple);
onBlur(id, enumOptionsValueForIndex3(newValue, enumOptions, optEmptyValue));
}),
onFocus: onFocus && ((event) => {
const newValue = getValue(event, multiple);
onFocus(id, enumOptionsValueForIndex3(newValue, enumOptions, optEmptyValue));
}),
onChange: (event) => {
const newValue = getValue(event, multiple);
onChange(enumOptionsValueForIndex3(newValue, enumOptions, optEmptyValue));
},
"aria-describedby": ariaDescribedByIds5(id),
children: [
showPlaceholderOption && /* @__PURE__ */ jsx22("option", { value: "", children: placeholder }),
enumOptions.map(({ value: value2, label }, i) => {
const disabled2 = Array.isArray(enumDisabled) && enumDisabled.indexOf(value2) != -1;
return /* @__PURE__ */ jsx22("option", { id: label, value: String(i), disabled: disabled2, children: label }, i);
})
]
}
);
}
// src/TextareaWidget/TextareaWidget.tsx
import { ariaDescribedByIds as ariaDescribedByIds6 } from "@rjsf/utils";
import FormControl from "react-bootstrap/FormControl";
import InputGroup from "react-bootstrap/InputGroup";
import { jsx as jsx23 } from "react/jsx-runtime";
function TextareaWidget({
id,
htmlName,
placeholder,
value,
required,
disabled,
autofocus,
readonly,
onBlur,
onFocus,
onChange,
options
}) {
const _onChange = ({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2);
const _onBlur = ({ target }) => onBlur(id, target && target.value);
const _onFocus = ({ target }) => onFocus(id, target && target.value);
return /* @__PURE__ */ jsx23(InputGroup, { children: /* @__PURE__ */ jsx23(
FormControl,
{
id,
name: htmlName || id,
as: "textarea",
placeholder,
disabled,
readOnly: readonly,
value,
required,
autoFocus: autofocus,
rows: options.rows || 5,
onChange: _onChange,
onBlur: _onBlur,
onFocus: _onFocus,
"aria-describedby": ariaDescribedByIds6(id)
}
) });
}
// src/Widgets/Widgets.ts
function generateWidgets() {
return {
CheckboxWidget,
CheckboxesWidget,
RadioWidget,
RangeWidget,
SelectWidget,
TextareaWidget
};
}
var Widgets_default = generateWidgets();
// src/Theme/Theme.tsx
function generateTheme() {
return {
templates: generateTemplates(),
widgets: generateWidgets()
};
}
var Theme_default = generateTheme();
// src/Form/Form.tsx
function generateForm() {
return withTheme(generateTheme());
}
var Form_default = generateForm();
// src/index.ts
var index_default = Form_default;
export {
Form_default as Form,
Templates_default as Templates,
Theme_default as Theme,
Widgets_default as Widgets,
index_default as default,
generateForm,
generateTemplates,
generateTheme,
generateWidgets
};
//# sourceMappingURL=react-bootstrap.esm.js.map