{"version":3,"sources":["../src/components/InfoButton/useInfoButton.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated */\n\n'use client';\n\nimport * as React from 'react';\nimport { DefaultInfoButtonIcon12, DefaultInfoButtonIcon16, DefaultInfoButtonIcon20 } from './DefaultInfoButtonIcons';\nimport {\n  getIntrinsicElementProps,\n  mergeCallbacks,\n  useControllableState,\n  slot,\n  useMergedRefs,\n  isHTMLElement,\n  elementContains,\n} from '@fluentui/react-utilities';\nimport { Popover, PopoverSurface } from '@fluentui/react-popover';\nimport type { InfoButtonProps, InfoButtonState } from './InfoButton.types';\nimport type { PopoverProps } from '@fluentui/react-popover';\n\nconst infoButtonIconMap = {\n  small: <DefaultInfoButtonIcon12 />,\n  medium: <DefaultInfoButtonIcon16 />,\n  large: <DefaultInfoButtonIcon20 />,\n} as const;\n\nconst popoverSizeMap = {\n  small: 'small',\n  medium: 'small',\n  large: 'medium',\n} as const;\n\n/**\n * Create the state required to render InfoButton.\n *\n * The returned state can be modified with hooks such as useInfoButtonStyles_unstable,\n * before being passed to renderInfoButton_unstable.\n *\n * @param props - props from this instance of InfoButton\n * @param ref - reference to root HTMLElement of InfoButton\n *\n * @deprecated use {@link @fluentui/react-components#InfoLabel} from `\\@fluentui/react-components` or `\\@fluentui/react-infolabel` instead\n */\nexport const useInfoButton_unstable = (props: InfoButtonProps, ref: React.Ref<HTMLElement>): InfoButtonState => {\n  const { size = 'medium', inline = true, popover, info, ...rest } = props;\n\n  const state: InfoButtonState = {\n    inline,\n    size,\n\n    components: {\n      root: 'button',\n      popover: Popover as React.FC<Partial<PopoverProps>>,\n      info: PopoverSurface,\n    },\n\n    root: slot.always(\n      getIntrinsicElementProps('button', {\n        children: infoButtonIconMap[size],\n        type: 'button',\n        'aria-label': 'information',\n        ...rest,\n        // FIXME:\n        // `ref` is wrongly assigned to be `HTMLElement` instead of `HTMLButtonElement`\n        // but since it would be a breaking change to fix it, we are casting ref to it's proper type\n        ref: ref as React.Ref<HTMLButtonElement>,\n      }),\n      { elementType: 'button' },\n    ),\n    popover: slot.always(popover, {\n      defaultProps: {\n        inline,\n        positioning: 'above-start',\n        size: popoverSizeMap[size],\n        withArrow: true,\n      },\n      elementType: Popover as React.FC<Partial<Omit<PopoverProps, 'openOnHover'>>>,\n    }),\n    info: slot.always(info, {\n      defaultProps: {\n        role: 'note',\n        tabIndex: -1,\n      },\n      elementType: PopoverSurface,\n    }),\n  };\n\n  const [popoverOpen, setPopoverOpen] = useControllableState({\n    state: state.popover.open,\n    defaultState: state.popover.defaultOpen,\n    initialState: false,\n  });\n\n  state.popover.open = popoverOpen;\n  state.popover.onOpenChange = mergeCallbacks(state.popover.onOpenChange, (e, data) => setPopoverOpen(data.open));\n\n  const focusOutRef = React.useCallback(\n    (el: HTMLDivElement) => {\n      if (!el) {\n        return;\n      }\n\n      el.addEventListener('focusout', e => {\n        const nextFocused = e.relatedTarget;\n\n        if (isHTMLElement(nextFocused) && !elementContains(el, nextFocused)) {\n          setPopoverOpen(false);\n        }\n      });\n    },\n    [setPopoverOpen],\n  );\n\n  state.info.ref = useMergedRefs(state.info.ref, focusOutRef);\n\n  return state;\n};\n"],"names":["React","DefaultInfoButtonIcon12","DefaultInfoButtonIcon16","DefaultInfoButtonIcon20","getIntrinsicElementProps","mergeCallbacks","useControllableState","slot","useMergedRefs","isHTMLElement","elementContains","Popover","PopoverSurface","infoButtonIconMap","small","medium","large","popoverSizeMap","useInfoButton_unstable","props","ref","size","inline","popover","info","rest","state","components","root","always","children","type","elementType","defaultProps","positioning","withArrow","role","tabIndex","popoverOpen","setPopoverOpen","open","defaultState","defaultOpen","initialState","onOpenChange","e","data","focusOutRef","useCallback","el","addEventListener","nextFocused","relatedTarget"],"mappings":"AAAA,mDAAmD,GAEnD;;;;;;;;eAwCakB;;;;iEAtCU,QAAQ;wCAC2D,8BAA2B;gCAS9G,4BAA4B;8BACK,0BAA0B;AAIlE,MAAML,oBAAoB;IACxBC,OAAAA,WAAAA,GAAO,OAAA,a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