{"version":3,"file":"Field.cjs","names":["_react","require","_FieldError","_FieldHint","_FieldLabel","_FieldsetContext","_i18n","_Typography","_useUniqueId","_jsxRuntime","_interopRequireDefault","e","__esModule","default","fieldTypeValues","exports","Field","ariaDescribedBy","errorMessage","errorMessageList","fieldType","hasVisibleLabel","hint","HintLinkComponent","id","idOverride","isDisabled","isDisabledProp","isFullWidth","isRadioGroup","isOptional","isReadOnly","label","renderFieldComponent","t","useTranslation","useUniqueId","hintId","undefined","errorMessageElementId","labelElementId","localAriaDescribedBy","useMemo","join","trim","isFieldsetDisabled","useFieldset","jsxs","_FormControl2","component","disabled","error","Boolean","Array","isArray","length","fullWidth","role","children","_FormLabel2","jsx","Subordinate","FieldLabel","inputId","text","FieldHint","LinkComponent","FieldError","message","messageList","MemoizedField","memo","displayName"],"sources":["../../src/Field.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {\n  FormControl as MuiFormControl,\n  FormLabel as MuiFormLabel,\n} from \"@mui/material\";\nimport { memo, ReactElement, useMemo } from \"react\";\n\nimport { FieldComponentProps } from \"./FieldComponentProps.js\";\nimport { FieldError } from \"./FieldError.js\";\nimport { FieldHint } from \"./FieldHint.js\";\nimport { FieldLabel } from \"./FieldLabel.js\";\nimport { useFieldset } from \"./FieldsetContext.js\";\nimport { HtmlProps } from \"./HtmlProps.js\";\nimport { useTranslation } from \"./i18n.generated/i18n.js\";\nimport { Subordinate } from \"./Typography.js\";\nimport { useUniqueId } from \"./useUniqueId.js\";\n\nexport const fieldTypeValues = [\"single\", \"group\"] as const;\n\nexport type RenderFieldComponentProps = {\n  ariaDescribedBy?: string;\n  dataSe?: string;\n  errorMessageElementId?: string;\n  id: string;\n  isReadOnly?: boolean;\n  labelElementId: string;\n};\n\nexport type FieldProps = {\n  /**\n   * If `error` is not undefined, the `input` will indicate an error.\n   */\n  errorMessageList?: string[];\n  /**\n   * Controls how ARIA attributes are applied to the field container.\n   * - If `'single'`, use when the field wraps a single control such as a text input.\n   * - If `'group'`, use when the field wraps multiple controls such as a radio or checkbox group.\n   */\n  fieldType: (typeof fieldTypeValues)[number];\n  /**\n   * If `true`, the field label is visible. If `false`, the label is visually hidden but remains accessible to screen readers.\n   */\n  hasVisibleLabel: boolean;\n  /**\n   * If `true`, child inputs inherit the group error state. Required for CheckboxGroup to propagate validity.\n   */\n  isCheckboxGroup?: boolean;\n  /**\n   * If `true`, narrows the fieldset ARIA role to `\"radiogroup\"`.\n   */\n  isRadioGroup?: boolean;\n  /**\n   * The label for the `input` element.\n   */\n  label: string;\n  /**\n   * The short hint displayed in the `input` before the user enters a value.\n   */\n  placeholder?: string;\n  /**\n   * Render-props function that sends back ARIA props to your field component.\n   */\n  renderFieldComponent: ({\n    ariaDescribedBy,\n    dataSe,\n    errorMessageElementId,\n    id,\n    labelElementId,\n    isReadOnly,\n  }: RenderFieldComponentProps) => ReactElement;\n};\n\nconst Field = ({\n  ariaDescribedBy,\n  errorMessage,\n  errorMessageList,\n  fieldType,\n  hasVisibleLabel,\n  hint,\n  HintLinkComponent,\n  id: idOverride,\n  isDisabled: isDisabledProp = false,\n  isFullWidth = false,\n  isRadioGroup = false,\n  isOptional = false,\n  isReadOnly = false,\n  label,\n  renderFieldComponent,\n}: FieldProps &\n  Pick<\n    FieldComponentProps,\n    | \"errorMessage\"\n    | \"errorMessageList\"\n    | \"hint\"\n    | \"HintLinkComponent\"\n    | \"id\"\n    | \"isDisabled\"\n    | \"isFullWidth\"\n    | \"isOptional\"\n    | \"isReadOnly\"\n  > &\n  Pick<HtmlProps, \"ariaDescribedBy\">) => {\n  const { t } = useTranslation();\n\n  const id = useUniqueId(idOverride);\n  const hintId = hint ? `${id}-hint` : undefined;\n  const errorMessageElementId =\n    errorMessage || errorMessageList ? `${id}-error` : undefined;\n  const labelElementId = `${id}-label`;\n\n  const localAriaDescribedBy = useMemo(\n    () =>\n      [hintId, errorMessageElementId, ariaDescribedBy].join(\" \").trim() ||\n      undefined,\n    [ariaDescribedBy, errorMessageElementId, hintId],\n  );\n\n  const { isDisabled: isFieldsetDisabled } = useFieldset();\n\n  const isDisabled = useMemo(\n    () => isDisabledProp || isFieldsetDisabled,\n    [isDisabledProp, isFieldsetDisabled],\n  );\n\n  return (\n    <MuiFormControl\n      component={fieldType === \"group\" ? \"fieldset\" : \"div\"}\n      disabled={isDisabled}\n      error={\n        Boolean(errorMessage) ||\n        (Array.isArray(errorMessageList) && errorMessageList.length > 0)\n      }\n      fullWidth={isFullWidth}\n      role={isRadioGroup ? \"radiogroup\" : undefined}\n    >\n      {fieldType === \"group\" ? (\n        <MuiFormLabel component=\"legend\" id={labelElementId}>\n          {label}{\" \"}\n          {isOptional && label && (\n            <Subordinate>{t(\"fieldlabel.optional.text\")}</Subordinate>\n          )}\n        </MuiFormLabel>\n      ) : (\n        <FieldLabel\n          hasVisibleLabel={hasVisibleLabel}\n          id={labelElementId}\n          inputId={id}\n          isOptional={isOptional}\n          text={label}\n        />\n      )}\n\n      {hint && (\n        <FieldHint id={hintId} LinkComponent={HintLinkComponent} text={hint} />\n      )}\n\n      {renderFieldComponent({\n        ariaDescribedBy: localAriaDescribedBy,\n        errorMessageElementId,\n        id,\n        labelElementId,\n        isReadOnly,\n      })}\n\n      {(errorMessage || errorMessageList) && (\n        <FieldError\n          id={errorMessageElementId}\n          message={errorMessage}\n          messageList={errorMessageList}\n        />\n      )}\n    </MuiFormControl>\n  );\n};\n\nconst MemoizedField = memo(Field);\nMemoizedField.displayName = \"Field\";\n\nexport { MemoizedField as Field };\n"],"mappings":";;;;;;;;AAgBA,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