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 React from 'react';
|
||||||
import { Field as FormikField } from 'formik';
|
import { Field as FormikField } from 'formik';
|
||||||
|
|
||||||
import { Options } from '@romanjaros/treejs-types/options';
|
|
||||||
|
|
||||||
import { FIELD_TYPE } from '../constants';
|
import { FIELD_TYPE } from '../constants';
|
||||||
|
|
||||||
import TextField from './fields/TextField';
|
import TextField from './fields/TextField';
|
||||||
|
@ -10,17 +8,12 @@ import CheckboxField from './fields/CheckboxField';
|
||||||
import RadioButtonField from './fields/RadioButtonField';
|
import RadioButtonField from './fields/RadioButtonField';
|
||||||
import SelectBoxField from './fields/SelectBoxField';
|
import SelectBoxField from './fields/SelectBoxField';
|
||||||
import DatePickerField from './fields/DatePickerField';
|
import DatePickerField from './fields/DatePickerField';
|
||||||
import { IField } from '@romanjaros/treejs-types/form';
|
import { IField } from '@romanjaros/treejs-forms/types';
|
||||||
|
|
||||||
type fieldValueTypes = string | Options | boolean;
|
|
||||||
|
|
||||||
type IProps<T> = T & IField;
|
type IProps<T> = T & IField;
|
||||||
|
|
||||||
export function Field<T> (props: IProps<T>) {
|
export function Field<T>(props: IProps<T>) {
|
||||||
const {
|
const { component = FIELD_TYPE.TEXT_FIELD, ...other } = props;
|
||||||
component = FIELD_TYPE.TEXT_FIELD,
|
|
||||||
...other
|
|
||||||
} = props;
|
|
||||||
|
|
||||||
switch (component) {
|
switch (component) {
|
||||||
case FIELD_TYPE.TEXT_FIELD:
|
case FIELD_TYPE.TEXT_FIELD:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
export enum FIELD_TYPE {
|
export enum FIELD_TYPE {
|
||||||
TEXT_FIELD,
|
TEXT_FIELD = 'TEXT_FIELD',
|
||||||
CHECKBOX,
|
CHECKBOX = 'CHECKBOX',
|
||||||
RADIO_BUTTON,
|
RADIO_BUTTON = 'RADIO_BUTTON',
|
||||||
SELECT_BOX,
|
SELECT_BOX = 'SELECT_BOX',
|
||||||
DATE_PICKER,
|
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;
|
onClick?: (value: Value, e: React.MouseEvent) => void;
|
||||||
onFocus?: (value: Value, e: React.FocusEvent) => void;
|
onFocus?: (value: Value, e: React.FocusEvent) => void;
|
||||||
title: string;
|
title: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type FormActions<FormValues> = FormikHelpers<FormValues>;
|
export type FormActions<FormValues> = FormikHelpers<FormValues>;
|
||||||
export type FormErrors<FormValues> = FormikErrors<FormValues>;
|
export type FormErrors<FormValues> = FormikErrors<FormValues>;
|
||||||
|
@ -23,4 +23,4 @@ export type IForm<FormValues> = {
|
||||||
handleSubmit: (values: FormValues, actions: FormikHelpers<FormValues>) => void;
|
handleSubmit: (values: FormValues, actions: FormikHelpers<FormValues>) => void;
|
||||||
handleValidate?: (values?: FormValues) => FormErrors<FormValues>;
|
handleValidate?: (values?: FormValues) => FormErrors<FormValues>;
|
||||||
validationSchema: any;
|
validationSchema: any;
|
||||||
}
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue