11import 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