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(subnav): add support for dark theme #381

Merged
merged 12 commits into from
Oct 5, 2021
Merged

feat(subnav): add support for dark theme #381

merged 12 commits into from
Oct 5, 2021

Conversation

zchsh
Copy link
Contributor

@zchsh zchsh commented Oct 4, 2021

🎟️ Asana Task
πŸ” Preview Link
πŸ“– Storybook Preview
🐣 Canary Test Preview via https://github.com/hashicorp/cloud.hashicorp.com/pull/192


This PR adds support for a theme prop to @hashicorp/react-subnav. The intent here is to enable a dark theme, as implemented in cloud.hashicorp.com (see preview) without using potentially brittle overrides (which are also now much harder to write at the project level due to our use of CSS modules).

PR Checklist πŸš€

Items in this checklist may not may not apply to your PR, but please consider each item carefully.

  • Add Asana and Preview links above.
  • Conduct thorough self-review.
  • Add or update tests as appropriate.
  • Conduct reasonable cross browser testing for both compatibility and responsive behavior (We have a Sauce Labs account for this, if you don't have access, just ask!).
  • Conduct reasonable accessibility review (use the WAS as a guide or an axe browser plugin until we establish more formal checks).
  • Identify (in the description above) and document (add Asana tasks on this board) any technical debt that you're aware of, but are not addressing as part of this PR.

@changeset-bot
Copy link

changeset-bot bot commented Oct 4, 2021

πŸ¦‹ Changeset detected

Latest commit: ae7e4a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hashicorp/react-subnav Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 4, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

πŸ” Inspect: https://vercel.com/hashicorp/react-components/2o4EoXBxQBsCj7EFRpsUnGpBUQWX
βœ… Preview: https://react-components-git-zssubnav-dark-theme-hashicorp.vercel.app

@@ -0,0 +1,43 @@
/* Theme settings. Note: also consumed in /partials */
Copy link
Contributor

Choose a reason for hiding this comment

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

❀️

@@ -2,6 +2,7 @@ import classNames from 'classnames'
import useProductMeta from '@hashicorp/platform-product-meta'
import useNavRef from './helpers/useNavRef'
import s from './style.module.css'
import themeStyles from './theme.module.css'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took a theming approach similar to that in code-block. While I am certainly not confident this will be the best approach to theming long-term (in fact I'm almost sure we can come up with something more extensible for product situations), this felt like a decent balance between using our existing tooling and conventions (CSS modules & custom properties) while splitting out theme properties.

My hot take is I don't think the theming is something we should aim to "solve" with this PR, really just trying to get this to work and be easy to transition to whatever theming approach we go with longer term. Very open to suggestions here, of course πŸ™‡

@@ -115,7 +119,7 @@ function Subnav({ className, ...restProps }) {
return (
<nav
ref={wrapperRef}
className={classNames(s.root, className, {
className={classNames(s.root, themeStyles[theme], className, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MOST of the theming is done via CSS custom properties - that comes from this class here πŸ‘

@@ -125,6 +129,7 @@ function Subnav({ className, ...restProps }) {
product={product}
hasOverflow={hasOverflow}
isSticky={isSticky}
theme={theme}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SOME of the theming, namely just the theme passed to button's theme.background, has to be passed through the CtaLinks component. This is a part that doesn't feel ideal long term (Context probably better?) but felt sustainable and reasonable given the scope & intent of this PR.

--stars-border-color: rgba(29, 30, 35, 0.2);
--scrim-opacity: 0;
--local-scrim-color: transparent;
--local-divider-color: var(--border-color); /* from theme.module.css */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These --local vars make it possible to group styles fully by element. Without them I think we'd have to group by state, which might be okay in this specific situation, but quickly gets messy so I think should be avoided (per CSS guidelines in Notion - though as always, open to discussion on those as well).

@@ -5,6 +5,7 @@ function GithubIcon(props) {
<svg width={16} height={16} viewBox="0 0 16 16" {...props}>
<path
fillRule="evenodd"
fill="#000000"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this as it's usually present in icon exports, and makes it possible to target the icon's fill in a less brittle way.

@@ -41,6 +40,8 @@ function CtaLinks(props) {
theme={{
brand: product,
variant: isLastButton ? 'primary' : 'secondary',
background: theme,
...link.theme /* allow theme overrides via the ctaLinks array */,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this in to remove a related override in cloud.hashicorp.com used to emulate a secondary button. Consumers can now add a link.theme attribute to set button themes, if desired.

--menu-item-heading-text-color: var(--gray-3);
}

.dark {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've riffed off the existing implementation at cloud.hashicorp.com. Have also changed the modals to match the dark theme of the bar to avoid a checkerboard look.

Not 100% sure if this matches design's intent - I found what I think is the reference Figma file but could not find deets on the nav theming. So, went with what I think would match design intent.

@zchsh zchsh changed the title [WIP] feat(subnav): add support for dark theme feat(subnav): add support for dark theme Oct 5, 2021
@zchsh zchsh added the release:canary Triggers a canary release for commits to this pull request label Oct 5, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2021

πŸ“¦ Canary Packages Published

Latest commit: ae7e4a1

Published 1 packages

@hashicorp/react-subnav@9.1.0-canary-20219522528

npm install @hashicorp/react-subnav@canary

@zchsh zchsh requested a review from BRKalow October 5, 2021 02:08
@BRKalow
Copy link
Contributor

BRKalow commented Oct 5, 2021

Nice work here! I think the only thing that I see in the HCP preview is that the logo svg paths have a black fill. πŸ’­

@zchsh
Copy link
Contributor Author

zchsh commented Oct 5, 2021

@BRKalow ugh, aack... yeah the CSS there is pretty brittle. Will switch to loading in the white logos proper πŸ‘ Extra weight but probably worth the stability.

@zchsh
Copy link
Contributor Author

zchsh commented Oct 5, 2021

Had some late-night-still-pretty-sick brain there but https://cloud-hashicorp-com-git-zsupgrade-subnav-hashicorp.vercel.app should be fixed now with all the new logos πŸ‘

5pa9nx

Note: also tested out all the light / dark and product combos on the Storybook preview to make sure they're all loading.

Copy link
Contributor

@BRKalow BRKalow left a comment

Choose a reason for hiding this comment

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

This all looks good to me, thanks for tackling this! Nice balance of get-it-out-the-door and forward-thinking πŸ™‡

@zchsh zchsh merged commit ba93441 into main Oct 5, 2021
@zchsh zchsh deleted the zs.subnav-dark-theme branch October 5, 2021 03:56
@github-actions github-actions bot mentioned this pull request Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:canary Triggers a canary release for commits to this pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants