-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ClampedText component #28664
Merged
Merged
feat: ClampedText component #28664
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
509f942
messy
daibhin 9d00d0e
Merge branch 'master' into dn-feat/clamping-description
daibhin ec6dd08
feat: expanding text
daibhin 785a491
fixes
daibhin 9b6fe11
Update UI snapshots for `chromium` (1)
github-actions[bot] 152213b
Update UI snapshots for `chromium` (1)
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions
29
frontend/src/lib/lemon-ui/ClampedText/ClampedText.stories.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,29 @@ | ||
import { Meta, StoryFn, StoryObj } from '@storybook/react' | ||
|
||
import { ClampedText, ClampedTextProps } from './ClampedText' | ||
|
||
type Story = StoryObj<typeof ClampedText> | ||
const meta: Meta<typeof ClampedText> = { | ||
title: 'Lemon UI/ClampedText', | ||
component: ClampedText, | ||
parameters: { | ||
testOptions: { | ||
waitForLoadersToDisappear: false, | ||
}, | ||
}, | ||
tags: ['autodocs'], | ||
} | ||
export default meta | ||
|
||
const Template: StoryFn<typeof ClampedText> = (props: ClampedTextProps) => { | ||
return <ClampedText {...props} /> | ||
} | ||
|
||
export const SingleLine: Story = Template.bind({}) | ||
SingleLine.args = { lines: 2, text: 'One line of text' } | ||
|
||
export const MultiLine: Story = Template.bind({}) | ||
MultiLine.args = { | ||
lines: 2, | ||
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', | ||
} |
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,78 @@ | ||
import React, { useEffect, useState } from 'react' | ||
|
||
import { Link } from '../Link' | ||
|
||
export interface ClampedTextProps { | ||
lines: number | ||
text: string | ||
} | ||
|
||
const isCssEllipsisApplied = (elem: HTMLDivElement): boolean => elem.scrollHeight > elem.clientHeight | ||
|
||
export const ClampedText = React.forwardRef<HTMLDivElement, ClampedTextProps>(function ClampedText( | ||
{ lines, text }, | ||
ref | ||
) { | ||
const [localLines, setLocalLines] = useState<number | undefined>(lines) | ||
const [isExpanded, setIsExpanded] = useState<boolean>(false) | ||
const [showMore, setShowMore] = useState<boolean>(false) | ||
|
||
const handleToggleShowMore = (show: boolean): void => { | ||
setShowMore(!showMore) | ||
setIsExpanded(!isExpanded) | ||
setLocalLines(show ? undefined : lines) | ||
} | ||
|
||
const handleConfigElement = (elem: HTMLDivElement): void => { | ||
if (!elem) { | ||
return | ||
} | ||
|
||
if (isCssEllipsisApplied(elem)) { | ||
if (!showMore || !isExpanded) { | ||
setShowMore(true) | ||
} | ||
} else { | ||
setShowMore(false) | ||
} | ||
} | ||
|
||
useEffect(() => setLocalLines(lines), [lines]) | ||
|
||
return ( | ||
<div ref={ref}> | ||
<TruncatedElement lines={localLines} ref={handleConfigElement} text={text} /> | ||
<div> | ||
{isExpanded || showMore ? ( | ||
<Link onClick={() => handleToggleShowMore(!isExpanded)}> | ||
{isExpanded ? 'Show less' : 'Show more'} | ||
</Link> | ||
) : null} | ||
</div> | ||
</div> | ||
) | ||
}) | ||
|
||
const TruncatedElement = React.forwardRef<HTMLDivElement, { lines?: number; text: string }>(function TruncatedElement( | ||
{ text, lines }, | ||
ref | ||
) { | ||
return ( | ||
<span | ||
// eslint-disable-next-line react/forbid-dom-props | ||
style={ | ||
lines | ||
? { | ||
overflow: 'hidden', | ||
display: '-webkit-box', | ||
WebkitBoxOrient: 'vertical', | ||
WebkitLineClamp: lines, | ||
} | ||
: {} | ||
} | ||
ref={ref} | ||
> | ||
{text} | ||
</span> | ||
) | ||
}) |
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 { ClampedText } from './ClampedText' |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ import { IconInfo } from '@posthog/icons' | |||||
import { LemonSkeleton, Tooltip } from '@posthog/lemon-ui' | ||||||
import { useValues } from 'kea' | ||||||
import { TZLabel } from 'lib/components/TZLabel' | ||||||
import { ClampedText } from 'lib/lemon-ui/ClampedText' | ||||||
import { humanFriendlyLargeNumber } from 'lib/utils' | ||||||
import { errorTrackingIssueSceneLogic } from 'scenes/error-tracking/errorTrackingIssueSceneLogic' | ||||||
|
||||||
|
@@ -32,7 +33,7 @@ export const Metadata = (): JSX.Element => { | |||||
|
||||||
return ( | ||||||
<div className="space-y-1"> | ||||||
{issue ? <div className="italic line-clamp-3">{issue.description}</div> : <LemonSkeleton />} | ||||||
{issue && issue.description ? <ClampedText text={issue.description} lines={2} /> : <LemonSkeleton />} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider handling empty string case - currently shows skeleton for null/undefined but renders empty ClampedText for ''
Suggested change
|
||||||
<div className="flex flex-1 justify-between"> | ||||||
<div className="flex items-end space-x-6"> | ||||||
<div> | ||||||
|
71 changes: 0 additions & 71 deletions
71
frontend/src/scenes/error-tracking/issue/panels/MetaPanel.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: handleToggleShowMore's 'show' parameter is unused - the function toggles based on !showMore and !isExpanded instead. This could lead to unexpected behavior if the passed show value doesn't match the current state.