This repository was archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathAttributeTable.js
119 lines (105 loc) · 2.82 KB
/
AttributeTable.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React from "react";
import styled from "styled-components";
import PropTypes from "prop-types";
import { PALETTE, FONT_FAMILY, FONT_WEIGHT } from "constants/styles";
import { buildAttributesList } from "helpers/documentation";
import { Text, MonoText } from "basics/Text";
import { Expansion } from "components/Expansion";
import PlusIcon from "assets/icons/icon-plus.svg";
import MinusIcon from "assets/icons/icon-minus.svg";
const El = styled.ul`
background: ${(props) =>
props.isCodeSnippet ? PALETTE.black90 : PALETTE.white};
margin: 0;
padding: 0;
font-size: 0.875rem;
font-family: ${FONT_FAMILY.base};
color: ${PALETTE.black60};
& > ${ListItemEl}:first-of-type {
// text-transform: uppercase;
padding: 1rem 0;
}
`;
const ListItemEl = styled.li`
list-style: none;
padding: 1.5rem 0;
border-bottom: 1px solid ${PALETTE.white60};
margin: 0;
&:last-child {
border-bottom: none;
}
`;
const DataTypeTextEl = styled(MonoText)`
padding: 0 0.75rem;
color: ${PALETTE.lightGrey};
`;
const AttributeNameEl = styled(MonoText)`
font-weight: ${FONT_WEIGHT.bold};
color: ${PALETTE.black80};
`;
const DescriptionEl = styled(Text)`
margin: 0;
color: ${PALETTE.black60};
`;
const SubAttributesEl = styled.ul`
min-width: 10rem;
padding: 1rem;
& ${ListItemEl}:first-child {
padding-top: 0;
}
& ${ListItemEl}:last-child {
padding-bottom: 0;
}
& ${AttributeNameEl} {
color: ${PALETTE.black60};
}
`;
const AttributeList = ({ attributes }) => (
<>
{attributes.map(({ name, type, description, childAttributes }) => (
<ListItemEl key={name}>
<AttributeNameEl>{name}</AttributeNameEl>
<DataTypeTextEl>{type}</DataTypeTextEl>
<DescriptionEl>{description}</DescriptionEl>
{childAttributes && (
<Expansion
title="Show child attributes"
expandedModeTitle="Hide child attributes"
hasBorder
collapseIcon={<MinusIcon />}
expandIcon={<PlusIcon />}
style={{ marginTop: "1rem" }}
>
<SubAttributesEl>
<AttributeList attributes={childAttributes} />
</SubAttributesEl>
</Expansion>
)}
</ListItemEl>
))}
</>
);
AttributeList.propTypes = {
attributes: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.node.isRequired,
type: PropTypes.node,
description: PropTypes.node.isRequired,
childAttributes: PropTypes.array,
}),
).isRequired,
};
export const AttributeTable = React.forwardRef(function AttributeTable(
{ children, ...props },
ref,
) {
const attributes = buildAttributesList(children);
return (
<El ref={ref} {...props}>
<AttributeList attributes={attributes} />
</El>
);
});
AttributeTable.propTypes = {
children: PropTypes.node.isRequired,
};