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
fd20ed86
Commit
fd20ed86
authored
Jul 18, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tooltip for regular text
parent
c0ab4182
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
3 deletions
+60
-3
AddressTagTableItem.tsx
ui/privateTags/AddressTagTable/AddressTagTableItem.tsx
+3
-3
TruncatedTextTooltip.tsx
ui/shared/TruncatedTextTooltip.tsx
+57
-0
No files found.
ui/privateTags/AddressTagTable/AddressTagTableItem.tsx
View file @
fd20ed86
...
...
@@ -5,7 +5,6 @@ import {
Tr
,
Td
,
HStack
,
Tooltip
,
}
from
'
@chakra-ui/react
'
import
AddressIcon
from
'
ui/shared/AddressIcon
'
;
...
...
@@ -14,6 +13,7 @@ import AddressLinkWithTooltip from 'ui/shared/AddressLinkWithTooltip';
import
type
{
TPrivateTagsAddressItem
}
from
'
data/privateTagsAddress
'
;
import
EditButton
from
'
ui/shared/EditButton
'
;
import
DeleteButton
from
'
ui/shared/DeleteButton
'
;
import
TruncatedTextTooltip
from
'
ui/shared/TruncatedTextTooltip
'
;
interface
Props
{
item
:
TPrivateTagsAddressItem
;
...
...
@@ -39,11 +39,11 @@ const AddressTagTableItem = ({ item, onEditClick, onDeleteClick }: Props) => {
</
HStack
>
</
Td
>
<
Td
>
<
Tooltip
label=
{
item
.
tag
}
>
<
T
runcatedTextT
ooltip
label=
{
item
.
tag
}
>
<
Tag
variant=
"gray"
lineHeight=
"24px"
>
{
item
.
tag
}
</
Tag
>
</
Tooltip
>
</
T
runcatedTextT
ooltip
>
</
Td
>
<
Td
>
<
HStack
spacing=
{
6
}
>
...
...
ui/shared/TruncatedTextTooltip.tsx
0 → 100644
View file @
fd20ed86
import
React
from
'
react
'
;
import
{
Tooltip
}
from
'
@chakra-ui/react
'
import
debounce
from
'
lodash/debounce
'
;
interface
Props
{
children
:
React
.
ReactNode
;
label
:
string
;
}
const
TruncatedTextTooltip
=
({
children
,
label
}:
Props
)
=>
{
const
childRef
=
React
.
useRef
<
HTMLElement
>
(
null
);
const
[
isTruncated
,
setTruncated
]
=
React
.
useState
(
false
);
const
updatedTruncateState
=
React
.
useCallback
(()
=>
{
if
(
childRef
.
current
)
{
const
scrollWidth
=
childRef
.
current
.
scrollWidth
;
const
clientWidth
=
childRef
.
current
.
clientWidth
;
if
(
scrollWidth
>
clientWidth
)
{
setTruncated
(
true
);
}
else
{
setTruncated
(
false
);
}
}
},
[]);
React
.
useLayoutEffect
(()
=>
{
updatedTruncateState
()
},
[
updatedTruncateState
]);
React
.
useEffect
(()
=>
{
const
handleResize
=
debounce
(
updatedTruncateState
,
1000
)
window
.
addEventListener
(
'
resize
'
,
handleResize
)
return
function
cleanup
()
{
window
.
removeEventListener
(
'
resize
'
,
handleResize
)
};
},
[
updatedTruncateState
]);
// as for now it supports only one child
// it is not cleared how to manage case with two or more children
const
child
=
React
.
Children
.
only
(
children
)
as
React
.
ReactElement
&
{
ref
?:
React
.
Ref
<
React
.
ReactNode
>
;
}
const
modifiedChildren
=
React
.
cloneElement
(
child
,
{
ref
:
childRef
},
);
if
(
isTruncated
)
{
return
<
Tooltip
label=
{
label
}
>
{
modifiedChildren
}
</
Tooltip
>;
}
return
modifiedChildren
;
};
export
default
React
.
memo
(
TruncatedTextTooltip
);
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