This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UIKIT-1771,OverflowTypography): Добавлен prop visibleLastSymbols…
…Count (#1138)
- Loading branch information
1 parent
e1147d8
commit 658f37b
Showing
8 changed files
with
150 additions
and
31 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useLogic'; |
35 changes: 35 additions & 0 deletions
35
packages/components/src/OverflowTypography/useLogic/useLogic.ts
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,35 @@ | ||
import { type ForwardedRef } from 'react'; | ||
|
||
import { useOverflowed } from '../hooks'; | ||
import { type OverflowedTypographyProps } from '../OverflowTypography'; | ||
import { truncateString } from '../utils'; | ||
|
||
type UseLogicParams = OverflowedTypographyProps & { | ||
forwardedRef: ForwardedRef<HTMLElement>; | ||
}; | ||
|
||
export const useLogic = ({ | ||
forwardedRef, | ||
children, | ||
visibleLastSymbolsCount, | ||
}: UseLogicParams) => { | ||
const { ref, isOverflowed } = useOverflowed(forwardedRef); | ||
|
||
const canSlice = children && typeof children === 'string'; | ||
|
||
const { firstPartLabel, secondPartLabel } = | ||
canSlice && isOverflowed && visibleLastSymbolsCount | ||
? truncateString(visibleLastSymbolsCount, children) | ||
: { firstPartLabel: '', secondPartLabel: '' }; | ||
|
||
const isTruncatedStringVisible = | ||
canSlice && isOverflowed && Boolean(visibleLastSymbolsCount); | ||
|
||
return { | ||
isTruncatedStringVisible, | ||
isOverflowed, | ||
ref, | ||
firstPartLabel, | ||
secondPartLabel, | ||
}; | ||
}; |
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 @@ | ||
export { truncateString } from './truncateString'; |
1 change: 1 addition & 0 deletions
1
packages/components/src/OverflowTypography/utils/truncateString/index.ts
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 @@ | ||
export * from './truncateString'; |
9 changes: 9 additions & 0 deletions
9
packages/components/src/OverflowTypography/utils/truncateString/truncateString.ts
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,9 @@ | ||
export const truncateString = ( | ||
visibleLastSymbolsCount: number, | ||
label: string, | ||
) => { | ||
const firstPartLabel = label.slice(0, -visibleLastSymbolsCount); | ||
const secondPartLabel = label.slice(-visibleLastSymbolsCount); | ||
|
||
return { firstPartLabel, secondPartLabel }; | ||
}; |