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>
This commit is contained in:
Amit Kumar Sharma 2022-10-04 21:56:09 +05:30 committed by GitHub
parent 66d782bdf0
commit 29abefd605
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 61 deletions

View file

@ -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;
}

View file

@ -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[];

View file

@ -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;
}