-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
Copy pathfunction-list.js
151 lines (145 loc) · 3.43 KB
/
function-list.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
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
import React from "react"
import { rhythm, scale, options } from "../utils/typography"
const Param = (param, depth = 0) => {
// The "plugin" parameter is used internally but not
// something a user should use.
if (param.name === `plugin` || param.name === `traceId`) {
return null
}
return (
<div
key={`param ${JSON.stringify(param)}`}
css={{
marginLeft: `${depth * 1.05}rem`,
...(depth > 0 && scale((depth === 1 ? -1 : -1.5) / 5)),
lineHeight: options.baseLineHeight,
}}
>
<h5
css={{
margin: 0,
...(depth > 0 && scale((depth === 1 ? 0 : -0.5) / 5)),
}}
>
{param.name === `$0` ? `destructured object` : param.name}
{` `}
{param.type &&
param.name !== `$0` && (
<span css={{ color: `#73725f` }}>{`{${param.type.name}}`}</span>
)}
{param.default && (
<span css={{ color: `#73725f` }}>[default={param.default}]</span>
)}
</h5>
{param.description && (
<div
css={{ marginBottom: rhythm(-1 / 4) }}
dangerouslySetInnerHTML={{
__html: param.description.childMarkdownRemark.html,
}}
/>
)}
{param.properties && (
<div css={{ marginBottom: rhythm(1), marginTop: rhythm(1 / 2) }}>
{param.properties.map(param => Param(param, depth + 1))}
</div>
)}
</div>
)
}
export default ({ functions }) => (
<div>
{functions.map(({ node }, i) => (
<div
id={node.name}
key={`reference list ${node.name}`}
css={{ marginBottom: rhythm(1) }}
>
{i !== 0 && <hr />}
<h3>
<a href={`#${node.name}`}>
<code>{node.name}</code>
</a>
</h3>
<div
dangerouslySetInnerHTML={{
__html: node.description.childMarkdownRemark.html,
}}
/>
{(node.params && node.params.length) > 0 && (
<div>
<h4>Parameters</h4>
{node.params.map(param => Param(param, 0))}
</div>
)}
{node.examples &&
node.examples.length > 0 && (
<div>
<h4 css={{ marginTop: rhythm(1) }}>Example</h4>
{` `}
{node.examples.map((example, i) => (
<pre key={`${node.name} example ${i}`}>
<code
className="language-javascript"
dangerouslySetInnerHTML={{
__html: example.highlighted,
}}
/>
</pre>
))}
</div>
)}
</div>
))}
</div>
)
export const pageQuery = graphql`
fragment FunctionList on DocumentationJs {
name
description {
childMarkdownRemark {
html
}
}
returns {
title
}
examples {
highlighted
}
params {
name
type {
name
}
description {
childMarkdownRemark {
html
}
}
properties {
name
type {
name
}
default
description {
childMarkdownRemark {
html
}
}
properties {
name
type {
name
}
description {
childMarkdownRemark {
html
}
}
}
}
}
}
`