@rjsf/bootstrap-4
Version:
Bootstrap 4 theme, fields and widgets for react-jsonschema-form
937 lines (911 loc) • 29.3 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,
{
...props,
style: { width: "100%" },
className: `ml-1 ${props.className}`,
title: translateString(TranslatableString.AddItemButton),
children: /* @__PURE__ */ jsx(BsPlus, {})
}
);
}
// src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
function ArrayFieldItemTemplate(props) {
const {
children,
disabled,
hasToolbar,
hasCopy,
hasMoveDown,
hasMoveUp,
hasRemove,
index,
onCopyIndexClick,
onDropIndexClick,
onReorderClick,
readonly,
registry,
uiSchema
} = props;
const { CopyButton: CopyButton2, MoveDownButton: MoveDownButton2, MoveUpButton: MoveUpButton2, RemoveButton: RemoveButton2 } = registry.templates.ButtonTemplates;
const btnStyle = {
flex: 1,
paddingLeft: 6,
paddingRight: 6,
fontWeight: "bold"
};
return /* @__PURE__ */ jsx2("div", { children: /* @__PURE__ */ jsxs(Row, { className: "mb-2 d-flex align-items-center", children: [
/* @__PURE__ */ jsx2(Col, { xs: "9", lg: "9", children }),
/* @__PURE__ */ jsx2(Col, { xs: "3", lg: "3", className: "py-4", children: hasToolbar && /* @__PURE__ */ jsxs("div", { className: "d-flex flex-row", children: [
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ jsx2("div", { className: "m-0 p-0", children: /* @__PURE__ */ jsx2(
MoveUpButton2,
{
className: "array-item-move-up",
style: btnStyle,
disabled: disabled || readonly || !hasMoveUp,
onClick: onReorderClick(index, index - 1),
uiSchema,
registry
}
) }),
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ jsx2("div", { className: "m-0 p-0", children: /* @__PURE__ */ jsx2(
MoveDownButton2,
{
style: btnStyle,
disabled: disabled || readonly || !hasMoveDown,
onClick: onReorderClick(index, index + 1),
uiSchema,
registry
}
) }),
hasCopy && /* @__PURE__ */ jsx2("div", { className: "m-0 p-0", children: /* @__PURE__ */ jsx2(
CopyButton2,
{
style: btnStyle,
disabled: disabled || readonly,
onClick: onCopyIndexClick(index),
uiSchema,
registry
}
) }),
hasRemove && /* @__PURE__ */ jsx2("div", { className: "m-0 p-0", children: /* @__PURE__ */ jsx2(
RemoveButton2,
{
style: btnStyle,
disabled: disabled || readonly,
onClick: onDropIndexClick(index),
uiSchema,
registry
}
) })
] }) })
] }) });
}
// src/ArrayFieldTemplate/ArrayFieldTemplate.tsx
import Row2 from "react-bootstrap/Row";
import Col2 from "react-bootstrap/Col";
import Container from "react-bootstrap/Container";
import {
getTemplate,
getUiOptions
} from "@rjsf/utils";
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
function ArrayFieldTemplate(props) {
const { canAdd, disabled, idSchema, uiSchema, items, onAddClick, readonly, registry, required, schema, title } = props;
const uiOptions = getUiOptions(uiSchema);
const ArrayFieldDescriptionTemplate = getTemplate(
"ArrayFieldDescriptionTemplate",
registry,
uiOptions
);
const ArrayFieldItemTemplate2 = getTemplate(
"ArrayFieldItemTemplate",
registry,
uiOptions
);
const ArrayFieldTitleTemplate = getTemplate(
"ArrayFieldTitleTemplate",
registry,
uiOptions
);
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,
{
idSchema,
title: uiOptions.title || title,
schema,
uiSchema,
required,
registry
}
),
/* @__PURE__ */ jsx3(
ArrayFieldDescriptionTemplate,
{
idSchema,
description: uiOptions.description || schema.description,
schema,
uiSchema,
registry
}
),
/* @__PURE__ */ jsxs2(Container, { fluid: true, className: "p-0 m-0", children: [
items && items.map(({ key, ...itemProps }) => /* @__PURE__ */ jsx3(ArrayFieldItemTemplate2, { ...itemProps }, key)),
canAdd && /* @__PURE__ */ jsx3(Container, { className: "", children: /* @__PURE__ */ jsxs2(Row2, { className: "mt-2", children: [
/* @__PURE__ */ jsx3(Col2, { xs: 9 }),
/* @__PURE__ */ jsx3(Col2, { xs: 3, className: "py-4 col-lg-3 col-3", children: /* @__PURE__ */ jsx3(
AddButton2,
{
className: "array-item-add",
onClick: onAddClick,
disabled: disabled || readonly,
uiSchema,
registry
}
) })
] }) })
] }, `array-item-list-${idSchema.$id}`)
] }) }) });
}
// src/BaseInputTemplate/BaseInputTemplate.tsx
import Form from "react-bootstrap/Form";
import {
ariaDescribedByIds,
examplesId,
getInputProps
} from "@rjsf/utils";
import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
function BaseInputTemplate({
id,
placeholder,
required,
readonly,
disabled,
type,
value,
onChange,
onChangeOverride,
onBlur,
onFocus,
autofocus,
options,
schema,
rawErrors = [],
children,
extraProps
}) {
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);
return /* @__PURE__ */ jsxs3(Fragment, { children: [
/* @__PURE__ */ jsx4(
Form.Control,
{
id,
name: 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)
}
),
children,
Array.isArray(schema.examples) ? /* @__PURE__ */ jsx4("datalist", { id: examplesId(id), children: schema.examples.concat(schema.default && !schema.examples.includes(schema.default) ? [schema.default] : []).map((example) => {
return /* @__PURE__ */ jsx4("option", { value: example }, example);
}) }) : null
] });
}
// src/DescriptionField/DescriptionField.tsx
import { jsx as jsx5 } from "react/jsx-runtime";
function DescriptionField({ id, description }) {
if (description) {
return /* @__PURE__ */ jsx5("div", { children: /* @__PURE__ */ jsx5("div", { id, className: "mb-3", children: description }) });
}
return null;
}
// 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 { jsx as jsx7 } from "react/jsx-runtime";
function IconButton(props) {
const { icon, iconType, className, uiSchema, registry, ...otherProps } = props;
return /* @__PURE__ */ jsx7(Button2, { block: iconType === "block", ...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),
...props,
variant: "danger",
icon: /* @__PURE__ */ jsx7(IoIosRemove, {})
}
);
}
// 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 = [], idSchema } = props;
if (errors.length === 0) {
return null;
}
const id = errorId(idSchema);
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 Form2 from "react-bootstrap/Form";
import { jsx as jsx9 } from "react/jsx-runtime";
function FieldHelpTemplate(props) {
const { idSchema, help, hasErrors } = props;
if (!help) {
return null;
}
const id = helpId(idSchema);
return /* @__PURE__ */ jsx9(Form2.Text, { className: hasErrors ? "text-danger" : "text-muted", id, children: help });
}
// src/FieldTemplate/FieldTemplate.tsx
import {
getTemplate as getTemplate2,
getUiOptions as getUiOptions2
} 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,
onDropPropertyClick,
onKeyChange,
readonly,
required,
schema,
uiSchema,
registry
}) {
const uiOptions = getUiOptions2(uiSchema);
const WrapIfAdditionalTemplate2 = getTemplate2(
"WrapIfAdditionalTemplate",
registry,
uiOptions
);
if (hidden) {
return /* @__PURE__ */ jsx10("div", { className: "hidden", children });
}
return /* @__PURE__ */ jsx10(
WrapIfAdditionalTemplate2,
{
classNames,
style,
disabled,
id,
label,
onDropPropertyClick,
onKeyChange,
readonly,
required,
schema,
uiSchema,
registry,
children: /* @__PURE__ */ jsxs5(Form3.Group, { children: [
displayLabel && /* @__PURE__ */ jsxs5(Form3.Label, { htmlFor: id, className: rawErrors.length > 0 ? "text-danger" : "", children: [
label,
required ? "*" : null
] }),
children,
displayLabel && rawDescription && /* @__PURE__ */ jsx10(Form3.Text, { className: rawErrors.length > 0 ? "text-danger" : "text-muted", children: description }),
errors,
help
] })
}
);
}
// src/ObjectFieldTemplate/ObjectFieldTemplate.tsx
import Row3 from "react-bootstrap/Row";
import Col3 from "react-bootstrap/Col";
import Container2 from "react-bootstrap/Container";
import {
canExpand,
descriptionId,
getTemplate as getTemplate3,
getUiOptions as getUiOptions3,
titleId
} from "@rjsf/utils";
import { Fragment as Fragment2, jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
function ObjectFieldTemplate({
description,
title,
properties,
required,
uiSchema,
idSchema,
schema,
formData,
onAddClick,
disabled,
readonly,
registry
}) {
const uiOptions = getUiOptions3(uiSchema);
const TitleFieldTemplate = getTemplate3("TitleFieldTemplate", registry, uiOptions);
const DescriptionFieldTemplate = getTemplate3(
"DescriptionFieldTemplate",
registry,
uiOptions
);
const {
ButtonTemplates: { AddButton: AddButton2 }
} = registry.templates;
return /* @__PURE__ */ jsxs6(Fragment2, { children: [
title && /* @__PURE__ */ jsx11(
TitleFieldTemplate,
{
id: titleId(idSchema),
title,
required,
schema,
uiSchema,
registry
}
),
description && /* @__PURE__ */ jsx11(
DescriptionFieldTemplate,
{
id: descriptionId(idSchema),
description,
schema,
uiSchema,
registry
}
),
/* @__PURE__ */ jsxs6(Container2, { fluid: true, className: "p-0", children: [
properties.map((element, index) => /* @__PURE__ */ jsx11(Row3, { style: { marginBottom: "10px" }, className: element.hidden ? "d-none" : void 0, children: /* @__PURE__ */ jsxs6(Col3, { xs: 12, children: [
" ",
element.content
] }) }, index)),
canExpand(schema, uiSchema, formData) ? /* @__PURE__ */ jsx11(Row3, { children: /* @__PURE__ */ jsx11(Col3, { xs: { offset: 9, span: 3 }, className: "py-4", children: /* @__PURE__ */ jsx11(
AddButton2,
{
onClick: onAddClick(schema),
disabled: disabled || readonly,
className: "object-property-expand",
uiSchema,
registry
}
) }) }) : null
] })
] });
}
// src/SubmitButton/SubmitButton.tsx
import Button3 from "react-bootstrap/Button";
import { getSubmitButtonOptions } from "@rjsf/utils";
import { jsx as jsx12 } from "react/jsx-runtime";
function SubmitButton(props) {
const { submitText, norender, props: submitButtonProps } = getSubmitButtonOptions(props.uiSchema);
if (norender) {
return null;
}
return /* @__PURE__ */ jsx12("div", { children: /* @__PURE__ */ jsx12(Button3, { variant: "primary", type: "submit", ...submitButtonProps, children: submitText }) });
}
// src/TitleField/TitleField.tsx
import { getUiOptions as getUiOptions4 } from "@rjsf/utils";
import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
function TitleField({
id,
title,
uiSchema
}) {
const uiOptions = getUiOptions4(uiSchema);
return /* @__PURE__ */ jsxs7("div", { id, className: "my-1", children: [
/* @__PURE__ */ jsx13("h5", { children: uiOptions.title || title }),
/* @__PURE__ */ jsx13("hr", { className: "border-0 bg-secondary", style: { height: "1px" } })
] });
}
// src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx
import {
ADDITIONAL_PROPERTY_FLAG,
TranslatableString as TranslatableString4
} from "@rjsf/utils";
import Row4 from "react-bootstrap/Row";
import Col4 from "react-bootstrap/Col";
import Form4 from "react-bootstrap/Form";
import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
function WrapIfAdditionalTemplate({
classNames,
style,
children,
disabled,
id,
label,
onDropPropertyClick,
onKeyChange,
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;
if (!additional) {
return /* @__PURE__ */ jsx14("div", { className: classNames, style, children });
}
const handleBlur = ({ target }) => onKeyChange(target.value);
const keyId = `${id}-key`;
return /* @__PURE__ */ jsxs8(Row4, { className: classNames, style, children: [
/* @__PURE__ */ jsx14(Col4, { xs: 5, children: /* @__PURE__ */ jsxs8(Form4.Group, { children: [
/* @__PURE__ */ jsx14(Form4.Label, { htmlFor: keyId, children: keyLabel }),
/* @__PURE__ */ jsx14(
Form4.Control,
{
required,
defaultValue: label,
disabled: disabled || readonly,
id: keyId,
name: keyId,
onBlur: !readonly ? handleBlur : void 0,
type: "text"
}
)
] }) }),
/* @__PURE__ */ jsx14(Col4, { xs: 5, children }),
/* @__PURE__ */ jsx14(Col4, { xs: 2, className: "py-4", children: /* @__PURE__ */ jsx14(
RemoveButton2,
{
iconType: "block",
className: "w-100",
disabled: disabled || readonly,
onClick: onDropPropertyClick(label),
uiSchema,
registry
}
) })
] }, keyId);
}
// src/Templates/Templates.ts
function generateTemplates() {
return {
ArrayFieldItemTemplate,
ArrayFieldTemplate,
BaseInputTemplate,
ButtonTemplates: {
AddButton,
CopyButton,
MoveDownButton,
MoveUpButton,
RemoveButton,
SubmitButton
},
DescriptionFieldTemplate: DescriptionField,
ErrorListTemplate: ErrorList,
FieldErrorTemplate,
FieldHelpTemplate,
FieldTemplate,
ObjectFieldTemplate,
TitleFieldTemplate: TitleField,
WrapIfAdditionalTemplate
};
}
var Templates_default = generateTemplates();
// src/CheckboxWidget/CheckboxWidget.tsx
import {
ariaDescribedByIds as ariaDescribedByIds2,
descriptionId as descriptionId2,
getTemplate as getTemplate4,
labelValue,
schemaRequiresTrueValue
} from "@rjsf/utils";
import Form5 from "react-bootstrap/Form";
import { jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
function CheckboxWidget(props) {
const {
id,
value,
disabled,
readonly,
label,
hideLabel,
schema,
autofocus,
options,
onChange,
onBlur,
onFocus,
registry,
uiSchema
} = props;
const required = schemaRequiresTrueValue(schema);
const DescriptionFieldTemplate = getTemplate4(
"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__ */ jsxs9(
Form5.Group,
{
className: `checkbox ${disabled || readonly ? "disabled" : ""}`,
"aria-describedby": ariaDescribedByIds2(id),
children: [
!hideLabel && !!description && /* @__PURE__ */ jsx15(
DescriptionFieldTemplate,
{
id: descriptionId2(id),
description,
schema,
uiSchema,
registry
}
),
/* @__PURE__ */ jsx15(
Form5.Check,
{
id,
name: 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 jsx16 } from "react/jsx-runtime";
function CheckboxesWidget({ id, 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__ */ jsx16(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__ */ jsx16(
Form6.Check,
{
inline,
custom: true,
required,
checked,
className: "bg-transparent border-0",
type: "checkbox",
id: optionId(id, index),
name: 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 jsx17 } from "react/jsx-runtime";
function RadioWidget({
id,
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__ */ jsx17(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__ */ jsx17(
Form7.Check,
{
inline,
label: option.label,
id: optionId2(id, index),
name: 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 { getTemplate as getTemplate5, labelValue as labelValue2 } from "@rjsf/utils";
import { jsx as jsx18 } from "react/jsx-runtime";
function RangeWidget(props) {
const { value, label, hideLabel, options, registry } = props;
const BaseInputTemplate2 = getTemplate5("BaseInputTemplate", registry, options);
return /* @__PURE__ */ jsx18(BaseInputTemplate2, { ...props, extraProps: { label: labelValue2(label || void 0, hideLabel) }, children: /* @__PURE__ */ jsx18("span", { className: "range-view", children: value }) });
}
// src/SelectWidget/SelectWidget.tsx
import Form8 from "react-bootstrap/Form";
import {
ariaDescribedByIds as ariaDescribedByIds5,
enumOptionsIndexForValue,
enumOptionsValueForIndex as enumOptionsValueForIndex3
} from "@rjsf/utils";
import { jsx as jsx19, jsxs as jsxs10 } from "react/jsx-runtime";
function SelectWidget({
schema,
id,
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__ */ jsxs10(
Form8.Control,
{
as: "select",
bsPrefix: "custom-select",
id,
name: 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__ */ jsx19("option", { value: "", children: placeholder }),
enumOptions.map(({ value: value2, label }, i) => {
const disabled2 = Array.isArray(enumDisabled) && enumDisabled.indexOf(value2) != -1;
return /* @__PURE__ */ jsx19("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 jsx20 } from "react/jsx-runtime";
function TextareaWidget({
id,
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__ */ jsx20(InputGroup, { children: /* @__PURE__ */ jsx20(
FormControl,
{
id,
name: 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 src_default = Form_default;
export {
Form_default as Form,
Templates_default as Templates,
Theme_default as Theme,
Widgets_default as Widgets,
src_default as default,
generateForm,
generateTemplates,
generateTheme,
generateWidgets
};
//# sourceMappingURL=bootstrap-4.esm.js.map