Skip to content
This repository was archived by the owner on Sep 14, 2022. It is now read-only.

Commit 2bf6c92

Browse files
committed
feat: add TSConfig, RuleConfig component
1 parent 3e9acd1 commit 2bf6c92

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

src/components/RuleConfig.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React, { useState, useEffect, useRef } from "react";
2+
import CodeMirror from "codemirror";
3+
import type { FC } from "react";
4+
import type { Linter } from "eslint";
5+
import "codemirror/lib/codemirror.css";
6+
import "codemirror/mode/javascript/javascript.js";
7+
import "@/css/editor.css";
8+
9+
interface Props {
10+
initial: Linter.RulesRecord;
11+
onChange?: (text: string) => void;
12+
ruleConfig: {
13+
[ruleName: string]: any;
14+
};
15+
}
16+
17+
const CODE_MIRROR_OPTIONS = {
18+
mode: "application/ld+json",
19+
lineNumbers: true,
20+
showCursorWhenSelecting: true,
21+
matchBrackets: true,
22+
} as const;
23+
24+
export const RuleConfig: FC<Props> = (props) => {
25+
const [text, setText] = useState<string>(
26+
JSON.stringify(props.initial, null, 2)
27+
);
28+
const ref = useRef<HTMLTextAreaElement>(null);
29+
30+
useEffect(() => {
31+
if (ref.current) {
32+
const codeMirror = CodeMirror.fromTextArea(
33+
ref.current,
34+
CODE_MIRROR_OPTIONS
35+
);
36+
codeMirror.on("change", () => {
37+
const value = codeMirror.getValue();
38+
props.onChange?.(value);
39+
setText(value);
40+
});
41+
}
42+
}, []);
43+
44+
return (
45+
<div className="rule-editor">
46+
<textarea id="code" readOnly autoComplete="off" ref={ref} value={text} />
47+
</div>
48+
);
49+
};

src/components/TSConfig.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from "react";
2+
import { Row, Col } from "react-bootstrap";
3+
import type { FC } from "react";
4+
5+
export const TSConfig: FC = () => {
6+
return (
7+
<>
8+
<Row>
9+
<Col md={4}>
10+
<label htmlFor="ecmaVersion"> ECMA Version </label>
11+
</Col>
12+
<Col md={8}>
13+
<select id="ecmaVersion">
14+
{["es2015", "es2016", "es2017", "es2018", "es2019", "es2020"].map(
15+
(version) => (
16+
<option value={version} key={version}>
17+
{version}
18+
</option>
19+
)
20+
)}
21+
</select>
22+
</Col>
23+
</Row>
24+
<Row>
25+
<Col md={4}>
26+
<label htmlFor="ecmaVersion"> ECMA Features </label>
27+
</Col>
28+
<Col md={8}>
29+
{["jsx", "globalReturn"].map((ecmaFeature) => (
30+
<div className="checkbox" key={ecmaFeature}>
31+
<label htmlFor={ecmaFeature}>
32+
<input
33+
type="checkbox"
34+
className="option-checkbox"
35+
id={ecmaFeature}
36+
/>
37+
{ecmaFeature}
38+
</label>
39+
</div>
40+
))}
41+
</Col>
42+
</Row>
43+
</>
44+
);
45+
};

0 commit comments

Comments
 (0)