Skip to content
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

7486 reduce tooltip over group #8494

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6caff3c
convert to class, get ref, add styles
LucioChavezFuentes Mar 21, 2022
2674c63
finish proposal
LucioChavezFuentes Mar 22, 2022
aeb366d
move getCorrectWidth func
LucioChavezFuentes Mar 23, 2022
3c506fa
create tooltipHorizontalPadding, add new param
LucioChavezFuentes Mar 23, 2022
c3aa571
remove unneeded maximumWords prop
LucioChavezFuentes Mar 30, 2022
9e8271c
simplify code
LucioChavezFuentes Mar 31, 2022
5163c67
remove unneeded maximumWords prop
LucioChavezFuentes Mar 31, 2022
66c912e
insert maxWidth and numberLines props, move measureTooltip
LucioChavezFuentes Apr 4, 2022
3232093
Merge branch 'main' into 7486_reduce-tooltip-over-group
LucioChavezFuentes Apr 4, 2022
c8efb52
remove maxWidth numberOfLines default values
LucioChavezFuentes Apr 5, 2022
2c68ac7
fix minor capital letter comments
LucioChavezFuentes Apr 6, 2022
7b42881
set tooltipTextWidth and maxWidth as optional
LucioChavezFuentes Apr 6, 2022
6e0bfe6
remove displayName
LucioChavezFuentes Apr 6, 2022
25e2938
avoid set state on tooltips with no maxWidth
LucioChavezFuentes Apr 8, 2022
764c569
remove memo, make component Pure, minor changes
LucioChavezFuentes Apr 8, 2022
c2e46ad
tooltip settings, create setWrapperWidth
LucioChavezFuentes Apr 8, 2022
259f44e
fix comment about adding 1px, add consts, minor changes
LucioChavezFuentes Apr 11, 2022
24bcfab
move TOOLTIP_MAX_LINES to CONST
LucioChavezFuentes Apr 12, 2022
39e859b
change comment about 1px add, minor change
LucioChavezFuentes Apr 12, 2022
f0524e7
set default values numberOfLines maxWidth, remove check
LucioChavezFuentes Apr 15, 2022
9229a4c
remove unneccesary props
LucioChavezFuentes Apr 15, 2022
0042574
return maxWidth if tooltipTextWidth is not set
LucioChavezFuentes Apr 15, 2022
707a4ff
minor comment change
LucioChavezFuentes Apr 15, 2022
f6a2832
avoid re-render on single line tooltips, minor changes
LucioChavezFuentes Apr 20, 2022
7b6abee
use width instead of max-width
LucioChavezFuentes Apr 25, 2022
3b6048e
remove check on componentDidMount
LucioChavezFuentes Apr 25, 2022
b66427b
remove unneccesary function, simplify code
LucioChavezFuentes Apr 25, 2022
706f227
move wrapper width logic close to its variables
LucioChavezFuentes Apr 26, 2022
b64b96e
Merge branch 'main' into 7486_reduce-tooltip-over-group
LucioChavezFuentes Apr 27, 2022
7895f01
remove unneeded wrapperView initializing
LucioChavezFuentes Apr 27, 2022
e076b95
move wrapper width condition to getTooltipStyles
LucioChavezFuentes May 2, 2022
6ade224
move maxWidth before optional parameters
LucioChavezFuentes May 2, 2022
e098176
update comment and change offsetWidth to measure function
LucioChavezFuentes May 3, 2022
89c5781
revert to offsetWidth, minor comment changes
LucioChavezFuentes May 4, 2022
34231f9
change on comments
LucioChavezFuentes May 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/components/DisplayNames/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {propTypes, defaultProps} from './displayNamesPropTypes';
import styles from '../../styles/styles';
import Tooltip from '../Tooltip';
import Text from '../Text';
import variables from '../../styles/variables';

class DisplayNames extends PureComponent {
constructor(props) {
Expand Down Expand Up @@ -110,7 +111,11 @@ class DisplayNames extends PureComponent {
{this.props.displayNamesWithTooltips.length > 1 && this.state.isEllipsisActive
&& (
<View style={styles.displayNameTooltipEllipsis}>
<Tooltip text={this.props.fullTitle}>
<Tooltip
text={this.props.fullTitle}
numberOfLines={3}
maxWidth={variables.sideBarWidth}
>
{/* There is some Gap for real ellipsis so we are adding 4 `.` to cover */}
<Text>....</Text>
</Tooltip>
Expand Down
34 changes: 27 additions & 7 deletions src/styles/getTooltipStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ function computeHorizontalShift(windowWidth, xOffset, componentWidth, tooltipWid
return 0;
}

/**
*
* @param {Number} [maxWidth] - Max-width for tooltip's wrapper.
* @param {Number} [tooltipTextWidth] - Max-width for tooltip's wrapper.
* @returns {Object}
*/
function setWrapperWidth(maxWidth, tooltipTextWidth) {
if (!maxWidth) {
return ({});
}

if (tooltipTextWidth >= maxWidth) {
return ({maxWidth});
}

// Sum left and right wrapper padding, otherwise the wrapper will clip the text.
// Add 1 px safe buffer to avoid last word wrap or clip on special cases
// where the real text width is float but a little larger than ref.offsetWidth, which will return integer
// ex. real text width: 172.2 px, ref.offsetWidth: 172px
return ({
maxWidth: tooltipTextWidth + (spacing.ph2.paddingHorizontal * 2) + 1,
});
}

/**
* Generate styles for the tooltip component.
*
Expand All @@ -67,8 +91,8 @@ function computeHorizontalShift(windowWidth, xOffset, componentWidth, tooltipWid
* and a negative value shifts it to the left.
* @param {Number} [manualShiftVertical] - Any additional amount to manually shift the tooltip up or down.
* A positive value shifts it down, and a negative value shifts it up.
* @param {Number} [tooltipTextWidth] - Tooltip's inner text width
* @param {Number} [maxWidth] - Max-width for tooltip's wrapper
* @param {Number} [tooltipTextWidth] - Tooltip's inner text width.
* @param {Number} [maxWidth] - Max-width for tooltip's wrapper.
* @returns {Object}
*/
export default function getTooltipStyles(
Expand Down Expand Up @@ -113,11 +137,7 @@ export default function getTooltipStyles(
...tooltipVerticalPadding,
...spacing.ph2,
zIndex: variables.tooltipzIndex,
maxWidth: tooltipTextWidth >= maxWidth
? maxWidth

// Sum left and right padding
: tooltipTextWidth + (spacing.ph2.paddingHorizontal * 2),
...setWrapperWidth(maxWidth, tooltipTextWidth),

// Because it uses fixed positioning, the top-left corner of the tooltip is aligned
// with the top-left corner of the window by default.
Expand Down