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

Add Table of Contents Component for api pages #1775

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from

Conversation

ShubhamOulkar
Copy link

@ShubhamOulkar ShubhamOulkar commented Feb 7, 2025

task list

  • styling table of content (TOC) component
  • responsive TOC
  • TOC dark theme

component added into following pages

  • 4x api page
  • 5x api page
  • 3x api page

Related PR #1760

desktop mobile mobile TOC clicked
Screenshot 2025-02-07 183718 Screenshot_20250207-181807_Chrome Screenshot_20250207-181902_Chrome

New table of content component design

mobile mobile TOC clicked tablet tablet TOC clicked
mobile-toc-close mobile-toc-open tablet-toc-close tablet-toc-open
mobile scroll tablet scroll
mobile-page-scroll tablet-page-scroll

@ShubhamOulkar ShubhamOulkar requested review from a team as code owners February 7, 2025 08:54
Copy link

netlify bot commented Feb 7, 2025

Deploy Preview for expressjscom-preview ready!

Name Link
🔨 Latest commit 9dc44b9
🔍 Latest deploy log https://app.netlify.com/sites/expressjscom-preview/deploys/67a985e28db85900083f13d1
😎 Deploy Preview https://deploy-preview-1775--expressjscom-preview.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 configuration.

Copy link
Member

@bjohansebas bjohansebas 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 opening this PR.

  • Please don't increase the font size in this PR, that's a separate issue that requires a dedicated PR, which distracts from the main focus of this one.
  • Also, keep the original style for desktop for now. The design you propose looks great for mobile, though some styles need to be adjusted.
  • Please don't format the code in areas that are outside the scope of this PR.

Most importantly, we should find a way for Jekyll to generate that table. Moving it to another file might not be the best approach since I'm working on making the API translatable in Crowdin, and managing translations in a separate file would be more complicated.

I'd even be open to using JavaScript to generate the table.

These are my main comments for now. I'll try to review it more thoroughly tomorrow or the day after, but I'm really tired today.

@chrisdel101
Copy link
Contributor

chrisdel101 commented Feb 8, 2025

Hi @ShubhamOulkar, Thanks for the PR. I was just looking at this and have some concerns.

  • The menu file should not be removed like this. It seems to me that this is already essentially a kind of TOC for the API pages, but for larger screens only.
  • So you'd really be adding this to screens where the menu is not visible, and mobile. I like the design.
  • So the TOC menu should operate and display the dropdowns in the same way as the current menu does. So when you click it opens the sublinks.
  • The current JS can likely be reused for that. It might be possible to just use the same menu or copy and rejig it - up to you. Seems unnecessary to rewrite this, unless that was part of the original issue.
  • why only on api V4x? If it's a simple includes I see no reason not to add everywhere it's going to be used.
  • As Sebastian says please remove all changes that are only formatting.

@ShubhamOulkar
Copy link
Author

@bjohansebas, Thank for your kind suggestions. Now it is ready for review.

  1. accessibility improvements removed: font size and line spacing removed.
  2. removed 4x api menu data .yml file.

@ShubhamOulkar ShubhamOulkar changed the title Add Table of Contents Component for Express 4.x API Documentation page Add Table of Contents Component for api pages Feb 9, 2025
@bjohansebas
Copy link
Member

This button should be visible on smaller screens, around 800px, or when the layout actually breaks, not on 1200px screens.
Image

Comment on lines +138 to +150
if (observer) observer.disconnect();

let options = {
root: null, // Observe relative to viewport
rootMargin: "-57px 0px 0px 0px", // Slight offset to ensure intersection triggers correctly
threshold: 0, // Trigger when the element is fully out of view (i.e. behind header)
};

observer = new IntersectionObserver(handleIntersect, options);
// observe intersection of TOC btn with header bar
observer.observe(firstHeader);
}
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to have an observer? I don't see why we should use it—the less JavaScript, the better. If we can use the menu logic instead, that would be better since this behaves like a menu

We could even use the <details> element for this case. Of course, I'll leave it up to you, but the less JavaScript, the better.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. Adapt or reusing the menu logic should theoretically get you pretty far, and save you time writing new JS.

@bjohansebas
Copy link
Member

It shouldn't create that element
image

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.

3 participants