From e1295e4f0fc19b80b4cee305a8abda2d2e1c185f Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Wed, 6 Apr 2022 11:18:18 +1000 Subject: [PATCH] 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 --- packages/components/src/CodeEditor.tsx | 51 ++++++++++--------- packages/components/src/SquiggleEditor.tsx | 2 +- .../components/src/SquigglePlayground.tsx | 6 +-- packages/components/src/index.ts | 6 +-- .../components/src/spec-distributions.json | 18 +++---- .../src/stories/SquiggleEditor.stories.mdx | 13 +++++ 6 files changed, 55 insertions(+), 41 deletions(-) diff --git a/packages/components/src/CodeEditor.tsx b/packages/components/src/CodeEditor.tsx index f2634307..3cee774e 100644 --- a/packages/components/src/CodeEditor.tsx +++ b/packages/components/src/CodeEditor.tsx @@ -1,10 +1,9 @@ +import _ from "lodash"; import React, { FC } from "react"; import AceEditor from "react-ace"; import "ace-builds/src-noconflict/mode-golang"; import "ace-builds/src-noconflict/theme-github"; -import "ace-builds/src-noconflict/ext-language_tools"; -import "ace-builds/src-noconflict/keybinding-vim"; interface CodeEditorProps { value: string; @@ -18,26 +17,30 @@ export let CodeEditor: FC = ({ onChange, oneLine = false, width = 500, -}: CodeEditorProps) => ( - -); +}: CodeEditorProps) => { + let lineCount = value.split("\n").length; + let id = _.uniqueId(); + return ( + + ); +}; export default CodeEditor; diff --git a/packages/components/src/SquiggleEditor.tsx b/packages/components/src/SquiggleEditor.tsx index 7bb741f8..37b471da 100644 --- a/packages/components/src/SquiggleEditor.tsx +++ b/packages/components/src/SquiggleEditor.tsx @@ -66,7 +66,7 @@ export let SquiggleEditor: React.FC = ({ ); }; -export function renderSquiggleEditor(props: SquiggleEditorProps) { +export function renderSquiggleEditorToDom(props: SquiggleEditorProps) { let parent = document.createElement("div"); ReactDOM.render( setContents(e.target.value)} - onBlur={() => { + onChange={(e) => { + setContents(e.target.value); let result = parseFloat(contents); if (_.isFinite(result)) { Props.onChange(result); @@ -123,7 +123,7 @@ let SquigglePlayground: FC = (props) => { ); }; export default SquigglePlayground; -export function renderSquigglePlayground(props: Props) { +export function renderSquigglePlaygroundToDom(props: Props) { let parent = document.createElement("div"); ReactDOM.render(, parent); return parent; diff --git a/packages/components/src/index.ts b/packages/components/src/index.ts index a3df37b7..48aa2b16 100644 --- a/packages/components/src/index.ts +++ b/packages/components/src/index.ts @@ -1,6 +1,6 @@ export { SquiggleChart } from "./SquiggleChart"; -export { SquiggleEditor, renderSquiggleEditor } from "./SquiggleEditor"; +export { SquiggleEditor, renderSquiggleEditorToDom } from "./SquiggleEditor"; import SquigglePlayground, { - renderSquigglePlayground, + renderSquigglePlaygroundToDom, } from "./SquigglePlayground"; -export { SquigglePlayground, renderSquigglePlayground }; +export { SquigglePlayground, renderSquigglePlaygroundToDom }; diff --git a/packages/components/src/spec-distributions.json b/packages/components/src/spec-distributions.json index f87c93b7..8a5bbff9 100644 --- a/packages/components/src/spec-distributions.json +++ b/packages/components/src/spec-distributions.json @@ -16,21 +16,19 @@ { "name": "xscale", "description": "The transform of the x scale", - "value": 1.0, + "value": false, "bind": { - "input": "select", - "options": [0.1, 1], - "labels": ["log", "linear"] + "input": "checkbox", + "name": "log x scale" } }, { "name": "yscale", "description": "The transform of the y scale", - "value": 1.0, + "value": false, "bind": { - "input": "select", - "options": [0.1, 1], - "labels": ["log", "linear"] + "input": "checkbox", + "name": "log y scale" } } ], @@ -39,7 +37,7 @@ { "name": "xscale", "type": "pow", - "exponent": { "signal": "xscale" }, + "exponent": { "signal": "xscale ? 0.1 : 1" }, "range": "width", "zero": false, "nice": false, @@ -53,7 +51,7 @@ { "name": "yscale", "type": "pow", - "exponent": { "signal": "yscale" }, + "exponent": { "signal": "yscale ? 0.1 : 1" }, "range": "height", "nice": true, "zero": true, diff --git a/packages/components/src/stories/SquiggleEditor.stories.mdx b/packages/components/src/stories/SquiggleEditor.stories.mdx index 9f3a5a1a..9c86d4b6 100644 --- a/packages/components/src/stories/SquiggleEditor.stories.mdx +++ b/packages/components/src/stories/SquiggleEditor.stories.mdx @@ -20,3 +20,16 @@ the distribution. {Template.bind({})} + +You can also name variables like so: + + + + {Template.bind({})} + +