Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
4fece895
Unverified
Commit
4fece895
authored
Sep 08, 2022
by
Igor Stuev
Committed by
GitHub
Sep 08, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #134 from blockscout/text-cut
page description cut
parents
ed382509
9b728a4f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
5 deletions
+60
-5
AccountPageDescription.tsx
ui/shared/AccountPageDescription.tsx
+60
-5
No files found.
ui/shared/AccountPageDescription.tsx
View file @
4fece895
import
{
Text
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Text
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
_debounce
from
'
lodash/debounce
'
;
import
React
,
{
useRef
,
useEffect
,
useState
,
useCallback
}
from
'
react
'
;
const
CUT_HEIGHT
=
144
;
const
AccountPageDescription
=
({
children
}:
{
children
:
React
.
ReactNode
})
=>
{
const
AccountPageDescription
=
({
children
}:
{
children
:
React
.
ReactNode
})
=>
{
const
ref
=
useRef
<
HTMLParagraphElement
>
(
null
);
const
[
needCut
,
setNeedCut
]
=
useState
(
false
);
const
[
expanded
,
setExpanded
]
=
useState
(
false
);
const
calculateCut
=
useCallback
(()
=>
{
const
textHeight
=
ref
.
current
?.
offsetHeight
;
if
(
!
needCut
&&
textHeight
&&
textHeight
>
CUT_HEIGHT
)
{
setNeedCut
(
true
);
}
else
if
(
needCut
&&
textHeight
&&
textHeight
<
CUT_HEIGHT
)
{
setNeedCut
(
false
);
}
},
[
needCut
]);
useEffect
(()
=>
{
calculateCut
();
const
resizeHandler
=
_debounce
(
calculateCut
,
300
);
window
.
addEventListener
(
'
resize
'
,
resizeHandler
);
return
function
cleanup
()
{
window
.
removeEventListener
(
'
resize
'
,
resizeHandler
);
};
},
[
calculateCut
]);
const
expand
=
useCallback
(()
=>
{
setExpanded
(
true
);
},
[]);
const
gradient
=
useColorModeValue
(
'
linear-gradient(360deg, rgba(255, 255, 255, 0.8) 38.1%, rgba(255, 255, 255, 0) 166.67%)
'
,
'
linear-gradient(360deg, rgba(16, 17, 18, 0.8) 38.1%, rgba(16, 17, 18, 0) 166.67%)
'
,
);
return
(
return
(
<
Text
marginBottom=
{
{
base
:
6
,
lg
:
12
}
}
>
<
Box
position=
"relative"
marginBottom=
{
{
base
:
6
,
lg
:
12
}
}
>
{
children
}
<
Text
</
Text
>
ref=
{
ref
}
maxHeight=
{
needCut
&&
!
expanded
?
`${ CUT_HEIGHT }px`
:
'
auto
'
}
overflow=
"hidden"
style=
{
needCut
&&
!
expanded
?
{
WebkitLineClamp
:
'
6
'
,
WebkitBoxOrient
:
'
vertical
'
,
display
:
'
-webkit-box
'
}
:
{}
}
>
{
children
}
</
Text
>
{
needCut
&&
!
expanded
&&
(
<
Box
position=
"absolute"
bottom=
"-16px"
left=
{
0
}
width=
"100%"
height=
"63px"
style=
{
{
background
:
gradient
}
}
onClick=
{
expand
}
>
</
Box
>
)
}
</
Box
>
);
);
};
};
...
...
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