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

Special bullet/style for sidebar docs home #1322

Merged
merged 18 commits into from
May 20, 2020
Merged

Conversation

rogermparent
Copy link
Contributor

@rogermparent rogermparent commented May 19, 2020

Builds on #1312
Fixes #1053, which is also one of the remaining parts of #1073

This branch adds capability for pre-defined special styles and icons to be applied on a per-item basis in sidebar.json.
It also uses this capability to give the doc home a little house icon.

I got the icon from here (It's under CC0 / public domain so we don't have to worry, but it can be replaced if needed) and modified it to use currentColor, meaning it takes on the color of the containing link.

The default :before based bullet behavior is left the same, but special icons are real elements because it offers much more flexibility for no cost, as well as the currentColor capability and optimization components like SVGR.

Custom icons are defined as React components, so we could define anything as one- even raster images or pure CSS divs!

This fixes an unreported issue (well, at least I haven't seen it) where the docs
sidebar wouldn't mark home as active when the user is on it.

This fix won't work if we decide to add children to the docs home later on, but
we currently don't, I'm pretty sure we have no plans to, and we can easily adapt
this fix to handle it if we ever do.
Beforehand, we were getting the value from the `location` global. This way, we
aren't subject to the whims of the browser and will get the canonical path every
time.
This branch adds the fields "icon" and "style" to the allowed fields in
sidebar.json.

The "style" field applies a class from the sidebar module to the item.
Similarly, the "icon" field lets one define a custom icon on a menu item that
replaces the default `::before` bullet. Usable icons must be added as a
component (any source works, I used SVGR but an `img` can be used for raster
images. The class has to exist in the sidebar CSS module to do anything, but
using one that doesn't exist won't break the build.

Once an icon is defined, it can be used and shared with any amount of sidebar
entries anywhere by using its key in the const as the value of "icon". Items
with `icon` defined will have the default triangle bullet removed.

The home SVG changes color with the link because it's made with `currentColor`
and an actual element instead of the more limited `::before`.
@shcheklein shcheklein temporarily deployed to dvc-landing-docs-sideba-fegbfz May 19, 2020 20:49 Inactive
@calibre-analytics
Copy link

calibre-analytics bot commented May 19, 2020

Comparing Special bullet/style for sidebar docs home Snapshot #10 to median since last deploy of DVC.org.

Performance FCP? TTI?
Overall
Median across all pages and test profiles
93
from 94
1s
no change
4s
from 3.8s
Chrome Desktop
Chrome • Cable
100
no change
660ms
from 520ms
1.9s
from 1.7s
MotoG4, 3G connection
Motorola Moto G4 • Regular 3G
88
from 81
1.5s
no change
5s
from 6.2s

3 pages tested

 Home

Browser previews

Chrome Desktop MotoG4, 3G connection
Chrome Desktop MotoG4, 3G connection

Most significant changes

Value Budget
Total JSON size in bytes
Chrome Desktop
7.4 KB
from 37 KB
Lighthouse Performance Score
MotoG4, 3G connection
88
from 75
 Docs

Browser previews

Chrome Desktop MotoG4, 3G connection
Chrome Desktop MotoG4, 3G connection

Most significant changes

Value Budget
Total JSON size in bytes
Chrome Desktop
58 KB
from 160 KB
Total JSON size in bytes
MotoG4, 3G connection
14 KB
from 28 KB
Total Page size in bytes
Chrome Desktop
1.2 MB
from 1.3 MB
 Blog

Browser previews

Chrome Desktop MotoG4, 3G connection
Chrome Desktop MotoG4, 3G connection

Most significant changes

Value Budget
Total JSON size in bytes
Chrome Desktop
69 KB
from 130 KB
Total JSON size in bytes
MotoG4, 3G connection
69 KB
from 91 KB

Calibre: Site dashboard | View this PR | Edit settings

@rogermparent rogermparent temporarily deployed to dvc-landing-docs-sideba-fegbfz May 19, 2020 21:06 Inactive
@rogermparent
Copy link
Contributor Author

This branch now also turns leaf item default bullets into circles via CSS. These are implemented as :before like the original bullets, not special ones like home.

@rogermparent rogermparent temporarily deployed to dvc-landing-docs-sideba-fegbfz May 19, 2020 21:29 Inactive
@shcheklein
Copy link
Member

@rogermparent looks cool but a bit noisy from the design perspective.

let's try this:

  1. change triangles state - it should face down when list is open
  2. if there are no children - skip the icon at all.
  3. don't make Home bold

@rogermparent
Copy link
Contributor Author

Can do! Thanks for the feedback!

I sourced from the wrong place in getting the current path earlier.
- Remove bullets on leaves
- Remove bold styling on home
- Change padding to make non-bullet items look a little better
@rogermparent rogermparent temporarily deployed to dvc-landing-docs-sideba-fegbfz May 20, 2020 20:33 Inactive
This would probably be better done by changing the file, so I'll do that
afterward.
@rogermparent rogermparent temporarily deployed to dvc-landing-docs-sideba-fegbfz May 20, 2020 20:56 Inactive
@rogermparent rogermparent temporarily deployed to dvc-landing-docs-sideba-fegbfz May 20, 2020 21:00 Inactive
Such that the default state doesn't depend on `animation`.
@rogermparent rogermparent temporarily deployed to dvc-landing-docs-sideba-fegbfz May 20, 2020 21:35 Inactive
@rogermparent rogermparent requested a review from shcheklein May 20, 2020 21:45
@rogermparent
Copy link
Contributor Author

1. change triangles state - it should face down when list is open

2. if there are no children - skip the icon at all.

3. don't make Home **bold**

All fixed! I changed some padding around too because the left pad looked oddly large without bullets sitting in the space.

@shcheklein
Copy link
Member

@rogermparent looks better! I still don't like the home 🏠 icon - let's try to remove it? or may be the problem is that we highlight along with the text (not the case for triangles) + it's not well aligned (should be a bit to the right and down). Let's play with it a little bit.

@shcheklein
Copy link
Member

@rogermparent I can do it on my won, give me a few minutes

@rogermparent
Copy link
Contributor Author

Sure! Get it exactly how you want it, I don't have a great eye for design. I'm sure you're already using the files changed to navigate what you need to edit.

It's worth noting that you can set color on the home icon to lock it to whatever you want, it's only inheriting the text color because it doesn't have one set- no special logic to undo.

@shcheklein
Copy link
Member

Configuration I like the most so far for the home icon:

Screen Shot 2020-05-20 at 3 04 07 PM

Screen Shot 2020-05-20 at 3 06 10 PM

The thing that was not easy to try for me - for leaf items - can we make a bullet, but a small one (it should fit inside a triangle to give you a reference).

Sorry for this pixel movements - I'm not a designer either, but have a good eye - just need to move things around to see myself to decide :)

@rogermparent
Copy link
Contributor Author

The thing that was not easy to try for me - for leaf items - can we make a bullet, but a small one (it should fit inside a triangle to give you a reference).

Ah, yes, I disabled leaf bullets in logic and removed them completely, sorry about that! I can re-add them with a new SVG that fits your description.

Sorry for this pixel movements - I'm not a designer either, but have a good eye - just need to move things around to see myself to decide :)

Don't worry at all! I'm glad that someone else is giving input, even if it's pixel movements- especially where bullets are positioned using absolute and not auto-centered.

- Re-add leaf bullets, but smaller now
- Implement suggested movement changes to home icon
- Lock icon to text gray
@rogermparent rogermparent temporarily deployed to dvc-landing-docs-sideba-fegbfz May 20, 2020 23:00 Inactive
@shcheklein shcheklein merged commit dbb8a4c into master May 20, 2020
@shcheklein
Copy link
Member

Cool 😎 thanks @rogermparent !

@rogermparent rogermparent deleted the docs-sidebar-bullets branch May 20, 2020 23:42
const { label, slug, source, tutorials, type, url } = rawItem
const { label, slug, source, tutorials, type, url, style, icon } = rawItem
Copy link
Contributor

@jorgeorpinel jorgeorpinel May 21, 2020

Choose a reason for hiding this comment

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

May want to update the inline doc example in in the top of this file.

Copy link
Member

Choose a reason for hiding this comment

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

👍 yep

Copy link
Contributor Author

@rogermparent rogermparent May 22, 2020

Choose a reason for hiding this comment

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

@jorgeorpinel I'm not sure what you mean by inline doc example in this file. Did you mean to link a doc file that describes how to use the sidebar?

I figured it out, I was looking at the wrong file! I'll update that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! #1332

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.

nav: allow different bullet icons in sidebar
3 participants