Skip to content

Commit

Permalink
General Maintenance (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikras authored Apr 14, 2017
1 parent 373bb32 commit a0f4fce
Show file tree
Hide file tree
Showing 30 changed files with 1,361 additions and 1,087 deletions.
16 changes: 1 addition & 15 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
{
"extends": "eslint-config-rackt",
"parser": "babel-eslint",
"env": {
"browser": true,
"mocha": true,
"node": true
},
"rules": {
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/jsx-no-undef": 2
},
"plugins": [
"react"
]
"extends": "react-app"
}
6 changes: 6 additions & 0 deletions example/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "react-app",
"rules": {
"import/no-webpack-loader-syntax": 0
}
}
54 changes: 27 additions & 27 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@
"prepublish": "npm run lint && npm run build"
},
"dependencies": {
"babel-polyfill": "^6.16.0",
"html-loader": "^0.4.4",
"babel-polyfill": "^6.23.0",
"html-loader": "^0.4.5",
"json-loader": "^0.5.4",
"markdown-loader": "^0.1.7",
"material-ui": "^0.16.4",
"markdown-loader": "^2.0.0",
"material-ui": "^0.17.3",
"raw-loader": "^0.5.1",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-redux": "^4.4.6",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-redux": "^5.0.4",
"react-tap-event-plugin": "^2.0.1",
"redux": "^3.6.0",
"redux-form": "^6.4.3",
"redux-form": "^6.6.3",
"redux-form-material-ui": "file:../",
"redux-form-website-template": "0.0.39"
"redux-form-website-template": "0.0.41"
},
"devDependencies": {
"babel-core": "^6.18.2",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.2.8",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-2": "^6.18.0",
"cross-env": "^3.1.3",
"eslint": "^3.11.1",
"babel-core": "^6.24.1",
"babel-eslint": "^7.2.2",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"cross-env": "^4.0.0",
"eslint": "^3.19.0",
"eslint-config-rackt": "^1.1.1",
"eslint-loader": "^1.6.1",
"eslint-plugin-babel": "^4.0.0",
"eslint-plugin-react": "^6.7.1",
"eslint-loader": "^1.7.1",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-react": "^6.10.3",
"eventsource-polyfill": "^0.9.6",
"express": "^4.13.3",
"extract-text-webpack-plugin": "^1.0.1",
"redbox-react": "^1.3.3",
"rimraf": "^2.4.3",
"webpack": "^1.13.3",
"webpack-dev-middleware": "^1.8.4",
"webpack-hot-middleware": "^2.13.2"
"express": "^4.15.2",
"extract-text-webpack-plugin": "^2.1.0",
"redbox-react": "^1.3.6",
"rimraf": "^2.6.1",
"webpack": "^2.3.3",
"webpack-dev-middleware": "^1.10.1",
"webpack-hot-middleware": "^2.18.0"
}
}
169 changes: 90 additions & 79 deletions example/src/Form.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { Component } from 'react'
import { Field, reduxForm } from 'redux-form'
import { RadioButton } from 'material-ui/RadioButton'
import MenuItem from 'material-ui/MenuItem'
import { AutoComplete as MUIAutoComplete } from 'material-ui'
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {Field, reduxForm, formValueSelector} from 'redux-form';
import {RadioButton} from 'material-ui/RadioButton';
import MenuItem from 'material-ui/MenuItem';
import {AutoComplete as MUIAutoComplete} from 'material-ui';
import {
AutoComplete,
Checkbox,
Expand All @@ -12,175 +13,185 @@ import {
SelectField,
Slider,
TextField,
Toggle
} from 'redux-form-material-ui'
Toggle,
} from 'redux-form-material-ui';

// validation functions
const required = value => value == null ? 'Required' : undefined
const email = value => value &&
!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value) ? 'Invalid email' : undefined
const tooManyPizzas = value => value > 15 ? 'Are you mad?' : undefined
const required = value => (value == null ? 'Required' : undefined);
const email = value =>
(value && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value)
? 'Invalid email'
: undefined);
const tooManyPizzas = value => (value > 15 ? 'Are you mad?' : undefined);

class Form extends Component {

constructor(props) {
super(props)
this.onSlideChange = this.onSlideChange.bind(this)
this.state = { pizzas: 0 }
}

componentDidMount() {
this.refs.name // the Field
this.refs.name // the Field
.getRenderedComponent() // on Field, returns ReduxFormMaterialUITextField
.getRenderedComponent() // on ReduxFormMaterialUITextField, returns TextField
.focus() // on TextField
}

onSlideChange(value) {
this.setState({ pizzas: value })
.focus(); // on TextField
}

render() {
const { handleSubmit, pristine, reset, submitting } = this.props
const {handleSubmit, pristine, numPizzas, reset, submitting} = this.props;
return (
<form onSubmit={handleSubmit}>
<div>
<Field name="name"
<Field
name="name"
component={TextField}
hintText="Name"
floatingLabelText="Name"
validate={required}
ref="name" withRef/>
ref="name"
withRef
/>
</div>
<div>
<Field name="email"
<Field
name="email"
component={TextField}
hintText="Email"
floatingLabelText="Email"
validate={[ required, email ]}/>
validate={[required, email]}
/>
</div>
<div>
<Field name="delivery" component={RadioButtonGroup}>
<RadioButton value="pickup" label="Pickup"/>
<RadioButton value="delivery" label="Delivery"/>
<RadioButton value="pickup" label="Pickup" />
<RadioButton value="delivery" label="Delivery" />
</Field>
</div>
<div>How many pizzas do you want?</div>
<div>{numPizzas}</div>
<div>
<Field
name="pizzas"
component={Slider}
description={'How many pizzas? (' + this.state.pizzas + ' pizzas chosen)'}
defaultValue={0}
format={null}
min={0}
max={20}
step={1}
onChange={this.onSlideChange}/>
warn={tooManyPizzas}/>
warn={tooManyPizzas}
/>
</div>
<div>
<Field
name="driver"
component={SelectField}
hintText="Driver"
floatingLabelText="Driver"
validate={required}>
<MenuItem value="[email protected]" primaryText="Alice"/>
<MenuItem value="[email protected]" primaryText="Bob"/>
<MenuItem value="[email protected]" primaryText="Carl"/>
validate={required}
>
<MenuItem value="[email protected]" primaryText="Alice" />
<MenuItem value="[email protected]" primaryText="Bob" />
<MenuItem value="[email protected]" primaryText="Carl" />
</Field>
</div>
<div>
<Field name="thinCrust" component={Toggle} label="Thin Crust" labelPosition="right"/>
<Field
name="thinCrust"
component={Toggle}
label="Thin Crust"
labelPosition="right"
/>
</div>
<div>
<Field name="pepperoni" component={Checkbox}
onCheck={value => {
console.log('onCheck ', value ) // eslint-disable-line no-console
}}
label="Pepperoni"/>
<Field name="pepperoni" component={Checkbox} label="Pepperoni" />
</div>
<div>
<Field name="mushrooms" component={Checkbox} label="Mushrooms"/>
<Field name="mushrooms" component={Checkbox} label="Mushrooms" />
</div>
<div>
<Field name="peppers" component={Checkbox} label="Peppers"/>
<Field name="peppers" component={Checkbox} label="Peppers" />
</div>
<div>
<Field name="when"
<Field
name="when"
component={DatePicker}
format={null}
onChange={(value) => {
console.log('date changed ', value) // eslint-disable-line no-console
}}
hintText="Day of delivery?"
validate={required}/>
validate={required}
/>
</div>
<div>
<Field name="at"
<Field
name="at"
component={TimePicker}
format={null}
defaultValue={null} // TimePicker requires an object,
// and redux-form defaults to ''
onChange={(value) => {
console.log('time changed ', value) // eslint-disable-line no-console
}}
// and redux-form defaults to ''
hintText="At what time?"
validate={required}/>
validate={required}
/>
</div>
<div>
<Field
name="notes"
component={TextField}
hintText="Notes"
floatingLabelText="Notes"
multiLine={true}
rows={2}/>
multiLine
rows={2}
/>
</div>
<div>
<Field
name="cheese"
component={AutoComplete}
floatingLabelText="Cheese"
openOnFocus={true}
openOnFocus
filter={MUIAutoComplete.fuzzyFilter}
onNewRequest={value => {
console.log('AutoComplete ', value) // eslint-disable-line no-console
}}
dataSource={[ 'Cheddar', 'Mozzarella', 'Parmesan', 'Provolone' ]}
/>
dataSource={['Cheddar', 'Mozzarella', 'Parmesan', 'Provolone']}
/>
</div>
<div>
<Field
name="referral"
component={AutoComplete}
floatingLabelText="How did you find us?"
openOnFocus={true}
openOnFocus
filter={MUIAutoComplete.fuzzyFilter}
dataSourceConfig={{ text: 'name', value: 'id' }}
dataSourceConfig={{text: 'name', value: 'id'}}
dataSource={[
{ id: 0, name: 'Facebook' },
{ id: 1, name: 'Yelp' },
{ id: 2, name: 'TV Ad' },
{ id: 3, name: 'Friend' },
{ id: 4, name: 'Other' }
]}/>
{id: 0, name: 'Facebook'},
{id: 1, name: 'Yelp'},
{id: 2, name: 'TV Ad'},
{id: 3, name: 'Friend'},
{id: 4, name: 'Other'},
]}
/>
</div>
<div>
<button type="submit" disabled={submitting}>Submit</button>
<button type="button" disabled={pristine || submitting} onClick={reset}>Clear</button>
<button
type="button"
disabled={pristine || submitting}
onClick={reset}
>
Clear
</button>
</div>
</form>
)
);
}
}

export default reduxForm({
const selector = formValueSelector('example');

Form = connect(state => ({
numPizzas: selector(state, 'pizzas'),
}))(Form);

Form = reduxForm({
form: 'example',
initialValues: {
delivery: 'delivery',
name: 'Jane Doe',
cheese: 'Cheddar'
}
})(Form)
cheese: 'Cheddar',
pizzas: 1,
},
})(Form);

export default Form;
Loading

0 comments on commit a0f4fce

Please sign in to comment.