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';
/* eslint react/no-did-mount-set-state: 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
})
=>
{
if
(
typeof
text
!==
'
string
'
)
{
...
...
@@ -20,16 +20,24 @@ const EllipsisText = ({ text, length, tooltip, ...other }) => {
if
(
length
-
tail
.
length
<=
0
)
{
displayText
=
''
;
}
else
{
displayText
=
text
.
slice
(
0
,
(
length
-
tail
.
length
)
);
displayText
=
text
.
slice
(
0
,
length
-
tail
.
length
);
}
if
(
tooltip
)
{
return
<
Tooltip
title
=
{
text
}
><
span
>
{
displayText
}{
tail
}
<
/span></
Tooltip
>
;
return
(
<
Tooltip
title
=
{
text
}
>
<
span
>
{
displayText
}
{
tail
}
<
/span
>
<
/Tooltip
>
);
}
return
(
<
span
{...
other
}
>
{
displayText
}{
tail
}
{
displayText
}
{
tail
}
<
/span
>
);
};
...
...
@@ -38,7 +46,7 @@ export default class Ellipsis extends Component {
state
=
{
text
:
''
,
targetCount
:
0
,
}
}
;
componentDidMount
()
{
if
(
this
.
node
)
{
...
...
@@ -81,7 +89,7 @@ export default class Ellipsis extends Component {
targetCount
:
count
,
});
}
}
}
;
bisection
=
(
th
,
m
,
b
,
e
,
text
,
shadowNode
)
=>
{
const
suffix
=
'
...
'
;
...
...
@@ -115,94 +123,88 @@ export default class Ellipsis extends Component {
return
this
.
bisection
(
th
,
mid
,
begin
,
end
,
text
,
shadowNode
);
}
}
}
}
;
handleRoot
=
(
n
)
=>
{
this
.
root
=
n
;
}
}
;
handleContent
=
(
n
)
=>
{
this
.
content
=
n
;
}
}
;
handleNode
=
(
n
)
=>
{
this
.
node
=
n
;
}
}
;
handleShadow
=
(
n
)
=>
{
this
.
shadow
=
n
;
}
}
;
handleShadowChildren
=
(
n
)
=>
{
this
.
shadowChildren
=
n
;
}
}
;
render
()
{
const
{
text
,
targetCount
}
=
this
.
state
;
const
{
children
,
lines
,
length
,
className
,
tooltip
,
...
restProps
}
=
this
.
props
;
const
{
children
,
lines
,
length
,
className
,
tooltip
,
...
restProps
}
=
this
.
props
;
const
cls
=
classNames
(
styles
.
ellipsis
,
className
,
{
[
styles
.
lines
]:
(
lines
&&
!
isSupportLineClamp
)
,
[
styles
.
lineClamp
]:
(
lines
&&
isSupportLineClamp
)
,
[
styles
.
lines
]:
lines
&&
!
isSupportLineClamp
,
[
styles
.
lineClamp
]:
lines
&&
isSupportLineClamp
,
});
if
(
!
lines
&&
!
length
)
{
return
(
<
span
className
=
{
cls
}
{...
restProps
}
>
{
children
}
<
/span>
)
;
return
(
<
span
className
=
{
cls
}
{...
restProps
}
>
{
children
}
<
/span
>
);
}
// length
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
)}
`
}
`
;
// support document.body.style.webkitLineClamp
if
(
isSupportLineClamp
)
{
const
style
=
`#
${
id
}
{-webkit-line-clamp:
${
lines
}
;}`
;
const
style
=
`#
${
id
}
{-webkit-line-clamp:
${
lines
}
;
-webkit-box-orient: vertical;
}`
;
return
(
<
div
id
=
{
id
}
className
=
{
cls
}
{...
restProps
}
>
<
style
>
{
style
}
<
/style
>
{
tooltip
?
(
<
Tooltip
title
=
{
children
}
>
{
children
}
<
/Tooltip>
)
: childre
n
}
<
/div>
)
;
{
tooltip
?
<
Tooltip
title
=
{
children
}
>
{
children
}
<
/Tooltip> : children
}
<
/div
>
);
}
const
childNode
=
(
<
span
ref
=
{
this
.
handleNode
}
>
{
(
targetCount
>
0
)
&&
text
.
substring
(
0
,
targetCount
)
}
{
(
targetCount
>
0
)
&&
(
targetCount
<
text
.
length
)
&&
'
...
'
}
{
targetCount
>
0
&&
text
.
substring
(
0
,
targetCount
)}
{
targetCount
>
0
&&
targetCount
<
text
.
length
&&
'
...
'
}
<
/span
>
);
return
(
<
div
{...
restProps
}
ref
=
{
this
.
handleRoot
}
className
=
{
cls
}
>
<
div
ref
=
{
this
.
handleContent
}
>
{
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
{...
restProps
}
ref
=
{
this
.
handleRoot
}
className
=
{
cls
}
>
<
div
ref
=
{
this
.
handleContent
}
>
{
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
>
);
...
...
src/components/Ellipsis/index.less
View file @
fc2862b7
...
...
@@ -21,5 +21,4 @@
overflow: hidden;
text-overflow: ellipsis;
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