line breaks in tooltips & text (#8783)

This feature goal is to :

1 - clean variables not used any longer

2 - add line breaks for tooltips and text wrapped

<img width="329" alt="Screenshot 2024-11-27 at 18 37 18"
src="https://github.com/user-attachments/assets/b3d7ed76-df30-4377-9d73-08d55c0f5c49">
<img width="468" alt="Screenshot 2024-11-27 at 18 37 31"
src="https://github.com/user-attachments/assets/48ef343e-6071-4a89-a73f-fb271f8284c0">


Request From @Bonapara

---------

Co-authored-by: guillim <guillaume@twenty.com>
This commit is contained in:
Guillim
2024-11-28 14:30:23 +01:00
committed by GitHub
parent 8aab063da3
commit 041b1f21bf
7 changed files with 30 additions and 29 deletions

View File

@ -39,7 +39,8 @@ const StyledLabelAndIconContainer = styled.div`
color: ${({ theme }) => theme.font.color.tertiary}; color: ${({ theme }) => theme.font.color.tertiary};
display: flex; display: flex;
gap: ${({ theme }) => theme.spacing(1)}; gap: ${({ theme }) => theme.spacing(1)};
height: 24px; height: 18px;
padding-top: 3px;
`; `;
const StyledValueContainer = styled.div` const StyledValueContainer = styled.div`
@ -61,7 +62,7 @@ const StyledInlineCellBaseContainer = styled.div`
width: 100%; width: 100%;
display: flex; display: flex;
height: fit-content; height: fit-content;
line-height: 24px; line-height: 18px;
gap: ${({ theme }) => theme.spacing(1)}; gap: ${({ theme }) => theme.spacing(1)};
user-select: none; user-select: none;
justify-content: center; justify-content: center;
@ -131,11 +132,7 @@ export const RecordInlineCellContainer = () => {
)} )}
{showLabel && label && ( {showLabel && label && (
<StyledLabelContainer width={labelWidth}> <StyledLabelContainer width={labelWidth}>
<OverflowingTextWithTooltip <OverflowingTextWithTooltip text={label} displayedMaxRows={1} />
text={label}
isLabel={true}
displayedMaxRows={1}
/>
</StyledLabelContainer> </StyledLabelContainer>
)} )}
{/* TODO: Displaying Tooltips on the board is causing performance issues https://react-tooltip.com/docs/examples/render */} {/* TODO: Displaying Tooltips on the board is causing performance issues https://react-tooltip.com/docs/examples/render */}

View File

@ -42,13 +42,11 @@ const StyledRecordInlineCellNormalModeInnerContainer = styled.div`
align-content: center; align-content: center;
align-items: center; align-items: center;
color: ${({ theme }) => theme.font.color.primary}; color: ${({ theme }) => theme.font.color.primary};
font-size: 'inherit'; padding-top: 3px;
padding-bottom: 3px;
font-weight: 'inherit';
height: fit-content; height: fit-content;
min-height: 24px;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;

View File

@ -46,7 +46,7 @@ export const RecordInlineCellEditMode = ({
crossAxis: 0, crossAxis: 0,
} }
: { : {
mainAxis: -28, mainAxis: -29,
crossAxis: -4, crossAxis: -4,
}, },
), ),

View File

@ -37,8 +37,8 @@ export const RecordTableCellEditMode = ({
middleware: [ middleware: [
flip(), flip(),
offset({ offset({
mainAxis: -32, mainAxis: -31,
crossAxis: 0, crossAxis: -2,
}), }),
], ],
whileElementsMounted: autoUpdate, whileElementsMounted: autoUpdate,

View File

@ -6,5 +6,9 @@ type TextDisplayProps = {
}; };
export const TextDisplay = ({ text, displayedMaxRows }: TextDisplayProps) => ( export const TextDisplay = ({ text, displayedMaxRows }: TextDisplayProps) => (
<OverflowingTextWithTooltip text={text} displayedMaxRows={displayedMaxRows} /> <OverflowingTextWithTooltip
text={text}
displayedMaxRows={displayedMaxRows}
isTooltipMultiline={true}
/>
); );

View File

@ -34,6 +34,7 @@ const StyledTextArea = styled(TextareaAutosize)`
max-height: 400px; max-height: 400px;
width: calc(100% - ${({ theme }) => theme.spacing(7)}); width: calc(100% - ${({ theme }) => theme.spacing(7)});
background: transparent; background: transparent;
line-height: 18px;
`; `;
const StyledTextAreaContainer = styled.div` const StyledTextAreaContainer = styled.div`
@ -41,7 +42,9 @@ const StyledTextAreaContainer = styled.div`
border: ${({ theme }) => `1px solid ${theme.border.color.medium}`}; border: ${({ theme }) => `1px solid ${theme.border.color.medium}`};
position: relative; position: relative;
width: 100%; width: 100%;
padding: ${({ theme }) => theme.spacing(2)} ${({ theme }) => theme.spacing(0)}; padding-top: ${({ theme }) => theme.spacing(2)};
padding-bottom: ${({ theme }) => theme.spacing(2)};
border-radius: ${({ theme }) => theme.border.radius.sm}; border-radius: ${({ theme }) => theme.border.radius.sm};
@supports ( @supports (
@ -56,7 +59,7 @@ const StyledTextAreaContainer = styled.div`
const StyledLightIconButtonContainer = styled.div` const StyledLightIconButtonContainer = styled.div`
background: transparent; background: transparent;
position: absolute; position: absolute;
top: 50%; top: 18px;
transform: translateY(-50%); transform: translateY(-50%);
right: 0; right: 0;
`; `;

View File

@ -12,8 +12,6 @@ const StyledOverflowingText = styled.div<{
cursorPointer: boolean; cursorPointer: boolean;
size: 'large' | 'small'; size: 'large' | 'small';
displayedMaxRows?: number; displayedMaxRows?: number;
isLabel: boolean;
allowDisplayWrap?: boolean;
}>` }>`
cursor: ${({ cursorPointer }) => (cursorPointer ? 'pointer' : 'inherit')}; cursor: ${({ cursorPointer }) => (cursorPointer ? 'pointer' : 'inherit')};
font-family: inherit; font-family: inherit;
@ -25,7 +23,7 @@ const StyledOverflowingText = styled.div<{
text-decoration: inherit; text-decoration: inherit;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: pre-wrap;
height: ${({ size }) => (size === 'large' ? spacing4 : 'auto')}; height: ${({ size }) => (size === 'large' ? spacing4 : 'auto')};
text-wrap: wrap; text-wrap: wrap;
@ -42,20 +40,21 @@ const StyledOverflowingText = styled.div<{
} }
`; `;
const Styledpre = styled.pre`
font-family: inherit;
white-space: pre-wrap;
`;
export const OverflowingTextWithTooltip = ({ export const OverflowingTextWithTooltip = ({
size = 'small', size = 'small',
text, text,
isTooltipMultiline, isTooltipMultiline,
displayedMaxRows, displayedMaxRows,
isLabel,
allowDisplayWrap,
}: { }: {
size?: 'large' | 'small'; size?: 'large' | 'small';
text: string | null | undefined; text: string | null | undefined;
isTooltipMultiline?: boolean; isTooltipMultiline?: boolean;
displayedMaxRows?: number; displayedMaxRows?: number;
isLabel?: boolean;
allowDisplayWrap?: boolean;
}) => { }) => {
const textElementId = `title-id-${+new Date()}`; const textElementId = `title-id-${+new Date()}`;
@ -81,7 +80,6 @@ export const OverflowingTextWithTooltip = ({
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
}; };
return ( return (
<> <>
<StyledOverflowingText <StyledOverflowingText
@ -89,8 +87,6 @@ export const OverflowingTextWithTooltip = ({
cursorPointer={isTitleOverflowing} cursorPointer={isTitleOverflowing}
size={size} size={size}
displayedMaxRows={displayedMaxRows} displayedMaxRows={displayedMaxRows}
allowDisplayWrap={allowDisplayWrap}
isLabel={isLabel ?? false}
ref={textRef} ref={textRef}
id={textElementId} id={textElementId}
onMouseEnter={handleMouseEnter} onMouseEnter={handleMouseEnter}
@ -103,7 +99,6 @@ export const OverflowingTextWithTooltip = ({
<div onClick={handleTooltipClick}> <div onClick={handleTooltipClick}>
<AppTooltip <AppTooltip
anchorSelect={`#${textElementId}`} anchorSelect={`#${textElementId}`}
content={isTooltipMultiline ? undefined : (text ?? '')}
offset={5} offset={5}
isOpen isOpen
noArrow noArrow
@ -111,7 +106,11 @@ export const OverflowingTextWithTooltip = ({
positionStrategy="absolute" positionStrategy="absolute"
delay={TooltipDelay.mediumDelay} delay={TooltipDelay.mediumDelay}
> >
{isTooltipMultiline ? <pre>{text}</pre> : ''} {isTooltipMultiline ? (
<Styledpre>{text}</Styledpre>
) : (
`${text || ''}`
)}
</AppTooltip> </AppTooltip>
</div>, </div>,
document.body, document.body,