{"version":3,"sources":["../../../src/components/InfoLabel/useInfoLabel.ts"],"sourcesContent":["import type * as React from 'react';\nimport { useId, slot } from '@fluentui/react-utilities';\n\nimport { Label } from '../Label';\nimport { InfoButton } from './InfoButton/InfoButton';\nimport type { InfoLabelProps, InfoLabelState } from './InfoLabel.types';\n\n/**\n * Create the state required to render InfoLabel.\n *\n * The returned state can be modified with hooks such as useInfoLabel,\n * before being passed to renderInfoLabel.\n *\n * @param props - props from this instance of InfoLabel\n * @param ref - reference to label element of InfoLabel\n */\nexport const useInfoLabel = (props: InfoLabelProps, ref: React.Ref<HTMLLabelElement>): InfoLabelState => {\n  const {\n    root: rootShorthand,\n    label: labelShorthand,\n    infoButton: infoButtonShorthand,\n    info,\n    className,\n    style,\n    ...labelProps\n  } = props;\n  const baseId = useId('infolabel-');\n\n  const root = slot.always(rootShorthand, {\n    defaultProps: {\n      className,\n      style,\n    },\n    elementType: 'span',\n  });\n\n  const label = slot.always(labelShorthand, {\n    defaultProps: {\n      id: baseId + '__label',\n      ref,\n      ...labelProps,\n    },\n    elementType: Label,\n  });\n\n  const infoButton = slot.optional(infoButtonShorthand, {\n    renderByDefault: !!info,\n    defaultProps: {\n      id: baseId + '__infoButton',\n      info,\n    },\n    elementType: InfoButton,\n  });\n\n  const infoButtonPopover = slot.always(infoButton?.popover, {\n    elementType: 'div',\n  });\n\n  if (infoButton) {\n    const infoPopupId = baseId + '__info'; // used as a self-referencing aria-labelledby to name the popup\n    infoButtonPopover.id ??= infoPopupId;\n    infoButton.popover = infoButtonPopover;\n    infoButton.info = slot.optional(infoButton?.info, {\n      defaultProps: {\n        'aria-labelledby': infoButtonPopover.id,\n      },\n      elementType: 'dialog',\n    });\n\n    infoButton['aria-labelledby'] ??= `${label.id} ${infoButton.id}`;\n  }\n\n  return {\n    components: {\n      root: 'span',\n      label: Label,\n      infoButton: InfoButton,\n    },\n    root,\n    label,\n    infoButton,\n  };\n};\n"],"names":["useInfoLabel","props","ref","root","rootShorthand","label","labelShorthand","infoButton","infoButtonShorthand","info","className","style","labelProps","baseId","useId","slot","always","defaultProps","elementType","id","Label","optional","renderByDefault","InfoButton","infoButtonPopover","popover","infoPopupId","components"],"mappings":";;;;+BAgBaA;;;eAAAA;;;gCAfe;uBAEN;4BACK;AAYpB,MAAMA,eAAe,CAACC,OAAuBC;IAClD,MAAM,EACJC,MAAMC,aAAa,EACnBC,OAAOC,cAAc,EACrBC,YAAYC,mBAAmB,EAC/BC,IAAI,EACJC,SAAS,EACTC,KAAK,EACL,GAAGC,YACJ,GAAGX;IACJ,MAAMY,SAASC,IAAAA,qBAAK,EAAC;IAErB,MAAMX,OAAOY,oBAAI,CAACC,MAAM,CAACZ,eAAe;QACtCa,cAAc;YACZP;YACAC;QACF;QACAO,aAAa;IACf;IAEA,MAAMb,QAAQU,oBAAI,CAACC,MAAM,CAACV,gBAAgB;QACxCW,cAAc;YACZE,IAAIN,SAAS;YACbX;YACA,GAAGU,UAAU;QACf;QACAM,aAAaE,YAAK;IACpB;IAEA,MAAMb,aAAaQ,oBAAI,CAACM,QAAQ,CAACb,qBAAqB;QACpDc,iBAAiB,CAAC,CAACb;QACnBQ,cAAc;YACZE,IAAIN,SAAS;YACbJ;QACF;QACAS,aAAaK,sBAAU;IACzB;IAEA,MAAMC,oBAAoBT,oBAAI,CAACC,MAAM,CAACT,YAAYkB,SAAS;QACzDP,aAAa;IACf;IAEA,IAAIX,YAAY;QACd,MAAMmB,cAAcb,SAAS,UAAU,+DAA+D;QACtGW,kBAAkBL,EAAE,KAAKO;QACzBnB,WAAWkB,OAAO,GAAGD;QACrBjB,WAAWE,IAAI,GAAGM,oBAAI,CAACM,QAAQ,CAACd,YAAYE,MAAM;YAChDQ,cAAc;gBACZ,mBAAmBO,kBAAkBL,EAAE;YACzC;YACAD,aAAa;QACf;QAEAX,UAAU,CAAC,kBAAkB,KAAK,GAAGF,MAAMc,EAAE,CAAC,CAAC,EAAEZ,WAAWY,EAAE,EAAE;IAClE;IAEA,OAAO;QACLQ,YAAY;YACVxB,MAAM;YACNE,OAAOe,YAAK;YACZb,YAAYgB,sBAAU;QACxB;QACApB;QACAE;QACAE;IACF;AACF"}