FormDebugger.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import React, { Component } from "react";
  2. import styled from "styled-components";
  3. import AceEditor from "react-ace";
  4. import yaml from "js-yaml";
  5. import "shared/ace-porter-theme"
  6. import "ace-builds/src-noconflict/mode-text";
  7. import Heading from "./Heading";
  8. import Helper from "./Helper";
  9. type PropsType = {
  10. goBack: () => void;
  11. };
  12. type StateType = {
  13. rawYaml: string;
  14. };
  15. export default class FormDebugger extends Component<PropsType, StateType> {
  16. state = {
  17. rawYaml: "",
  18. }
  19. renderForm = () => {
  20. let formData = yaml.load(this.state.rawYaml);
  21. return <h1>silver lining</h1>
  22. }
  23. aceEditorRef = React.createRef<AceEditor>();
  24. render() {
  25. return (
  26. <StyledFormDebugger>
  27. <Button onClick={this.props.goBack}>
  28. <i className="material-icons">keyboard_backspace</i>
  29. Back
  30. </Button>
  31. <Heading>✨ Form.yaml Editor</Heading>
  32. <Helper>Write and test form.yaml free of consequence.</Helper>
  33. <EditorWrapper>
  34. <AceEditor
  35. ref={this.aceEditorRef}
  36. mode="yaml"
  37. value={this.state.rawYaml}
  38. theme="porter"
  39. onChange={(e: string) => this.setState({ rawYaml: e })}
  40. name="codeEditor"
  41. editorProps={{ $blockScrolling: true }}
  42. height="300px"
  43. width="100%"
  44. style={{
  45. borderRadius: "5px",
  46. border: "1px solid #ffffff22",
  47. marginTop: "27px"
  48. }}
  49. showPrintMargin={false}
  50. showGutter={true}
  51. highlightActiveLine={true}
  52. />
  53. </EditorWrapper>
  54. <Heading>🎨 Rendered Form</Heading>
  55. {this.renderForm()}
  56. </StyledFormDebugger>
  57. );
  58. }
  59. }
  60. const EditorWrapper = styled.div`
  61. .ace_editor,
  62. .ace_editor * {
  63. font-family: "Monaco", "Menlo", "Ubuntu Mono", "Droid Sans Mono", "Consolas",
  64. monospace !important;
  65. font-size: 12px !important;
  66. font-weight: 400 !important;
  67. letter-spacing: 0 !important;
  68. }
  69. `;
  70. const StyledFormDebugger = styled.div`
  71. position: relative;
  72. `;
  73. const Button = styled.div`
  74. display: flex;
  75. flex-direction: row;
  76. align-items: center;
  77. justify-content: space-between;
  78. font-size: 13px;
  79. cursor: pointer;
  80. font-family: "Work Sans", sans-serif;
  81. border-radius: 20px;
  82. color: white;
  83. height: 35px;
  84. margin-left: -2px;
  85. padding: 0px 8px;
  86. width: 85px;
  87. float: right;
  88. padding-bottom: 1px;
  89. font-weight: 500;
  90. padding-right: 15px;
  91. overflow: hidden;
  92. white-space: nowrap;
  93. text-overflow: ellipsis;
  94. cursor: pointer;
  95. border: 2px solid #969fbbaa;
  96. :hover {
  97. background: #ffffff11;
  98. }
  99. > i {
  100. color: white;
  101. width: 18px;
  102. height: 18px;
  103. color: #969fbbaa;
  104. font-weight: 600;
  105. font-size: 14px;
  106. border-radius: 20px;
  107. display: flex;
  108. align-items: center;
  109. margin-right: 5px;
  110. justify-content: center;
  111. }
  112. `;