/
PropsTable.tsx
161 lines (137 loc) · 3.68 KB
/
PropsTable.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import React from 'react';
import { styled } from '@storybook/theming';
import { opacify, transparentize } from 'polished';
import { PropRow } from './PropRow';
import { PropDef } from './PropDef';
import { EmptyBlock } from '../EmptyBlock';
export const Table = styled.table(({ theme }) => ({
'&&': {
// Resets for cascading/system styles
borderCollapse: 'collapse',
borderSpacing: 0,
tr: {
border: 'none',
background: 'none',
},
'td, th': {
padding: 0,
border: 'none',
},
// End Resets
fontSize: theme.typography.size.s2,
lineHeight: '20px',
textAlign: 'left',
width: '100%',
// Margin collapse
marginTop: '25px',
marginBottom: '40px',
'th:first-of-type, td:first-of-type': {
paddingLeft: 20,
},
'th:last-of-type, td:last-of-type': {
paddingRight: '20px',
width: '20%',
},
th: {
color:
theme.base === 'light'
? transparentize(0.4, theme.color.defaultText)
: transparentize(0.6, theme.color.defaultText),
paddingTop: 10,
paddingBottom: 10,
'&:not(:first-of-type)': {
paddingLeft: 15,
paddingRight: 15,
},
},
td: {
paddingTop: '16px',
paddingBottom: '16px',
'&:not(:first-of-type)': {
paddingLeft: 15,
paddingRight: 15,
},
'&:last-of-type': {
paddingRight: '20px',
},
},
// Table "block" styling
// Emphasize tbody's background and set borderRadius
// Calling out because styling tables is finicky
// Makes border alignment consistent w/other DocBlocks
marginLeft: 1,
marginRight: 1,
'tr:first-child td:first-child': {
borderTopLeftRadius: theme.appBorderRadius,
},
'tr:first-child td:last-child': {
borderTopRightRadius: theme.appBorderRadius,
},
'tr:last-child td:first-child': {
borderBottomLeftRadius: theme.appBorderRadius,
},
'tr:last-child td:last-child': {
borderBottomRightRadius: theme.appBorderRadius,
},
tbody: {
// slightly different than the other DocBlock shadows to account for table styling gymnastics
boxShadow:
theme.base === 'light'
? `rgba(0, 0, 0, 0.10) 0 1px 3px 1px,
${transparentize(0.035, theme.appBorderColor)} 0 0 0 1px`
: `rgba(0, 0, 0, 0.20) 0 2px 5px 1px,
${opacify(0.05, theme.appBorderColor)} 0 0 0 1px`,
borderRadius: theme.appBorderRadius,
tr: {
background: 'transparent',
'&:not(:first-child)': {
borderTop: `1px solid ${theme.appBorderColor}`,
},
},
td: {
background: theme.background.content,
},
},
// End finicky table styling
},
}));
export enum PropsTableError {
NO_COMPONENT = 'No component found',
PROPS_UNSUPPORTED = 'The props unsupported. Check to see if your framework is supported.',
}
export interface PropsTableProps {
rows?: PropDef[];
error?: PropsTableError;
hasInteractiveProps?: boolean;
// FIXME: table options
}
const PropsTable: React.FunctionComponent<PropsTableProps> = ({
rows,
hasInteractiveProps,
error = null,
}) => {
if (error) {
return <EmptyBlock>{error}</EmptyBlock>;
}
if (rows.length === 0) {
return <EmptyBlock>No props found for this component</EmptyBlock>;
}
return (
<Table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Default</th>
{hasInteractiveProps && <th>Knobs</th>}
</tr>
</thead>
<tbody>
{rows.map(row => (
<PropRow key={row.name} row={row} />
))}
</tbody>
</Table>
);
};
export { PropsTable, PropDef };