This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathDefinitionsContainer.tsx
More file actions
78 lines (74 loc) · 2.68 KB
/
DefinitionsContainer.tsx
File metadata and controls
78 lines (74 loc) · 2.68 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { useRef } from 'react';
import ComponentMapping from '../../mappings/ComponentMapping';
import { useStoreActions, useStoreState } from '../../state/Hooks';
import ComponentInfo from '../atoms/ComponentInfo';
import Definition from '../atoms/Definition';
import {
InspectorDefinitionMenu,
InspectorDefinitionMenuNav,
} from '../menus/definitions/InspectorDefinitionMenu';
import SubTypeMenuNav from '../menus/SubTypeMenu';
import CollapsibleList from './CollapsibleList';
import GuideContainer from './GuideContainer';
export interface DefinitionsProps {
type: ComponentMapping;
expanded?: boolean;
onChange?: (expanded: boolean) => void;
}
const DefinitionsContainer = (props: DefinitionsProps) => {
const items = useStoreState(props.type.store.get);
const navigateTo = useStoreActions((actions) => actions.navigateTo);
const guideStep = useStoreState((state) => state.guideStep);
const ref = useRef(null);
return (
<div ref={ref} className="w-full p-4 pb-0">
{props.type.guide && guideStep === props.type.guide.step && (
<GuideContainer target={ref}>{props.type.guide.info}</GuideContainer>
)}
<CollapsibleList
title={props.type.name.plural}
expanded={props.expanded}
onChange={props.onChange}
titleExpanded={
<button
onClick={() =>
navigateTo(
props.type.subtypes?.component
? {
component: SubTypeMenuNav,
props: {
typePage: props.type.subtypes?.component,
menuPage: InspectorDefinitionMenu,
menuProps: { dataType: props.type, flatten: true },
},
}
: {
component: InspectorDefinitionMenuNav,
props: { dataType: props.type, flatten: true },
},
)
}
className="ml-auto tracking-wide hover:underline leading-6 text-sm text-circle-blue font-medium"
>
New
</button>
}
>
<div className="w-full pl-2 pt-2">
<ComponentInfo type={props.type} />
{(items || []).length > 0 ? (
items?.map((item) => (
<Definition data={item} key={item.name} type={props.type} />
))
) : (
<div className="font-medium text-sm text-circle-gray-500">
No {props.type.name.plural} found.
</div>
)}
</div>
</CollapsibleList>
<div className="w-full p-2 border-b border-circle-gray-300"></div>
</div>
);
};
export default DefinitionsContainer;