{"version":3,"file":"composeRefs.mjs","names":[],"sources":["../src/composeRefs.ts"],"sourcesContent":["/**\n * Copyright (c) 2023-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { Ref, RefObject } from \"react\";\n\ntype PossibleRef<T> = Ref<T> | undefined;\n\nconst setRef = <T>(ref: PossibleRef<T>, value: T) => {\n  if (typeof ref === \"function\") {\n    ref(value);\n  } else if (ref !== null && ref !== undefined) {\n    const mutableRef = ref as RefObject<T>;\n    mutableRef.current = value;\n  }\n};\n\n/**\n * Applies multiple refs to a single element. This is useful for when you need to utilize a local ref\n * and a forwarded ref simultaneously.\n * Taken from https://github.com/chakra-ui/ark/blob/main/packages/frameworks/react/src/compose-refs.ts\n */\nexport const composeRefs = <T>(...refs: PossibleRef<T>[]) => {\n  return (node: T): void => refs.forEach((ref) => setRef(ref, node));\n};\n"],"mappings":";AAYA,MAAM,UAAa,KAAqB,UAAa;AACnD,KAAI,OAAO,QAAQ,WACjB,KAAI,MAAM;UACD,QAAQ,QAAQ,QAAQ,KAAA,GAAW;EAC5C,MAAM,aAAa;AACnB,aAAW,UAAU;;;;;;;;AASzB,MAAa,eAAkB,GAAG,SAA2B;AAC3D,SAAQ,SAAkB,KAAK,SAAS,QAAQ,OAAO,KAAK,KAAK,CAAC"}