{"version":3,"file":"inputUtils.cjs","names":["_react","require","ComponentControlledState","exports","CONTROLLED","UNCONTROLLED","getControlState","controlledValue","uncontrolledValue","undefined","useInputValues","defaultValue","value","controlState","inputValues","useMemo"],"sources":["../../src/inputUtils.ts"],"sourcesContent":["/*!\n * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { useMemo } from \"react\";\n\nexport type FocusHandle = {\n  focus: () => void;\n};\n\ntype UseControlledStateProps<Value> = {\n  controlledValue?: Value;\n  uncontrolledValue?: Value;\n};\n\nexport const ComponentControlledState = {\n  CONTROLLED: \"CONTROLLED\",\n  UNCONTROLLED: \"UNCONTROLLED\",\n};\n\nexport type ModeType = keyof typeof ComponentControlledState;\nexport type ModeTypeValue = (typeof ComponentControlledState)[ModeType];\n\nexport const getControlState = <Value>({\n  controlledValue,\n  uncontrolledValue,\n}: UseControlledStateProps<Value>): ModeTypeValue => {\n  if (uncontrolledValue !== undefined || controlledValue === undefined) {\n    return ComponentControlledState.UNCONTROLLED;\n  }\n  return ComponentControlledState.CONTROLLED;\n};\n\ntype InputValueProps<Value> = {\n  controlState: ModeTypeValue;\n  defaultValue?: Value;\n  value?: Value;\n};\n\ntype InputValue<Value> =\n  | {\n      defaultValue: Value | undefined;\n      value?: undefined;\n    }\n  | {\n      defaultValue?: undefined;\n      value: Value | undefined;\n    };\n\n/**\n * In components that support being used in a controlled or uncontrolled way, the defaultValue and value props need to be supplied values in a mutually exclusive way.\n * If a `value` is being provided to the component, then it is being used in a controlled manner and `defaultValue` needs to be undefined.\n * If `value` is undefined, then that means the component is being used in an uncontrolled way and `defaultValue` is either Value or undefined. This helper helps ensure this mutual exclusivity between the 2 props so the component can operate as expected.\n *\n * @param {InputValueProps<Value>}: { defaultValue: Value | undefined, value: Value | undefined }\n * @returns {InputValue<Value>}: { defaultValue: Value | undefined, value?: undefined } | { defaultValue?: undefined, value: Value }\n */\nexport const useInputValues = <Value>({\n  defaultValue,\n  value,\n  controlState,\n}: InputValueProps<Value>): InputValue<Value> => {\n  const inputValues = useMemo(() => {\n    if (controlState === ComponentControlledState.CONTROLLED) {\n      return { value };\n    }\n    return { defaultValue };\n  }, [controlState, defaultValue, value]);\n  return inputValues;\n};\n"],"mappings":";;;;;;AAYA,IAAAA,MAAA,GAAAC,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaO,MAAMC,wBAAwB,GAAAC,OAAA,CAAAD,wBAAA,GAAG;EACtCE,UAAU,EAAE,YAAY;EACxBC,YAAY,EAAE;AAChB,CAAC;AAKM,MAAMC,eAAe,GAAGA,CAAQ;EACrCC,eAAe;EACfC;AAC8B,CAAC,KAAoB;EACnD,IAAIA,iBAAiB,KAAKC,SAAS,IAAIF,eAAe,KAAKE,SAAS,EAAE;IACpE,OAAOP,wBAAwB,CAACG,YAAY;EAC9C;EACA,OAAOH,wBAAwB,CAACE,UAAU;AAC5C,CAAC;AAACD,OAAA,CAAAG,eAAA,GAAAA,eAAA;AA0BK,MAAMI,cAAc,GAAGA,CAAQ;EACpCC,YAAY;EACZC,KAAK;EACLC;AACsB,CAAC,KAAwB;EAC/C,MAAMC,WAAW,GAAG,IAAAC,cAAO,EAAC,MAAM;IAChC,IAAIF,YAAY,KAAKX,wBAAwB,CAACE,UAAU,EAAE;MACxD,OAAO;QAAEQ;MAAM,CAAC;IAClB;IACA,OAAO;MAAED;IAAa,CAAC;EACzB,CAAC,EAAE,CAACE,YAAY,EAAEF,YAAY,EAAEC,KAAK,CAAC,CAAC;EACvC,OAAOE,WAAW;AACpB,CAAC;AAACX,OAAA,CAAAO,cAAA,GAAAA,cAAA","ignoreList":[]}