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
Hide 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 }) => (
...
@@ -15,19 +15,17 @@ const TagSelectOption = ({ children, checked, onChange, value }) => (
{
children
}
{
children
}
<
/CheckableTag
>
<
/CheckableTag
>
);
);
TagSelectOption
.
defaultProps
=
{
displayName
:
'
TagSelectOption
'
,
TagSelectOption
.
isTagSelectOption
=
true
;
};
class
TagSelect
extends
Component
{
class
TagSelect
extends
Component
{
static
defaultProps
=
{
static
defaultProps
=
{
initial
Value
:
[],
default
Value
:
[],
};
};
state
=
{
state
=
{
checkedAll
:
false
,
expand
:
false
,
expand
:
false
,
checkedTags
:
this
.
props
.
initial
Value
||
[],
checkedTags
:
this
.
props
.
default
Value
||
[],
};
};
onSelectAll
=
(
checked
)
=>
{
onSelectAll
=
(
checked
)
=>
{
...
@@ -37,10 +35,7 @@ class TagSelect extends Component {
...
@@ -37,10 +35,7 @@ class TagSelect extends Component {
checkedTags
=
this
.
getAllTags
();
checkedTags
=
this
.
getAllTags
();
}
}
this
.
setState
({
this
.
setState
({
checkedTags
});
checkedAll
:
checked
,
checkedTags
,
});
if
(
onChange
)
{
if
(
onChange
)
{
onChange
(
checkedTags
);
onChange
(
checkedTags
);
...
@@ -50,7 +45,7 @@ class TagSelect extends Component {
...
@@ -50,7 +45,7 @@ class TagSelect extends Component {
getAllTags
()
{
getAllTags
()
{
const
{
children
}
=
this
.
props
;
const
{
children
}
=
this
.
props
;
const
checkedTags
=
children
const
checkedTags
=
children
.
filter
(
child
=>
child
.
props
.
displayName
===
'
TagSelectOption
'
)
.
filter
(
child
=>
this
.
isTagSelectOption
(
child
)
)
.
map
(
child
=>
child
.
props
.
value
);
.
map
(
child
=>
child
.
props
.
value
);
return
checkedTags
;
return
checkedTags
;
}
}
...
@@ -66,12 +61,7 @@ class TagSelect extends Component {
...
@@ -66,12 +61,7 @@ class TagSelect extends Component {
checkedTags
.
splice
(
index
,
1
);
checkedTags
.
splice
(
index
,
1
);
}
}
const
tags
=
this
.
getAllTags
();
this
.
setState
({
checkedTags
});
this
.
setState
({
checkedAll
:
tags
.
length
===
checkedTags
.
length
,
checkedTags
,
});
if
(
onChange
)
{
if
(
onChange
)
{
onChange
(
checkedTags
);
onChange
(
checkedTags
);
...
@@ -84,10 +74,18 @@ class TagSelect extends Component {
...
@@ -84,10 +74,18 @@ class TagSelect extends Component {
});
});
}
}
isTagSelectOption
=
(
node
)
=>
{
return
node
&&
node
.
type
&&
(
node
.
type
.
isTagSelectOption
||
node
.
type
.
displayName
===
'
TagSelectOption
'
);
}
render
()
{
render
()
{
const
{
checkedTags
,
checkedAll
,
expand
}
=
this
.
state
;
const
{
checkedTags
,
expand
}
=
this
.
state
;
const
{
children
,
className
,
style
,
expandable
}
=
this
.
props
;
const
{
children
,
className
,
style
,
expandable
}
=
this
.
props
;
const
checkedAll
=
this
.
getAllTags
().
length
===
checkedTags
.
length
;
const
cls
=
classNames
(
styles
.
tagSelect
,
className
,
{
const
cls
=
classNames
(
styles
.
tagSelect
,
className
,
{
[
styles
.
hasExpandTag
]:
expandable
,
[
styles
.
hasExpandTag
]:
expandable
,
[
styles
.
expanded
]:
expand
,
[
styles
.
expanded
]:
expand
,
...
@@ -103,16 +101,22 @@ class TagSelect extends Component {
...
@@ -103,16 +101,22 @@ class TagSelect extends Component {
ε ¨ι¨
ε ¨ι¨
<
/CheckableTag
>
<
/CheckableTag
>
{
{
checkedTags
&&
children
.
filter
(
child
=>
child
.
props
.
displayName
===
'
TagSelectOption
'
).
map
(
child
=>
React
.
cloneElement
(
child
,
{
checkedTags
&&
children
key
:
`tag-select-
${
child
.
props
.
value
}
`
,
.
map
((
child
)
=>
{
checked
:
checkedTags
.
indexOf
(
child
.
props
.
value
)
>
-
1
,
if
(
this
.
isTagSelectOption
(
child
))
{
onChange
:
this
.
handleTagChange
,
return
React
.
cloneElement
(
child
,
{
}))
key
:
`tag-select-
${
child
.
props
.
value
}
`
,
checked
:
checkedTags
.
indexOf
(
child
.
props
.
value
)
>
-
1
,
onChange
:
this
.
handleTagChange
,
});
}
return
child
;
})
}
}
{
{
expandable
&&
(
expandable
&&
(
<
a
className
=
{
styles
.
trigger
}
onClick
=
{
this
.
handleExpand
}
>
<
a
className
=
{
styles
.
trigger
}
onClick
=
{
this
.
handleExpand
}
>
{
expand
?
'
ζΆθ΅·
'
:
'
ε±εΌ
'
}
<
Icon
type
=
{
expand
?
'
up
'
:
'
down
'
}
/
>
{
expand
?
'
ζΆθ΅·
'
:
'
ε±εΌ
'
}
<
Icon
type
=
{
expand
?
'
up
'
:
'
down
'
}
/
>
<
/a
>
<
/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