{"ast":null,"code":"import { useId, useLabels } from \"@react-aria/utils\";\nexport function useLabel(props) {\n  var id = props.id,\n      label = props.label,\n      ariaLabelledby = props['aria-labelledby'],\n      ariaLabel = props['aria-label'],\n      _props$labelElementTy = props.labelElementType,\n      labelElementType = _props$labelElementTy === void 0 ? 'label' : _props$labelElementTy;\n  id = useId(id);\n  var labelId = useId();\n  var labelProps = {};\n\n  if (label) {\n    ariaLabelledby = ariaLabelledby ? ariaLabelledby + \" \" + labelId : labelId;\n    labelProps = {\n      id: labelId,\n      htmlFor: labelElementType === 'label' ? id : undefined\n    };\n  } else if (!ariaLabelledby && !ariaLabel) {\n    console.warn('If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility');\n  }\n\n  var fieldProps = useLabels({\n    id: id,\n    'aria-label': ariaLabel,\n    'aria-labelledby': ariaLabelledby\n  });\n  return {\n    labelProps: labelProps,\n    fieldProps: fieldProps\n  };\n}","map":{"version":3,"sources":["packages/@react-aria/label/src/useLabel.ts"],"names":["labelElementType","id","useId","labelId","labelProps","ariaLabelledby","htmlFor","undefined","console","fieldProps","useLabels"],"mappings":";OAoCO,SAAA,QAAA,CAAA,KAAA,EAAoD;AAAA,MACrD,EADqD,GACzD,KADyD,CACrD,EADqD;AAAA,MACrD,KADqD,GACzD,KADyD,CACrD,KADqD;AAAA,MACrD,cADqD,GACzD,KADyD,CAIvD,iBAJuD;AAAA,MACrD,SADqD,GACzD,KADyD,CAKvD,YALuD;AAAA,8BACzD,KADyD,CAMvDA,gBANuD;AAAA,MAMvDA,gBANuD,sCAMpC,OANoC;AASzDC,EAAAA,EAAE,GAAGC,KAAK,CAAVD,EAAU,CAAVA;AACA,MAAIE,OAAO,GAAGD,KAAd,EAAA;AACA,MAAIE,UAAU,GAAd,EAAA;;AACA,MAAA,KAAA,EAAW;AACTC,IAAAA,cAAc,GAAGA,cAAc,GAAMA,cAAN,GAAA,GAAMA,GAAN,OAAA,GAA/BA,OAAAA;AACAD,IAAAA,UAAU,GAAG;AACXH,MAAAA,EAAE,EADS,OAAA;AAEXK,MAAAA,OAAO,EAAEN,gBAAgB,KAAhBA,OAAAA,GAAAA,EAAAA,GAAoCO;AAFlC,KAAbH;AAFF,GAAA,MAMO,IAAI,CAAA,cAAA,IAAmB,CAAvB,SAAA,EAAmC;AACxCI,IAAAA,OAAO,CAAPA,IAAAA,CAAAA,sHAAAA;AACD;;AAED,MAAIC,UAAU,GAAGC,SAAS,CAAC;AACzBT,IAAAA,EADyB,EACzBA,EADyB;AAEzB,kBAFyB,SAAA;AAGzB,uBAAmBI;AAHM,GAAD,CAA1B;AAMA,SAAO;AACLD,IAAAA,UADK,EACLA,UADK;AAELK,IAAAA,UAAAA,EAAAA;AAFK,GAAP;AAID","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 {AriaLabelingProps, DOMProps, LabelableProps} from '@react-types/shared';\nimport {ElementType, HTMLAttributes, LabelHTMLAttributes} from 'react';\nimport {useId, useLabels} from '@react-aria/utils';\n\ninterface LabelAriaProps extends LabelableProps, DOMProps, AriaLabelingProps {\n  /**\n   * The HTML element used to render the label, e.g. 'label', or 'span'.\n   * @default 'label'\n   */\n  labelElementType?: ElementType\n}\n\ninterface LabelAria {\n  /** Props to apply to the label container element. */\n  labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n  /** Props to apply to the field container element being labeled. */\n  fieldProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the accessibility implementation for labels and their associated elements.\n * Labels provide context for user inputs.\n * @param props - The props for labels and fields.\n */\nexport function useLabel(props: LabelAriaProps): LabelAria {\n  let {\n    id,\n    label,\n    'aria-labelledby': ariaLabelledby,\n    'aria-label': ariaLabel,\n    labelElementType = 'label'\n  } = props;\n\n  id = useId(id);\n  let labelId = useId();\n  let labelProps = {};\n  if (label) {\n    ariaLabelledby = ariaLabelledby ? `${ariaLabelledby} ${labelId}` : labelId;\n    labelProps = {\n      id: labelId,\n      htmlFor: labelElementType === 'label' ? id : undefined\n    };\n  } else if (!ariaLabelledby && !ariaLabel) {\n    console.warn('If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility');\n  }\n\n  let fieldProps = useLabels({\n    id,\n    'aria-label': ariaLabel,\n    'aria-labelledby': ariaLabelledby\n  });\n\n  return {\n    labelProps,\n    fieldProps\n  };\n}\n"]},"metadata":{},"sourceType":"module"}