Skip to content

Commit 4f36d69

Browse files
committed
Add button to submit expression.
1 parent 8be4478 commit 4f36d69

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

src/Playground.css

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
.playground p.expression {
1+
form.playground p.expression {
22
display: flex;
33
align-items: center;
44
}
5-
.playground p.expression * {
5+
form.playground p.expression label,
6+
form.playground p.expression input {
67
font-family: monospace !important;
78
}
8-
.playground p.expression input {
9+
form.playground p.expression input,
10+
form.playground p.expression button {
11+
height: 2em;
12+
border: 1px solid #ccc;
13+
box-sizing: border-box;
14+
}
15+
form.playground p.expression input {
916
flex-grow: 1;
17+
margin-right: 1ex;
18+
}
19+
form.playground p.expression button {
20+
font-weight: bold;
21+
}
22+
form.playground p.expression button:hover,
23+
form.playground p.expression button:active {
24+
background-color: #ccc;
25+
}
26+
form.playground p.expression button:active {
27+
margin: 1px -1px -1px 1px;
1028
}
1129

12-
.playground p.single [data-error]:before {
30+
form.playground p.single [data-error]:before {
1331
content: 'Expression error: ' attr(data-error);
1432
font-style: italic;
1533
font-weight: bold;

src/Playground.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,35 @@ import { Value, List } from '@solid/react';
33
import './Playground.css';
44

55
export default class Playground extends React.Component {
6-
state = { expression: this.props.expression };
6+
state = {
7+
input: this.props.expression,
8+
expression: this.props.expression,
9+
};
710

811
componentDidUpdate({ expression }) {
912
if (this.props.expression !== expression)
1013
this.setState({ expression: this.props.expression });
1114
}
1215

13-
onExpressionChanged({ target: { value: expression } }) {
16+
onChangeInput = event => {
17+
this.setState({ input: event.target.value });
18+
}
19+
20+
onSubmitInput = event => {
21+
const expression = this.state.input;
1422
this.setState({ expression });
1523
if (this.props.onExpressionChange)
1624
this.props.onExpressionChange(expression);
1725
}
1826

1927
render() {
20-
const { expression } = this.state;
28+
const { input, expression } = this.state;
2129
return (
22-
<div className="playground">
30+
<form className="playground" onSubmit={this.onSubmitInput}>
2331
<p className="expression">
2432
<label><code>solid.data</code></label>
25-
<input value={expression}
26-
onChange={e => this.onExpressionChanged(e)}/>
33+
<input value={input} onChange={this.onChangeInput} required />
34+
<button>Execute</button>
2735
</p>
2836
<h3>Single result</h3>
2937
<p className="single"><Value src={expression}/></p>
@@ -33,7 +41,7 @@ export default class Playground extends React.Component {
3341
<pre className="sparql"><code>
3442
<Value src={expression && `${expression}.sparql`}/>
3543
</code></pre>
36-
</div>
44+
</form>
3745
);
3846
}
3947
}

0 commit comments

Comments
 (0)