This repository was archived by the owner on Feb 29, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +60
-3
lines changed Expand file tree Collapse file tree 5 files changed +60
-3
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import ReactDOM from 'react-dom' ;
3
+ import Form from '@cat-react/form/Form' ;
4
+ import TextInput from '../components/TextInput' ;
3
5
4
6
class App extends React . Component {
5
7
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
+ ) ;
7
14
} ;
8
15
}
9
16
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ module.exports = {
7
7
entry : fs . readdirSync ( __dirname ) . reduce ( function ( entries , dir ) {
8
8
const isDir = fs . lstatSync ( path . join ( __dirname , dir ) ) . isDirectory ( ) ;
9
9
10
- if ( isDir ) {
10
+ if ( isDir && dir !== 'components' ) {
11
11
entries [ dir ] = path . join ( __dirname , dir , 'app.js' ) ;
12
12
}
13
13
@@ -26,7 +26,8 @@ module.exports = {
26
26
exclude : / n o d e _ m o d u l e s / ,
27
27
loader : 'babel-loader' ,
28
28
query : {
29
- presets : [ 'es2015' , 'react' ]
29
+ presets : [ 'es2015' , 'react' , 'stage-0' ] ,
30
+ plugins : [ 'transform-runtime' , 'transform-class-properties' , 'transform-decorators-legacy' ]
30
31
}
31
32
}
32
33
]
Original file line number Diff line number Diff line change 21
21
"babel-loader" : " ^7.1.2" ,
22
22
"babel-plugin-transform-class-properties" : " ^6.24.1" ,
23
23
"babel-plugin-transform-decorators-legacy" : " ^1.3.4" ,
24
+ "babel-plugin-transform-runtime" : " ^6.23.0" ,
24
25
"babel-preset-es2015" : " ^6.24.1" ,
25
26
"babel-preset-react" : " ^6.24.1" ,
26
27
"babel-preset-stage-0" : " ^6.24.1" ,
Original file line number Diff line number Diff line change @@ -826,6 +826,12 @@ babel-plugin-transform-regenerator@^6.24.1:
826
826
dependencies :
827
827
regenerator-transform "^0.10.0"
828
828
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
+
829
835
babel-plugin-transform-strict-mode@^6.24.1 :
830
836
version "6.24.1"
831
837
resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758"
You can’t perform that action at this time.
0 commit comments