@@ -2,15 +2,21 @@ import type { ComponentType } from "react";
22
33import type { ComponentProps } from "@/components/Component" ;
44
5+ export type ComponentRegistration =
6+ | ComponentType < Record < string , unknown > >
7+ | ComponentType < ComponentProps > ;
8+
59/**
610 * A registry for Chartlets components.
711 */
812export interface Registry {
913 /**
1014 * Register a React component that renders a Chartlets component.
1115 *
12- * `component` must be a functional React component with at
13- * least the following two component props:
16+ * `component` can be any React component. However, if you want to register
17+ * a custom, reactive component, then `component` must be of type
18+ * `ComponentType<ComponentProps>` where a `ComponentProps` has at
19+ * least the following two properties:
1420 *
1521 * - `type: string`: your component's type name.
1622 * This will be the same as the `type` used for registration.
@@ -23,14 +29,14 @@ export interface Registry {
2329 * @param type The Chartlets component's unique type name.
2430 * @param component A functional React component.
2531 */
26- register ( type : string , component : ComponentType < ComponentProps > ) : ( ) => void ;
32+ register ( type : string , component : ComponentRegistration ) : ( ) => void ;
2733
2834 /**
2935 * Lookup the component of the provided type.
3036 *
3137 * @param type The Chartlets component's type name.
3238 */
33- lookup ( type : string ) : ComponentType < ComponentProps > | undefined ;
39+ lookup ( type : string ) : ComponentRegistration | undefined ;
3440
3541 /**
3642 * Clears the registry.
@@ -46,9 +52,9 @@ export interface Registry {
4652
4753// export for testing only
4854export class RegistryImpl implements Registry {
49- private components = new Map < string , ComponentType < ComponentProps > > ( ) ;
55+ private components = new Map < string , ComponentRegistration > ( ) ;
5056
51- register ( type : string , component : ComponentType < ComponentProps > ) : ( ) => void {
57+ register ( type : string , component : ComponentRegistration ) : ( ) => void {
5258 const oldComponent = this . components . get ( type ) ;
5359 this . components . set ( type , component ) ;
5460 return ( ) => {
@@ -60,7 +66,7 @@ export class RegistryImpl implements Registry {
6066 } ;
6167 }
6268
63- lookup ( type : string ) : ComponentType < ComponentProps > | undefined {
69+ lookup ( type : string ) : ComponentRegistration | undefined {
6470 return this . components . get ( type ) ;
6571 }
6672
@@ -77,12 +83,5 @@ export class RegistryImpl implements Registry {
7783 * The Chartlets component registry.
7884 *
7985 * Use `registry.register("C", C)` to register your own component `C`.
80- *
81- * `C` must be a functional React component with at least the following
82- * two properties:
83- *
84- * - `type: string`: your component's type name.
85- * - `onChange: ComponentChangeHandler`: an event handler
86- * that your component may call to signal change events.
8786 */
8887export const registry = new RegistryImpl ( ) ;
0 commit comments