File tree Expand file tree Collapse file tree 5 files changed +129
-5
lines changed
impl-react/src/Components Expand file tree Collapse file tree 5 files changed +129
-5
lines changed Original file line number Diff line number Diff line change 4
4
</ nav >
5
5
6
6
< div class ="container ">
7
- < form >
7
+ < form *ngIf ="true ">
8
+ < div *ngFor ="let config of formConfig " [ngSwitch] ="config.type ">
9
+ < app-email *ngSwitchCase ="'email' " [config] ="config "> </ app-email >
10
+ < app-secret *ngSwitchCase ="'secret' " [config] ="config "> </ app-secret >
11
+ < app-toggle *ngSwitchCase ="'toggle' " [config] ="config "> </ app-toggle >
12
+ < app-submit *ngSwitchCase ="'submit' " [config] ="config "> </ app-submit >
13
+ </ div >
14
+ </ form >
15
+
16
+
17
+
18
+ < form *ngIf ="false ">
8
19
< div class ="form-group ">
9
20
< label > Email</ label >
10
21
< input type ="email " class ="form-control " />
Original file line number Diff line number Diff line change @@ -2,13 +2,15 @@ import { BrowserModule } from '@angular/platform-browser';
2
2
import { NgModule } from '@angular/core' ;
3
3
4
4
import { AppComponent } from './app.component' ;
5
+ import * as Controls from './controls' ;
5
6
6
7
@NgModule ( {
7
8
declarations : [
8
- AppComponent
9
+ AppComponent ,
10
+ ...Object . values ( Controls ) ,
9
11
] ,
10
12
imports : [
11
- BrowserModule
13
+ BrowserModule ,
12
14
] ,
13
15
providers : [ ] ,
14
16
bootstrap : [ AppComponent ]
Original file line number Diff line number Diff line change
1
+ import { Component , Input } from '@angular/core' ;
2
+
3
+ @Component ( {
4
+ selector : 'app-email' ,
5
+ template : `
6
+ <div class="form-group">
7
+ <label>{{ config.label }}</label>
8
+ <input type="email" class="form-control" />
9
+ </div>
10
+ ` } )
11
+ export class EmailComponent {
12
+ @Input ( ) config : any ;
13
+ }
14
+
15
+
16
+
17
+ @Component ( {
18
+ selector : 'app-secret' ,
19
+ template : `
20
+ <div class="form-group">
21
+ <label>{{ config.label }}</label>
22
+ <input type="password" class="form-control" />
23
+ </div>
24
+ ` } )
25
+ export class SecretComponent {
26
+ @Input ( ) config : any ;
27
+ }
28
+
29
+
30
+
31
+ @Component ( {
32
+ selector : 'app-toggle' ,
33
+ template : `
34
+ <div class="form-group form-check">
35
+ <input type="checkbox" class="form-check-input" />
36
+ <label class="form-check-label">{{ config.label }}</label>
37
+ </div>
38
+ ` } )
39
+ export class ToggleComponent {
40
+ @Input ( ) config : any ;
41
+ }
42
+
43
+
44
+
45
+ @Component ( {
46
+ selector : 'app-submit' ,
47
+ template : `
48
+ <button type="submit" class="btn btn-primary">{{ config.label }}</button>
49
+ ` } )
50
+ export class SubmitComponent {
51
+ @Input ( ) config : any ;
52
+ }
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
2
import './App.css' ;
3
3
import { formConfig } from '../FormBuilder/formConfig.js' ;
4
+ import * as Controls from './controls' ;
4
5
5
6
export class App extends Component {
6
7
render ( ) {
@@ -11,7 +12,18 @@ export class App extends Component {
11
12
</ nav >
12
13
13
14
< div className = "container" >
14
- < form >
15
+ { formConfig . map ( ( config , index ) => {
16
+ switch ( config . type ) {
17
+ case 'email' : return < Controls . Email key = { index } config = { config } /> ;
18
+ case 'secret' : return < Controls . Secret key = { index } config = { config } /> ;
19
+ case 'toggle' : return < Controls . Toggle key = { index } config = { config } /> ;
20
+ case 'submit' : return < Controls . Submit key = { index } config = { config } /> ;
21
+ default : return null ;
22
+ }
23
+ } ) }
24
+
25
+
26
+ { /*<form>
15
27
<div className="form-group">
16
28
<label>Email</label>
17
29
<input type="email" className="form-control" />
@@ -25,7 +37,7 @@ export class App extends Component {
25
37
<label className="form-check-label">Remain logged in</label>
26
38
</div>
27
39
<button type="submit" className="btn btn-primary">Login</button>
28
- </ form >
40
+ </form>*/ }
29
41
</ div >
30
42
</ div >
31
43
) ;
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react' ;
2
+
3
+ export class Email extends Component {
4
+ render ( ) {
5
+ const { config} = this . props ;
6
+ return (
7
+ < div className = "form-group" >
8
+ < label > { config . label } </ label >
9
+ < input type = "email" className = "form-control" />
10
+ </ div >
11
+ ) ;
12
+ }
13
+ }
14
+
15
+ export class Secret extends Component {
16
+ render ( ) {
17
+ const { config} = this . props ;
18
+ return (
19
+ < div className = "form-group" >
20
+ < label > { config . label } </ label >
21
+ < input type = "password" className = "form-control" />
22
+ </ div >
23
+ ) ;
24
+ }
25
+ }
26
+
27
+ export class Toggle extends Component {
28
+ render ( ) {
29
+ const { config} = this . props ;
30
+ return (
31
+ < div className = "form-group form-check" >
32
+ < input type = "checkbox" className = "form-check-input" />
33
+ < label className = "form-check-label" > { config . label } </ label >
34
+ </ div >
35
+ ) ;
36
+ }
37
+ }
38
+
39
+
40
+ export class Submit extends Component {
41
+ render ( ) {
42
+ const { config} = this . props ;
43
+ return (
44
+ < button type = "submit" className = "btn btn-primary" > { config . label } </ button >
45
+ ) ;
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments