Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
npm
common
Commits
36769d46
Commit
36769d46
authored
Nov 23, 2018
by
Vladislav Lagunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Исправления в тайпингак полей ввода
parent
4685aafc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
26 deletions
+23
-26
create-form/index.ts
+16
-19
fields/AutoComplete.tsx
+1
-1
fields/MultiSelect.tsx
+6
-6
No files found.
create-form/index.ts
View file @
36769d46
...
...
@@ -32,6 +32,7 @@ export type Validation<A> = Partial<Record<keyof A, Error>>;
// Props
export
type
CardProps
<
T
>
=
{
ctx
?:
any
,
model
:
{
initial
:
T
;
modified
:
T
|
null
;
...
...
@@ -51,26 +52,22 @@ export default function createForm<O extends CreateFormOptions<any>>(options: O)
type
T
=
O
extends
CreateFormOptions
<
infer
T
>
?
T
:
never
;
function
bindZoom
(
self
:
React
.
Component
<
CardProps
<
T
>>
)
{
function
Zoom
<
K1
extends
keyof
T
,
C
extends
Any
<
T
[
K1
]
>>
(...
keys
:
[
K1
]):
(
Component
:
C
,
props
?:
GetProps
<
C
>
)
=>
JSX
.
Element
;
function
Zoom
<
K1
extends
keyof
T
,
K2
extends
keyof
T
[
K1
],
C
extends
Any
<
T
[
K1
][
K2
]
>>
(...
keys
:
[
K1
,
K2
]):
(
Component
:
C
,
props
?:
GetProps
<
C
>
)
=>
JSX
.
Element
;
function
Zoom
<
K1
extends
keyof
T
,
K2
extends
keyof
T
[
K1
],
K3
extends
keyof
T
[
K1
][
K2
],
C
extends
Any
<
T
[
K1
][
K2
][
K3
]
>>
(...
keys
:
[
K1
,
K2
,
K3
]):
(
Component
:
C
,
props
?:
GetProps
<
C
>
)
=>
JSX
.
Element
;
function
Zoom
<
K1
extends
keyof
T
,
C
extends
Any
<
T
[
K1
]
>>
(...
keys
:
[
K1
]):
FieldProps
<
T
[
K1
]
>
;
function
Zoom
<
K1
extends
keyof
T
,
K2
extends
keyof
T
[
K1
],
C
extends
Any
<
T
[
K1
][
K2
]
>>
(...
keys
:
[
K1
,
K2
]):
FieldProps
<
T
[
K1
][
K2
]
>
;
function
Zoom
<
K1
extends
keyof
T
,
K2
extends
keyof
T
[
K1
],
K3
extends
keyof
T
[
K1
][
K2
],
C
extends
Any
<
T
[
K1
][
K2
][
K3
]
>>
(...
keys
:
[
K1
,
K2
,
K3
]):
FieldProps
<
T
[
K1
][
K2
][
K3
]
>
;
function
Zoom
(...
keys
)
{
return
(
Component
,
props
=
{})
=>
{
const
{
dispatch
}
=
self
.
props
;
const
value
=
self
.
props
.
model
.
modified
||
self
.
props
.
model
.
initial
;
const
error
=
options
.
validate
?
options
.
validate
(
value
)
:
{};
const
disabled
=
options
.
disabled
?
options
.
disabled
(
value
,
self
)
:
{};
const
onValueChange
=
(
value
,
at
:
ObjectPath
=
[])
=>
dispatch
({
tag
:
'Change'
,
value
,
at
});
const
props_
=
{
...
props
,
value
:
zoomAny
(
keys
,
value
),
error
:
zoomAny
(
keys
,
error
),
disabled
:
zoomAny
(
keys
,
disabled
),
onValueChange
:
zoomOnChange
(
keys
,
onValueChange
),
};
return
React
.
createElement
(
Component
,
props_
);
const
{
dispatch
,
ctx
}
=
self
.
props
;
const
value
=
self
.
props
.
model
.
modified
||
self
.
props
.
model
.
initial
;
const
error
=
options
.
validate
?
options
.
validate
(
value
)
:
{};
const
disabled
=
options
.
disabled
?
options
.
disabled
(
value
,
self
)
:
{};
const
onValueChange
=
(
value
,
at
:
ObjectPath
=
[])
=>
dispatch
({
tag
:
'Change'
,
value
,
at
});
return
{
ctx
,
value
:
zoomAny
(
keys
,
value
),
error
:
zoomAny
(
keys
,
error
),
disabled
:
zoomAny
(
keys
,
disabled
),
onValueChange
:
zoomOnChange
(
keys
,
onValueChange
),
};
}
return
Zoom
;
...
...
fields/AutoComplete.tsx
View file @
36769d46
...
...
@@ -18,7 +18,7 @@ import classNames = require('classnames');
// Props
export
type
Props
<
A
>
=
StandardProps
<
React
.
HTMLProps
<
HTMLDivElement
>
,
string
,
'value'
>
&
FieldProps
<
A
>
&
{
export
type
Props
<
A
>
=
StandardProps
<
React
.
HTMLProps
<
HTMLDivElement
>
,
string
,
'value'
|
'disabled'
>
&
FieldProps
<
A
>
&
{
ctx
?:
Ctx
;
source
:
Source
<
A
>
;
debounce
?:
number
;
...
...
fields/MultiSelect.tsx
View file @
36769d46
...
...
@@ -12,21 +12,21 @@ import { FieldProps } from '~/create-form';
// Props
export
type
Props
<
A
>
=
StandardProps
<
React
.
HTMLProps
<
HTMLDivElement
>
,
string
,
'value
'
>
&
FieldProps
<
A
>
&
{
source
:
Source
<
A
>
;
export
type
Props
<
A
extends
any
[]
>
=
StandardProps
<
React
.
HTMLProps
<
HTMLDivElement
>
,
string
,
'value'
|
'disabled
'
>
&
FieldProps
<
A
>
&
{
source
:
Source
<
A
[
number
]
>
;
fullWidth
?:
boolean
;
textFieldProps
?:
Partial
<
TextFieldProps
>
;
renderItem
?(
a
:
A
,
selected
:
boolean
):
React
.
ReactNode
;
renderItem
?(
a
:
A
[
number
]
,
selected
:
boolean
):
React
.
ReactNode
;
placeholder
?:
string
;
printItem
?(
a
:
A
):
string
;
printItem
?(
a
:
A
[
number
]
):
string
;
id
?:
string
;
// Используется для установки `key` пропсов
isEqual
?(
a
:
A
,
b
:
A
):
boolean
;
isEqual
?(
a
:
A
[
number
],
b
:
A
[
number
]
):
boolean
;
}
// @ts-ignore Component
@
withStyles
(
styles
)
export
default
class
MultiSelect
<
A
>
extends
React
.
Component
<
Props
<
A
>>
{
export
default
class
MultiSelect
<
A
extends
any
[]
>
extends
React
.
Component
<
Props
<
A
>>
{
static
defaultProps
=
{
printItem
:
String
,
}
as
any
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment