Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit f233e7a

Browse files
committed
started with login example
1 parent c9b4d73 commit f233e7a

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

examples/components/TextInput.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import Input from '@cat-react/form/Input'
3+
4+
@Input
5+
export default class TextInput extends React.Component {
6+
onChange(event) {
7+
this.props.setValue(event.target.value);
8+
}
9+
10+
renderErrors() {
11+
let errorMessages = [];
12+
if (!this.props.isPristine()) {
13+
errorMessages = this.props.getErrorMessages();
14+
}
15+
16+
if (!errorMessages || errorMessages.length <= 0) {
17+
return null;
18+
}
19+
20+
return <ul>{errorMessages.map((message, i) => <li key={i}>{message}</li>)}</ul>;
21+
}
22+
23+
render() {
24+
let className = '';
25+
if (!this.props.isPristine()) {
26+
className = this.props.isValid() ? null : 'error';
27+
}
28+
29+
// TODO: remove onBlur
30+
return (
31+
<label>
32+
{this.props.label} {this.props.isRequired() ? '*' : null}
33+
<input className={className}
34+
type="text"
35+
value={this.props.getValue()}
36+
onChange={this.onChange.bind(this)}
37+
onBlur={this.props.onBlur}/>
38+
{this.renderErrors()}
39+
</label>
40+
);
41+
}
42+
}

examples/login/app.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3+
import Form from '@cat-react/form/Form';
4+
import TextInput from '../components/TextInput';
35

46
class App extends React.Component {
57
render() {
6-
return <div>Login</div>;
8+
return (
9+
<Form>
10+
<h1>Login</h1>
11+
<TextInput label="Username" name="username" value="" validations={{isRequired: true}} />
12+
</Form>
13+
);
714
};
815
}
916

examples/webpack.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
entry: fs.readdirSync(__dirname).reduce(function (entries, dir) {
88
const isDir = fs.lstatSync(path.join(__dirname, dir)).isDirectory();
99

10-
if (isDir) {
10+
if (isDir && dir !== 'components') {
1111
entries[dir] = path.join(__dirname, dir, 'app.js');
1212
}
1313

@@ -26,7 +26,8 @@ module.exports = {
2626
exclude: /node_modules/,
2727
loader: 'babel-loader',
2828
query: {
29-
presets: ['es2015', 'react']
29+
presets: ['es2015', 'react', 'stage-0'],
30+
plugins: ['transform-runtime', 'transform-class-properties', 'transform-decorators-legacy']
3031
}
3132
}
3233
]

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"babel-loader": "^7.1.2",
2222
"babel-plugin-transform-class-properties": "^6.24.1",
2323
"babel-plugin-transform-decorators-legacy": "^1.3.4",
24+
"babel-plugin-transform-runtime": "^6.23.0",
2425
"babel-preset-es2015": "^6.24.1",
2526
"babel-preset-react": "^6.24.1",
2627
"babel-preset-stage-0": "^6.24.1",

yarn.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,12 @@ babel-plugin-transform-regenerator@^6.24.1:
826826
dependencies:
827827
regenerator-transform "^0.10.0"
828828

829+
babel-plugin-transform-runtime@^6.23.0:
830+
version "6.23.0"
831+
resolved "https://registry.yarnpkg.com/babel-plugin-transform-runtime/-/babel-plugin-transform-runtime-6.23.0.tgz#88490d446502ea9b8e7efb0fe09ec4d99479b1ee"
832+
dependencies:
833+
babel-runtime "^6.22.0"
834+
829835
babel-plugin-transform-strict-mode@^6.24.1:
830836
version "6.24.1"
831837
resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758"

0 commit comments

Comments
 (0)