{"version":3,"file":"useLabels.mjs","names":[],"sources":["../../../../package/common/configProvider/useLabels.ts"],"sourcesContent":["import { useContext } from 'react';\n\nimport { ConfigContext } from './configProvider';\nimport type { ComponentDefaults } from './configProvider.types';\n\n/**\n * Resolves the text a component renders of its own, per key, from three places:\n * the component's built-in English, the nearest `ConfigProvider`, and the\n * instance's `labels` prop, in that order of increasing precedence.\n *\n * Per key is the point, and the reason this exists next to `useComponentDefaults`\n * rather than relying on it. That one fills in whole props: a `labels` object on\n * an instance would replace the provider's entirely, so translating an app once\n * and overriding a single string on one instance would silently drop every other\n * translation for that component.\n *\n * ```tsx\n * const DEFAULT_LABELS: Required<ModalLabels> = { close: 'Close' };\n *\n * function Modal({ labels, ...rest }: ModalProps) {\n *   const text = useLabels('Modal', labels, DEFAULT_LABELS);\n *   // text.close\n * }\n * ```\n */\nexport function useLabels<L extends object>(\n  component: keyof ComponentDefaults,\n  labels: Partial<L> | undefined,\n  defaults: L,\n): L {\n  const ctx = useContext(ConfigContext);\n  const global = (ctx?.[component] as { labels?: Partial<L> } | undefined)?.labels;\n  // Not memoised on purpose: `defaults` and `labels` are object literals at every\n  // call site, so a dependency list would never hit and the bookkeeping would\n  // cost more than three spreads of a handful of strings.\n  return { ...defaults, ...global, ...labels };\n}\n"],"mappings":"qGAyBA,SAAgB,EACd,EACA,EACA,EACG,CAEH,IAAM,EADM,EAAW,CACP,CAAA,GAAM,EAAA,EAAoD,OAI1E,MAAO,CAAE,GAAG,EAAU,GAAG,EAAQ,GAAG,CAAO,CAC7C"}