-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core/presentation): Split forms interfaces into three files:
- /forms/fields/interface.ts - /forms/inputs/interface.ts - /forms/layouts/interface.ts
- Loading branch information
1 parent
2d6c9e7
commit eafb077
Showing
15 changed files
with
108 additions
and
71 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
app/scripts/modules/core/src/presentation/forms/fields/interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as React from 'react'; | ||
|
||
import { IFormInputProps, IFormInputValidation } from '../inputs'; | ||
import { ILayoutProps } from '../layouts'; | ||
import { IValidator } from '../validation'; | ||
|
||
/** These props are used by FormFields such as FormikFormField and FormField */ | ||
export interface ICommonFormFieldProps { | ||
/** The Form Input component (or render function) */ | ||
input: React.ComponentType<IFormInputProps>; | ||
|
||
/** | ||
* An optional layout component (or render function). | ||
* If none is provided, the default layout (from context) will be used | ||
*/ | ||
layout?: React.ComponentType<ILayoutProps>; | ||
|
||
/** An inline validator function or functions */ | ||
validate?: IValidator | IValidator[]; | ||
|
||
/** | ||
* A string (or React Node) containing an explicit validation message for the Form Field. | ||
* | ||
* This string can be constructed using the helper methods from core/presentation i.e.: | ||
* errorMessage('Something went wrong!') | ||
* | ||
* Alternatively, a react node can be provided. | ||
*/ | ||
validationMessage?: IFormInputValidation['messageNode']; | ||
|
||
/** An explicit 'touched' status for the Form Field */ | ||
touched?: IFormInputValidation['touched']; | ||
|
||
// The following props are a subset of layout props that are accepted by a FormField or FormikFormField | ||
|
||
/** A boolean marking this field as required */ | ||
required?: ILayoutProps['required']; | ||
|
||
/** A string (or ReactNode) containing the field's label */ | ||
label?: ILayoutProps['label']; | ||
|
||
/** A ReactNode containing the field's help component */ | ||
help?: ILayoutProps['help']; | ||
|
||
/** A ReactNode containing the field's actions, such as 'delete item' */ | ||
actions?: ILayoutProps['actions']; | ||
} |
2 changes: 1 addition & 1 deletion
2
app/scripts/modules/core/src/presentation/forms/inputs/CheckboxInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/scripts/modules/core/src/presentation/forms/inputs/ChecklistInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/scripts/modules/core/src/presentation/forms/inputs/TextAreaInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/scripts/modules/core/src/presentation/forms/inputs/TextInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/scripts/modules/core/src/presentation/forms/inputs/interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as React from 'react'; | ||
|
||
import { FieldProps } from 'formik'; | ||
import { IValidationCategory, IValidator } from '../validation'; | ||
|
||
/** | ||
* These props are used by controlled components, such as <input> or Input components like TextInput | ||
* Some of the typings reference the typings supplied by formik FieldProps | ||
*/ | ||
export interface IControlledInputProps { | ||
value: FieldProps['field']['value']; | ||
|
||
onChange(e: React.ChangeEvent<any>): void; | ||
|
||
onBlur: FieldProps['field']['onBlur']; | ||
name: FieldProps['field']['name']; | ||
} | ||
|
||
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>; | ||
export type OmitControlledInputPropsFrom<T> = Omit<T, keyof IControlledInputProps>; | ||
|
||
/** These props are used by Input components, such as TextInput */ | ||
export interface IFormInputValidation { | ||
touched?: boolean; | ||
category?: IValidationCategory; | ||
messageNode?: React.ReactNode; | ||
hidden?: boolean; | ||
addValidator?: (validator: IValidator) => void; | ||
removeValidator?: (validator: IValidator) => void; | ||
} | ||
|
||
/** These props are used by Form Input components, such as TextInput */ | ||
export interface IFormInputProps extends Partial<IControlledInputProps> { | ||
validation?: IFormInputValidation; | ||
inputClassName?: string; | ||
} |
61 changes: 0 additions & 61 deletions
61
app/scripts/modules/core/src/presentation/forms/interface.ts
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
app/scripts/modules/core/src/presentation/forms/layouts/LayoutContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as React from 'react'; | ||
import { IFieldLayoutProps } from '../interface'; | ||
import { ILayoutProps } from './interface'; | ||
import { StandardFieldLayout } from './StandardFieldLayout'; | ||
|
||
export const LayoutContext = React.createContext<React.ComponentType<IFieldLayoutProps>>(StandardFieldLayout); | ||
export const LayoutContext = React.createContext<React.ComponentType<ILayoutProps>>(StandardFieldLayout); | ||
export const { Provider: LayoutProvider, Consumer: LayoutConsumer } = LayoutContext; |
1 change: 1 addition & 0 deletions
1
app/scripts/modules/core/src/presentation/forms/layouts/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './StandardFieldLayout'; | ||
export * from './LayoutContext'; | ||
export * from './ResponsiveFieldLayout'; | ||
export * from './interface'; |
13 changes: 13 additions & 0 deletions
13
app/scripts/modules/core/src/presentation/forms/layouts/interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as React from 'react'; | ||
|
||
import { IFormInputValidation } from '../inputs'; | ||
|
||
/** These props are used by FieldLayout components, such as StandardFieldLayout */ | ||
export interface ILayoutProps { | ||
required?: boolean; | ||
label?: React.ReactNode; | ||
help?: React.ReactNode; | ||
actions?: React.ReactNode; | ||
input: React.ReactNode; | ||
validation?: IFormInputValidation; | ||
} |