refactor: IFormControl to FormControlBase and added radio prop (#6)

Fixes #6: refactored IFormControl to FormControlBase and added radio prop.
This commit is contained in:
Ayo Ayco 2022-10-02 17:17:01 +02:00 committed by GitHub
commit 2393186c43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View file

@ -25,7 +25,7 @@ type FormControlType =
| 'url'
| 'week';
export interface IFormControl {
export interface FormControlBase {
name: string;
type?: FormControlType;
value?: string | number | string[];
@ -41,7 +41,7 @@ export class FormControl {
private _label?: string;
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;
this._name = name;
this._type = type || 'text';
@ -80,22 +80,22 @@ export class FormControl {
* TODO: Create classes for each control type
*/
export interface Checkbox extends IFormControl {
export interface Checkbox extends FormControlBase {
type: 'checkbox';
checked: boolean;
}
export interface Radio extends IFormControl {
type: 'checkbox';
export interface Radio extends FormControlBase {
type: 'radio';
checked: boolean;
}
export interface Submit extends IFormControl {
export interface Submit extends FormControlBase {
type: 'submit';
callBack: () => void;
}
export interface Button extends IFormControl {
export interface Button extends FormControlBase {
type: 'button';
callBack: () => void;
}

View file

@ -1,10 +1,10 @@
import { FormControl, IFormControl } from './form-control';
import { FormControl, FormControlBase } from './form-control';
export class FormGroup {
controls: FormControl[];
name?: string;
constructor(controls: IFormControl[], name: string = '') {
constructor(controls: FormControlBase[], name: string = '') {
this.name = name;
this.controls = controls.map((control) => new FormControl(control));
}