refactor: IFormControl to FormControlBase and added radio prop (#6)
Fixes #6: refactored IFormControl to FormControlBase and added radio prop.
This commit is contained in:
commit
2393186c43
2 changed files with 9 additions and 9 deletions
|
@ -25,7 +25,7 @@ type FormControlType =
|
||||||
| 'url'
|
| 'url'
|
||||||
| 'week';
|
| 'week';
|
||||||
|
|
||||||
export interface IFormControl {
|
export interface FormControlBase {
|
||||||
name: string;
|
name: string;
|
||||||
type?: FormControlType;
|
type?: FormControlType;
|
||||||
value?: string | number | string[];
|
value?: string | number | string[];
|
||||||
|
@ -41,7 +41,7 @@ export class FormControl {
|
||||||
private _label?: string;
|
private _label?: string;
|
||||||
private _labelPosition?: 'right' | 'left' = 'left';
|
private _labelPosition?: 'right' | 'left' = 'left';
|
||||||
|
|
||||||
constructor(config: IFormControl | Checkbox | Radio | Submit | Button) {
|
constructor(config: FormControlBase | Checkbox | Radio | Submit | Button) {
|
||||||
const { name, type, value, label, labelPosition } = config;
|
const { name, type, value, label, labelPosition } = config;
|
||||||
this._name = name;
|
this._name = name;
|
||||||
this._type = type || 'text';
|
this._type = type || 'text';
|
||||||
|
@ -80,22 +80,22 @@ export class FormControl {
|
||||||
* TODO: Create classes for each control type
|
* TODO: Create classes for each control type
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export interface Checkbox extends IFormControl {
|
export interface Checkbox extends FormControlBase {
|
||||||
type: 'checkbox';
|
type: 'checkbox';
|
||||||
checked: boolean;
|
checked: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Radio extends IFormControl {
|
export interface Radio extends FormControlBase {
|
||||||
type: 'checkbox';
|
type: 'radio';
|
||||||
checked: boolean;
|
checked: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Submit extends IFormControl {
|
export interface Submit extends FormControlBase {
|
||||||
type: 'submit';
|
type: 'submit';
|
||||||
callBack: () => void;
|
callBack: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Button extends IFormControl {
|
export interface Button extends FormControlBase {
|
||||||
type: 'button';
|
type: 'button';
|
||||||
callBack: () => void;
|
callBack: () => void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { FormControl, IFormControl } from './form-control';
|
import { FormControl, FormControlBase } from './form-control';
|
||||||
|
|
||||||
export class FormGroup {
|
export class FormGroup {
|
||||||
controls: FormControl[];
|
controls: FormControl[];
|
||||||
name?: string;
|
name?: string;
|
||||||
|
|
||||||
constructor(controls: IFormControl[], name: string = '') {
|
constructor(controls: FormControlBase[], name: string = '') {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.controls = controls.map((control) => new FormControl(control));
|
this.controls = controls.map((control) => new FormControl(control));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue