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
fc2862b7
Commit
fc2862b7
authored
Jan 18, 2018
by
nikogu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move -webkit-box-orient to js Ellipsis
parent
4a87502d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
51 deletions
+52
-51
src/components/Ellipsis/index.js
src/components/Ellipsis/index.js
+52
-50
src/components/Ellipsis/index.less
src/components/Ellipsis/index.less
+0
-1
No files found.
src/components/Ellipsis/index.js
View file @
fc2862b7
...
@@ -6,7 +6,7 @@ import styles from './index.less';
...
@@ -6,7 +6,7 @@ import styles from './index.less';
/* eslint react/no-did-mount-set-state: 0 */
/* eslint react/no-did-mount-set-state: 0 */
/* eslint no-param-reassign: 0 */
/* eslint no-param-reassign: 0 */
const
isSupportLineClamp
=
(
document
.
body
.
style
.
webkitLineClamp
!==
undefined
)
;
const
isSupportLineClamp
=
document
.
body
.
style
.
webkitLineClamp
!==
undefined
;
const
EllipsisText
=
({
text
,
length
,
tooltip
,
...
other
})
=>
{
const
EllipsisText
=
({
text
,
length
,
tooltip
,
...
other
})
=>
{
if
(
typeof
text
!==
'
string
'
)
{
if
(
typeof
text
!==
'
string
'
)
{
...
@@ -20,16 +20,24 @@ const EllipsisText = ({ text, length, tooltip, ...other }) => {
...
@@ -20,16 +20,24 @@ const EllipsisText = ({ text, length, tooltip, ...other }) => {
if
(
length
-
tail
.
length
<=
0
)
{
if
(
length
-
tail
.
length
<=
0
)
{
displayText
=
''
;
displayText
=
''
;
}
else
{
}
else
{
displayText
=
text
.
slice
(
0
,
(
length
-
tail
.
length
)
);
displayText
=
text
.
slice
(
0
,
length
-
tail
.
length
);
}
}
if
(
tooltip
)
{
if
(
tooltip
)
{
return
<
Tooltip
title
=
{
text
}
><
span
>
{
displayText
}{
tail
}
<
/span></
Tooltip
>
;
return
(
<
Tooltip
title
=
{
text
}
>
<
span
>
{
displayText
}
{
tail
}
<
/span
>
<
/Tooltip
>
);
}
}
return
(
return
(
<
span
{...
other
}
>
<
span
{...
other
}
>
{
displayText
}{
tail
}
{
displayText
}
{
tail
}
<
/span
>
<
/span
>
);
);
};
};
...
@@ -38,7 +46,7 @@ export default class Ellipsis extends Component {
...
@@ -38,7 +46,7 @@ export default class Ellipsis extends Component {
state
=
{
state
=
{
text
:
''
,
text
:
''
,
targetCount
:
0
,
targetCount
:
0
,
}
}
;
componentDidMount
()
{
componentDidMount
()
{
if
(
this
.
node
)
{
if
(
this
.
node
)
{
...
@@ -81,7 +89,7 @@ export default class Ellipsis extends Component {
...
@@ -81,7 +89,7 @@ export default class Ellipsis extends Component {
targetCount
:
count
,
targetCount
:
count
,
});
});
}
}
}
}
;
bisection
=
(
th
,
m
,
b
,
e
,
text
,
shadowNode
)
=>
{
bisection
=
(
th
,
m
,
b
,
e
,
text
,
shadowNode
)
=>
{
const
suffix
=
'
...
'
;
const
suffix
=
'
...
'
;
...
@@ -115,94 +123,88 @@ export default class Ellipsis extends Component {
...
@@ -115,94 +123,88 @@ export default class Ellipsis extends Component {
return
this
.
bisection
(
th
,
mid
,
begin
,
end
,
text
,
shadowNode
);
return
this
.
bisection
(
th
,
mid
,
begin
,
end
,
text
,
shadowNode
);
}
}
}
}
}
}
;
handleRoot
=
(
n
)
=>
{
handleRoot
=
(
n
)
=>
{
this
.
root
=
n
;
this
.
root
=
n
;
}
}
;
handleContent
=
(
n
)
=>
{
handleContent
=
(
n
)
=>
{
this
.
content
=
n
;
this
.
content
=
n
;
}
}
;
handleNode
=
(
n
)
=>
{
handleNode
=
(
n
)
=>
{
this
.
node
=
n
;
this
.
node
=
n
;
}
}
;
handleShadow
=
(
n
)
=>
{
handleShadow
=
(
n
)
=>
{
this
.
shadow
=
n
;
this
.
shadow
=
n
;
}
}
;
handleShadowChildren
=
(
n
)
=>
{
handleShadowChildren
=
(
n
)
=>
{
this
.
shadowChildren
=
n
;
this
.
shadowChildren
=
n
;
}
}
;
render
()
{
render
()
{
const
{
text
,
targetCount
}
=
this
.
state
;
const
{
text
,
targetCount
}
=
this
.
state
;
const
{
const
{
children
,
lines
,
length
,
className
,
tooltip
,
...
restProps
}
=
this
.
props
;
children
,
lines
,
length
,
className
,
tooltip
,
...
restProps
}
=
this
.
props
;
const
cls
=
classNames
(
styles
.
ellipsis
,
className
,
{
const
cls
=
classNames
(
styles
.
ellipsis
,
className
,
{
[
styles
.
lines
]:
(
lines
&&
!
isSupportLineClamp
)
,
[
styles
.
lines
]:
lines
&&
!
isSupportLineClamp
,
[
styles
.
lineClamp
]:
(
lines
&&
isSupportLineClamp
)
,
[
styles
.
lineClamp
]:
lines
&&
isSupportLineClamp
,
});
});
if
(
!
lines
&&
!
length
)
{
if
(
!
lines
&&
!
length
)
{
return
(
<
span
className
=
{
cls
}
{...
restProps
}
>
{
children
}
<
/span>
)
;
return
(
<
span
className
=
{
cls
}
{...
restProps
}
>
{
children
}
<
/span
>
);
}
}
// length
// length
if
(
!
lines
)
{
if
(
!
lines
)
{
return
(
<
EllipsisText
className
=
{
cls
}
length
=
{
length
}
text
=
{
children
||
''
}
tooltip
=
{
tooltip
}
{...
restProps
}
/>
)
;
return
(
<
EllipsisText
className
=
{
cls
}
length
=
{
length
}
text
=
{
children
||
''
}
tooltip
=
{
tooltip
}
{...
restProps
}
/
>
);
}
}
const
id
=
`antd-pro-ellipsis-
${
`
${
new
Date
().
getTime
()}${
Math
.
floor
(
Math
.
random
()
*
100
)}
`
}
`
;
const
id
=
`antd-pro-ellipsis-
${
`
${
new
Date
().
getTime
()}${
Math
.
floor
(
Math
.
random
()
*
100
)}
`
}
`
;
// support document.body.style.webkitLineClamp
// support document.body.style.webkitLineClamp
if
(
isSupportLineClamp
)
{
if
(
isSupportLineClamp
)
{
const
style
=
`#
${
id
}
{-webkit-line-clamp:
${
lines
}
;}`
;
const
style
=
`#
${
id
}
{-webkit-line-clamp:
${
lines
}
;
-webkit-box-orient: vertical;
}`
;
return
(
return
(
<
div
id
=
{
id
}
className
=
{
cls
}
{...
restProps
}
>
<
div
id
=
{
id
}
className
=
{
cls
}
{...
restProps
}
>
<
style
>
{
style
}
<
/style
>
<
style
>
{
style
}
<
/style
>
{
{
tooltip
?
<
Tooltip
title
=
{
children
}
>
{
children
}
<
/Tooltip> : children
}
tooltip
?
(
<
Tooltip
title
=
{
children
}
>
{
children
}
<
/Tooltip>
)
: childre
n
<
/div
>
}
);
<
/div>
)
;
}
}
const
childNode
=
(
const
childNode
=
(
<
span
ref
=
{
this
.
handleNode
}
>
<
span
ref
=
{
this
.
handleNode
}
>
{
{
targetCount
>
0
&&
text
.
substring
(
0
,
targetCount
)}
(
targetCount
>
0
)
&&
text
.
substring
(
0
,
targetCount
)
{
targetCount
>
0
&&
targetCount
<
text
.
length
&&
'
...
'
}
}
{
(
targetCount
>
0
)
&&
(
targetCount
<
text
.
length
)
&&
'
...
'
}
<
/span
>
<
/span
>
);
);
return
(
return
(
<
div
<
div
{...
restProps
}
ref
=
{
this
.
handleRoot
}
className
=
{
cls
}
>
{...
restProps
}
<
div
ref
=
{
this
.
handleContent
}
>
ref
=
{
this
.
handleRoot
}
{
tooltip
?
<
Tooltip
title
=
{
text
}
>
{
childNode
}
<
/Tooltip> : childNode
}
className
=
{
cls
}
<
div
className
=
{
styles
.
shadow
}
ref
=
{
this
.
handleShadowChildren
}
>
>
{
children
}
<
div
<
/div
>
ref
=
{
this
.
handleContent
}
<
div
className
=
{
styles
.
shadow
}
ref
=
{
this
.
handleShadow
}
>
>
<
span
>
{
text
}
<
/span
>
{
<
/div
>
tooltip
?
(
<
Tooltip
title
=
{
text
}
>
{
childNode
}
<
/Tooltip
>
)
:
childNode
}
<
div
className
=
{
styles
.
shadow
}
ref
=
{
this
.
handleShadowChildren
}
>
{
children
}
<
/div
>
<
div
className
=
{
styles
.
shadow
}
ref
=
{
this
.
handleShadow
}
><
span
>
{
text
}
<
/span></
div
>
<
/div
>
<
/div
>
<
/div
>
<
/div
>
);
);
...
...
src/components/Ellipsis/index.less
View file @
fc2862b7
...
@@ -21,5 +21,4 @@
...
@@ -21,5 +21,4 @@
overflow: hidden;
overflow: hidden;
text-overflow: ellipsis;
text-overflow: ellipsis;
display: -webkit-box;
display: -webkit-box;
-webkit-box-orient: vertical;
}
}
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