@availity/form
Version:
Form Wrapper around formik using reactstrap components
977 lines (962 loc) • 33.6 kB
JavaScript
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/Form.js
import React, { useEffect, useState } from "react";
import PropTypes from "prop-types";
import { v4 as uuid } from "uuid";
import { Form as RsForm } from "reactstrap";
import { Formik, Form as FForm, useFormikContext } from "formik";
import { jsx } from "react/jsx-runtime";
var useFormikFocusFirstInvalidField = (id, focusInvalidField, invalidInputSelectors) => {
const formik = useFormikContext();
const [submitCount, setSubmitCount] = useState(formik.submitCount);
useEffect(() => {
if (focusInvalidField && !formik.isValid && formik.submitCount > submitCount) {
const form = document.getElementById(id);
const firstInvalidInput = form.querySelector(invalidInputSelectors);
firstInvalidInput == null ? void 0 : firstInvalidInput.focus();
setSubmitCount(formik.submitCount);
}
}, [id, focusInvalidField, formik.isValid, formik.submitCount, invalidInputSelectors, submitCount, formik.errors]);
};
var FocusableForm = (_a) => {
var _b = _a, { children, focusProps } = _b, rest = __objRest(_b, ["children", "focusProps"]);
useFormikFocusFirstInvalidField(...focusProps);
return /* @__PURE__ */ jsx(RsForm, __spreadProps(__spreadValues({}, rest), { children }));
};
var defaultInvalidInputSelectors = 'input[aria-invalid="true"], div.is-invalid input:first-of-type:not([hidden]):not([style*="display:none"]):not([style*="display: none"])';
var Form = (_a) => {
var _b = _a, {
initialValues,
enableReinitialize,
onSubmit = () => {
},
initialStatus,
initialErrors,
initialTouched,
onReset,
validationSchema,
validate,
focusInvalidField = true,
id,
innerRef,
invalidInputSelectors = defaultInvalidInputSelectors,
children
} = _b, rest = __objRest(_b, [
"initialValues",
"enableReinitialize",
"onSubmit",
"initialStatus",
"initialErrors",
"initialTouched",
"onReset",
"validationSchema",
"validate",
"focusInvalidField",
"id",
"innerRef",
"invalidInputSelectors",
"children"
]);
const formId = id || uuid();
const focusProps = [id = formId, focusInvalidField, invalidInputSelectors];
return /* @__PURE__ */ jsx(
Formik,
{
initialValues,
enableReinitialize,
onSubmit,
onReset,
initialStatus,
initialErrors,
initialTouched,
validationSchema,
validate,
innerRef,
children: (props) => /* @__PURE__ */ jsx(FocusableForm, __spreadProps(__spreadValues({ "data-testid": "form-container", tag: FForm, id: formId, focusProps }, rest), { children: typeof children === "function" ? children(props) : children }))
}
);
};
Form.propTypes = {
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
enableReinitialize: PropTypes.bool,
focusInvalidField: PropTypes.bool,
id: PropTypes.string,
initialErrors: PropTypes.object,
initialStatus: PropTypes.any,
initialTouched: PropTypes.object,
initialValues: PropTypes.object.isRequired,
innerRef: PropTypes.any,
invalidInputSelectors: PropTypes.string,
onReset: PropTypes.func,
onSubmit: PropTypes.func,
validate: PropTypes.func,
validationSchema: PropTypes.object
};
FocusableForm.propTypes = {
children: PropTypes.node,
focusProps: PropTypes.array
};
var Form_default = Form;
// src/Field.js
import React7 from "react";
import PropTypes7 from "prop-types";
import { Col, FormText, Input as RsInput2, InputGroup, InputGroupAddon, InputGroupText } from "reactstrap";
import { v4 as uuid3 } from "uuid";
// src/Feedback.js
import React2 from "react";
import PropTypes2 from "prop-types";
import { FormFeedback } from "reactstrap";
import { ErrorMessage } from "formik";
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
var AvFeedback = (_a) => {
var _b = _a, { children } = _b, rest = __objRest(_b, ["children"]);
return /* @__PURE__ */ jsxs(FormFeedback, __spreadProps(__spreadValues({}, rest), { children: [
/* @__PURE__ */ jsx2("i", { className: "icon icon-attention", "aria-hidden": true }),
/* @__PURE__ */ jsx2("div", { className: "sr-only", children: "Error:" }),
children
] }));
};
var Feedback = (_a) => {
var _b = _a, { name } = _b, rest = __objRest(_b, ["name"]);
const feedbackId = `${name}-feedback`.toLowerCase();
return /* @__PURE__ */ jsx2(ErrorMessage, __spreadValues({ id: feedbackId, component: AvFeedback, name }, rest));
};
AvFeedback.propTypes = {
children: PropTypes2.node
};
Feedback.propTypes = {
name: PropTypes2.string.isRequired
};
var Feedback_default = Feedback;
// src/FormGroup.js
import React3 from "react";
import PropTypes3 from "prop-types";
import { FormGroup as RsFormGroup } from "reactstrap";
import classNames from "classnames";
import { useField } from "formik";
import { jsx as jsx3 } from "react/jsx-runtime";
var FormGroup = (_a) => {
var _b = _a, { className, for: For } = _b, props = __objRest(_b, ["className", "for"]);
const [, metadata] = useField(For);
const classname = classNames(className, metadata.touched && metadata.error && `text-danger`);
return /* @__PURE__ */ jsx3(RsFormGroup, __spreadValues({ className: classname }, props));
};
FormGroup.propTypes = {
className: PropTypes3.string,
/** Used to match the wrapped input. Must be the same name given to the input field. */
for: PropTypes3.string
};
var FormGroup_default = FormGroup;
// src/Input.js
import React4 from "react";
import PropTypes4 from "prop-types";
import classNames2 from "classnames";
import { Input as RsInput } from "reactstrap";
import { useField as useField2 } from "formik";
import { jsx as jsx4 } from "react/jsx-runtime";
var Input = (_a) => {
var _b = _a, {
name,
tag: Tag = RsInput,
className,
onChange: propsOnChange,
validate,
feedback,
help,
required
} = _b, rest = __objRest(_b, [
"name",
"tag",
"className",
"onChange",
"validate",
"feedback",
"help",
"required"
]);
const [_a2, ..._b2] = useField2({
name,
validate
}), _c = _a2, { onChange } = _c, field = __objRest(_c, ["onChange"]), [metadata] = _b2;
const classes = classNames2(
className,
metadata.touched ? "is-touched" : "is-untouched",
metadata.error ? "av-invalid" : "av-valid",
metadata.touched && metadata.error && "is-invalid",
rest.type === "checkbox" && metadata.touched && metadata.error && "was-validated"
);
const error = !!metadata.touched && !!metadata.error;
const feedbackId = error && feedback ? `${name}-feedback`.toLowerCase() : "";
const helpMessageId = help ? ` ${name}-helpmessage`.toLowerCase() : "";
const extraProps = {};
if (rest.type === "checkbox") {
extraProps.checked = !!field.value;
}
return /* @__PURE__ */ jsx4(
Tag,
__spreadValues(__spreadValues(__spreadValues({
className: classes,
onChange: (e) => {
onChange(e);
if (propsOnChange) {
propsOnChange(e);
}
},
name,
invalid: error,
"aria-describedby": feedbackId + helpMessageId,
"aria-required": required
}, field), extraProps), rest)
);
};
Input.propTypes = {
/** Identifies the field and matches the validation */
name: PropTypes4.string.isRequired,
/** Class name passed to the input. */
className: PropTypes4.string,
/** Will add default feedback id to aria-describedby. */
feedback: PropTypes4.bool,
/** Will add default help message id to aria-describedby. Used by <Field />. */
help: PropTypes4.bool,
onChange: PropTypes4.func,
/** Will add aria-required to input. */
required: PropTypes4.bool,
/** The Node or tag to substitute as the input field. Default is reactstrap Input tag. */
tag: PropTypes4.oneOfType([PropTypes4.func, PropTypes4.string]),
validate: PropTypes4.func
};
var Input_default = Input;
// src/Label.js
import React6 from "react";
import PropTypes6 from "prop-types";
import { v4 as uuid2 } from "uuid";
import { Label as RSLabel } from "reactstrap";
// src/FieldHelpIcon.js
import React5 from "react";
import PropTypes5 from "prop-types";
import avMessages from "@availity/message-core";
import Icon from "@availity/icon";
import { jsx as jsx5 } from "react/jsx-runtime";
var OPEN_FIELD_HELP = "nav:help:field";
var triggerFieldHelp = (id) => {
avMessages.send({
event: OPEN_FIELD_HELP,
id
});
};
var handleKeyPress = (event, id) => {
if (event.key === "Enter") {
triggerFieldHelp(id);
}
};
var FieldHelpIcon = ({ id, color = "primary", size = "1x", labelId, isHelpVideoType }) => /* @__PURE__ */ jsx5(
Icon,
{
role: "link",
"data-testid": "field-help-icon",
name: isHelpVideoType ? "video-help" : "help-circle",
size,
color,
onClick: () => triggerFieldHelp(id),
tabIndex: 0,
onKeyDown: (event) => handleKeyPress(event, id),
"aria-hidden": "false",
"aria-label": "help",
"aria-describedby": labelId
}
);
FieldHelpIcon.propTypes = {
id: PropTypes5.string,
color: PropTypes5.string,
size: PropTypes5.string,
labelId: PropTypes5.string,
isHelpVideoType: PropTypes5.bool
};
var FieldHelpIcon_default = FieldHelpIcon;
// src/Label.js
import { Fragment, jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
var RequiredAsterisk = () => (
// required-asterisk class available in availity-uikit v4.1.5+
/* @__PURE__ */ jsx6(
"strong",
{
className: "text-danger d-inline align-text-top",
"data-testid": "required-asterisk",
style: {
fontSize: "130%",
lineHeight: "100%"
},
children: "*"
}
)
);
var RequiredKey = () => /* @__PURE__ */ jsxs2("div", { children: [
"Fields marked with an asterisk ",
/* @__PURE__ */ jsx6(RequiredAsterisk, {}),
" are required."
] });
var Label = (_a) => {
var _b = _a, { helpId, id, required, children, isHelpVideoType } = _b, attributes = __objRest(_b, ["helpId", "id", "required", "children", "isHelpVideoType"]);
const labelId = id || uuid2();
const Wrapper = ({ children: children2 }) => {
if (helpId && (attributes.className || attributes.style)) {
return /* @__PURE__ */ jsx6("div", { className: attributes.className, style: attributes.style, children: children2 });
}
return /* @__PURE__ */ jsx6(Fragment, { children: children2 });
};
return /* @__PURE__ */ jsxs2(Wrapper, { children: [
/* @__PURE__ */ jsxs2(RSLabel, __spreadProps(__spreadValues({ id: labelId, "data-testid": "label" }, attributes), { children: [
required ? /* @__PURE__ */ jsxs2(Fragment, { children: [
/* @__PURE__ */ jsx6(RequiredAsterisk, {}),
" "
] }) : null,
children
] })),
helpId ? /* @__PURE__ */ jsx6(FieldHelpIcon_default, { labelId, id: helpId, isHelpVideoType }) : null
] });
};
Label.propTypes = {
/** Id of the label element. Default is generated UUID. */
id: PropTypes6.string,
/** Help topic id, adds <FieldHelpIcon/> next to the label (should not be within label for accessibility). */
helpId: PropTypes6.string,
/** Will add <RequiredAsterisk /> to label. */
required: PropTypes6.bool,
children: PropTypes6.oneOfType([PropTypes6.func, PropTypes6.node]),
/** Allows the type of `<FieldHelpIcon/>` to be changed between help-icon and video-help */
isHelpVideoType: PropTypes6.bool
};
var Label_default = Label;
// src/Field.js
import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
var colSizes = ["xs", "sm", "md", "lg", "xl"];
var Field = (_a) => {
var _b = _a, {
helpMessage,
helpId,
required,
label,
labelHidden,
inputClass,
labelClass,
name: id,
size,
disabled,
readOnly,
grid,
labelAttrs,
groupAttrs,
prepend,
append,
children,
isHelpVideoType,
tag = RsInput2
} = _b, attributes = __objRest(_b, [
"helpMessage",
"helpId",
"required",
"label",
"labelHidden",
"inputClass",
"labelClass",
"name",
"size",
"disabled",
"readOnly",
"grid",
"labelAttrs",
"groupAttrs",
"prepend",
"append",
"children",
"isHelpVideoType",
"tag"
]);
let row = false;
const inputId = attributes.id || uuid3();
const col = {};
const labelCol = {};
if (grid) {
for (const colSize of colSizes) {
if (grid[colSize]) {
row = true;
const sizeNum = Number.parseInt(grid[colSize], 10);
col[colSize] = sizeNum;
labelCol[colSize] = 12 - sizeNum;
}
}
}
let input = /* @__PURE__ */ jsx7(
Input_default,
__spreadValues({
name: id,
id: inputId,
className: inputClass,
size,
required,
disabled,
readOnly,
feedback: true,
help: !!helpMessage,
tag
}, attributes)
);
if (prepend || append) {
input = /* @__PURE__ */ jsxs3(InputGroup, { children: [
prepend && /* @__PURE__ */ jsx7(InputGroupAddon, { addonType: "prepend", children: typeof prepend === "string" ? /* @__PURE__ */ jsx7(InputGroupText, { children: prepend }) : prepend }),
input,
append && /* @__PURE__ */ jsx7(InputGroupAddon, { addonType: "append", children: typeof append === "string" ? /* @__PURE__ */ jsx7(InputGroupText, { children: append }) : append }),
/* @__PURE__ */ jsx7(Feedback_default, { name: id })
] });
}
const help = helpMessage ? /* @__PURE__ */ jsx7(FormText, { id: `${id}-helpmessage`.toLowerCase(), children: helpMessage }) : null;
const feedback = /* @__PURE__ */ jsx7(Feedback_default, { name: id });
let inputRow = row ? /* @__PURE__ */ jsxs3(Col, __spreadProps(__spreadValues({}, col), { children: [
input,
!prepend && !append && /* @__PURE__ */ jsx7(Feedback_default, { name: id }),
help
] })) : input;
if (children && typeof children === "function") {
inputRow = children({ input: inputRow, feedback });
}
const check = attributes.type === "checkbox";
return /* @__PURE__ */ jsxs3(FormGroup_default, __spreadProps(__spreadValues({ for: id, check, disabled, row }, groupAttrs), { children: [
check && inputRow,
label && /* @__PURE__ */ jsx7(
Label_default,
__spreadProps(__spreadValues(__spreadValues({
id: `${inputId}-label`,
for: inputId,
className: labelClass,
hidden: labelHidden,
size,
required: !!required,
helpId,
disabled,
isHelpVideoType
}, labelCol), labelAttrs), {
children: label
})
),
!check && inputRow,
!row && !prepend && !append && feedback,
!row && help
] }));
};
Field.propTypes = {
/** Identifies the field and matches the validation schema. */
name: PropTypes7.string.isRequired,
/** Append an InputAddon to the end of the Input. */
append: PropTypes7.node,
/** Optionally override the way the input is rendered with child render prop. */
children: PropTypes7.func,
/** Disable the <Field />. */
disabled: PropTypes7.bool,
/* Object mapping number of columns to the label and input. */
grid: PropTypes7.object,
/** Pass additional attributes to Form Group */
groupAttrs: PropTypes7.object,
/** Help topic id, adds <FieldHelpIcon/> next to the label (should not be within label for accessibility). */
helpId: PropTypes7.string,
/** Display info text below the field */
helpMessage: PropTypes7.node,
/** Class names passed to the input tag. */
inputClass: PropTypes7.string,
/** Contents of the field label. Renders within a Reactstrap <Label />. */
label: PropTypes7.node,
/** Pass additional attributes to the label */
labelAttrs: PropTypes7.object,
/** Class names passed to the label tag. */
labelClass: PropTypes7.string,
/** Used to hide the label. */
labelHidden: PropTypes7.bool,
/** Append an InputAddon to the start of the Input. */
prepend: PropTypes7.node,
/** Mark the field as read only. */
readOnly: PropTypes7.bool,
/** Will add aria-required to input, will add <RequiredAsterisk /> to label. */
required: PropTypes7.bool,
/** Size of the input field. Potential values: "lg", "sm" */
size: PropTypes7.string,
/** The Node or tag to substitute as the input field. Default is reactstrap Input tag. */
tag: PropTypes7.oneOfType([PropTypes7.func, PropTypes7.string]),
/** Allows the type of `<FieldHelpIcon/>` to be changed between help-icon and video-help */
isHelpVideoType: PropTypes7.bool
};
var Field_default = Field;
// src/CheckboxGroup.js
import React8, { createContext, useContext } from "react";
import PropTypes8 from "prop-types";
import classNames3 from "classnames";
import { useField as useField3, useFormikContext as useFormikContext2 } from "formik";
import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
var CheckboxGroupContext = createContext();
var useCheckboxGroup = (name) => {
const { setFieldValue } = useFormikContext2();
const _a = useContext(CheckboxGroupContext), { name: groupName, groupOnChange, value = [] } = _a, rest = __objRest(_a, ["name", "groupOnChange", "value"]);
const toggle = () => {
const valueArray = [...value];
const indexOfVal = valueArray.indexOf(name);
if (indexOfVal === -1) {
valueArray.push(name);
} else {
valueArray.splice(indexOfVal, 1);
}
setFieldValue(groupName, valueArray);
if (groupOnChange) {
groupOnChange(valueArray);
}
};
return __spreadValues({ toggle, value: value.indexOf(name) > -1 }, rest);
};
var CheckboxGroup = (_a) => {
var _b = _a, {
name,
children,
onChange: groupOnChange,
groupClassName,
label,
labelClassName,
required,
helpId,
isHelpVideoType
} = _b, rest = __objRest(_b, [
"name",
"children",
"onChange",
"groupClassName",
"label",
"labelClassName",
"required",
"helpId",
"isHelpVideoType"
]);
const [field, metadata] = useField3(name);
const classes = classNames3(
groupClassName,
"form-control border-0 p-0 h-auto",
metadata.touched ? "is-touched" : "is-untouched",
metadata.touched && metadata.error && "is-invalid"
);
let tag = "div";
let legend = null;
if (label) {
tag = "fieldset";
const legendId = `${name}-legend`.toLowerCase();
const srRequiredAsterisk = required ? "* " : null;
const styles = { cursor: "default", lineHeight: "inherit", color: "#000" };
const labelClasses = classNames3("form-inline", labelClassName, !labelClassName && "h4 font-weight-normal");
legend = /* @__PURE__ */ jsxs4(Fragment2, { children: [
/* @__PURE__ */ jsxs4("legend", { id: legendId, className: "sr-only", children: [
srRequiredAsterisk,
label
] }),
/* @__PURE__ */ jsx8("div", { className: labelClasses, style: styles, children: /* @__PURE__ */ jsx8(Label_default, { tag: "div", "aria-hidden": true, helpId, required, isHelpVideoType, children: label }) })
] });
}
return (
// eslint-disable-next-line react/jsx-no-constructed-context-values
/* @__PURE__ */ jsx8(CheckboxGroupContext.Provider, { value: __spreadProps(__spreadValues({}, field), { groupOnChange, metadata }), children: /* @__PURE__ */ jsxs4(FormGroup_default, __spreadProps(__spreadValues({ tag, for: name }, rest), { children: [
legend,
/* @__PURE__ */ jsx8("div", { className: classes, "data-testid": `check-items-${name}`, children }),
/* @__PURE__ */ jsx8(Feedback_default, { name })
] })) })
);
};
CheckboxGroup.propTypes = {
/** Name of the checkbox group. Should match name given in initialValues/validationSchema. */
name: PropTypes8.string.isRequired,
children: PropTypes8.node,
/** Class name to apply to the form control. */
groupClassName: PropTypes8.string,
/** Help topic id, adds <FieldHelpIcon/> next to the label (should not be within label for accessibility). */
helpId: PropTypes8.string,
/** Label for the group or checkboxes. */
label: PropTypes8.node,
onChange: PropTypes8.func,
/** Class name to apply to the Label. Default is Legend styling */
labelClassName: PropTypes8.string,
/** Will add <RequiredAsterisk /> to label. */
required: PropTypes8.bool,
/** Allows the type of `<FieldHelpIcon/>` to be changed between help-icon and video-help */
isHelpVideoType: PropTypes8.bool
};
var CheckboxGroup_default = CheckboxGroup;
// src/Checkbox.js
import React9, { useState as useState2 } from "react";
import PropTypes9 from "prop-types";
import { Input as Input2 } from "reactstrap";
import { v4 as uuid4 } from "uuid";
import classNames4 from "classnames";
import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
var Checkbox = (_a) => {
var _b = _a, {
className,
groupClassName,
groupName,
helpId,
id,
inline = true,
label,
value: checkValue,
isHelpVideoType
} = _b, attributes = __objRest(_b, [
"className",
"groupClassName",
"groupName",
"helpId",
"id",
"inline",
"label",
"value",
"isHelpVideoType"
]);
const { value, toggle, metadata } = useCheckboxGroup(checkValue);
const [inputId] = useState2(id || uuid4());
const classes = classNames4(
className,
metadata.touched ? "is-touched" : "is-untouched",
metadata.touched && metadata.error && "is-invalid"
);
const errorIndicated = !!metadata.touched && !!metadata.error;
const groupFeedbackId = errorIndicated && groupName ? `${groupName}-feedback`.toLowerCase() : "";
const labelId = `${inputId}-label`.toLowerCase();
return /* @__PURE__ */ jsxs5(FormGroup_default, { for: inputId, className: groupClassName, check: true, inline, disabled: attributes.disabled, children: [
/* @__PURE__ */ jsx9(
Input2,
__spreadProps(__spreadValues({
id: inputId,
name: inputId,
className: classes,
type: "checkbox",
invalid: errorIndicated,
"aria-describedby": groupFeedbackId
}, attributes), {
value: checkValue,
checked: value,
onChange: toggle
})
),
/* @__PURE__ */ jsx9(Label_default, { check: true, id: labelId, for: inputId, helpId, isHelpVideoType, children: label })
] });
};
Checkbox.propTypes = {
className: PropTypes9.string,
/** Disables the checkbox. */
disabled: PropTypes9.bool,
groupClassName: PropTypes9.string,
/** Should match <CheckboxGroup /> name to accessibly link input to form feedback. */
groupName: PropTypes9.string,
/** Help topic id, adds <FieldHelpIcon/> next to the label (should not be within label for accessibility). */
helpId: PropTypes9.string,
/** Id and name for the checkbox. */
id: PropTypes9.string,
/** Will render the checkbox inline with other checkboxes. Default: true. */
inline: PropTypes9.bool,
/** Label for the checkbox. */
label: PropTypes9.node,
/** Value of the checkbox. */
value: PropTypes9.oneOfType([PropTypes9.string, PropTypes9.bool, PropTypes9.object]),
/** Allows the type of `<FieldHelpIcon/>` to be changed between help-icon and video-help */
isHelpVideoType: PropTypes9.bool
};
var Checkbox_default = Checkbox;
// src/RadioGroup.js
import React10, { createContext as createContext2, useContext as useContext2 } from "react";
import PropTypes10 from "prop-types";
import classNames5 from "classnames";
import { useField as useField4, useFormikContext as useFormikContext3 } from "formik";
import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
var RadioGroupContext = createContext2();
var useRadioGroup = (radioValue) => {
const { setFieldValue } = useFormikContext3();
const _a = useContext2(RadioGroupContext), { name: groupName, value = "", groupOnChange } = _a, rest = __objRest(_a, ["name", "value", "groupOnChange"]);
const setValue = () => {
setFieldValue(groupName, radioValue);
if (groupOnChange) {
groupOnChange(radioValue);
}
};
return __spreadValues({ groupName, setValue, value: value === radioValue }, rest);
};
var RadioGroup = (_a) => {
var _b = _a, {
name,
children,
label,
onChange: groupOnChange,
groupClassName,
inline = false,
helpId,
labelClassName,
required,
isHelpVideoType
} = _b, rest = __objRest(_b, [
"name",
"children",
"label",
"onChange",
"groupClassName",
"inline",
"helpId",
"labelClassName",
"required",
"isHelpVideoType"
]);
const [field, metadata] = useField4(name);
const classes = classNames5(
groupClassName,
"form-control border-0 p-0 h-auto",
metadata.touched ? "is-touched" : "is-untouched",
metadata.touched && metadata.error && "is-invalid"
);
let tag = "div";
let legend = null;
if (label) {
tag = "fieldset";
const legendId = `${name}-legend`.toLowerCase();
const styles = { cursor: "default", lineHeight: "inherit", color: "#000" };
const labelClasses = classNames5("form-inline", labelClassName, !labelClassName && "h4 font-weight-normal");
legend = /* @__PURE__ */ jsxs6(Fragment3, { children: [
/* @__PURE__ */ jsxs6("legend", { id: legendId, className: "sr-only", children: [
required ? "* " : null,
label
] }),
/* @__PURE__ */ jsx10("div", { className: labelClasses, style: styles, children: /* @__PURE__ */ jsx10(Label_default, { tag: "div", "aria-hidden": true, helpId, required, isHelpVideoType, children: label }) })
] });
}
return (
// eslint-disable-next-line react/jsx-no-constructed-context-values
/* @__PURE__ */ jsx10(RadioGroupContext.Provider, { value: __spreadProps(__spreadValues({}, field), { groupOnChange, metadata, inline }), children: /* @__PURE__ */ jsxs6(FormGroup_default, __spreadProps(__spreadValues({ tag, for: name }, rest), { children: [
legend,
/* @__PURE__ */ jsx10("div", { className: classes, "data-testid": `radio-items-${name}`, children }),
/* @__PURE__ */ jsx10(Feedback_default, { name })
] })) })
);
};
RadioGroup.propTypes = {
children: PropTypes10.node,
groupClassName: PropTypes10.string,
helpId: PropTypes10.string,
inline: PropTypes10.bool,
label: PropTypes10.node,
name: PropTypes10.string,
onChange: PropTypes10.func,
labelClassName: PropTypes10.string,
required: PropTypes10.bool,
isHelpVideoType: PropTypes10.bool
};
var RadioGroup_default = RadioGroup;
// src/Radio.js
import React11, { useState as useState3 } from "react";
import PropTypes11 from "prop-types";
import { Input as Input3 } from "reactstrap";
import { v4 as uuid5 } from "uuid";
import classNames6 from "classnames";
import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
var Radio = (_a) => {
var _b = _a, {
label,
id,
name,
value: checkValue,
className,
groupClassName,
children,
helpId,
isHelpVideoType
} = _b, attributes = __objRest(_b, [
"label",
"id",
"name",
"value",
"className",
"groupClassName",
"children",
"helpId",
"isHelpVideoType"
]);
const { value, setValue, metadata, inline } = useRadioGroup(checkValue);
const [inputId] = useState3(id || uuid5());
const classes = classNames6(
className,
metadata.touched ? "is-touched" : "is-untouched",
metadata.touched && metadata.error && "is-invalid"
);
const errorIndicated = !!metadata.touched && !!metadata.error;
const feedbackId = errorIndicated && name ? `${name}-feedback`.toLowerCase() : "";
const labelId = `${inputId}-label`.toLowerCase();
return /* @__PURE__ */ jsxs7(FormGroup_default, { for: inputId, check: true, className: groupClassName, inline, disabled: attributes.disabled, children: [
/* @__PURE__ */ jsx11(
Input3,
__spreadProps(__spreadValues({
id: inputId,
name: name || inputId,
className: classes,
type: "radio",
invalid: errorIndicated,
"aria-describedby": feedbackId
}, attributes), {
value: checkValue,
checked: value,
onChange: setValue
})
),
/* @__PURE__ */ jsx11(Label_default, { check: true, id: labelId, for: inputId, helpId, isHelpVideoType, children: label || children })
] });
};
Radio.propTypes = {
children: PropTypes11.node,
className: PropTypes11.string,
/** Disables the radio button. */
disabled: PropTypes11.bool,
groupClassName: PropTypes11.string,
/** Help topic id, adds <FieldHelpIcon/> next to the label (should not be within label for accessibility). */
helpId: PropTypes11.string,
/** Id for the radio button. */
id: PropTypes11.string,
/** Label for the radio button. */
label: PropTypes11.node,
/** Should match <RadioGroup /> name for validation and accessibly linking button to form feedback. */
name: PropTypes11.string,
/** Value of the radio button. */
value: PropTypes11.oneOfType([PropTypes11.string, PropTypes11.bool, PropTypes11.object]),
/** Allows the type of `<FieldHelpIcon/>` to be changed between help-icon and video-help */
isHelpVideoType: PropTypes11.bool
};
var Radio_default = Radio;
// src/CurrencyInput.tsx
import ReactCurrencyInput from "react-currency-input-field";
import classnames from "classnames";
import { useField as useField5, useFormikContext as useFormikContext4 } from "formik";
import { Fragment as Fragment4, jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
var CurrencyInput = (_a) => {
var _b = _a, { name, onValueChanged, id, value, placeholder, disabled } = _b, attributes = __objRest(_b, ["name", "onValueChanged", "id", "value", "placeholder", "disabled"]);
const { setFieldValue, setFieldTouched } = useFormikContext4();
const [, metadata] = useField5({
name
});
const classes = classnames(
metadata.touched ? "is-touched" : "is-untouched",
metadata.error ? "av-invalid" : "av-valid",
metadata.touched && metadata.error && "is-invalid",
"form-control"
);
const formatDecimals = (value2) => __async(null, null, function* () {
setFieldTouched(name, true);
if (value2 === "") {
setFieldValue(name, void 0);
if (onValueChanged) {
onValueChanged(void 0);
}
return;
}
const noCommasValue = value2 == null ? void 0 : value2.replace(/,/g, "");
const number = Number(noCommasValue);
const options = {
minimumFractionDigits: 2,
maximumFractionDigits: 2
};
const decimalValue = number.toLocaleString(void 0, options).replace(/,/g, "");
setFieldValue(name, decimalValue);
if (onValueChanged) {
onValueChanged(decimalValue);
}
});
return /* @__PURE__ */ jsxs8(Fragment4, { children: [
/* @__PURE__ */ jsx12(
ReactCurrencyInput,
__spreadValues({
id,
name,
className: classes,
prefix: "$",
placeholder,
disabled,
decimalsLimit: 2,
value,
"aria-invalid": !!metadata.error,
onBlur: (event) => __async(null, null, function* () {
formatDecimals(event.target.value.replace("$", ""));
}),
onValueChange: onValueChanged,
allowNegativeValue: false,
transformRawValue: (rawValue) => {
if (rawValue && rawValue.startsWith(".")) {
return `0${rawValue}`;
}
return rawValue;
}
}, attributes)
),
/* @__PURE__ */ jsx12(Feedback_default, { name })
] });
};
var CurrencyInput_default = CurrencyInput;
export {
Checkbox_default as Checkbox,
CheckboxGroup_default as CheckboxGroup,
CurrencyInput_default as CurrencyInput,
Feedback_default as Feedback,
Field_default as Field,
FieldHelpIcon_default as FieldHelpIcon,
Form_default as Form,
FormGroup_default as FormGroup,
Input_default as Input,
Label_default as Label,
Radio_default as Radio,
RadioGroup_default as RadioGroup,
RequiredAsterisk,
RequiredKey,
triggerFieldHelp
};