Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
f2817dfd
Commit
f2817dfd
authored
Nov 13, 2017
by
afc163
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor TagSelect state, close #161
parent
7815eecd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
24 deletions
+28
-24
src/components/TagSelect/index.js
src/components/TagSelect/index.js
+28
-24
No files found.
src/components/TagSelect/index.js
View file @
f2817dfd
...
...
@@ -15,19 +15,17 @@ const TagSelectOption = ({ children, checked, onChange, value }) => (
{
children
}
<
/CheckableTag
>
);
TagSelectOption
.
defaultProps
=
{
displayName
:
'
TagSelectOption
'
,
};
TagSelectOption
.
isTagSelectOption
=
true
;
class
TagSelect
extends
Component
{
static
defaultProps
=
{
initial
Value
:
[],
default
Value
:
[],
};
state
=
{
checkedAll
:
false
,
expand
:
false
,
checkedTags
:
this
.
props
.
initial
Value
||
[],
checkedTags
:
this
.
props
.
default
Value
||
[],
};
onSelectAll
=
(
checked
)
=>
{
...
...
@@ -37,10 +35,7 @@ class TagSelect extends Component {
checkedTags
=
this
.
getAllTags
();
}
this
.
setState
({
checkedAll
:
checked
,
checkedTags
,
});
this
.
setState
({
checkedTags
});
if
(
onChange
)
{
onChange
(
checkedTags
);
...
...
@@ -50,7 +45,7 @@ class TagSelect extends Component {
getAllTags
()
{
const
{
children
}
=
this
.
props
;
const
checkedTags
=
children
.
filter
(
child
=>
child
.
props
.
displayName
===
'
TagSelectOption
'
)
.
filter
(
child
=>
this
.
isTagSelectOption
(
child
)
)
.
map
(
child
=>
child
.
props
.
value
);
return
checkedTags
;
}
...
...
@@ -66,12 +61,7 @@ class TagSelect extends Component {
checkedTags
.
splice
(
index
,
1
);
}
const
tags
=
this
.
getAllTags
();
this
.
setState
({
checkedAll
:
tags
.
length
===
checkedTags
.
length
,
checkedTags
,
});
this
.
setState
({
checkedTags
});
if
(
onChange
)
{
onChange
(
checkedTags
);
...
...
@@ -84,10 +74,18 @@ class TagSelect extends Component {
});
}
isTagSelectOption
=
(
node
)
=>
{
return
node
&&
node
.
type
&&
(
node
.
type
.
isTagSelectOption
||
node
.
type
.
displayName
===
'
TagSelectOption
'
);
}
render
()
{
const
{
checkedTags
,
checkedAll
,
expand
}
=
this
.
state
;
const
{
checkedTags
,
expand
}
=
this
.
state
;
const
{
children
,
className
,
style
,
expandable
}
=
this
.
props
;
const
checkedAll
=
this
.
getAllTags
().
length
===
checkedTags
.
length
;
const
cls
=
classNames
(
styles
.
tagSelect
,
className
,
{
[
styles
.
hasExpandTag
]:
expandable
,
[
styles
.
expanded
]:
expand
,
...
...
@@ -103,16 +101,22 @@ class TagSelect extends Component {
ε ¨ι¨
<
/CheckableTag
>
{
checkedTags
&&
children
.
filter
(
child
=>
child
.
props
.
displayName
===
'
TagSelectOption
'
).
map
(
child
=>
React
.
cloneElement
(
child
,
{
checkedTags
&&
children
.
map
((
child
)
=>
{
if
(
this
.
isTagSelectOption
(
child
))
{
return
React
.
cloneElement
(
child
,
{
key
:
`tag-select-
${
child
.
props
.
value
}
`
,
checked
:
checkedTags
.
indexOf
(
child
.
props
.
value
)
>
-
1
,
onChange
:
this
.
handleTagChange
,
}))
});
}
return
child
;
})
}
{
expandable
&&
(
<
a
className
=
{
styles
.
trigger
}
onClick
=
{
this
.
handleExpand
}
>
{
expand
?
'
ζΆθ΅·
'
:
'
ε±εΌ
'
}
<
Icon
type
=
{
expand
?
'
up
'
:
'
down
'
}
/
>
{
expand
?
'
ζΆθ΅·
'
:
'
ε±εΌ
'
}
<
Icon
type
=
{
expand
?
'
up
'
:
'
down
'
}
/
>
<
/a
>
)
}
...
...
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