|
1 | 1 | import React from 'react' |
2 | 2 | import classnames from 'classnames' |
3 | 3 | import styles from './styles.module.css' |
| 4 | +import { Collapse } from '@theme/Collapse' |
4 | 5 |
|
5 | 6 | import { Opening, Closing } from '@theme/CurlyBraces' |
6 | 7 |
|
7 | | -export default ({ rows, anchorRoot = '' }) => ( |
8 | | - <div className={styles.row}> |
9 | | - <Opening /> |
10 | | - {rows.map((row) => ( |
11 | | - <div |
12 | | - id={(anchorRoot ? anchorRoot + '.' : '') + row.property} |
13 | | - className={classnames(styles.content, 'anchorify')} |
14 | | - > |
| 8 | +function Header(row) { |
| 9 | + return ( |
| 10 | + <span |
| 11 | + className={styles.property} |
| 12 | + dangerouslySetInnerHTML={{ |
| 13 | + __html: `<code><strong>${row.property}</strong><span>${ |
| 14 | + row.optional ? '?' : '' |
| 15 | + }: ${row.type}</span></code>`, |
| 16 | + }} |
| 17 | + ></span> |
| 18 | + ) |
| 19 | +} |
| 20 | + |
| 21 | +function Content(row) { |
| 22 | + return ( |
| 23 | + <div> |
| 24 | + {!row.child && Header(row)} |
| 25 | + {!row.child && ( |
15 | 26 | <div |
16 | | - className={styles.property} |
17 | | - dangerouslySetInnerHTML={{ |
18 | | - __html: `<code><strong>${row.property}</strong><span>${ |
19 | | - row.optional ? '?' : '' |
20 | | - }: ${row.type}</span></code>`, |
21 | | - }} |
| 27 | + className={styles.description} |
| 28 | + dangerouslySetInnerHTML={{ __html: row.description }} |
22 | 29 | ></div> |
23 | | - {!row.child && ( |
24 | | - <div |
25 | | - className={styles.description} |
26 | | - dangerouslySetInnerHTML={{ __html: row.description }} |
27 | | - ></div> |
28 | | - )} |
| 30 | + )} |
29 | 31 |
|
30 | | - {row.child} |
| 32 | + {row.child} |
| 33 | + </div> |
| 34 | + ) |
| 35 | +} |
| 36 | + |
| 37 | +export default ({ rows, anchorRoot = '' }) => { |
| 38 | + return ( |
| 39 | + <div className={styles.row}> |
| 40 | + <Opening /> |
| 41 | + |
| 42 | + <div className={classnames(styles.content)}> |
| 43 | + {rows.map((row) => |
| 44 | + row.child ? ( |
| 45 | + <Collapse header={Header(row)}> |
| 46 | + {Content(row)} |
| 47 | + </Collapse> |
| 48 | + ) : ( |
| 49 | + <div |
| 50 | + id={(anchorRoot ? anchorRoot + '.' : '') + row.property} |
| 51 | + className={classnames('anchorify')} |
| 52 | + > |
| 53 | + {Content(row)} |
| 54 | + </div> |
| 55 | + ) |
| 56 | + )} |
31 | 57 | </div> |
32 | | - ))} |
33 | | - <Closing /> |
34 | | - </div> |
35 | | -) |
| 58 | + <Closing /> |
| 59 | + </div> |
| 60 | + ) |
| 61 | +} |
0 commit comments