Skip to content

Commit afd165f

Browse files
committed
Improved type definitions + documentation
#1207
1 parent 7967eef commit afd165f

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

packages/dashboard/src/DashboardPlugin.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Component, ComponentType, NamedExoticComponent } from 'react';
1+
import {
2+
Component,
3+
ComponentType,
4+
ForwardRefExoticComponent,
5+
PropsWithoutRef,
6+
RefAttributes,
7+
} from 'react';
28
import { ConnectedComponent } from 'react-redux';
39
import GoldenLayout from '@deephaven/golden-layout';
410
import type {
@@ -8,10 +14,33 @@ import type {
814
} from '@deephaven/golden-layout';
915
import PanelManager from './PanelManager';
1016

11-
export type PanelFunctionComponentType<P> = NamedExoticComponent<P> & {
17+
/**
18+
* Alias for the return type of React.forwardRef()
19+
*/
20+
export type ForwardRefComponentType<P, R> = ForwardRefExoticComponent<
21+
PropsWithoutRef<P> & RefAttributes<R>
22+
>;
23+
24+
/**
25+
* Panel components can provide static props that provide meta data about the
26+
* panel.
27+
*/
28+
export interface PanelStaticMetaData {
29+
/**
30+
* Should be set to the same name as the component type.
31+
* @deprecated Use `displayName` instead.
32+
*/
1233
COMPONENT?: string;
34+
35+
/** Title of the panel. */
1336
TITLE?: string;
14-
};
37+
}
38+
39+
/**
40+
* Panels defined as functional components have to use React.forwardRef.
41+
*/
42+
export type PanelFunctionComponentType<P, R> = ForwardRefComponentType<P, R> &
43+
PanelStaticMetaData;
1544

1645
export type WrappedComponentType<
1746
P extends PanelProps,
@@ -24,8 +53,9 @@ export type PanelComponentType<
2453
> = (
2554
| ComponentType<P>
2655
| WrappedComponentType<P, C>
27-
| PanelFunctionComponentType<P>
28-
) & { COMPONENT?: string; TITLE?: string };
56+
| PanelFunctionComponentType<P, unknown>
57+
) &
58+
PanelStaticMetaData;
2959

3060
export function isWrappedComponent<
3161
P extends PanelProps,

0 commit comments

Comments
 (0)