-
Notifications
You must be signed in to change notification settings - Fork 14
/
LiveTyping.tsx
52 lines (48 loc) · 1.3 KB
/
LiveTyping.tsx
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, { useState } from "react";
import { SourceSpecification, useMathJax } from "mathjax-react";
import Example from "./Example";
const exampleConfig = {
title: "Live Typing",
caption: `Type in the text box below and see the rendered result.`,
relSrc: "examples/LiveTyping.tsx",
};
const inputStyles = {
display: "block",
margin: "auto",
};
export default function LiveTyping() {
const [sourceSpec, setSourceSpec] = useState<SourceSpecification>({
lang: "TeX",
src: "",
});
const { getProps, error } = useMathJax({
...sourceSpec,
display: true,
settings: {},
});
return (
<Example {...exampleConfig}>
<select
onChange={(evt) => {
evt.preventDefault();
const lang = evt.target.value;
if (lang === "TeX" || lang === "MathML")
setSourceSpec({ ...sourceSpec, lang });
}}
>
<option value="TeX">TeX</option>
<option value="MathML">MathML</option>
</select>
<input
style={inputStyles}
type="text"
onChange={(evt) => {
evt.preventDefault();
setSourceSpec({ ...sourceSpec, src: evt.target.value });
}}
/>
<p style={{ textAlign: "center" }}>{error ?? "No Errors"}</p>
<div {...getProps()} />
</Example>
);
}