{"version":3,"file":"useComponentDefaults.mjs","names":[],"sources":["../../../../package/common/configProvider/useComponentDefaults.ts"],"sourcesContent":["import { useContext } from 'react';\nimport { ConfigContext } from './configProvider';\nimport type { ComponentDefaults } from './configProvider.types';\n\n/**\n * Merge global defaults from the nearest `ConfigProvider` **under** the props\n * the caller actually passed: an explicit prop always wins, a global default\n * fills in only props the caller left `undefined`, and the component's own\n * built-in default (its destructuring default) applies when neither is set.\n *\n * Call it at the very top of a component and destructure from the result\n * instead of from the raw props:\n *\n * ```tsx\n * function Input(props: InputProps) {\n *   const { alwaysFloatLabel = false, ... } = useComponentDefaults('Input', props);\n * }\n * ```\n */\nexport function useComponentDefaults<P extends object>(component: keyof ComponentDefaults, props: P): P {\n  const ctx = useContext(ConfigContext);\n  const defaults = ctx?.[component];\n  if (!defaults) return props;\n\n  const merged: Record<string, unknown> = { ...defaults };\n  for (const key in props) {\n    const value = (props as Record<string, unknown>)[key];\n    if (value !== undefined) merged[key] = value;\n  }\n  return merged as P;\n}\n"],"mappings":"qGAmBA,SAAgB,EAAuC,EAAoC,EAAa,CAEtG,IAAM,EADM,EAAW,CACN,CAAA,GAAM,GACvB,GAAI,CAAC,EAAU,OAAO,EAEtB,IAAM,EAAkC,CAAE,GAAG,CAAS,EACtD,IAAK,IAAM,KAAO,EAAO,CACvB,IAAM,EAAS,EAAkC,GAC7C,IAAU,IAAA,KAAW,EAAO,GAAO,EACzC,CACA,OAAO,CACT"}