From 29abefd605bf4119c1997dca56eafb5b0fcd379a Mon Sep 17 00:00:00 2001 From: Amit Kumar Sharma Date: Tue, 4 Oct 2022 21:56:09 +0530 Subject: [PATCH] refactor: astro-reactive-form types (#40) * [refactor]: astro-reactive-form types * cleanup: comments and empty lines Co-authored-by: Amit Kumar Sharma <91947037+amit-2k1@users.noreply.github.com> --- .../astro-reactive-form/core/form-control.ts | 61 +------------------ .../astro-reactive-form/core/form-group.ts | 3 +- packages/astro-reactive-form/types.ts | 55 +++++++++++++++++ 3 files changed, 58 insertions(+), 61 deletions(-) create mode 100644 packages/astro-reactive-form/types.ts diff --git a/packages/astro-reactive-form/core/form-control.ts b/packages/astro-reactive-form/core/form-control.ts index 3e06e03..04fcc2a 100644 --- a/packages/astro-reactive-form/core/form-control.ts +++ b/packages/astro-reactive-form/core/form-control.ts @@ -1,38 +1,4 @@ -/** - * FormControlType - determines the type of form control - * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types - */ -type FormControlType = - | 'text' - | 'checkbox' - | 'radio' - | 'password' - | 'button' - | 'color' - | 'date' - | 'datetime-local' - | 'email' - | 'file' - | 'hidden' - | 'image' - | 'month' - | 'number' - | 'range' - | 'search' - | 'submit' - | 'tel' - | 'time' - | 'url' - | 'week'; - -export interface FormControlBase { - name: string; - type?: FormControlType; - value?: string | number | string[]; - label?: string; - labelPosition?: 'right' | 'left'; -} - +import type { FormControlType, Button, Checkbox, FormControlBase, Radio, Submit } from "../types"; export class FormControl { private _name: string = ''; @@ -75,28 +41,3 @@ export class FormControl { } } - -/** - * TODO: Create classes for each control type - */ - -export interface Checkbox extends FormControlBase { - type: 'checkbox'; - checked: boolean; -} - -export interface Radio extends FormControlBase { - type: 'radio'; - checked: boolean; -} - -export interface Submit extends FormControlBase { - type: 'submit'; - callBack: () => void; -} - -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 22bd3e0..3623f03 100644 --- a/packages/astro-reactive-form/core/form-group.ts +++ b/packages/astro-reactive-form/core/form-group.ts @@ -1,4 +1,5 @@ -import { FormControl, FormControlBase } from './form-control'; +import type { FormControlBase } from '../types'; +import { FormControl } from './form-control'; export class FormGroup { controls: FormControl[]; diff --git a/packages/astro-reactive-form/types.ts b/packages/astro-reactive-form/types.ts new file mode 100644 index 0000000..231169d --- /dev/null +++ b/packages/astro-reactive-form/types.ts @@ -0,0 +1,55 @@ +/** + * FormControlType - determines the type of form control + * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types + */ +export type FormControlType = + | 'text' + | 'checkbox' + | 'radio' + | 'password' + | 'button' + | 'color' + | 'date' + | 'datetime-local' + | 'email' + | 'file' + | 'hidden' + | 'image' + | 'month' + | 'number' + | 'range' + | 'search' + | 'submit' + | 'tel' + | 'time' + | 'url' + | 'week'; + +export interface FormControlBase { + name: string; + type?: FormControlType; + value?: string | number | string[]; + label?: string; + labelPosition?: 'right' | 'left'; +} + +export interface Checkbox extends FormControlBase { + type: 'checkbox'; + checked: boolean; +} + +export interface Radio extends FormControlBase { + type: 'radio'; + checked: boolean; +} + +export interface Submit extends FormControlBase { + type: 'submit'; + callBack: () => void; +} + +export interface Button extends FormControlBase { + type: 'button'; + callBack: () => void; +} + \ No newline at end of file