Skip to content

Commit a009bb7

Browse files
authored
Move example core directly into README (#257)
* Switch to np for clean releases * Move example core directly into README * Add peer dependencies to README
1 parent a9beb93 commit a009bb7

File tree

15 files changed

+1362
-523
lines changed

15 files changed

+1362
-523
lines changed

README.md

Lines changed: 167 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,33 @@
1-
# Help Wanted
1+
# ⚠️ Help Wanted ⚠️
22

3-
This package is currently being updated after a long hiatus, and all help is appreciated.
4-
5-
In the meantime, here are some alternatives:
6-
7-
- https://www.npmjs.com/package/react-material-ui-form-validator
8-
- https://redux-form.com/6.6.2/examples/material-ui/
9-
- https://github.com/foxhound87/mobx-react-form
3+
This package is currently under active restoration after a long hiatus, and all help is appreciated, especially MUI users.
104

115
# formsy-material-ui [![npm version](https://badge.fury.io/js/formsy-material-ui.svg)](https://badge.fury.io/js/formsy-material-ui) [![Build Status](https://travis-ci.org/mbrookes/formsy-material-ui.svg?branch=master)](https://travis-ci.org/mbrookes/formsy-material-ui)
126

137
This library is a wrapper for [Material-UI](http://material-ui.com/) form components to allow them to be used with
14-
[formsy-react](https://github.com/christianalfoni/formsy-react), a form validation component for React forms.
8+
[formsy-react](https://github.com/formsy/formsy-react), a form validation component for React forms.
159

1610
## Installation
1711

1812
To and install formsy-material-ui and add it to your `package.json`, run:
1913

2014
```
21-
$ npm install --save formsy-material-ui
15+
$ yarn add formsy-material-ui
2216
```
2317

24-
You will also need to add formsy-react if not already installed:
18+
You will also need to add these peer dependencies if not already installed:
2519

26-
```
27-
$ npm install --save formsy-react
28-
```
29-
30-
Note: For React 15.0.x compatibility, specify `"formsy-react": "^0.18.0"`.
20+
- `create-react-class`
21+
- `formsy-react@0.19.5`
22+
- `material-ui@0.18.7`
23+
- `react-dom`
24+
- `react`
3125

3226
## Usage
3327

34-
### ES6 Imports
35-
36-
```js
37-
import FormsyCheckbox from 'formsy-material-ui/lib/FormsyCheckbox';
38-
import FormsyDate from 'formsy-material-ui/lib/FormsyDate';
39-
import FormsyRadio from 'formsy-material-ui/lib/FormsyRadio';
40-
import FormsyRadioGroup from 'formsy-material-ui/lib/FormsyRadioGroup';
41-
import FormsySelect from 'formsy-material-ui/lib/FormsySelect';
42-
import FormsyText from 'formsy-material-ui/lib/FormsyText';
43-
import FormsyTime from 'formsy-material-ui/lib/FormsyTime';
44-
import FormsyToggle from 'formsy-material-ui/lib/FormsyToggle';
45-
import FormsyAutoComplete from 'formsy-material-ui/lib/FormsyAutoComplete';
46-
```
47-
48-
OR:
49-
50-
```js
28+
```ts
5129
import {
30+
FormsyAutoComplete,
5231
FormsyCheckbox,
5332
FormsyDate,
5433
FormsyRadio,
@@ -57,8 +36,7 @@ import {
5736
FormsyText,
5837
FormsyTime,
5938
FormsyToggle,
60-
FormsyAutoComplete,
61-
} from 'formsy-material-ui/lib';
39+
} from 'formsy-material-ui';
6240
```
6341

6442
### Events
@@ -68,22 +46,161 @@ regardless of the underlying handler (eg, `FormsyToggle` uses `onToggle` interna
6846
props to hook into the event.)
6947

7048
The call back signatures for all `onChange` handlers conform to Material-UI's proposed
71-
[Standardized Callback Signatures](https://github.com/callemall/material-ui/issues/2957).
49+
[Standardized Callback Signatures](https://github.com/mui-org/material-ui/issues/2957).
7250

7351
An example usage of this would be to use an `onChange` for the FormsySelect and receive notifications when it changes.
7452

75-
### Examples
76-
77-
#### Example App
78-
79-
The `formsy-material-ui` repo contains a
80-
[sample webpack SPA](https://github.com/formsy/formsy-material-ui/tree/master/examples/webpack-example).
81-
82-
#### Example Code
53+
### Example Form
54+
55+
```tsx
56+
import React from 'react';
57+
import createClass from 'create-react-class';
58+
import Formsy from 'formsy-react';
59+
import getMuiTheme from 'material-ui/styles/getMuiTheme';
60+
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
61+
import Paper from 'material-ui/Paper';
62+
import RaisedButton from 'material-ui/RaisedButton';
63+
import MenuItem from 'material-ui/MenuItem';
64+
import {
65+
FormsyCheckbox,
66+
FormsyDate,
67+
FormsyRadio,
68+
FormsyRadioGroup,
69+
FormsySelect,
70+
FormsyText,
71+
FormsyTime,
72+
FormsyToggle,
73+
FormsyAutoComplete,
74+
} from 'formsy-material-ui/lib';
8375

84-
You can find an
85-
[example form](https://github.com/formsy/formsy-material-ui/blob/master/examples/webpack-example/src/app/Main.js#L80) in
86-
the example app directory.
76+
const Main = createClass<any, any>({
77+
/**
78+
* As an alternative to `MuiThemeProvider` you can add a theme directly into context.
79+
* See the [Material-UI themes](http://www.material-ui.com/#/customization/themes) docs for details.
80+
*
81+
* childContextTypes: {
82+
* muiTheme: PropTypes.object,
83+
* },
84+
* getChildContext(){
85+
* return {
86+
* muiTheme: getMuiTheme(),
87+
* }
88+
* },
89+
*/
90+
91+
getInitialState() {
92+
return {
93+
canSubmit: false,
94+
};
95+
},
96+
97+
errorMessages: {
98+
wordsError: 'Please only use letters',
99+
numericError: 'Please provide a number',
100+
urlError: 'Please provide a valid URL',
101+
},
102+
103+
styles: {
104+
paperStyle: {
105+
width: 300,
106+
margin: 'auto',
107+
padding: 20,
108+
},
109+
switchStyle: {
110+
marginBottom: 16,
111+
},
112+
submitStyle: {
113+
marginTop: 32,
114+
},
115+
},
116+
117+
enableButton() {
118+
this.setState({
119+
canSubmit: true,
120+
});
121+
},
122+
123+
disableButton() {
124+
this.setState({
125+
canSubmit: false,
126+
});
127+
},
128+
129+
submitForm(data) {
130+
alert(JSON.stringify(data, null, 4));
131+
},
132+
133+
notifyFormError(data) {
134+
console.error('Form error:', data);
135+
},
136+
137+
render() {
138+
let { paperStyle, switchStyle, submitStyle } = this.styles;
139+
let { wordsError, numericError, urlError } = this.errorMessages;
140+
141+
return (
142+
<MuiThemeProvider muiTheme={getMuiTheme()}>
143+
<Paper style={paperStyle}>
144+
<Formsy.Form
145+
onValid={this.enableButton}
146+
onInvalid={this.disableButton}
147+
onValidSubmit={this.submitForm}
148+
onInvalidSubmit={this.notifyFormError}
149+
>
150+
<FormsyDate name="date" required floatingLabelText="Date" />
151+
<FormsyTime name="time" required floatingLabelText="Time" />
152+
<FormsySelect name="frequency" required floatingLabelText="How often do you?">
153+
<MenuItem value={'never'} primaryText="Never" />
154+
<MenuItem value={'nightly'} primaryText="Every Night" />
155+
<MenuItem value={'weeknights'} primaryText="Weeknights" />
156+
</FormsySelect>
157+
<FormsyAutoComplete
158+
name="frequency-auto-complete"
159+
required
160+
floatingLabelText="How often do you?"
161+
dataSource={['Never', 'Every Night', 'Weeknights']}
162+
/>
163+
<FormsyCheckbox name="agree" label="Do you agree to disagree?" style={switchStyle} />
164+
<FormsyToggle name="toggle" label="Toggle" style={switchStyle} />
165+
<FormsyRadioGroup name="shipSpeed" defaultSelected="not_light">
166+
<FormsyRadio value="light" label="prepare for light speed" style={switchStyle} />
167+
<FormsyRadio value="not_light" label="light speed too slow" style={switchStyle} />
168+
<FormsyRadio value="ludicrous" label="go to ludicrous speed" style={switchStyle} disabled={true} />
169+
</FormsyRadioGroup>
170+
<FormsyText
171+
name="name"
172+
validations="isWords"
173+
validationError={wordsError}
174+
required
175+
hintText="What is your name?"
176+
floatingLabelText="Name"
177+
/>
178+
<FormsyText
179+
name="age"
180+
validations="isNumeric"
181+
validationError={numericError}
182+
hintText="Are you a wrinkly?"
183+
floatingLabelText="Age (optional)"
184+
/>
185+
<FormsyText
186+
name="url"
187+
validations="isUrl"
188+
validationError={urlError}
189+
required
190+
hintText="http://www.example.com"
191+
floatingLabelText="URL"
192+
updateImmediately
193+
/>
194+
<RaisedButton style={submitStyle} type="submit" label="Submit" disabled={!this.state.canSubmit} />
195+
</Formsy.Form>
196+
</Paper>
197+
</MuiThemeProvider>
198+
);
199+
},
200+
});
201+
202+
export default Main;
203+
```
87204

88205
## Known Issues
89206

@@ -104,5 +221,6 @@ Thanks to our [contributors](https://github.com/formsy/formsy-material-ui/graphs
104221

105222
Here are some alternative solutions you might also wish to consider:
106223

107-
- [react-material-ui-form-validator](https://github.com/NewOldMax/react-material-ui-form-validator)
108-
- Redux Form [Material-UI example](http://redux-form.com/6.1.1/examples/material-ui/)
224+
- [Validation component for material-ui forms](https://github.com/NewOldMax/react-material-ui-form-validator)
225+
- Redux Form [Material-UI example](https://redux-form.com/6.6.2/examples/material-ui/)
226+
- [MobX React Form](https://github.com/foxhound87/mobx-react-form)

examples/webpack-example/.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/webpack-example/.eslintrc

Lines changed: 0 additions & 35 deletions
This file was deleted.

examples/webpack-example/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/webpack-example/README.md

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)