DEV;New forms
This commit is contained in:
parent
7d4ee7fbbf
commit
eaa6d91dad
4 changed files with 15 additions and 17 deletions
|
@ -1,8 +1,6 @@
|
|||
import React from 'react';
|
||||
import { Field as FormikField } from 'formik';
|
||||
|
||||
import { Options } from '@romanjaros/treejs-types/options';
|
||||
|
||||
import { FIELD_TYPE } from '../constants';
|
||||
|
||||
import TextField from './fields/TextField';
|
||||
|
@ -10,17 +8,12 @@ import CheckboxField from './fields/CheckboxField';
|
|||
import RadioButtonField from './fields/RadioButtonField';
|
||||
import SelectBoxField from './fields/SelectBoxField';
|
||||
import DatePickerField from './fields/DatePickerField';
|
||||
import { IField } from '@romanjaros/treejs-types/form';
|
||||
|
||||
type fieldValueTypes = string | Options | boolean;
|
||||
import { IField } from '@romanjaros/treejs-forms/types';
|
||||
|
||||
type IProps<T> = T & IField;
|
||||
|
||||
export function Field<T>(props: IProps<T>) {
|
||||
const {
|
||||
component = FIELD_TYPE.TEXT_FIELD,
|
||||
...other
|
||||
} = props;
|
||||
const { component = FIELD_TYPE.TEXT_FIELD, ...other } = props;
|
||||
|
||||
switch (component) {
|
||||
case FIELD_TYPE.TEXT_FIELD:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export enum FIELD_TYPE {
|
||||
TEXT_FIELD,
|
||||
CHECKBOX,
|
||||
RADIO_BUTTON,
|
||||
SELECT_BOX,
|
||||
DATE_PICKER,
|
||||
TEXT_FIELD = 'TEXT_FIELD',
|
||||
CHECKBOX = 'CHECKBOX',
|
||||
RADIO_BUTTON = 'RADIO_BUTTON',
|
||||
SELECT_BOX = 'SELECT_BOX',
|
||||
DATE_PICKER = 'DATE_PICKER',
|
||||
}
|
||||
|
|
5
modules/treejs-forms/src/types/index.ts
Normal file
5
modules/treejs-forms/src/types/index.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { FIELD_TYPE } from '../constants';
|
||||
|
||||
export type IField = {
|
||||
component: FIELD_TYPE;
|
||||
};
|
|
@ -13,7 +13,7 @@ export type IHTMLElement<Value> = {
|
|||
onClick?: (value: Value, e: React.MouseEvent) => void;
|
||||
onFocus?: (value: Value, e: React.FocusEvent) => void;
|
||||
title: string;
|
||||
}
|
||||
};
|
||||
|
||||
export type FormActions<FormValues> = FormikHelpers<FormValues>;
|
||||
export type FormErrors<FormValues> = FormikErrors<FormValues>;
|
||||
|
@ -23,4 +23,4 @@ export type IForm<FormValues> = {
|
|||
handleSubmit: (values: FormValues, actions: FormikHelpers<FormValues>) => void;
|
||||
handleValidate?: (values?: FormValues) => FormErrors<FormValues>;
|
||||
validationSchema: any;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue