@liveblocks/react-ui
Version:
A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.
1 lines • 1.73 kB
Source Map (JSON)
{"version":3,"file":"components.cjs","sources":["../src/components.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n ComponentPropsWithoutRef,\n ComponentType,\n PropsWithChildren,\n} from \"react\";\nimport { createContext, useContext, useMemo } from \"react\";\n\nexport interface GlobalComponents {\n Anchor: ComponentType<ComponentPropsWithoutRef<\"a\">> | \"a\";\n}\n\nexport type Components = GlobalComponents;\n\ntype ComponentsProviderProps = PropsWithChildren<{\n components?: Partial<Components>;\n}>;\n\nexport const defaultComponents: Components = {\n Anchor: \"a\",\n};\n\nexport const ComponentsContext = createContext<Components | undefined>(\n undefined\n);\n\nexport function useComponents(components?: Partial<Components>): Components {\n const contextComponents = useContext(ComponentsContext);\n\n return useMemo(\n () => ({\n ...defaultComponents,\n ...contextComponents,\n ...components,\n }),\n [contextComponents, components]\n );\n}\n\nexport function ComponentsProvider({\n children,\n components: providerComponents,\n}: ComponentsProviderProps) {\n const contextComponents = useContext(ComponentsContext);\n const components = useMemo(\n () => ({\n ...defaultComponents,\n ...contextComponents,\n ...providerComponents,\n }),\n [contextComponents, providerComponents]\n );\n\n return (\n <ComponentsContext.Provider value={components}>\n {children}\n </ComponentsContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;;;AAmBO;AAAsC;AAE7C;AAEO;AAA0B;AAEjC;AAEO;AACL;AAEA;AAAO;AACE;AACF;AACA;AACA;AACL;AAC8B;AAElC;AAEO;AAA4B;AACjC;AAEF;AACE;AACA;AAAmB;AACV;AACF;AACA;AACA;AACL;AACsC;AAGxC;AACG;AAAkC;AAChC;AAGP;;;;;"}