{"version":3,"sources":["../src/components/Radio/useRadio.tsx"],"sourcesContent":["'use client';\n\nimport type * as React from 'react';\nimport { Label } from '@fluentui/react-label';\nimport { getPartitionedNativeProps, mergeCallbacks, useId, slot } from '@fluentui/react-utilities';\nimport { useRadioGroupContextValue_unstable } from '../../contexts/RadioGroupContext';\nimport { useFocusWithin } from '@fluentui/react-tabster';\nimport type { RadioBaseProps, RadioBaseState, RadioProps, RadioState } from './Radio.types';\n\n/**\n * Create the state required to render Radio.\n *\n * The returned state can be modified with hooks such as useRadioStyles_unstable,\n * before being passed to renderRadio_unstable.\n *\n * @param props - props from this instance of Radio\n * @param ref - reference to `<input>` element of Radio\n */\nexport const useRadio_unstable = (props: RadioProps, ref: React.Ref<HTMLInputElement>): RadioState => {\n  const state = useRadioBase_unstable(props, ref);\n\n  return {\n    ...state,\n    // eslint-disable-next-line @typescript-eslint/no-deprecated\n    components: { ...state.components, label: Label },\n    label: slot.optional(props.label, {\n      defaultProps: { ...state.label },\n      elementType: Label,\n    }),\n  };\n};\n\n/**\n * Create the state required to render Radio.\n *\n * The returned state can be modified with hooks such as useRadioStyles_unstable,\n * before being passed to renderRadio_unstable.\n *\n * @param props - props from this instance of Radio\n * @param ref - reference to `<input>` element of Radio\n */\nexport const useRadioBase_unstable = (props: RadioBaseProps, ref: React.Ref<HTMLInputElement>): RadioBaseState => {\n  const group = useRadioGroupContextValue_unstable();\n\n  const {\n    name = group.name,\n    checked = group.value !== undefined ? group.value === props.value : undefined,\n    defaultChecked = group.defaultValue !== undefined ? group.defaultValue === props.value : undefined,\n    labelPosition = group.layout === 'horizontal-stacked' ? 'below' : 'after',\n    disabled = group.disabled,\n    required = group.required,\n    'aria-describedby': ariaDescribedBy = group['aria-describedby'],\n    onChange,\n  } = props;\n\n  const nativeProps = getPartitionedNativeProps({\n    props,\n    primarySlotTagName: 'input',\n    excludedPropNames: ['checked', 'defaultChecked', 'onChange'],\n  });\n\n  const root = slot.always(props.root, {\n    defaultProps: {\n      ref: useFocusWithin<HTMLSpanElement>(),\n      ...nativeProps.root,\n    },\n    elementType: 'span',\n  });\n  const input = slot.always(props.input, {\n    defaultProps: {\n      ref,\n      type: 'radio',\n      id: useId('radio-', nativeProps.primary.id),\n      name,\n      checked,\n      defaultChecked,\n      disabled,\n      required,\n      'aria-describedby': ariaDescribedBy,\n      ...nativeProps.primary,\n    },\n    elementType: 'input',\n  });\n  input.onChange = mergeCallbacks(input.onChange, ev => onChange?.(ev, { value: ev.currentTarget.value }));\n  const label = slot.optional(props.label, {\n    defaultProps: { htmlFor: input.id, disabled: input.disabled },\n    elementType: 'label',\n  });\n  const indicator = slot.always(props.indicator, {\n    defaultProps: { 'aria-hidden': true },\n    elementType: 'div',\n  });\n  return {\n    labelPosition,\n    components: { root: 'span', input: 'input', label: 'label', indicator: 'div' },\n    root,\n    input,\n    label,\n    indicator,\n  };\n};\n"],"names":["Label","getPartitionedNativeProps","mergeCallbacks","useId","slot","useRadioGroupContextValue_unstable","useFocusWithin","useRadio_unstable","props","ref","state","useRadioBase_unstable","components","label","optional","defaultProps","elementType","group","name","checked","value","undefined","defaultChecked","defaultValue","labelPosition","layout","disabled","required","ariaDescribedBy","onChange","nativeProps","primarySlotTagName","excludedPropNames","root","always","input","type","id","primary","ev","currentTarget","htmlFor","indicator"],"mappings":"AAAA;;;;;;;;;;;;IAyCaW,qBAAAA;;;qBAvBAJ;;;;4BAfS,wBAAwB;gCACyB,4BAA4B;mCAChD,sCAAmC;8BACvD,0BAA0B;AAYlD,MAAMA,oBAAoB,CAACC,OAAmBC;IACnD,MAAMC,QAAQC,sBAAsBH,OAAOC;IAE3C,OAAO;QACL,GAAGC,KAAK;QACR,4DAA4D;QAC5DE,YAAY;YAAE,GAAGF,MAAME,UAAU;YAAEC,OAAOb,iBAAAA;QAAM;QAChDa,OAAOT,oBAAAA,CAAKU,QAAQ,CAACN,MAAMK,KAAK,EAAE;YAChCE,cAAc;gBAAE,GAAGL,MAAMG,KAAK;YAAC;YAC/BG,aAAahB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