Fix PR comments:

- change the onChange handler to return onChange rather than onBlur
- Change the vega component to a checkbox
- Create new IDs + check whether it works with multiple editors
- Multiple line squiggle editors (noticed this was an issue)
- Remove ace imports that are not used
This commit is contained in:
Sam Nolan 2022-04-06 11:18:18 +10:00
parent 427c5d5615
commit e1295e4f0f
6 changed files with 55 additions and 41 deletions

View File

@ -1,10 +1,9 @@
import _ from "lodash";
import React, { FC } from "react"; import React, { FC } from "react";
import AceEditor from "react-ace"; import AceEditor from "react-ace";
import "ace-builds/src-noconflict/mode-golang"; import "ace-builds/src-noconflict/mode-golang";
import "ace-builds/src-noconflict/theme-github"; import "ace-builds/src-noconflict/theme-github";
import "ace-builds/src-noconflict/ext-language_tools";
import "ace-builds/src-noconflict/keybinding-vim";
interface CodeEditorProps { interface CodeEditorProps {
value: string; value: string;
@ -18,26 +17,30 @@ export let CodeEditor: FC<CodeEditorProps> = ({
onChange, onChange,
oneLine = false, oneLine = false,
width = 500, width = 500,
}: CodeEditorProps) => ( }: CodeEditorProps) => {
<AceEditor let lineCount = value.split("\n").length;
value={value} let id = _.uniqueId();
mode="golang" return (
theme="github" <AceEditor
width={width + "px"} value={value}
maxLines={oneLine ? 1 : 15} mode="golang"
minLines={oneLine ? 1 : 15} theme="github"
showGutter={false} width={width + "px"}
highlightActiveLine={false} minLines={oneLine ? lineCount : 15}
showPrintMargin={false} maxLines={oneLine ? lineCount : 15}
onChange={onChange} showGutter={false}
name="UNIQUE_ID_OF_DIV" highlightActiveLine={false}
editorProps={{ showPrintMargin={false}
$blockScrolling: true, onChange={onChange}
}} name={id}
setOptions={{ editorProps={{
enableBasicAutocompletion: false, $blockScrolling: true,
enableLiveAutocompletion: true, }}
}} setOptions={{
/> enableBasicAutocompletion: false,
); enableLiveAutocompletion: false,
}}
/>
);
};
export default CodeEditor; export default CodeEditor;

View File

@ -66,7 +66,7 @@ export let SquiggleEditor: React.FC<SquiggleEditorProps> = ({
); );
}; };
export function renderSquiggleEditor(props: SquiggleEditorProps) { export function renderSquiggleEditorToDom(props: SquiggleEditorProps) {
let parent = document.createElement("div"); let parent = document.createElement("div");
ReactDOM.render( ReactDOM.render(
<SquiggleEditor <SquiggleEditor

View File

@ -20,8 +20,8 @@ function FieldFloat(Props: FieldFloatProps) {
<Input <Input
value={contents} value={contents}
className={Props.className ? Props.className : ""} className={Props.className ? Props.className : ""}
onChange={(e) => setContents(e.target.value)} onChange={(e) => {
onBlur={() => { setContents(e.target.value);
let result = parseFloat(contents); let result = parseFloat(contents);
if (_.isFinite(result)) { if (_.isFinite(result)) {
Props.onChange(result); Props.onChange(result);
@ -123,7 +123,7 @@ let SquigglePlayground: FC<Props> = (props) => {
); );
}; };
export default SquigglePlayground; export default SquigglePlayground;
export function renderSquigglePlayground(props: Props) { export function renderSquigglePlaygroundToDom(props: Props) {
let parent = document.createElement("div"); let parent = document.createElement("div");
ReactDOM.render(<SquigglePlayground {...props} />, parent); ReactDOM.render(<SquigglePlayground {...props} />, parent);
return parent; return parent;

View File

@ -1,6 +1,6 @@
export { SquiggleChart } from "./SquiggleChart"; export { SquiggleChart } from "./SquiggleChart";
export { SquiggleEditor, renderSquiggleEditor } from "./SquiggleEditor"; export { SquiggleEditor, renderSquiggleEditorToDom } from "./SquiggleEditor";
import SquigglePlayground, { import SquigglePlayground, {
renderSquigglePlayground, renderSquigglePlaygroundToDom,
} from "./SquigglePlayground"; } from "./SquigglePlayground";
export { SquigglePlayground, renderSquigglePlayground }; export { SquigglePlayground, renderSquigglePlaygroundToDom };

View File

@ -16,21 +16,19 @@
{ {
"name": "xscale", "name": "xscale",
"description": "The transform of the x scale", "description": "The transform of the x scale",
"value": 1.0, "value": false,
"bind": { "bind": {
"input": "select", "input": "checkbox",
"options": [0.1, 1], "name": "log x scale"
"labels": ["log", "linear"]
} }
}, },
{ {
"name": "yscale", "name": "yscale",
"description": "The transform of the y scale", "description": "The transform of the y scale",
"value": 1.0, "value": false,
"bind": { "bind": {
"input": "select", "input": "checkbox",
"options": [0.1, 1], "name": "log y scale"
"labels": ["log", "linear"]
} }
} }
], ],
@ -39,7 +37,7 @@
{ {
"name": "xscale", "name": "xscale",
"type": "pow", "type": "pow",
"exponent": { "signal": "xscale" }, "exponent": { "signal": "xscale ? 0.1 : 1" },
"range": "width", "range": "width",
"zero": false, "zero": false,
"nice": false, "nice": false,
@ -53,7 +51,7 @@
{ {
"name": "yscale", "name": "yscale",
"type": "pow", "type": "pow",
"exponent": { "signal": "yscale" }, "exponent": { "signal": "yscale ? 0.1 : 1" },
"range": "height", "range": "height",
"nice": true, "nice": true,
"zero": true, "zero": true,

View File

@ -20,3 +20,16 @@ the distribution.
{Template.bind({})} {Template.bind({})}
</Story> </Story>
</Canvas> </Canvas>
You can also name variables like so:
<Canvas>
<Story
name="Variables"
args={{
initialSquiggleString: "x = 2\nnormal(x,2)",
}}
>
{Template.bind({})}
</Story>
</Canvas>