Fixed story link preview tooltip fonts and avoid scaling them as the story scales

This commit is contained in:
Alvaro 2022-09-20 18:32:37 -06:00 committed by GitHub
parent 249f5c37fc
commit fe455a482f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 148 additions and 123 deletions

View file

@ -165,11 +165,12 @@
border-radius: 12px; border-radius: 12px;
color: $color-white; color: $color-white;
display: flex; display: flex;
font-size: 30px; font-size: 13px;
font-weight: 400;
justify-content: center; justify-content: center;
line-height: 32px; line-height: 18px;
max-width: 656px; max-width: 656px;
padding: 24px 32px; padding: 12px;
position: absolute; position: absolute;
text-decoration: none; text-decoration: none;
z-index: $z-index-above-base; z-index: $z-index-above-base;
@ -185,6 +186,11 @@
top: 100%; top: 100%;
} }
&__title {
font-size: 14px;
font-weight: 600;
}
&__url { &__url {
margin-top: 4px; margin-top: 4px;
max-width: 566px; max-width: 566px;

View file

@ -139,7 +139,10 @@ export const TextAttachment = ({
return ( return (
<Measure bounds> <Measure bounds>
{({ contentRect, measureRef }) => ( {({ contentRect, measureRef }) => {
const scaleFactor = (contentRect.bounds?.height || 1) / 1280;
return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions // eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div <div
className="TextAttachment" className="TextAttachment"
@ -157,11 +160,39 @@ export const TextAttachment = ({
ref={measureRef} ref={measureRef}
style={isThumbnail ? storyBackgroundColor : undefined} style={isThumbnail ? storyBackgroundColor : undefined}
> >
{/*
The tooltip must be outside of the scaled area, as it should not scale with
the story, but it must be positioned using the scaled offset
*/}
{textAttachment.preview &&
textAttachment.preview.url &&
linkPreviewOffsetTop &&
!isThumbnail && (
<a
className="TextAttachment__preview__tooltip"
href={textAttachment.preview.url}
rel="noreferrer"
style={{
top: linkPreviewOffsetTop * scaleFactor - 89, // minus height of tooltip and some spacing
}}
target="_blank"
>
<div>
<div className="TextAttachment__preview__tooltip__title">
{i18n('TextAttachment__preview__link')}
</div>
<div className="TextAttachment__preview__tooltip__url">
{textAttachment.preview.url}
</div>
</div>
<div className="TextAttachment__preview__tooltip__arrow" />
</a>
)}
<div <div
className="TextAttachment__story" className="TextAttachment__story"
style={{ style={{
...(isThumbnail ? {} : storyBackgroundColor), ...(isThumbnail ? {} : storyBackgroundColor),
transform: `scale(${(contentRect.bounds?.height || 1) / 1280})`, transform: `scale(${scaleFactor})`,
}} }}
> >
{(textContent || onChange) && ( {(textContent || onChange) && (
@ -212,25 +243,6 @@ export const TextAttachment = ({
)} )}
{textAttachment.preview && textAttachment.preview.url && ( {textAttachment.preview && textAttachment.preview.url && (
<> <>
{linkPreviewOffsetTop && !isThumbnail && (
<a
className="TextAttachment__preview__tooltip"
href={textAttachment.preview.url}
rel="noreferrer"
style={{
top: linkPreviewOffsetTop - 150,
}}
target="_blank"
>
<div>
<div>{i18n('TextAttachment__preview__link')}</div>
<div className="TextAttachment__preview__tooltip__url">
{textAttachment.preview.url}
</div>
</div>
<div className="TextAttachment__preview__tooltip__arrow" />
</a>
)}
<div <div
className={classNames('TextAttachment__preview-container', { className={classNames('TextAttachment__preview-container', {
'TextAttachment__preview-container--large': Boolean( 'TextAttachment__preview-container--large': Boolean(
@ -240,19 +252,25 @@ export const TextAttachment = ({
ref={linkPreview} ref={linkPreview}
onFocus={() => { onFocus={() => {
if (!disableLinkPreviewPopup) { if (!disableLinkPreviewPopup) {
setLinkPreviewOffsetTop(linkPreview?.current?.offsetTop); setLinkPreviewOffsetTop(
linkPreview?.current?.offsetTop
);
} }
}} }}
onMouseOver={() => { onMouseOver={() => {
if (!disableLinkPreviewPopup) { if (!disableLinkPreviewPopup) {
setLinkPreviewOffsetTop(linkPreview?.current?.offsetTop); setLinkPreviewOffsetTop(
linkPreview?.current?.offsetTop
);
} }
}} }}
> >
{onRemoveLinkPreview && ( {onRemoveLinkPreview && (
<div className="TextAttachment__preview__remove"> <div className="TextAttachment__preview__remove">
<button <button
aria-label={i18n('Keyboard--remove-draft-link-preview')} aria-label={i18n(
'Keyboard--remove-draft-link-preview'
)}
type="button" type="button"
onClick={onRemoveLinkPreview} onClick={onRemoveLinkPreview}
/> />
@ -272,7 +290,8 @@ export const TextAttachment = ({
)} )}
</div> </div>
</div> </div>
)} );
}}
</Measure> </Measure>
); );
}; };