-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { OidcClient } from '@axa-fr/oidc-client'; | ||
import React, { useState } from 'react'; | ||
|
||
// @ts-ignore | ||
window.OidcClient = OidcClient; | ||
const CodeExecutor: React.FC = () => { | ||
const [code, setCode] = useState<string>(''); | ||
Check failure on line 7 in examples/react-oidc-demo/src/CodeExecutor.tsx GitHub Actions / Run linters
|
||
const [output, setOutput] = useState<string>(''); | ||
Check failure on line 8 in examples/react-oidc-demo/src/CodeExecutor.tsx GitHub Actions / Run linters
|
||
|
||
Check failure on line 9 in examples/react-oidc-demo/src/CodeExecutor.tsx GitHub Actions / Run linters
|
||
const executeCode = () => { | ||
Check failure on line 10 in examples/react-oidc-demo/src/CodeExecutor.tsx GitHub Actions / Run linters
|
||
try { | ||
Check failure on line 11 in examples/react-oidc-demo/src/CodeExecutor.tsx GitHub Actions / Run linters
|
||
const result = eval(` | ||
Check failure on line 12 in examples/react-oidc-demo/src/CodeExecutor.tsx GitHub Actions / Run linters
|
||
(function() { | ||
${code} | ||
})() | ||
`); | ||
setOutput(String(result)); | ||
} catch (error) { | ||
setOutput(`Erreur : ${(error as Error).message}`); | ||
} | ||
}; | ||
|
||
return ( | ||
<div style={{ padding: '20px', maxWidth: '600px', margin: '0 auto' }}> | ||
<h2>Execute your JavaScript Code</h2> | ||
<textarea | ||
value={code} | ||
onChange={(e) => setCode(e.target.value)} | ||
placeholder="Write your JavaScript code here..." | ||
rows={10} | ||
style={{ width: '100%', marginBottom: '10px' }} | ||
></textarea> | ||
<button onClick={executeCode} style={{ padding: '10px 20px' }}> | ||
Execute the code | ||
</button> | ||
<div style={{ marginTop: '20px', padding: '10px', backgroundColor: '#f5f5f5' }}> | ||
<h3>Result :</h3> | ||
<pre>{output}</pre> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CodeExecutor; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.