From 5fb10d9b8c9b7adfac47f35b25bf505c6dd5bb55 Mon Sep 17 00:00:00 2001 From: Shivam Chourasia <73788982+shivamchourasia4@users.noreply.github.com> Date: Sun, 2 Oct 2022 20:41:47 +0530 Subject: [PATCH] Fix #6: refactored IFormControl to FormControlBase and added radio prop. --- packages/astro-reactive-form/core/form-control.ts | 14 +++++++------- packages/astro-reactive-form/core/form-group.ts | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/astro-reactive-form/core/form-control.ts b/packages/astro-reactive-form/core/form-control.ts index 3f9d823..3e06e03 100644 --- a/packages/astro-reactive-form/core/form-control.ts +++ b/packages/astro-reactive-form/core/form-control.ts @@ -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; } diff --git a/packages/astro-reactive-form/core/form-group.ts b/packages/astro-reactive-form/core/form-group.ts index 8e5618b..22bd3e0 100644 --- a/packages/astro-reactive-form/core/form-group.ts +++ b/packages/astro-reactive-form/core/form-group.ts @@ -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)); }