canonical / vanilla-framework

From community websites to web applications, this CSS framework will help you achieve a consistent look and feel.
https://vanillaframework.io
GNU Lesser General Public License v3.0
799 stars 163 forks source link

Heading anchor links styling #5036

Open petesfrench opened 3 months ago

petesfrench commented 3 months ago

Visual

Normal: image Hover: image

Context

All docs

SCSS example

.p-anchor-link {
  color: $color-dark;

  &:visited {
    color: $color-dark;
  }

  &:after {
    @extend .p-icon--anchor;
    content: "¶";
    display: inline-block;
    padding: 1rem;
    top: 0.6rem;
    visibility: hidden;
    margin-left: 0.75rem;
  }

  &:hover {
    &::after {
      visibility: visible;
    }
  }
}
<h2><a class="p-anchor-link" href="#in-this-documentation-1" name="in-this-documentation-1">In this documentation</a></h2>
danielmutis commented 3 months ago

WG: @petesfrench @juanruitina to provide a couple of examples of how this has been implemented in other DSs and we could look into commissioning a design for the icon.

juanruitina commented 3 months ago

I've had a look at a handful of websites that have heading anchor links:

Benchmarking

Discourse: icon to the left, shows on hover, only icon is linked, points to anchor

Screenshot 2024-04-03 at 11 35 10

Carbon design system: same as Discourse

Screenshot 2024-04-03 at 11 34 09

Apple Developer: same as Discourse (but icon to the right)

Screenshot 2024-04-03 at 11 52 28

React documentation: same as Discourse (but icon to the right)

Screenshot 2024-04-03 at 11 28 20

MDN Docs: hash to the left on hover, both heading and icon point to anchor

Screenshot 2024-04-03 at 12 14 58

GitHub documentation: icon to the right, always visible, both heading and icon point to anchor

Screenshot 2024-04-03 at 11 31 44:

Material: icon to the left shows on hover, copies link

Screenshot 2024-04-03 at 11 37 48

Google Cloud documentation: same as Material (unsurprisingly), icon to the right

Screenshot 2024-04-03 at 11 32 37
bartaz commented 3 months ago

Gov.uk doesn't seem to use anchor links on headings. Headings have ids (so can be linked to), but anchor is only accessible via table of contents, not the heading itself.

https://www.gov.uk/government/news/bird-flu-avian-influenza-latest-situation-in-england#cases

image
petesfrench commented 3 months ago

@bartaz The request to have the headings clickable comes from the documentation team

bartaz commented 3 months ago

@bartaz The request to have the headings clickable comes from the documentation team

Yes, I know. We are just gathering examples of how others are doing something similar.

juanruitina commented 3 months ago

Hold on, we do have a link icon in the Figma library! It just doesn't seem to be implemented. Could we just add it to Vanilla? @lyubomir-popov @bartaz

bartaz commented 3 months ago

Hmm… we have the icon of that name, but it's a chevron… I can try to track down if that was a deliberate decision or just some mistake:

image
bartaz commented 3 months ago

We have the icon in code snippet component, it looks like a bug that it got replaced to chevon. We can bring it back.

image
danielmutis commented 2 months ago

WG: Link icon is a good fit.

petesfrench commented 2 months ago

@bartaz What do we have to do to get this upstreamed to vanilla?

bartaz commented 2 months ago

@petesfrench Create a PR and we can take it from there in review.

bartaz commented 2 months ago

It may be good to verify it first by some local implementation on one of the docs websites, to see if that works as intended in the context of the docs.

bartaz commented 1 month ago

@petesfrench What's the status of this? You had some PR for that on one of docs websites, but I don't know where it was and has it landed?