{"version":3,"sources":["../../../src/components/Input/useInput.ts"],"sourcesContent":["'use client';\n\nimport type * as React from 'react';\nimport { useFieldControlProps_unstable, useFieldContext_unstable } from '@fluentui/react-field';\nimport { getPartitionedNativeProps, useControllableState, useEventCallback, slot } from '@fluentui/react-utilities';\nimport type { InputBaseProps, InputBaseState, InputProps, InputState } from './Input.types';\nimport { useOverrides_unstable as useOverrides } from '@fluentui/react-shared-contexts';\n\n/**\n * Create the state required to render Input.\n *\n * The returned state can be modified with hooks such as useInputStyles_unstable,\n * before being passed to renderInput_unstable.\n *\n * @param props - props from this instance of Input\n * @param ref - reference to `<input>` element of Input\n */\nexport const useInput_unstable = (props: InputProps, ref: React.Ref<HTMLInputElement>): InputState => {\n  const overrides = useOverrides();\n  const fieldContext = useFieldContext_unstable();\n\n  const {\n    size = fieldContext?.size ?? 'medium',\n    appearance = overrides.inputDefaultAppearance ?? 'outline',\n    ...baseProps\n  } = props;\n\n  if (\n    process.env.NODE_ENV !== 'production' &&\n    (appearance === 'filled-darker-shadow' || appearance === 'filled-lighter-shadow')\n  ) {\n    // eslint-disable-next-line no-console\n    console.error(\n      \"The 'filled-darker-shadow' and 'filled-lighter-shadow' appearances are deprecated and will be removed in the\" +\n        ' future.',\n    );\n  }\n\n  const state = useInputBase_unstable(baseProps, ref);\n\n  return {\n    size,\n    appearance,\n    ...state,\n  };\n};\n\n/**\n * Base hook for Input component, which manages state related to controlled/uncontrolled value,\n * slot structure, and onChange handling. This hook excludes design-specific props (appearance, size).\n *\n * @param props - User provided props to the Input component.\n * @param ref - User provided ref to be passed to the Input component.\n */\nexport const useInputBase_unstable = (props: InputBaseProps, ref: React.Ref<HTMLInputElement>): InputBaseState => {\n  const fieldControlProps = useFieldControlProps_unstable(props, {\n    supportsLabelFor: true,\n    supportsRequired: true,\n  });\n\n  const [value, setValue] = useControllableState({\n    state: fieldControlProps.value,\n    defaultState: fieldControlProps.defaultValue,\n    initialState: '',\n  });\n\n  const nativeProps = getPartitionedNativeProps({\n    props: fieldControlProps,\n    primarySlotTagName: 'input',\n    excludedPropNames: ['onChange', 'value', 'defaultValue'],\n  });\n\n  const state: InputBaseState = {\n    components: {\n      root: 'span',\n      input: 'input',\n      contentBefore: 'span',\n      contentAfter: 'span',\n    },\n    input: slot.always(fieldControlProps.input, {\n      defaultProps: {\n        type: 'text',\n        ref,\n        ...nativeProps.primary,\n      },\n      elementType: 'input',\n    }),\n    contentAfter: slot.optional(fieldControlProps.contentAfter, { elementType: 'span' }),\n    contentBefore: slot.optional(fieldControlProps.contentBefore, { elementType: 'span' }),\n    root: slot.always(fieldControlProps.root, {\n      defaultProps: nativeProps.root,\n      elementType: 'span',\n    }),\n  };\n\n  state.input.value = value;\n  state.input.onChange = useEventCallback(ev => {\n    const newValue = ev.target.value;\n    fieldControlProps.onChange?.(ev, { value: newValue });\n    setValue(newValue);\n  });\n\n  return state;\n};\n"],"names":["useFieldControlProps_unstable","useFieldContext_unstable","getPartitionedNativeProps","useControllableState","useEventCallback","slot","useOverrides_unstable","useOverrides","useInput_unstable","props","ref","overrides","fieldContext","size","appearance","inputDefaultAppearance","baseProps","process","env","NODE_ENV","console","error","state","useInputBase_unstable","fieldControlProps","supportsLabelFor","supportsRequired","value","setValue","defaultState","defaultValue","initialState","nativeProps","primarySlotTagName","excludedPropNames","components","root","input","contentBefore","contentAfter","always","defaultProps","type","primary","elementType","optional","onChange","ev","newValue","target"],"mappings":"AAAA;;;;;;;;;;;;QAsDauB;;;QArCAf;;;;4BAd2D,wBAAwB;gCACR,4BAA4B;qCAE9D,kCAAkC;AAWjF,0BAA0B,CAACC,OAAmBC;cAMpCC;IALf,MAAMA,gBAAYJ,0CAAAA;IAClB,MAAMK,mBAAeX,oCAAAA;IAErB,MAAM,EACJY,OAAAA,CAAAA,OAAOD,iBAAAA,QAAAA,iBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,aAAcC,IAAAA,AAAI,MAAA,QAAA,SAAA,KAAA,IAAA,OAAI,QAAQ,EACrCC,aAAA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