@contember/react-form 2.0.0-beta.2 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/components/FormInput.cjs +8 -6
- package/dist/development/src/components/FormInput.cjs.map +1 -1
- package/dist/development/src/components/FormInput.js +9 -7
- package/dist/development/src/components/FormInput.js.map +1 -1
- package/dist/development/src/internal/useFormInputHandler.cjs +9 -3
- package/dist/development/src/internal/useFormInputHandler.cjs.map +1 -1
- package/dist/development/src/internal/useFormInputHandler.js +9 -3
- package/dist/development/src/internal/useFormInputHandler.js.map +1 -1
- package/dist/production/src/components/FormInput.cjs +6 -4
- package/dist/production/src/components/FormInput.cjs.map +1 -1
- package/dist/production/src/components/FormInput.js +7 -5
- package/dist/production/src/components/FormInput.js.map +1 -1
- package/dist/production/src/internal/useFormInputHandler.cjs +9 -3
- package/dist/production/src/internal/useFormInputHandler.cjs.map +1 -1
- package/dist/production/src/internal/useFormInputHandler.js +9 -3
- package/dist/production/src/internal/useFormInputHandler.js.map +1 -1
- package/dist/types/components/FormInput.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types/index.d.ts +7 -3
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/components/FormInput.tsx +8 -5
- package/src/internal/useFormInputHandler.ts +11 -5
- package/src/types/index.ts +8 -3
|
@@ -16,7 +16,7 @@ export const useFormInputHandler = (field: FieldAccessor, { formatValue, parseVa
|
|
|
16
16
|
}, [field.getAccessor, field.schema, formatValue, parseValue])
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
type ColumnTypeHandlerFactory = (column: SchemaColumn, getAccessor: FieldAccessor.GetFieldAccessor) => FormInputHandler
|
|
19
|
+
type ColumnTypeHandlerFactory = (column: SchemaColumn, getAccessor: FieldAccessor.GetFieldAccessor) => FormInputHandler<any>
|
|
20
20
|
|
|
21
21
|
const defaultHandlerFactory: ColumnTypeHandlerFactory = (schema, field) => ({
|
|
22
22
|
parseValue: (value: string) => {
|
|
@@ -45,15 +45,21 @@ const ColumnTypeHandlerFactories: Record<SchemaKnownColumnType, ColumnTypeHandle
|
|
|
45
45
|
type: 'number',
|
|
46
46
|
},
|
|
47
47
|
}),
|
|
48
|
-
Double: () => ({
|
|
49
|
-
parseValue: (value: string) => {
|
|
48
|
+
Double: (): FormInputHandler<{ rawValue: string; parsedValue: number | null }> => ({
|
|
49
|
+
parseValue: (value: string, ctx) => {
|
|
50
50
|
if (value === '') {
|
|
51
|
+
ctx.setState({ rawValue: '', parsedValue: null })
|
|
51
52
|
return null
|
|
52
53
|
}
|
|
53
54
|
const parsed = parseFloat(value)
|
|
54
|
-
|
|
55
|
+
const parsedValue = isNaN(parsed) ? null : parsed
|
|
56
|
+
ctx.setState({ rawValue: value, parsedValue })
|
|
57
|
+
return parsedValue
|
|
55
58
|
},
|
|
56
|
-
formatValue: (value: number | null) => {
|
|
59
|
+
formatValue: (value: number | null, ctx) => {
|
|
60
|
+
if (value === ctx.state?.parsedValue) {
|
|
61
|
+
return ctx.state.rawValue
|
|
62
|
+
}
|
|
57
63
|
return value === null ? '' : value.toString(10)
|
|
58
64
|
},
|
|
59
65
|
defaultInputProps: {
|
package/src/types/index.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { ErrorAccessor } from '@contember/react-binding'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export type FormInputHandlerContext<State = unknown> = {
|
|
5
|
+
state?: State
|
|
6
|
+
setState: (state: State) => void
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type FormInputHandler<State = unknown> = {
|
|
10
|
+
parseValue: (value: string, ctx: FormInputHandlerContext<State>) => any
|
|
11
|
+
formatValue: (value: any, ctx: FormInputHandlerContext<State>) => string
|
|
7
12
|
defaultInputProps?: React.InputHTMLAttributes<HTMLInputElement>
|
|
8
13
|
}
|
|
9
14
|
|