Skip to content

Commit

Permalink
TrimEndLinkLabel: Add support for highlighting part of label
Browse files Browse the repository at this point in the history
Also, always show the part that is around the highlight.
  • Loading branch information
csillag committed May 9, 2024
1 parent 8f42d89 commit 832d974
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/app/components/TrimLinkLabel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { FC } from 'react'
import { FC, ReactNode } from 'react'
import { Link as RouterLink } from 'react-router-dom'
import Link from '@mui/material/Link'
import Tooltip from '@mui/material/Tooltip'
import { trimLongString } from '../../utils/trimLongString'
import { tooltipDelay } from '../../../styles/theme'
import { HighlightedTrimmedText } from '../HighlightedText/HighlightedTrimmedText'

type TrimLinkLabelProps = {
label: string
Expand All @@ -24,15 +25,17 @@ type TrimEndLinkLabelProps = TrimLinkLabelProps & {
}

export const TrimEndLinkLabel: FC<TrimEndLinkLabelProps> = ({ label, to, trimStart, highlightedPart }) => {
const trimmedLabel = trimLongString(label, trimStart, 0) // TODO:
const trimmedLabel = (
<HighlightedTrimmedText text={label} pattern={highlightedPart} fragmentLength={trimStart} />
)
if (!trimmedLabel) {
return null
}
return <TrimLink label={label} to={to} trimmedLabel={trimmedLabel} />
}

type TrimLinkProps = TrimLinkLabelProps & {
trimmedLabel: string
trimmedLabel: ReactNode
}

const TrimLink: FC<TrimLinkProps> = ({ label, to, trimmedLabel }) => {
Expand Down

0 comments on commit 832d974

Please sign in to comment.