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
91bcfa06
Commit
91bcfa06
authored
Oct 16, 2018
by
Vladislav Lagunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
printItem в MultiSelect
parent
82b10bbc
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
8 deletions
+50
-8
AutoComplete.tsx
+12
-4
MultiSelect.tsx
+14
-4
WithContext.tsx
+23
-0
index.ts
+1
-0
No files found.
AutoComplete.tsx
View file @
91bcfa06
...
...
@@ -14,6 +14,7 @@ import * as ST from '~/fields/AutoComplete/state-machine';
import
*
as
Rx
from
'rxjs'
;
import
{
memoize
}
from
'~/utils'
;
import
{
pick
}
from
'lodash'
;
import
classNames
=
require
(
'classnames'
);
// Props
...
...
@@ -47,7 +48,7 @@ export type State<A> = AutoCompleteState<A> & {
// Component
// @ts-ignore Хак для работы дженерик-параметров
@
withStyles
(
styles
)
export
default
class
AutoComplete
<
A
=
string
>
extends
React
.
Pure
Component
<
Props
<
A
>
,
State
<
A
>>
{
export
default
class
AutoComplete
<
A
=
string
>
extends
React
.
Component
<
Props
<
A
>
,
State
<
A
>>
{
static
defaultProps
=
{
openOnFocus
:
true
,
openOnClick
:
true
,
...
...
@@ -184,10 +185,13 @@ export default class AutoComplete<A=string> extends React.PureComponent<Props<A>
};
render
()
{
const
{
children
,
ctx
,
source
,
debounce
,
renderItem
,
printItem
,
openOnFocus
,
openOnClick
,
suggestionProps
,
keepOpenAfterSelect
,
textFieldProps
,
classes
,
anchorEl
,
observable
,
...
rest
}
=
this
.
props
;
const
{
c
lassName
,
fullWidth
,
c
hildren
,
ctx
,
source
,
debounce
,
renderItem
,
printItem
,
openOnFocus
,
openOnClick
,
suggestionProps
,
keepOpenAfterSelect
,
textFieldProps
,
classes
,
anchorEl
,
observable
,
...
rest
}
=
this
.
props
;
const
{
suggestions
,
open
}
=
this
.
state
;
const
rootClass
=
classNames
(
classes
!
.
root
,
className
,
{
[
classes
!
.
fullWidth
!
]:
fullWidth
});
return
<
div
{
...
rest
}
className=
{
classes
!
.
wrapper
}
>
return
<
div
{
...
rest
}
className=
{
rootClass
}
>
{
!
observable
&&
(
children
?
React
.
cloneElement
(
children
,
this
.
childrenProps
())
:
<
TextField
{
...
this
.
childrenProps
()
as
any
}
{
...
textFieldProps
}
/>)
}
<
Suggestions
{
...
suggestionProps
}
...
...
@@ -267,10 +271,14 @@ export function styles(theme: Theme): StyleRules {
// const { unit } = theme.spacing;
return
{
wrapper
:
{
root
:
{
'& > div'
:
{
position
:
'relative'
,
}
},
fullWidth
:
{
width
:
'100%'
,
},
};
}
MultiSelect.tsx
View file @
91bcfa06
...
...
@@ -14,8 +14,9 @@ import { FieldProps } from '~/fields';
// Props
export
type
Props
<
A
>
=
StandardProps
<
React
.
HTMLProps
<
HTMLDivElement
>
,
string
,
'value'
>
&
FieldProps
&
{
source
:
Source
<
A
>
;
fullWidth
?:
boolean
;
textFieldProps
?:
Partial
<
TextFieldProps
>
;
render
Suggestion
?(
a
:
A
):
React
.
ReactNode
;
render
Item
?(
a
:
A
,
selected
:
boolean
):
React
.
ReactNode
;
placeholder
?:
string
;
printItem
?(
a
:
A
):
string
;
id
?:
string
;
// Используется для установки `key` пропсов
...
...
@@ -77,20 +78,23 @@ export default class MultiSelect<A> extends React.Component<Props<A>> {
});
renderSuggestion
=
(
item
:
A
)
=>
{
const
{
render
Suggestion
,
printItem
,
value
}
=
this
.
props
;
const
{
render
Item
,
printItem
,
value
}
=
this
.
props
;
const
selected
=
!!
value
!
.
find
(
x
=>
this
.
isEqual
(
x
,
item
));
const
id
=
this
.
props
.
id
||
'id'
;
if
(
renderItem
)
return
renderItem
(
item
,
selected
);
return
<
MenuItem
key=
{
item
[
id
]
}
disableRipple
>
<
Checkbox
disableRipple
checked=
{
selected
}
/>
<
ListItemText
primary=
{
(
renderSuggestion
||
printItem
||
String
)(
item
)
}
/>
<
ListItemText
primary=
{
(
printItem
||
String
)(
item
)
}
/>
</
MenuItem
>;
};
render
()
{
const
{
classes
,
className
,
source
,
renderSuggestion
,
printItem
,
id
,
textFieldProps
,
value
,
error
,
disabled
,
onValueChange
,
placeholder
,
...
rest
}
=
this
.
props
;
const
{
classes
,
fullWidth
,
className
,
source
,
renderItem
,
printItem
,
id
,
textFieldProps
,
value
,
error
,
disabled
,
onValueChange
,
placeholder
,
...
rest
}
=
this
.
props
;
const
rootClass
=
classNames
(
className
,
classes
!
.
root
,
{
[
classes
!
.
disabled
!
]:
disabled
,
[
classes
!
.
fullWidth
!
]:
fullWidth
,
});
return
<
div
{
...
rest
}
className=
{
rootClass
}
>
...
...
@@ -99,12 +103,14 @@ export default class MultiSelect<A> extends React.Component<Props<A>> {
value=
{
null
}
printItem=
{
printItem
}
source=
{
source
}
// @ts-ignore
renderItem=
{
this
.
renderSuggestion
}
onValueChange=
{
this
.
handleValueChange
}
textFieldProps=
{
textFieldProps
}
placeholder=
{
placeholder
}
error=
{
error
}
disabled=
{
disabled
}
fullWidth=
{
fullWidth
}
keepOpenAfterSelect
openOnClick
openOnFocus
...
...
@@ -137,5 +143,9 @@ export function styles(theme: Theme): StyleRules {
disabled
:
{
cursor
:
'not-allowed'
,
},
fullWidth
:
{
width
:
'100%'
,
},
};
}
WithContext.tsx
0 → 100644
View file @
91bcfa06
import
*
as
React
from
'react'
;
import
{
FieldProps
}
from
'./'
;
import
*
as
F
from
'./'
;
// Props
export
type
Props
<
A
>
=
Partial
<
FieldProps
<
A
>>
&
{
Component
:
React
.
ReactType
<
FieldProps
<
A
>>
;
};
// Component
export
default
class
WithContext
<
A
>
extends
React
.
Component
<
Props
<
A
>>
{
renderConsumer
=
(
context
:
FieldProps
<
A
>
)
=>
{
const
{
Component
,
...
rest
}
=
this
.
props
;
// @ts-ignore
return
React
.
createElement
(
Component
,
{
...
context
,
...
rest
});
};
render
()
{
return
<
F
.
Consumer
>
{
this
.
renderConsumer
}
</
F
.
Consumer
>;
}
}
index.ts
View file @
91bcfa06
...
...
@@ -7,6 +7,7 @@ export { default as Label } from './Label';
export
{
default
as
ResourceID
}
from
'./ResourceID'
;
export
{
default
as
ArrayIDS
}
from
'./ArrayIDS'
;
export
{
default
as
Debounce
}
from
'./Debounce'
;
export
{
default
as
WithContext
}
from
'./WithContext'
;
import
BooleanField_
from
'./BooleanField'
;
...
...
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