-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add dynamically resizing label with highlight, for adaptively filling up horizontal space #1397
Add dynamically resizing label with highlight, for adaptively filling up horizontal space #1397
Conversation
Deployed to Cloudflare Pages
|
Code extracted from the Pontus-X branch |
b36a4a4
to
6cb1ec6
Compare
d88be0c
to
3b22b90
Compare
extraTooltip={ | ||
extraTooltip ? ( | ||
<> | ||
<InfoIcon /> | ||
{extraTooltip} |
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.
It's confusing that AdaptiveHighlightedText's extraTooltip
prepends the icon and AdaptiveDynamicTrimmer's extraTooltip
doesn't.
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.
True. Will think about this 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.
those things can be fixed as separate PR, if it adds too many conflicts
e67837a
to
46f6996
Compare
First step: rename to AdaptiveDynamicTrimmer
- Instead of string, we will work with ReactNode. - Instead of a fixed text, we take a function to generate our content using the specified length.
Also, always show the part that is around the highlight.
46f6996
to
756b4a1
Compare
You mean the fact that the highlight has some margin, so we are selecting half a character to the left and to the right? |
8561aed
to
e3c7af2
Compare
When we trim a text around a pattern match, and later we try to highlight the match, pass the information along from the trimming phase to the highlighting phase. This avoids a round of unnecessary text matching, and fixes the corner case when the trimmed part is actually shorter than the pattern.
e3c7af2
to
a6f8cc8
Compare
This PR adds:
cutAroundMatch()
: utility function for getting a fixed-length a part of a text string which contains the match to the pattern (if any)HighlightedTrimmedText
: component that takes a text and a search pattern, and displays the text, with the matching part (if any) highlighted, the whole thing trimmed to a specific length around the highlight. (Or the beginning if there is no match.) This usescutAroundMatch()
.AdaptiveDynamicTrimmer
: a component which can display content, dynamically filling up the available space until scrolling/overflow happens. The dynamic part in name references to the fact that it expects a function prop to provide a version of the content shortened for any specific length. This function will be called with various length, to find the best version of the content that fits. Note that this function can do smart things to get the best representation for the given length, which might be more complex than simply getting the beginning, the end or the middle.AdaptiveHighlightedText
: a component that displays text with a part highlighted, adaptively trimmed around the highlight to fit the maximum available length without overflow. This usesHighlightedTrimmedText
andAdaptiveDynamicTrimmer
.Changes:
TrimEndLinkLabel
component to support highlighting parts within the labels, and show the relevant part instead of always showing the beginning of the label.Testing
None of these changes are immediately visible on the UI. To see this in action, check out some other PRs that use this: