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

feat: add explicit buttons to heading titles #377

Merged
merged 1 commit into from
Oct 14, 2023
Merged

Conversation

sorawee
Copy link
Contributor

@sorawee sorawee commented Oct 13, 2023

This commit adds two buttons to each heading title.
These buttons are by default hidden, but they will
appear on hovering on the heading titles.

The first button is a "link here" button, which adjusts the URL of the
current page to include an anchor to link to that heading title, similar
to how GitHub makes each heading title in README documents a link
to add an anchor.

The second button is to view Scribble source and internal link.
Previously, clicking heading titles serves this functionality,
but without an indicator that heading titles can be clicked,
the feature is not discoverable. So this commit makes a
transition toward an explicit button.

Example screenshots:

Page title

Screenshot 2023-10-14 at 1 38 13 PM

Section title

Screenshot 2023-10-14 at 1 38 04 PM

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Resyntax analyzed 1 file in this pull request and found no issues.

if (info.style.display == "none")
/* Clicking the information button shows the explanation element: */
const heading = elem.querySelector('.heading-source');
if (heading) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this test needed? Can it ever fail?

Copy link
Contributor Author

@sorawee sorawee Oct 13, 2023

Choose a reason for hiding this comment

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

Technically, yes. If a Scribble writer inserts, say, a h3 element with custom attributes that happen to match the structure that we are looking for, but did not have the corresponding .heading-source button, then heading would be null.

Copy link
Member

@jryans jryans left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, I agree it's good to make this more discoverable than it currently is. 😄

I wonder if it's a bit too visually noisy / distracting to show these buttons all the time though...? Some sites that do this sort of thing only show the buttons for a single header when you hover on the header text. Sure, it reduces discoverability a bit, but you're still bound to encounter them after a bit of reading time. Just a suggestion from my initial reaction to your screenshots.

About vertical alignment, the buttons seem to be a few pixel lower than I'd expect. Here's GitHub vs. this PR (with an added line at the text baseline):

GitHub:

2023-10-13 at 14 25

This PR:

2023-10-13 at 14 27

I would recommend nudging the icons up a few pixels so that none of them drop below the text baseline. If you're not sure how, I could also give it a try if you like.

@sorawee
Copy link
Contributor Author

sorawee commented Oct 13, 2023

Still not perfect, but this should be a bit better.

Screenshot 2023-10-13 at 9 13 31 PM

(It can be made better, but that will require a percentage value that is "ugly" instead. This is my best attempt without resorting to using the ugly numbers.)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Resyntax analyzed 1 file in this pull request and found no issues.

@mflatt
Copy link
Member

mflatt commented Oct 13, 2023

I'll second @jryans's suggestion and rationale to show the buttons only when mousing over the title.

This commit adds two buttons to each heading title.
These buttons are by default hidden, but they will
appear on hovering on the heading titles.

The first button is a "link here" button, which adjusts the URL of the
current page to include an anchor to link to that heading title, similar
to how GitHub makes each heading title in README documents a link
to add an anchor.

The second button is to view Scribble source and internal link.
Previously, clicking heading titles serves this functionality,
but without an indicator that heading titles can be clicked,
the feature is not discoverable. So this commit makes a
transition toward an explicit button.
@sorawee
Copy link
Contributor Author

sorawee commented Oct 14, 2023

I made the update as requested.

Since we now show the buttons only on hovering over the heading titles, I removed the adjustments to make the buttons smaller*, to help with discoverability.

[*] well, there's still a place that needs this adjustment, since it would be too large with the full size.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Resyntax analyzed 1 file in this pull request and found no issues.

@mflatt
Copy link
Member

mflatt commented Oct 14, 2023

Thanks for the update! This looks good to me.

@sorawee sorawee merged commit 140a355 into master Oct 14, 2023
5 checks passed
@sorawee sorawee deleted the heading-buttons branch October 14, 2023 23:59
sorawee added a commit that referenced this pull request Dec 20, 2023
sorawee added a commit that referenced this pull request Dec 21, 2023
This PR fixes a couple of issues related to the button group.

- On `#lang scribble/base`, only show the "Link to here" button,
  and do so with correct styling.
- Make it possible for the button group to exceed the right margin
  to preserve the previous HTML layout.
- Place anchor at the beginning of the headings, not at the end,
  so that on navigation, we will see the full heading.

Thanks to @mflatt who reported some of the issues above and
helped with testing.

Fixes #381

make the button group unbreakaable

do not include the "i" button when it does not make sense

Add anchors at the beginning so that we see the entire heading

This partially reverts ##377

make the button group be able to exceed the right margin

switch from the link emoji to "#"

.

.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants