1 | {"version":3,"file":"getPropsWithDefaults.js","sourceRoot":"../src/","sources":["getPropsWithDefaults.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,YAA6B,EAC7B,oBAA4B;IAE5B,IAAM,KAAK,gBAAQ,oBAAoB,CAAE,CAAC;IAC1C,KAAkB,UAA6C,EAA7C,KAAA,MAAM,CAAC,IAAI,CAAC,YAAY,CAAqB,EAA7C,cAA6C,EAA7C,IAA6C,EAAE;QAA5D,IAAM,GAAG,SAAA;QACZ,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;YAC5B,KAAK,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAE,CAAC;SACjC;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Function to apply default values to a component props object. This function is intended for function components,\n * to maintain parity with the `defaultProps` feature of class components. It accounts for properties that are\n * specified, but undefined.\n * @param defaultProps- An object with default values for various properties\n * @param propsWithoutDefaults- The props object passed into the component\n */\nexport function getPropsWithDefaults<TProps extends {}>(\n defaultProps: Partial<TProps>,\n propsWithoutDefaults: TProps,\n): TProps {\n const props = { ...propsWithoutDefaults };\n for (const key of Object.keys(defaultProps) as (keyof TProps)[]) {\n if (props[key] === undefined) {\n props[key] = defaultProps[key]!;\n }\n }\n\n return props;\n}\n"]} |