Skip to content

Commit 3fa768f

Browse files
more strict wrapper definition
1 parent ed171d4 commit 3fa768f

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

src/App.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { formsDemo } from './demos/forms';
99
import { sideBySideDemo } from './demos/sideBySide';
1010
import { longContentDemo } from './demos/longContent';
1111
import { inputsDemo } from './demos/inputs';
12+
import { WrapperProps } from './components/registry/componentWrapper';
1213

1314
const widgets = new Registry('widgets', {componentWrapper: DemoWrapper});
1415
widgets
@@ -46,14 +47,10 @@ export class App extends React.Component {
4647
}
4748
}
4849

49-
interface Props {
50-
children: JSX.Element | JSX.Element[];
51-
}
52-
53-
function DemoWrapper({children}: Props) {
50+
function DemoWrapper({OriginalComponent}: WrapperProps) {
5451
return (
5552
<div className="component-demo-local-wrapper">
56-
{children}
53+
<OriginalComponent/>
5754
</div>
5855
);
5956
}

src/components/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import { LayoutProps } from './layouts/LayoutProps';
88

99
import { simulateState, refreshComponents } from './state/stateSimulation';
1010

11+
import { WrapperProps } from './registry/componentWrapper';
12+
1113
export {
1214
Registry,
1315
Registries,
1416
ComponentDemo,
1517
ComponentViewer,
18+
WrapperProps,
1619
LayoutProps,
1720
GridLayout,
1821
TabsLayout,

src/components/registry/Registry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { TabsLayout } from '../layouts/TabsLayout';
66
import { LayoutProps } from '../layouts/LayoutProps';
77
import { LabelInstanceTableLayout } from '../layouts/LabelInstanceTableLayout';
88
import { SingleItemLayout } from '../layouts/SingleItemLayout';
9-
import { wrapComponent } from './componentWrapper';
9+
import { wrapComponent, WrapperProps } from './componentWrapper';
1010

1111
export interface RegistryConfig {
12-
componentWrapper?: React.ComponentType;
12+
componentWrapper?: React.ComponentType<WrapperProps>;
1313
}
1414

1515
class Registry {
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as React from 'react';
22

3-
export function wrapComponent(Wrapper: React.ComponentType, Component: React.ComponentType) {
3+
export interface WrapperProps {
4+
OriginalComponent: React.ComponentType;
5+
}
6+
7+
export function wrapComponent(Wrapper: React.ComponentType<WrapperProps>, Component: React.ComponentType) {
48
return () => (
5-
<Wrapper>
6-
<Component/>
7-
</Wrapper>
9+
<Wrapper OriginalComponent={Component}/>
810
);
911
}

0 commit comments

Comments
 (0)