-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDemoGroupItems.tsx
40 lines (33 loc) · 1022 Bytes
/
DemoGroupItems.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React, { Fragment } from 'react';
import { Demo } from './Demo';
import { DemosGroup } from './DemoGroup';
export function isDemo(item: DemosGroup | Demo): item is Demo {
return item instanceof Demo;
}
export function isDemosGroup(item: DemosGroup | Demo): item is DemosGroup {
return item instanceof DemosGroup;
}
export type DemoItemProps = {
demo: Demo;
path: string[];
};
export type DemosGroupProps = {
group: DemosGroup;
path: string[];
};
type DemoGroupItemsProps = {
groups: DemosGroup[];
path: string[];
Demo?: React.ComponentType<DemoItemProps>;
Group?: React.ComponentType<DemosGroupProps>;
};
export const DemoGroupItems: React.FC<DemoGroupItemsProps> = ({ groups, path, Demo, Group }) => (
<>
{Object.entries(groups).map(([name, item]) => (
<Fragment key={name}>
{isDemo(item) && Demo && <Demo demo={item} path={[...path, name]} />}
{isDemosGroup(item) && Group && <Group group={item} path={[...path, name]} />}
</Fragment>
))}
</>
);