File tree 7 files changed +109
-5
lines changed
7 files changed +109
-5
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @qoretechnologies/reqraft" ,
3
- "version" : " 0.0.1 " ,
3
+ "version" : " 0.1.0 " ,
4
4
"description" : " ReQraft is a collection of React components and hooks that are used across Qore Technologies' products made using the ReQore component library from Qore." ,
5
5
"main" : " dist/index.js" ,
6
6
"types" : " dist/index.d.ts" ,
Original file line number Diff line number Diff line change
1
+ import { TFormFieldType , TFormFieldValueType } from '../../../types/Form' ;
2
+ import { FormStringField } from './string/String' ;
3
+
4
+ export interface IFormFieldProps < T extends TFormFieldType = TFormFieldType > {
5
+ type ?: T ;
6
+ value : TFormFieldValueType < T > ;
7
+ onChange : ( value : TFormFieldValueType < T > , event ?: unknown ) => void ;
8
+
9
+ validateSelf ?: boolean ;
10
+ onValidateChange ?: ( isValid : boolean ) => void ;
11
+ }
12
+
13
+ export const FormField = < T extends TFormFieldType > ( {
14
+ type,
15
+ onChange,
16
+ ...rest
17
+ } : IFormFieldProps < T > ) => {
18
+ const handleChange = ( value : TFormFieldValueType < T > , event ?: unknown ) => {
19
+ onChange ( value , event ) ;
20
+ } ;
21
+
22
+ const renderField = ( type : T ) => {
23
+ switch ( type ) {
24
+ case 'string' :
25
+ return (
26
+ < FormStringField
27
+ { ...rest }
28
+ onChange = { ( value : string ) => handleChange ( value as TFormFieldValueType < T > ) }
29
+ />
30
+ ) ;
31
+ default :
32
+ return null ;
33
+ }
34
+ } ;
35
+
36
+ return renderField ( type ) ;
37
+ } ;
Original file line number Diff line number Diff line change 1
1
import { StoryObj } from '@storybook/react' ;
2
- import { StoryMeta } from '../../../types' ;
2
+ import { StoryMeta } from '../../../../ types' ;
3
3
import { FormStringField } from './String' ;
4
4
5
5
const meta = {
Original file line number Diff line number Diff line change @@ -3,15 +3,16 @@ import { IReqoreControlGroupProps } from '@qoretechnologies/reqore/dist/componen
3
3
import { IReqoreInputProps } from '@qoretechnologies/reqore/dist/components/Input' ;
4
4
import { IReqoreTagProps } from '@qoretechnologies/reqore/dist/components/Tag' ;
5
5
import { ChangeEvent , useCallback } from 'react' ;
6
+ import { TFormFieldValueType } from '../../../../types/Form' ;
6
7
7
8
export interface IStringFormFieldProps extends Omit < IReqoreInputProps , 'onChange' | 'value' > {
8
9
sensitive ?: boolean ;
9
- value ?: string ;
10
+ value ?: TFormFieldValueType < ' string' > ;
10
11
label ?: IReqoreTagProps [ 'label' ] ;
11
12
labelPosition ?: 'top' | 'left' | 'right' | 'bottom' ;
12
13
labelProps ?: IReqoreTagProps ;
13
14
wrapperProps ?: IReqoreControlGroupProps ;
14
- onChange ?: ( value ?: string , event ?: ChangeEvent < HTMLInputElement > ) => void ;
15
+ onChange ?: ( value ?: TFormFieldValueType < ' string' > , event ?: ChangeEvent < HTMLInputElement > ) => void ;
15
16
}
16
17
17
18
export const FormStringField = ( {
Original file line number Diff line number Diff line change
1
+ import { TFormFieldType } from '../types/Form' ;
2
+
3
+ // @ts -expect-error "need to implement this"
4
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
+ export const useValidation = ( value : any , type ?: TFormFieldType ) => {
6
+ // Build validation...
7
+
8
+ return true ;
9
+ } ;
Original file line number Diff line number Diff line change 1
- export { FormStringField , IStringFormFieldProps } from './components/form/string/String' ;
1
+ export { FormStringField , IStringFormFieldProps } from './components/form/fields/ string/String' ;
Original file line number Diff line number Diff line change
1
+ export type TFormFieldType =
2
+ | 'string'
3
+ | 'number'
4
+ | 'boolean'
5
+ | 'date'
6
+ | 'time'
7
+ | 'datetime'
8
+ | 'select'
9
+ | 'multiSelect'
10
+ | 'radio'
11
+ | 'checkbox'
12
+ | 'file'
13
+ | 'image'
14
+ | 'color'
15
+ | 'password'
16
+ | 'email'
17
+ | 'phone'
18
+ | 'url'
19
+ | 'markdown' ;
20
+
21
+ export type TFormFieldValueType < T > = T extends 'string'
22
+ ? string
23
+ : T extends 'number'
24
+ ? number
25
+ : T extends 'boolean'
26
+ ? boolean
27
+ : T extends 'date'
28
+ ? Date | string
29
+ : T extends 'time'
30
+ ? Date | string
31
+ : T extends 'datetime'
32
+ ? Date | string
33
+ : T extends 'select'
34
+ ? string
35
+ : T extends 'multiSelect'
36
+ ? string [ ]
37
+ : T extends 'radio'
38
+ ? string
39
+ : T extends 'checkbox'
40
+ ? boolean
41
+ : T extends 'file'
42
+ ? File
43
+ : T extends 'image'
44
+ ? string
45
+ : T extends 'color'
46
+ ? string
47
+ : T extends 'password'
48
+ ? string
49
+ : T extends 'email'
50
+ ? string
51
+ : T extends 'phone'
52
+ ? string
53
+ : T extends 'url'
54
+ ? string
55
+ : T extends 'markdown'
56
+ ? string
57
+ : any ;
You can’t perform that action at this time.
0 commit comments