-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathStateTable.tsx
More file actions
98 lines (90 loc) · 3.24 KB
/
StateTable.tsx
File metadata and controls
98 lines (90 loc) · 3.24 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import {Code, styles as codeStyles} from './Code';
import {CSSProperties, Fragment} from 'react';
import {renderHTMLfromMarkdown, setLinks, TInterface} from './types';
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
import {Table, TableBody, TableCell, TableColumn, TableHeader, TableRow} from './Table';
const codeStyle = style({font: {default: 'code-xs', lg: 'code-sm'}});
interface StateTableProps {
properties: TInterface['properties'],
links?: any,
showOptional?: boolean,
hideSelector?: boolean,
cssVariables?: {[name: string]: string},
style?: CSSProperties
}
export function StateTable({properties, links, showOptional, hideSelector, cssVariables, style: styleProp}: StateTableProps) {
if (links) {
setLinks(links);
}
let props = Object.values(properties);
if (!showOptional) {
props = props.filter(prop => !prop.optional);
}
let showSelector = !hideSelector && props.some(prop => prop.type === 'property' && prop.selector);
let table = (
<Table style={styleProp}>
<TableHeader>
<TableRow>
<TableColumn role="columnheader">Render Prop</TableColumn>
{showSelector && <TableColumn role="columnheader">CSS Selector</TableColumn>}
</TableRow>
</TableHeader>
<TableBody>
{props.map((prop, index) => (
<Fragment key={index}>
<TableRow>
<TableCell role="rowheader" hideBorder>
<code className={codeStyle}>
<span className={codeStyles.property}>{prop.name}</span>
</code>
</TableCell>
{showSelector && <TableCell hideBorder>
<strong className={style({font: 'ui', fontWeight: 'bold', display: {sm: 'none'}})}>CSS Selector: </strong>
{prop.type === 'property' && prop.selector ? <span className={codeStyle}><Code lang="css">{prop.selector}</Code></span> : <code className={codeStyle}>—</code>}
</TableCell>}
</TableRow>
<TableRow>
<TableCell colSpan={2}>{prop.description && renderHTMLfromMarkdown(prop.description, {forceInline: true})}</TableCell>
</TableRow>
</Fragment>
))}
</TableBody>
</Table>
);
if (cssVariables) {
table = (
<>
{table}
<CSSVariables cssVariables={cssVariables} />
</>
);
}
return table;
}
export function CSSVariables({cssVariables}: {cssVariables: {[name: string]: string}}) {
return (
<Table style={{marginTop: 16}}>
<TableHeader>
<TableRow>
<TableColumn role="columnheader">CSS Variable</TableColumn>
</TableRow>
</TableHeader>
<TableBody>
{Object.entries(cssVariables).map(([name, description]) => (
<Fragment key={name}>
<TableRow>
<TableCell role="rowheader" hideBorder>
<code className={codeStyle}>
<span className={codeStyles.property}>{name}</span>
</code>
</TableCell>
</TableRow>
<TableRow>
<TableCell>{renderHTMLfromMarkdown(description, {forceInline: true})}</TableCell>
</TableRow>
</Fragment>
))}
</TableBody>
</Table>
);
}