import { createContext, createElement, useContext } from 'react' // The components' own visible/announced texts. English defaults; an app translates // them once at the root: // (useUiLabels from @xenia/i18n: translated labels) // A prop on a component (closeLabel, label…) still wins over the context. export const DEFAULT_LABELS = { close: 'Close', dismiss: 'Dismiss', loading: 'Loading', moreInfo: 'More info', notifications: 'Notifications', backspace: 'Delete', pinProgress: (n, total) => `${n} of ${total} digits entered`, } const LabelsContext = createContext(DEFAULT_LABELS) export function UiLabelsProvider({ labels, children }) { return createElement(LabelsContext.Provider, { value: { ...DEFAULT_LABELS, ...labels } }, children) } /** The labels in effect (internal to the components). */ export function useLabels() { return useContext(LabelsContext) }