@@ -28,6 +28,8 @@ interface Props {
28
28
language ?: string ;
29
29
size ?: Size ;
30
30
trim ?: boolean ;
31
+ lineNumbers ?: boolean ;
32
+ copy ?: boolean ;
31
33
}
32
34
33
35
export const CodeBlock = ( {
@@ -38,6 +40,8 @@ export const CodeBlock = ({
38
40
language : rawLanguage ,
39
41
size = DEFAULT_SIZE ,
40
42
trim = true ,
43
+ lineNumbers = true ,
44
+ copy = true ,
41
45
} : Props ) => {
42
46
const children = normaliseChildren (
43
47
typeof rawChildren === 'string'
@@ -90,47 +94,58 @@ export const CodeBlock = ({
90
94
</ Box >
91
95
) : undefined ;
92
96
97
+ const topRow =
98
+ children . some ( ( { label } ) => label ) || copy || graphqlPlaygroundButton ;
99
+
93
100
return (
94
101
< Stack space = { tablePadding } >
95
- < ScrollableInline whiteSpace = "nowrap" >
96
- < Box display = "flex" justifyContent = "spaceBetween" >
97
- < Box display = "flex" >
98
- { children . map ( ( { label } , labelIndex ) => (
99
- < Box
100
- component = "span"
101
- key = { label }
102
- paddingLeft = { labelIndex === 0 ? undefined : tablePadding }
103
- >
104
- < Text
105
- size = { smallerSize }
106
- tone = { index . value === labelIndex ? 'secondary' : undefined }
107
- weight = "medium"
108
- >
109
- { children . length === 1 || index . value === labelIndex ? (
110
- label
111
- ) : (
112
- < TextLinkButton
113
- onClick = { ( ) =>
114
- setIndex ( { dirty : true , value : labelIndex } )
102
+ { topRow ? (
103
+ < ScrollableInline whiteSpace = "nowrap" >
104
+ < Box display = "flex" justifyContent = "spaceBetween" >
105
+ < Box display = "flex" >
106
+ { children . map ( ( { label } , labelIndex ) =>
107
+ label ? (
108
+ < Box
109
+ component = "span"
110
+ key = { label }
111
+ paddingLeft = { labelIndex === 0 ? undefined : tablePadding }
112
+ >
113
+ < Text
114
+ size = { smallerSize }
115
+ tone = {
116
+ index . value === labelIndex ? 'secondary' : undefined
115
117
}
118
+ weight = "medium"
116
119
>
117
- { label }
118
- </ TextLinkButton >
119
- ) }
120
- </ Text >
121
- </ Box >
122
- ) ) }
123
- </ Box >
124
-
125
- < Box display = "flex" >
126
- < Box component = "span" paddingLeft = { tablePadding } >
127
- < CopyableText size = { smallerSize } > { child . code } </ CopyableText >
120
+ { children . length === 1 || index . value === labelIndex ? (
121
+ label
122
+ ) : (
123
+ < TextLinkButton
124
+ onClick = { ( ) =>
125
+ setIndex ( { dirty : true , value : labelIndex } )
126
+ }
127
+ >
128
+ { label }
129
+ </ TextLinkButton >
130
+ ) }
131
+ </ Text >
132
+ </ Box >
133
+ ) : null ,
134
+ ) }
128
135
</ Box >
129
136
130
- { graphqlPlaygroundButton }
137
+ < Box display = "flex" >
138
+ { copy ? (
139
+ < Box component = "span" paddingLeft = { tablePadding } >
140
+ < CopyableText size = { smallerSize } > { child . code } </ CopyableText >
141
+ </ Box >
142
+ ) : null }
143
+
144
+ { graphqlPlaygroundButton }
145
+ </ Box >
131
146
</ Box >
132
- </ Box >
133
- </ ScrollableInline >
147
+ </ ScrollableInline >
148
+ ) : null }
134
149
135
150
< Box borderRadius = "large" className = { styles . codeContainer } >
136
151
< Highlight
@@ -141,7 +156,9 @@ export const CodeBlock = ({
141
156
>
142
157
{ ( { getTokenProps, tokens } ) => (
143
158
< Box display = "flex" >
144
- < LineNumbers count = { tokens . length } size = { size } />
159
+ { lineNumbers ? (
160
+ < LineNumbers count = { tokens . length } size = { size } />
161
+ ) : null }
145
162
146
163
< Lines getTokenProps = { getTokenProps } lines = { tokens } size = { size } />
147
164
</ Box >
0 commit comments