YamlEditor.jsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React from 'react';
  2. import styled from 'styled-components';
  3. import AceEditor from 'react-ace';
  4. import 'ace-builds/src-noconflict/mode-yaml';
  5. import 'ace-builds/src-noconflict/theme-monokai';
  6. class YamlEditor extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. yaml: ``,
  11. }
  12. this.handleChange = this.handleChange.bind(this);
  13. this.handleSubmit = this.handleSubmit.bind(this);
  14. }
  15. // Uses the yaml-lint library to determine if a given string is valid yaml.
  16. // If the code is invalid, it returns an error message detailing what went wrong.
  17. checkYaml = (y) => {
  18. /*
  19. yamlLint.lint(y).then(() => {
  20. alert('Valid YAML file.');
  21. }).catch((error) => {
  22. alert(error.message);
  23. });
  24. */
  25. }
  26. // Calls checkYaml and passes in the value from the textarea
  27. handleChange = (e) => {
  28. this.setState({ yaml: e });
  29. }
  30. handleSubmit = (e) => {
  31. this.checkYaml(this.state.yaml);
  32. e.preventDefault();
  33. }
  34. render() {
  35. return (
  36. <Holder>
  37. <Editor onSubmit={this.handleSubmit}>
  38. <AceEditor
  39. mode='yaml'
  40. theme='monokai'
  41. onChange={this.handleChange}
  42. name='codeEditor'
  43. editorProps={{ $blockScrolling: true }}
  44. width='100%'
  45. defaultValue={`# If you are using certificate files, include those explicitly`}
  46. style={{
  47. borderRadius: '5px',
  48. }}
  49. />
  50. </Editor>
  51. </Holder>
  52. );
  53. }
  54. }
  55. export default YamlEditor;
  56. const Editor = styled.form`
  57. margin-top: 0px;
  58. margin-bottom: 12px;
  59. width: calc(100% - 0px);
  60. border-radius: 5px;
  61. border: 1px solid #ffffff22;
  62. height: 295px;
  63. overflow: auto;
  64. `;
  65. const Holder = styled.div`
  66. `;