File tree Expand file tree Collapse file tree 2 files changed +68
-31
lines changed
Expand file tree Collapse file tree 2 files changed +68
-31
lines changed Original file line number Diff line number Diff line change @@ -41,39 +41,60 @@ export function CollapseJSON({ json }: { json: string }): JSX.Element {
4141 return indexOf5thLine
4242 } , [ originalString ] )
4343
44+ function copyContents ( ) {
45+ if ( ! navigator . clipboard ) return
46+
47+ navigator . clipboard . writeText ( json ) . catch ( ( e ) => console . error ( 'Unable to copy JSON contents to clipboard' , e ) )
48+ }
49+
4450 if ( originalString . length < 100 && indexOf5thLine === null ) {
4551 return < pre className = "collapse-json__block" > { originalString } </ pre >
4652 }
4753
4854 const displayContents = expanded ? (
4955 < >
5056 { originalString }
51- < button
52- key = { 'collapse' }
53- className = "collapse-json__collapser"
54- tabIndex = { 0 }
55- onClick = { ( e ) => {
56- e . stopPropagation ( )
57- setExpanded ( false )
58- } }
59- >
60- ⮥
61- </ button >
57+ < div className = "collapse-json__tools" >
58+ < button
59+ key = { 'collapse' }
60+ className = "collapse-json__copy"
61+ tabIndex = { 0 }
62+ onClick = { ( e ) => {
63+ e . stopPropagation ( )
64+ copyContents ( )
65+ } }
66+ >
67+ Copy
68+ </ button >
69+ < button
70+ key = { 'collapse' }
71+ className = "collapse-json__collapser"
72+ tabIndex = { 0 }
73+ onClick = { ( e ) => {
74+ e . stopPropagation ( )
75+ setExpanded ( false )
76+ } }
77+ >
78+ ⮥
79+ </ button >
80+ </ div >
6281 </ >
6382 ) : (
6483 < >
6584 { originalString . substring ( 0 , Math . min ( indexOf5thLine || 100 , 100 ) ) }
66- < button
67- key = { 'expand' }
68- className = "collapse-json__collapser"
69- tabIndex = { 0 }
70- onClick = { ( e ) => {
71- e . stopPropagation ( )
72- setExpanded ( true )
73- } }
74- >
75- …
76- </ button >
85+ < div className = "collapse-json__tools" >
86+ < button
87+ key = { 'expand' }
88+ className = "collapse-json__collapser"
89+ tabIndex = { 0 }
90+ onClick = { ( e ) => {
91+ e . stopPropagation ( )
92+ setExpanded ( true )
93+ } }
94+ >
95+ …
96+ </ button >
97+ </ div >
7798 </ >
7899 )
79100
Original file line number Diff line number Diff line change 88 }
99}
1010
11- .collapse-json__collapser {
11+ .collapse-json__tools {
1212 display : block ;
13+ float : right ;
14+ clear : both ;
15+ }
16+
17+ .collapse-json__tools > button {
1318 background : #eee ;
1419 border-radius : 3px ;
15- line-height : 1.3 em ;
16- padding : 0 0.3 em ;
17- margin-top : 0.2 em ;
20+ line-height : 1 rem ;
21+ padding : 0 0.3 rem ;
22+ margin-top : 0.2 rem ;
1823 border : none ;
19- float : right ;
20- clear : both ;
2124 user-select : none ;
25+ margin-left : 0.2rem ;
26+ vertical-align : top ;
27+
28+ & :focus {
29+ outline : none ;
30+ box-shadow : 0 0 0 2px #00feff ;
31+ }
32+
33+ & :active {
34+ background-color : #ddd ;
35+ }
2236}
2337
24- .collapse-json__collapser :focus {
25- outline : none ;
26- box-shadow : 0 0 0 2px #00feff ;
38+ .collapse-json__copy {
39+ font-family : Roboto, arial , sans-serif ;
40+ font-weight : 500 ;
41+ font-size : 0.8em ;
42+ color : #888 ;
2743}
You can’t perform that action at this time.
0 commit comments