-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
π¦ Changeset detectedLatest commit: ae7e4a1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This pull request is being automatically deployed with Vercel (learn more). π Inspect: https://vercel.com/hashicorp/react-components/2o4EoXBxQBsCj7EFRpsUnGpBUQWX |
packages/subnav/theme.module.css
Outdated
@@ -0,0 +1,43 @@ | |||
/* Theme settings. Note: also consumed in /partials */ |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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, { |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 */, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
π¦ Canary Packages PublishedLatest commit: ae7e4a1 Published 1 packages@hashicorp/react-subnav@9.1.0-canary-20219522528
|
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. π |
@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. |
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 π
|
There was a problem hiding this 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 π
ποΈ 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.