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

fix(theme-classic): polish admonition details, render title-only admonitions #8150

Merged
merged 6 commits into from
Dec 9, 2022
Merged

fix(theme-classic): polish admonition details, render title-only admonitions #8150

merged 6 commits into from
Dec 9, 2022

Conversation

attitude
Copy link
Contributor

@attitude attitude commented Sep 30, 2022

Changes

  • Render admonition content <div /> only when children are present
  • Apply bottom margin only when admonition content exists
  • Apply proper optics of the inlined SVG icon and re-calculate margins to compensate for changes
  • Narrow scope of BrowserWindow selector
  • Document example

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

Fixing optics of Admonition in user-land is repetitive and could be fixed upstream for everyone.

  1. Omitting Admonition content causes visual bug–vertical padding is off due empty <div>;
  2. Vertical (and horizontal) alignment of icons does not respect rules of optics, also causes extra bottom space;
  3. BrowserWindow selector .browserWindowBody *:last-child applies margin-bottom: 0 too aggressively and should only apply to its direct children.

Problematic elements with bounding boxes outlined:

docusaurus io_docs_markdown-features_admonitions

Before After
docusaurus io_docs_markdown-features_admonitions (2) localhost_3000_docs_markdown-features_admonitions (6)
Before After
docusaurus io_docs_markdown-features_admonitions (1) localhost_3000_docs_markdown-features_admonitions (5)

Test Plan

Test links

Deploy preview:

Local:

Related issues/PRs

@facebook-github-bot
Copy link
Contributor

Hi @attitude!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@netlify
Copy link

netlify bot commented Sep 30, 2022

[V2]

Name Link
🔨 Latest commit c2aac9f
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/6393812bbed3b80009729023
😎 Deploy Preview https://deploy-preview-8150--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@Josh-Cena Josh-Cena added the pr: polish This PR adds a very minor behavior improvement that users will enjoy. label Sep 30, 2022
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Sep 30, 2022
@github-actions
Copy link

github-actions bot commented Sep 30, 2022

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 81 🟢 98 🟢 100 🟢 100 🟠 80 Report
/docs/installation 🟠 85 🟢 100 🟢 100 🟢 100 🟢 90 Report

- Render admonition content `<div />` only when children are present
- Apply bottom margin only when admonition content exists
- Apply proper optics of the inlined SVG icon and re-calculate margins
to compensate for changes
- Narrow scope of `BrowserWindow` selector
- Document example
@slorber
Copy link
Collaborator

slorber commented Oct 13, 2022

Omitting Admonition content causes visual bug–vertical padding is off due empty

;

Seems legit 👍 although it won't take into account children being an empty fragment, not a big deal

BrowserWindow selector .browserWindowBody *:last-child applies margin-bottom: 0 too aggressively and should only apply to its direct children.

Also LGTM 👍

Vertical (and horizontal) alignment of icons does not respect rules of optics, also causes extra bottom space;

I'm not sure to understand what you mean here, can you expand considering I don't know what the rules of optics are in the first place?

}

.admonitionIcon svg {
display: inline-block;
height: 1.6em;
margin: -0.1875em;
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is this magic number? Can't we align icon/text without this thing? Will it work constantly with any SVG that the user provide?

Remember that users might as well provide custom SVGs through CSS, but also with swizzling, and many do this kind of customization: we don't want to make their life harder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems legit 👍 although it won't take into account children being an empty fragment, not a big deal

The empty fragment will still render an empty div causing some hard time removing the bottom margin that is not necessary. That's why I changed the ternary operator around the rest.


I'm not sure to understand what you mean here, can you expand considering I don't know what the rules of optics are in the first place?

We apply negative margin in typography all the time. We push shapes like "O", "T", "V" or "A" outside of its apparent bounding box to align with other glyphs. When using custom shapes, e.g. icons alongside the text we should apply same rules.

Read more about the rules of optical alignments for example here:


what is this magic number? Can't we align icon/text without this thing? Will it work constantly with any SVG that the user provide?

It is because of 1.6em enlargement of icon and isn't that also a magic number too? I understand your point but it won't work without it (I've tried).

The magic number is a result of reversing the height: 1.6em rule side-effects. Height messes up line (but it can be seen only when >= 2 lines, e.g. long title on small screen or with extra large text A11Y accommodation).

Screenshot of uneven space below the 1st line

Apart from fixing the extra space under the first line, pushing some of the transparent parts of SVG icons outside of the bounding box fixes the optical alignment too. (If anyone uses same construction of icons as Docusaurus does it will just work for them. And most icon libraries I have used do use some kind of a similar construction.)

I also tried emojis instead of SVGs and now they look much more well aligned.

What I try to say here is that the original code has the same "user might use some of its own SVG" flaws. What I propose is a little more optically corrected version that repositions the icon box to its expected optical centre at the 1.6em size.

If you want I could remove everything but the Fragment children and the BrowserWindow selector fixes. The rest could be done in the user land more easily after those get changed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The empty fragment will still render an empty div causing some hard time removing the bottom margin that is not necessary. That's why I changed the ternary operator around the rest.

Yes but see my dogfood test here:

:::note Title Only

<></>

:::

It will still render an empty div in this case.

CleanShot 2022-10-14 at 19 08 28@2x

But nevermind, it's an edge case and not a big deal and the rendering look fine in both cases

CleanShot 2022-10-14 at 19 09 57@2x

Copy link
Collaborator

@slorber slorber Oct 14, 2022

Choose a reason for hiding this comment

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

I'm not skilled enough in typography, optical alignment and all these things to say, and unfortunately I don't really have time to learn all that just for this specific PR 😅

Now, as a Docusaurus user, I want to be able to use larger svgs and fontSize for the icon, and I expect the icon / text to be "approximately" aligned by default without having to do anything with CSS

Here's a test:

https://deploy-preview-8150--docusaurus-2.netlify.app/tests/docs/tests/admonitions

## Large font icon

<admonition
  type="tip"
  icon={<span style={{fontSize: 60}}>💡</span>}
  title="Did you know...">
  <p>
    content
  </p>
</admonition>

<admonition
  type="info"
  icon={<span style={{fontSize: 40}}>ℹ️</span>}
  title="Did you know...">
  <p>
    content
  </p>
</admonition>

## Large svg icon

import InfoIcon from "@theme/Admonition/Icon/Info"

<admonition
  type="tip"
  icon={<InfoIcon style={{width: 60, height: 60}}/>}
  title="Did you know...">
  <p>
    content
  </p>
</admonition>

<admonition
  type="info"
  icon={<InfoIcon style={{width: 40, height: 40}}/>}
  title="Did you know...">
  <p>
    content
  </p>
</admonition>

And by default, that does not look good to me:

CleanShot 2022-10-14 at 19 17 01@2x

I'd rather have imperfect optical alignment, but convenience for users to just increase font/svg and things work not too badly by default, rather than asking users to tweak/revert the CSS changes that you want to do here.

Does it make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Any opinion?

Maybe we could just merge the other fixes for now and eventually discuss the rest in another PR?

@slorber
Copy link
Collaborator

slorber commented Dec 9, 2022

Reverted some changes we couldn't agree on, good enough to merge

If you want to reopen the debate on optical spacing we can do that in another PR (preferably only focusing on optical spacing)

@slorber slorber changed the title fix(theme-classic): fix admonition optical spacing fix(theme-classic): polish admonition details, render title-only admonitions Dec 9, 2022
@slorber slorber merged commit f3563ca into facebook:main Dec 9, 2022
@attitude attitude deleted the pr/remove-admonition-content-when-empty branch January 2, 2023 08:25
@slorber slorber added to backport This PR is planned to be backported to a stable version of Docusaurus and removed to backport This PR is planned to be backported to a stable version of Docusaurus labels Jan 26, 2023
This was referenced Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: polish This PR adds a very minor behavior improvement that users will enjoy.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants