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
0c437340
Commit
0c437340
authored
Nov 28, 2018
by
Vladislav Lagunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] Динамическая загрузка автодополнений
parent
26433fa3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
5 deletions
+25
-5
fields/AutoComplete.tsx
+15
-2
fields/AutoComplete/state-machine.ts
+6
-1
fields/Suggestions.tsx
+4
-2
No files found.
fields/AutoComplete.tsx
View file @
0c437340
...
@@ -5,7 +5,7 @@ import { AuthCtx as Ctx } from '~/context';
...
@@ -5,7 +5,7 @@ import { AuthCtx as Ctx } from '~/context';
import
{
FieldProps
}
from
'~/create-form'
;
import
{
FieldProps
}
from
'~/create-form'
;
import
TextField
from
'~/fields/TextField'
;
import
TextField
from
'~/fields/TextField'
;
import
{
Props
as
TextFieldProps
}
from
'~/fields/TextField'
;
import
{
Props
as
TextFieldProps
}
from
'~/fields/TextField'
;
import
{
StandardProps
}
from
'@material-ui/core'
;
import
{
StandardProps
,
ListItem
}
from
'@material-ui/core'
;
import
Icon
from
'./Icon'
;
import
Icon
from
'./Icon'
;
import
withStyles
,
{
StyleRules
}
from
'@material-ui/core/styles/withStyles'
;
import
withStyles
,
{
StyleRules
}
from
'@material-ui/core/styles/withStyles'
;
import
{
Theme
}
from
'@material-ui/core/styles/createMuiTheme'
;
import
{
Theme
}
from
'@material-ui/core/styles/createMuiTheme'
;
...
@@ -185,18 +185,30 @@ export default class AutoComplete<A=string> extends React.Component<Props<A> & {
...
@@ -185,18 +185,30 @@ export default class AutoComplete<A=string> extends React.Component<Props<A> & {
endAdornment
:
this
.
endAdornment
(
!!
nonNull
,
!!
disabled
,
__
),
endAdornment
:
this
.
endAdornment
(
!!
nonNull
,
!!
disabled
,
__
),
};
};
};
};
handleSeeMore
=
(
e
:
React
.
MouseEvent
)
=>
{
e
.
preventDefault
();
e
.
stopPropagation
();
// const { query: { offset, limit } } = this.state;
this
.
dispatch
({
tag
:
'More'
});
};
render
()
{
render
()
{
const
{
className
,
fullWidth
,
children
,
ctx
,
source
,
debounce
,
renderItem
,
printItem
,
openOnFocus
,
openOnClick
,
suggestionProps
,
keepOpenAfterSelect
,
textFieldProps
,
classes
,
anchorEl
,
observable
,
...
rest
}
=
this
.
props
;
const
{
className
,
fullWidth
,
children
,
ctx
,
source
,
debounce
,
renderItem
,
printItem
,
openOnFocus
,
openOnClick
,
suggestionProps
,
keepOpenAfterSelect
,
textFieldProps
,
classes
,
anchorEl
,
observable
,
...
rest
}
=
this
.
props
;
const
{
suggestions
,
open
}
=
this
.
state
;
const
{
suggestions
,
open
,
pending
}
=
this
.
state
;
const
rootClass
=
classNames
(
classes
!
.
root
,
className
,
{
const
rootClass
=
classNames
(
classes
!
.
root
,
className
,
{
[
classes
!
.
fullWidth
!
]:
fullWidth
[
classes
!
.
fullWidth
!
]:
fullWidth
});
});
const
seeMoreLink
=
<
ListItem
>
<
a
href=
{
"#"
}
onMouseDown=
{
this
.
handleSeeMore
}
>
{
(
'See more'
)
}
</
a
>
</
ListItem
>;
return
<
div
{
...
rest
}
className=
{
rootClass
}
>
return
<
div
{
...
rest
}
className=
{
rootClass
}
>
{
!
observable
&&
(
children
?
React
.
cloneElement
(
children
,
this
.
childrenProps
())
:
<
TextField
{
...
this
.
childrenProps
()
as
any
}
{
...
textFieldProps
}
/>)
}
{
!
observable
&&
(
children
?
React
.
cloneElement
(
children
,
this
.
childrenProps
())
:
<
TextField
{
...
this
.
childrenProps
()
as
any
}
{
...
textFieldProps
}
/>)
}
<
Suggestions
<
Suggestions
{
...
suggestionProps
}
{
...
suggestionProps
}
pending=
{
pending
}
ctx=
{
ctx
!
}
ctx=
{
ctx
!
}
anchorEl=
{
anchorEl
||
this
.
anchorEl
||
undefined
}
anchorEl=
{
anchorEl
||
this
.
anchorEl
||
undefined
}
open=
{
open
}
open=
{
open
}
...
@@ -204,6 +216,7 @@ export default class AutoComplete<A=string> extends React.Component<Props<A> & {
...
@@ -204,6 +216,7 @@ export default class AutoComplete<A=string> extends React.Component<Props<A> & {
renderSuggestion=
{
renderItem
||
printItem
}
renderSuggestion=
{
renderItem
||
printItem
}
onSelect=
{
this
.
handleSuggestionSelect
}
onSelect=
{
this
.
handleSuggestionSelect
}
onVisibilityChange=
{
this
.
handleVisibilityChnage
}
onVisibilityChange=
{
this
.
handleVisibilityChnage
}
after=
{
seeMoreLink
}
/>
/>
</
div
>;
</
div
>;
}
}
...
...
fields/AutoComplete/state-machine.ts
View file @
0c437340
...
@@ -68,6 +68,7 @@ export type Action<A> =
...
@@ -68,6 +68,7 @@ export type Action<A> =
|
{
tag
:
'Error'
,
error
:
Err
}
|
{
tag
:
'Error'
,
error
:
Err
}
|
{
tag
:
'Search'
,
value
:
string
}
|
{
tag
:
'Search'
,
value
:
string
}
|
{
tag
:
'Offset'
,
value
:
number
}
|
{
tag
:
'Offset'
,
value
:
number
}
|
{
tag
:
'More'
}
|
{
tag
:
'Query'
,
query
:
AutoCompleteQuery
}
|
{
tag
:
'Query'
,
query
:
AutoCompleteQuery
}
|
{
tag
:
'Query/success'
,
suggestions
:
A
[],
total
:
number
,
query
:
AutoCompleteQuery
}
|
{
tag
:
'Query/success'
,
suggestions
:
A
[],
total
:
number
,
query
:
AutoCompleteQuery
}
|
{
tag
:
'Focus'
}
|
{
tag
:
'Focus'
}
...
@@ -146,7 +147,11 @@ export function update<A>(ctx: Ctx<A>, action: Action<A>, state: State<A>): [Sta
...
@@ -146,7 +147,11 @@ export function update<A>(ctx: Ctx<A>, action: Action<A>, state: State<A>): [Sta
return
[
state
,
cmd
.
of
<
Action
<
A
>>
({
tag
:
'Query'
,
query
:
{
...
state
.
query
,
offset
:
action
.
value
}
})];
return
[
state
,
cmd
.
of
<
Action
<
A
>>
({
tag
:
'Query'
,
query
:
{
...
state
.
query
,
offset
:
action
.
value
}
})];
}
}
case
'Search'
:
{
case
'Search'
:
{
return
[
state
,
cmd
.
of
<
Action
<
A
>>
({
tag
:
'Query'
,
query
:
{
...
state
.
query
,
search
:
action
.
value
}
})];
return
[
state
,
cmd
.
of
<
Action
<
A
>>
({
tag
:
'Query'
,
query
:
{
...
defaultQuery
,
search
:
action
.
value
}
})];
}
case
'More'
:
{
const
{
query
:
{
limit
}
}
=
state
;
return
[
state
,
cmd
.
of
<
Action
<
A
>>
({
tag
:
'Query'
,
query
:
{
...
state
.
query
,
limit
:
limit
+
20
}
})];
}
}
case
'Focus'
:
{
case
'Focus'
:
{
if
(
ctx
.
options
.
openOnFocus
&&
!
ctx
.
options
.
openOnClick
)
{
if
(
ctx
.
options
.
openOnFocus
&&
!
ctx
.
options
.
openOnClick
)
{
...
...
fields/Suggestions.tsx
View file @
0c437340
...
@@ -22,6 +22,8 @@ export type Props<A=any> = StandardProps<React.HTMLProps<HTMLDivElement>, string
...
@@ -22,6 +22,8 @@ export type Props<A=any> = StandardProps<React.HTMLProps<HTMLDivElement>, string
marginThreshold
?:
number
;
marginThreshold
?:
number
;
pending
?:
boolean
;
pending
?:
boolean
;
dontMove
?:
boolean
;
dontMove
?:
boolean
;
before
?:
React
.
ReactNode
;
after
?:
React
.
ReactNode
;
// Callbacks
// Callbacks
onSelect
?(
a
:
A
):
void
;
onSelect
?(
a
:
A
):
void
;
...
@@ -179,12 +181,12 @@ class Suggestions<A> extends React.Component<Props<A>, State> {
...
@@ -179,12 +181,12 @@ class Suggestions<A> extends React.Component<Props<A>, State> {
}
}
render()
{
render()
{
const
{
__
,
classes
,
open
,
pending
,
suggestions
}
=
this
.
props
;
const
{
__
,
classes
,
open
,
pending
,
suggestions
,
before
,
after
}
=
this
.
props
;
const
PaperProps
=
{
ref
:
this
.
handlePaperRef
,
className
:
classes
.
paper
};
const
PaperProps
=
{
ref
:
this
.
handlePaperRef
,
className
:
classes
.
paper
};
return
<
Modal
className=
{
classes
.
modal
}
open=
{
!!
open
}
onClose=
{
this
.
handleClose
}
disableAutoFocus
disableEnforceFocus
disableRestoreFocus
hideBackdrop
>
return
<
Modal
className=
{
classes
.
modal
}
open=
{
!!
open
}
onClose=
{
this
.
handleClose
}
disableAutoFocus
disableEnforceFocus
disableRestoreFocus
hideBackdrop
>
<
Paper
{
...
PaperProps
}
>
<
Paper
{
...
PaperProps
}
>
{
!!
suggestions
.
length
&&
<
MenuList
className=
{
classes
.
menu
}
>
{
this
.
renderSuggestions
(
suggestions
)
}
</
MenuList
>
}
{
!!
suggestions
.
length
&&
<
MenuList
className=
{
classes
.
menu
}
>
{
before
}{
this
.
renderSuggestions
(
suggestions
)
}{
after
}
</
MenuList
>
}
{
!
suggestions
.
length
&&
<
div
className=
{
classes
.
empty
}
><
span
>
{
__
(
'Nothing found…'
)
}
</
span
></
div
>
}
{
!
suggestions
.
length
&&
<
div
className=
{
classes
.
empty
}
><
span
>
{
__
(
'Nothing found…'
)
}
</
span
></
div
>
}
<
PendingOverlay
pending=
{
pending
||
false
}
/>
<
PendingOverlay
pending=
{
pending
||
false
}
/>
</
Paper
>
</
Paper
>
...
...
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