aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/Inputs/Code.js
blob: 5b8e06a23a919bfb495eae1accc017e04d1d0043 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from "react";
import styled from 'styled-components'
import CharLimit from "../decorators/CharLimit";
import Editor from 'react-simple-code-editor';
import {Highlighter} from "../renderers/Code";

const EditorWrapper = styled(Editor)`
  overflow: visible !important;
  
  & > * {
    padding: 0 !important;
    width: 100%;
  }
  
  & pre, & code, & > textarea {
    font-family: JetBrains Mono !important;
    font-size: 14px !important;
    line-height: 1.2em !important;
    min-height: 40vh;
  }
  
  & > textarea {
    padding: 0.8em !important;
    z-index: 1;
    border: none !important;
    background-color: transparent !important;
    outline: none !important;
  }
`

const DefaultText = `Paste your text here`

export const Code = ({content, id, readOnly, setContentCallback, ...props}) => {
  return (
    <div>
      <EditorWrapper
        name="content"
        readOnly={readOnly}
        placeholder={DefaultText}
        value={content}
        id={id}
        required
        highlight={code => <Highlighter theme="atom">{code}</Highlighter> }
        onValueChange={code => setContentCallback(code)}
        padding={15}
      />
      <CharLimit
        content={content}
        maxLength={props.maxLength} />
    </div>
  );
}