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:
parent
66d782bdf0
commit
29abefd605
3 changed files with 58 additions and 61 deletions
|
@ -1,38 +1,4 @@
|
||||||
/**
|
import type { FormControlType, Button, Checkbox, FormControlBase, Radio, Submit } from "../types";
|
||||||
* 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';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export class FormControl {
|
export class FormControl {
|
||||||
private _name: string = '';
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { FormControl, FormControlBase } from './form-control';
|
import type { FormControlBase } from '../types';
|
||||||
|
import { FormControl } from './form-control';
|
||||||
|
|
||||||
export class FormGroup {
|
export class FormGroup {
|
||||||
controls: FormControl[];
|
controls: FormControl[];
|
||||||
|
|
55
packages/astro-reactive-form/types.ts
Normal file
55
packages/astro-reactive-form/types.ts
Normal 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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue