Skip to content

Commit 37d32ff

Browse files
committed
feat(configure): finalize configure ui
1 parent fbdf1bb commit 37d32ff

File tree

3 files changed

+68
-45
lines changed

3 files changed

+68
-45
lines changed

packages/calculator/configure/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"test": "echo \"Error: no test specified\" && exit 1"
99
},
1010
"dependencies": {
11-
"@pie-framework/material-ui-calculator": "^1.1.1",
12-
"@pie-framework/pie-configure-events": "^1.2.0",
11+
"@pie-framework/pie-configure-events": "^1.3.0",
1312
"@pie-lib/config-ui": "^2.2.1",
13+
"@pie-ui/calculator": "^1.2.0",
1414
"react": "^15.6.1",
1515
"react-dom": "^15.6.1"
1616
},

packages/calculator/configure/src/index.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import Main from './main';
44
import { ModelUpdatedEvent } from '@pie-framework/pie-configure-events';
55

66
export default class extends HTMLElement {
7-
8-
constructor(){
7+
constructor() {
98
super();
10-
this._render();
119
this.onModelChanged = this.onModelChanged.bind(this);
1210
}
1311

@@ -16,21 +14,22 @@ export default class extends HTMLElement {
1614
this._render();
1715
}
1816

19-
dispatchModelUpdated() {
17+
onModelChanged(m) {
18+
this._model = m;
2019
this.dispatchEvent(new ModelUpdatedEvent(this._model, false));
2120
}
2221

23-
onModelChanged(m) {
24-
this._model = m;
25-
this.dispatchModelUpdated();
22+
connectedCallback() {
23+
this._render();
2624
}
2725

2826
_render() {
29-
let element = React.createElement(Main, {
30-
model: this._model,
31-
onModelChanged: this.onModelChanged
32-
});
33-
ReactDOM.render(element, this);
27+
if (this._model) {
28+
const element = React.createElement(Main, {
29+
model: this._model,
30+
onChange: this.onModelChanged
31+
});
32+
ReactDOM.render(element, this);
33+
}
3434
}
35-
36-
}
35+
}
Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,69 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import { InputRadio, TwoChoice } from '@pie-lib/config-ui';
2+
import { TwoChoice } from '@pie-lib/config-ui';
3+
import PropTypes from 'prop-types';
4+
import Typography from 'material-ui/Typography';
5+
import { CalculatorLayout } from '@pie-ui/calculator';
46

5-
export default class Main extends React.Component {
7+
const MainTypes = {
8+
model: PropTypes.object.isRequired,
9+
onChange: PropTypes.func.isRequired
10+
};
11+
12+
export class Main extends React.Component {
13+
static propTypes = MainTypes;
14+
15+
onModeChange = mode => {
16+
const { model } = this.props;
17+
const update = { ...model, mode };
18+
this.props.onChange(update);
19+
};
20+
21+
render() {
22+
const { model } = this.props;
23+
return (
24+
<div>
25+
<TwoChoice
26+
header="Choose a Calculator"
27+
value={model.mode}
28+
onChange={this.onModeChange}
29+
one={{ label: 'Basic', value: 'basic' }}
30+
two={{ label: 'Scientific', value: 'scientific' }}
31+
/>
32+
<br />
33+
<CalculatorLayout mode={model.mode} onClose={() => ({})} />
34+
<br />
35+
<br />
36+
37+
<Typography>
38+
Please note that the calculators are tools for students and do not
39+
record answers.
40+
</Typography>
41+
</div>
42+
);
43+
}
44+
}
45+
46+
export default class Stateful extends React.Component {
47+
static propTypes = MainTypes;
648

749
constructor(props) {
850
super(props);
951
this.state = {
10-
twoChoice: '',
1152
model: props.model
1253
};
1354
}
1455

15-
handleModelChange(){
16-
this.props.onModelChanged(this.state.model);
56+
componentWillReceiveProps(props) {
57+
this.setState({ model: props.model });
1758
}
1859

19-
update(model){
60+
onChange = model => {
2061
this.setState({ model }, () => {
21-
this.handleModelChange();
22-
})
23-
}
24-
25-
onChangeHandler = (twoChoice) => {
26-
this.setState({ twoChoice, model: this.props.model});
27-
let update = this.props.model;
28-
update.mode = twoChoice;
29-
this.update(update);
30-
}
62+
this.props.onChange(this.state.model);
63+
});
64+
};
3165

3266
render() {
33-
const { basic, scientific } = this.state;
34-
return (
35-
<div>
36-
<TwoChoice
37-
header="Choose Calculator Type"
38-
value={this.state.twoChoice}
39-
onChange={twoChoice => this.onChangeHandler(twoChoice)}
40-
one={{ label: 'Basic', value: 'basic' }}
41-
two={{ label: 'Scientific', value: 'scientific' }} />
42-
</div>
43-
);
67+
return <Main model={this.state.model} onChange={this.onChange} />;
4468
}
45-
}
69+
}

0 commit comments

Comments
 (0)