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A,oCAAS,EAAE,CAAA,GAAA,mDAAU,GAAG;OACrC;IAMT,qBACE,0DAAC;QACE,GAAG,UAAU;QACb,GAAG,YAAY;QAChB,KAAK;QACL,WAAW;OACV,wBACA;AAGP","sources":["packages/@adobe/react-spectrum/src/label/Field.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {classNames} from '../utils/classNames';\n\nimport {Flex} from '../layout/Flex';\nimport {HelpText} from './HelpText';\nimport {Label, SpectrumLabelPropsBase} from './Label';\nimport {\n  LabelPosition,\n  RefObject,\n  SpectrumFieldValidation,\n  SpectrumHelpTextProps,\n  Validation,\n  ValidationResult\n} from '@react-types/shared';\nimport labelStyles from '@adobe/spectrum-css-temp/components/fieldlabel/vars.css';\nimport {mergeProps} from 'react-aria/mergeProps';\nimport React, {HTMLAttributes, LabelHTMLAttributes, ReactElement, ReactNode, Ref} from 'react';\nimport {SlotProvider} from '../utils/Slots';\nimport {useFormProps} from '../form/Form';\nimport {useId} from 'react-aria/useId';\nimport {useStyleProps} from '../utils/styleProps';\n\nexport interface SpectrumFieldProps\n  extends\n    SpectrumLabelPropsBase,\n    SpectrumHelpTextProps,\n    Omit<Validation<any>, 'validationState'>,\n    SpectrumFieldValidation<any>,\n    Partial<ValidationResult> {\n  children: ReactElement;\n  label?: ReactNode;\n  contextualHelp?: ReactNode;\n  labelProps?: LabelHTMLAttributes<HTMLLabelElement>;\n  descriptionProps?: HTMLAttributes<HTMLElement>;\n  errorMessageProps?: HTMLAttributes<HTMLElement>;\n  wrapperClassName?: string;\n  wrapperProps?: HTMLAttributes<HTMLElement>;\n}\n\nexport const Field = React.forwardRef(function Field(\n  props: SpectrumFieldProps,\n  ref: Ref<HTMLElement>\n) {\n  let formProps = useFormProps(props);\n  let isInForm = formProps !== props;\n  props = formProps;\n  let {\n    label,\n    labelPosition = 'top' as LabelPosition,\n    labelAlign,\n    isRequired,\n    necessityIndicator,\n    includeNecessityIndicatorInAccessibilityName,\n    validationState,\n    isInvalid,\n    description,\n    errorMessage = e => e.validationErrors.join(' '),\n    validationErrors,\n    validationDetails,\n    isDisabled,\n    showErrorIcon,\n    contextualHelp,\n    children,\n    labelProps = {},\n    // Not every component that uses <Field> supports help text.\n    descriptionProps = {},\n    errorMessageProps = {},\n    elementType,\n    wrapperClassName,\n    wrapperProps = {},\n    ...otherProps\n  } = props;\n  let {styleProps} = useStyleProps(otherProps);\n  let errorMessageString: ReactNode = null;\n  if (typeof errorMessage === 'function') {\n    errorMessageString =\n      isInvalid != null && validationErrors != null && validationDetails != null\n        ? errorMessage({\n            isInvalid,\n            validationErrors,\n            validationDetails\n          })\n        : null;\n  } else {\n    errorMessageString = errorMessage;\n  }\n  let hasHelpText =\n    !!description || (errorMessageString && (isInvalid || validationState === 'invalid'));\n  let contextualHelpId = useId();\n\n  let fallbackLabelPropsId = useId();\n  if (label && contextualHelp && !labelProps.id) {\n    labelProps.id = fallbackLabelPropsId;\n  }\n\n  let labelWrapperClass = classNames(\n    labelStyles,\n    'spectrum-Field',\n    {\n      'spectrum-Field--positionTop': labelPosition === 'top',\n      'spectrum-Field--positionSide': labelPosition === 'side',\n      'spectrum-Field--alignEnd': labelAlign === 'end',\n      'spectrum-Field--hasContextualHelp': !!props.contextualHelp\n    },\n    styleProps.className,\n    wrapperClassName\n  );\n\n  children = React.cloneElement(\n    children,\n    mergeProps(children.props as any, {\n      className: classNames(labelStyles, 'spectrum-Field-field')\n    })\n  );\n\n  let renderHelpText = () => (\n    <HelpText\n      descriptionProps={descriptionProps}\n      errorMessageProps={errorMessageProps}\n      description={description}\n      errorMessage={errorMessageString}\n      validationState={validationState}\n      isInvalid={isInvalid}\n      isDisabled={isDisabled}\n      showErrorIcon={showErrorIcon}\n      gridArea={labelStyles.helpText}\n    />\n  );\n\n  let renderChildren = () => {\n    if (labelPosition === 'side') {\n      return (\n        <Flex\n          direction=\"column\"\n          UNSAFE_className={classNames(labelStyles, 'spectrum-Field-wrapper')}>\n          {children}\n          {hasHelpText && renderHelpText()}\n        </Flex>\n      );\n    }\n\n    return (\n      <>\n        {children}\n        {hasHelpText && renderHelpText()}\n      </>\n    );\n  };\n\n  let labelAndContextualHelp = (\n    <>\n      {label && (\n        <Label\n          {...labelProps}\n          labelPosition={labelPosition}\n          labelAlign={labelAlign}\n          isRequired={isRequired}\n          necessityIndicator={necessityIndicator}\n          includeNecessityIndicatorInAccessibilityName={\n            includeNecessityIndicatorInAccessibilityName\n          }\n          elementType={elementType}>\n          {label}\n        </Label>\n      )}\n      {label && contextualHelp && (\n        <SlotProvider\n          slots={{\n            actionButton: {\n              UNSAFE_className: classNames(labelStyles, 'spectrum-Field-contextualHelp'),\n              id: contextualHelpId,\n              'aria-labelledby': labelProps?.id ? `${labelProps.id} ${contextualHelpId}` : undefined\n            }\n          }}>\n          {contextualHelp}\n        </SlotProvider>\n      )}\n    </>\n  );\n\n  // Need to add an extra wrapper for the label and contextual help if labelPosition is side,\n  // so that the table layout works inside forms.\n  if (isInForm && labelPosition === 'side' && label && contextualHelp) {\n    labelAndContextualHelp = (\n      <div className={classNames(labelStyles, 'spectrum-Field-labelCell')}>\n        <div className={classNames(labelStyles, 'spectrum-Field-labelWrapper')}>\n          {labelAndContextualHelp}\n        </div>\n      </div>\n    );\n  }\n\n  return (\n    <div\n      {...styleProps}\n      {...wrapperProps}\n      ref={ref as RefObject<HTMLDivElement | null>}\n      className={labelWrapperClass}>\n      {labelAndContextualHelp}\n      {renderChildren()}\n    </div>\n  );\n});\n"],"names":[],"version":3,"file":"Field.cjs.map"}