-
-
Notifications
You must be signed in to change notification settings - Fork 521
refactor: Rebuild header components #1317
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
Conversation
button, | ||
span { | ||
button { |
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.
The span
styles only existed for the (now altered) LanguagePicker
&[open] { | ||
&[data-open='true'] { |
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.
For TS, and we use data-open
for every other menu too. Previously the hamburger menu used just open
on the container div.
return out; | ||
return out || null; |
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.
Just to avoid empty class
attributes sitting around in prerendered HTML, more than anything.
> :information*desk_person: You [don't \_have* to use ES2015 to use Preact](https://github.com/developit/preact-without-babel)... but you should. This guide assumes you have some sort of ES2015 build set up using babel and/or webpack/browserify/gulp/grunt/etc. If you don't, start with [preact-cli](https://github.com/preactjs/preact-cli) or a [CodePen Template](http://codepen.io/developit/pen/pgaROe?editors=0010). | ||
> :information_desk_person: You [don't _have_ to use ES2015 to use Preact](https://github.com/developit/preact-without-babel)... but you should. This guide assumes you have some sort of ES2015 build set up using babel and/or webpack/browserify/gulp/grunt/etc. If you don't, start with [preact-cli](https://github.com/preactjs/preact-cli) or a [CodePen Template](http://codepen.io/developit/pen/pgaROe?editors=0010). |
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.
Sorry, unrelated but correcting a Prettier bug that screwed up the content.
Didn't want to bother w/ a separate PR for something so tiny.
<Nav class={style.nav} routes={config.nav} current={url} /> | ||
<MainNav /> | ||
<Search /> | ||
<div class={style.social}> | ||
<ReleaseLink class={cx(style.socialItem, style.release)} /> | ||
<SocialIcon | ||
label="Browse the code on GitHub" | ||
href="https://github.com/preactjs/preact" | ||
viewbox="0 0 24 24" | ||
id="github" | ||
/> | ||
<SocialIcon | ||
label="Follow us on Twitter" | ||
href="https://twitter.com/preactjs" | ||
viewbox="0 0 34 27.646" | ||
id="twitter" | ||
/> | ||
<SocialIcon | ||
label="Follow us on Bluesky" | ||
href="https://bsky.app/profile/preactjs.com" | ||
viewbox="0 0 568 501" | ||
id="bluesky" | ||
/> | ||
<SocialIcon | ||
label="Chat with us on Slack" | ||
href="http://chat.preactjs.com/" | ||
viewbox="0 0 512 512" | ||
id="slack" | ||
/> | ||
</div> | ||
<div class={style.translation}> | ||
<NavMenu language /> | ||
</div> | ||
<SocialLinks /> | ||
<LanguagePicker /> |
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.
Broke this up as it was getting a bit big, though there's no complexity so equally I could merge everything back together too. Felt it looked marginally cleaner this way?
|
||
/** | ||
* Get the translated name of a path based upon the current language. | ||
* @param {string} path | ||
*/ | ||
export function useNavTranslation(path) { | ||
const [lang] = useLanguage(); | ||
|
||
for (const route in config.nav) { | ||
if (config.nav[route].path === path) { | ||
return getRouteName(config.nav[route], lang); | ||
} else if (config.nav[route].routes) { | ||
for (const subRoute of config.nav[route].routes) { | ||
if (subRoute.path === path) { | ||
return getRouteName(subRoute, lang); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @param {{ name: Record<string, string> | string }} route | ||
* @param {string} lang | ||
* @return {string} | ||
*/ | ||
export function getRouteName(route, lang) { | ||
return typeof route.name === 'object' | ||
? route.name[lang] || route.name.en | ||
: route.name; | ||
} |
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.
More of a hold over mechanism, I hope to switch the nav translations into a keyed object & break them away from the route paths in the future.
62c3d90
to
0f7da0c
Compare
f98167a
to
ce0c7fb
Compare
Forewarning, sorry, this is fairly big.
Refactors most of the header to make everything a bit more fit for purpose but there are no real functional changes. It corrects a few (IMO) minor grievances that have popped up whilst making other edits:
<NavMenu>
for the "About" routes, we later added a language drop down. This overlapped somewhat with the drop-down menu, but not completely, so there's this awkward ternary in the component./branding
inconfig.nav
so that it was detected as a valid route (404 detection and whatnot), but that list makes up the header items, so we had to add a magic prop<NavLink>
returns an actual link, sometimes it's just a button that triggers no navigation whatsoever. A bit weird.pathMatchesRoute
function to apply the "selected" header style, but then have added additional conditionals outside of that because the function doesn't actually cover the cases we need.config.json
's responsibilitiesconfig.json
is a bit of a weird god-file, in that it controls templating (config.nav
-> header links), route definitions (used in/lib/route-utils.js
for 404 detection & prerendering), and internationalization, all at once.The responsibilities of
config.json
is still a problem that still needs work, but this has at least gotten the templating out for the most part -- no where else are we really passing props via JSON. Ideally, I'll get routes split out from the internationalization in a sane way and then write a plugin to split the i18n file per language, should be about ~5kb of savings there. You'll only need 1 locale at a time of course.This ships a tiny bit less JS, but nothing stellar. ~1kb less.