@@ -4,6 +4,9 @@ import Row from 'react-bootstrap/Row';
4
4
import Col from 'react-bootstrap/Col' ;
5
5
import Stack from 'react-bootstrap/Stack' ;
6
6
import Form from 'react-bootstrap/Form' ;
7
+ import Button from 'react-bootstrap/Button' ;
8
+ import ToastContainer from 'react-bootstrap/ToastContainer' ;
9
+ import Toast from 'react-bootstrap/Toast' ;
7
10
import SyntaxHighlighter from 'react-syntax-highlighter' ;
8
11
import { atomOneLight } from 'react-syntax-highlighter/dist/esm/styles/hljs' ;
9
12
import { compareVersions } from 'compare-versions' ;
@@ -18,6 +21,7 @@ function App() {
18
21
const [ error , setError ] = useState < string | null > ( null ) ;
19
22
const [ code , setCode ] = useState < string > ( 'Loading...' ) ;
20
23
const [ language , setLanguage ] = useState < string > ( formats [ 0 ] ) ;
24
+ const [ showClipboardMsg , setShowClipboardMsg ] = useState ( false ) ;
21
25
22
26
useEffect ( ( ) => {
23
27
const sourceElem = document . getElementById ( "source" ) ;
@@ -71,15 +75,43 @@ function App() {
71
75
} ) ( ) ;
72
76
} , [ hasSchema , source , language ] ) ;
73
77
74
- const onRequestChanged = ( ev : React . ChangeEvent < HTMLSelectElement > ) => {
78
+ const onRequestChanged = ( ev : React . ChangeEvent < HTMLSelectElement > ) : null => {
75
79
setSource ( ev . target . value ) ;
76
80
ev . target . style . height = ev . target . scrollHeight + "px" ;
77
81
} ;
78
82
83
+ const copyToClipboard = async ( ) => {
84
+ await navigator . clipboard . writeText ( code ) ;
85
+ setShowClipboardMsg ( true ) ;
86
+ } ;
87
+
79
88
return (
80
89
< Container id = "main-container" >
81
- < h1 > Elasticsearch Request Converter Demo</ h1 >
82
- < p > → < a href = "./docs/index.html" > Library documentation</ a > </ p >
90
+ < div aria-live = "polite" aria-atomic = "true" className = "position-relative" >
91
+ < ToastContainer className = "clipboard-toast p-3" position = "top-end" style = { { zIndex : 1 } } >
92
+ < Toast onClose = { ( ) => setShowClipboardMsg ( false ) } show = { showClipboardMsg } delay = { 2000 } autohide >
93
+ < Toast . Body > Copied to clipboard!</ Toast . Body >
94
+ </ Toast >
95
+ </ ToastContainer >
96
+ </ div >
97
+ < Row >
98
+ < Col >
99
+ < h1 > Elasticsearch Request Converter Demo</ h1 >
100
+ </ Col >
101
+ < Col sm = "auto" >
102
+ < p >
103
+ < small >
104
+ < svg width = "16" viewBox = "0 0 24 24" fill = "none" xmlns = "http://www.w3.org/2000/svg" > < g id = "SVGRepo_bgCarrier" strokeWidth = "0" > </ g > < g id = "SVGRepo_tracerCarrier" strokeLinecap = "round" strokeLinejoin = "round" > </ g > < g id = "SVGRepo_iconCarrier" > < g id = "Interface / External_Link" > < path id = "Vector" d = "M10.0002 5H8.2002C7.08009 5 6.51962 5 6.0918 5.21799C5.71547 5.40973 5.40973 5.71547 5.21799 6.0918C5 6.51962 5 7.08009 5 8.2002V15.8002C5 16.9203 5 17.4801 5.21799 17.9079C5.40973 18.2842 5.71547 18.5905 6.0918 18.7822C6.5192 19 7.07899 19 8.19691 19H15.8031C16.921 19 17.48 19 17.9074 18.7822C18.2837 18.5905 18.5905 18.2839 18.7822 17.9076C19 17.4802 19 16.921 19 15.8031V14M20 9V4M20 4H15M20 4L13 11" stroke = "#000000" strokeWidth = "2" strokeLinecap = "round" strokeLinejoin = "round" > </ path > </ g > </ g > </ svg >
105
+
106
+ < a href = "https://github.com/elastic/request-converter" > GitHub project</ a >
107
+ < br />
108
+ < svg width = "16" viewBox = "0 0 24 24" fill = "none" xmlns = "http://www.w3.org/2000/svg" > < g id = "SVGRepo_bgCarrier" strokeWidth = "0" > </ g > < g id = "SVGRepo_tracerCarrier" strokeLinecap = "round" strokeLinejoin = "round" > </ g > < g id = "SVGRepo_iconCarrier" > < g id = "Interface / External_Link" > < path id = "Vector" d = "M10.0002 5H8.2002C7.08009 5 6.51962 5 6.0918 5.21799C5.71547 5.40973 5.40973 5.71547 5.21799 6.0918C5 6.51962 5 7.08009 5 8.2002V15.8002C5 16.9203 5 17.4801 5.21799 17.9079C5.40973 18.2842 5.71547 18.5905 6.0918 18.7822C6.5192 19 7.07899 19 8.19691 19H15.8031C16.921 19 17.48 19 17.9074 18.7822C18.2837 18.5905 18.5905 18.2839 18.7822 17.9076C19 17.4802 19 16.921 19 15.8031V14M20 9V4M20 4H15M20 4L13 11" stroke = "#000000" strokeWidth = "2" strokeLinecap = "round" strokeLinejoin = "round" > </ path > </ g > </ g > </ svg >
109
+
110
+ < a href = "./docs/index.html" > Library documentation</ a >
111
+ </ small >
112
+ </ p >
113
+ </ Col >
114
+ </ Row >
83
115
< Row >
84
116
< Col className = "col-6" >
85
117
< Stack direction = "horizontal" className = "heading" >
@@ -91,12 +123,13 @@ function App() {
91
123
</ Stack >
92
124
</ Col >
93
125
< Col className = "col-6" >
94
- < Stack direction = "horizontal" className = "heading" >
126
+ < Stack direction = "horizontal" className = "heading" gap = { 1 } >
95
127
< p > Converted Code</ p >
96
128
< p className = "spacer" > </ p >
97
129
< Form . Select id = "language-choice" size = "sm" defaultValue = { language } onChange = { ev => setLanguage ( ev . target . value ) } >
98
130
{ formats . map ( fmt => < option key = { fmt } value = { fmt } > { fmt } </ option > ) }
99
131
</ Form . Select >
132
+ < Button className = "copy-clipboard" size = "sm" variant = "outline-secondary" onClick = { ( ) => copyToClipboard ( ) } > ⎘</ Button >
100
133
</ Stack >
101
134
</ Col >
102
135
</ Row >
0 commit comments