-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from KasperskyLab/feature/hide-selected-info-f…
…or-non-selectable-tables feat: hide selected info for non selectable tables
- Loading branch information
Showing
32 changed files
with
1,639 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/kaspersky-components/helpers/components/TextReducer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Tooltip } from '@src/tooltip' | ||
import React, { ReactNode, useEffect, useRef, useState, VFC } from 'react' | ||
import styled from 'styled-components' | ||
|
||
const TooltipWrapper = styled.div` | ||
overflow: hidden; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
word-break: keep-all; | ||
` | ||
|
||
const StyledContainer = styled.div` | ||
width: 100% | ||
` | ||
|
||
type TextReducerProps = { children?: ReactNode } | ||
|
||
export const TextReducer: VFC<TextReducerProps> = ({ children }: TextReducerProps) => { | ||
const ref = useRef<HTMLDivElement>(null) | ||
const containerRef = useRef<HTMLDivElement>(null) | ||
const [hasOverflow, setHasOverflow] = useState(false) | ||
|
||
useEffect(() => { | ||
if (!containerRef.current) return | ||
const container = containerRef.current | ||
const resizeObserver = new ResizeObserver(() => { | ||
if (!ref.current) return | ||
setHasOverflow(ref.current.offsetWidth < ref.current.scrollWidth) | ||
}) | ||
resizeObserver.observe(container) | ||
return () => resizeObserver.unobserve(container) | ||
}, [containerRef.current]) | ||
|
||
return ( | ||
<StyledContainer ref={containerRef}> | ||
{ | ||
hasOverflow | ||
? <Tooltip text={children}> | ||
<TooltipWrapper ref={ref}>{children}</TooltipWrapper> | ||
</Tooltip> | ||
: <TooltipWrapper ref={ref}>{children}</TooltipWrapper> | ||
} | ||
</StyledContainer> | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.