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

Font Library: Fix font preview vertical alignment and respect reduce motion preference #58451

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,10 @@ function FontFaceDemo( { customPreviewUrl, fontFace, text, style = {} } ) {

const faceStyles = getFacePreviewStyle( fontFace );
const textDemoStyle = {
whiteSpace: 'nowrap',
flexShrink: 0,
fontSize: '18px',
opacity: isAssetLoaded ? '1' : '0',
transition: 'opacity 0.3s ease-in-out',
...faceStyles,
...style,
};
const imageDemoStyle = {
height: '23px',
width: 'auto',
};

useEffect( () => {
const observer = new window.IntersectionObserver( ( [ entry ] ) => {
Expand Down Expand Up @@ -71,10 +63,15 @@ function FontFaceDemo( { customPreviewUrl, fontFace, text, style = {} } ) {
src={ previewUrl }
loading="lazy"
alt={ text }
style={ imageDemoStyle }
className="font-library-modal__font-variant_demo-image"
/>
) : (
<Text style={ textDemoStyle }>{ text }</Text>
<Text
style={ textDemoStyle }
className="font-library-modal__font-variant_demo-text"
>
{ text }
</Text>
) }
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@
margin-top: -1px; /* To collapse the margin with the previous element */
}

.font-library-modal__font-variant_demo-image {
display: block;
height: $grid-unit-30;
width: auto;
}

.font-library-modal__font-variant_demo-text {
white-space: nowrap;
flex-shrink: 0;
font-size: 18px;
transition: opacity 0.3s ease-in-out;
@include reduce-motion("transition");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to include the transition into the demo-image class, too, to apply the same transition when the font has and lacks an image preview.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep consistency would be nice. Unrelated to the scope of this PR though.

}

.font-library-modal__font-variant {
border-bottom: 1px solid $gray-200;
padding-bottom: $grid-unit-20;
}

.font-library-modal__tabs {
[role="tablist"] {
position: sticky;
Expand Down
Loading