-
Notifications
You must be signed in to change notification settings - Fork 155
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
fix: header breaks on mobile screens #374
Conversation
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.
Looking good! Just a few technical concerns.
components/Header.tsx
Outdated
function MenuItem(props: MenuItemProps) { | ||
return ( | ||
<a | ||
href={props.href} | ||
class={cx( | ||
props.active ? ACTIVE_LINK_STYLES : LINK_STYLES, | ||
"relative text-gray-500 px-3 py-4 sm:py-2", | ||
props.class, | ||
)} | ||
aria-label={props.ariaLabel} | ||
> | ||
{props.name} | ||
</a> | ||
); | ||
} |
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 think it'd be cleaner if we just wrote the menu HTML without iterating over an array of elements. Menu items can vary in requirements, making a flexible <MenuItem />
challenging to manage past a certain point. We can have a MENU_ITEM_STYLES
constant for any common styles between these menu items. WDYT?
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.
Hmm I wanted to use the practice of defining menus with JSON, which used in our repos (Example), but okay let me revert last refactoring commit. let's discuss this in another PR
import { Bell, CircleFilled } from "./Icons.tsx"; | ||
import { getToggledStyles } from "@/utils/display.ts"; | ||
import { Bars, Bell, CircleFilled, Cross } from "./Icons.tsx"; | ||
import { cx } from "@twind/core"; |
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.
Sidenote: this might be able to replace the new getToggledStyles()
.
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.
Yes, we can use it. I was just writing code like this at first:
class={cx(
getToggledStyles(
LINK_STYLES,
ACTIVE_LINK_STYLES,
props.url.pathname === "/pricing",
),
NAV_ITEM,
)}
I noticed that this code can be rewritten as:
class={cx(
props.url.pathname === "/pricing" ? ACTIVE_LINK_STYLES : LINK_STYLES,
NAV_ITEM,
)}
This cx style description is used in deno deploy and can handle both concatenation and toggle of CSS strings.
Since this header component uses cx throughout, I removed getToggledStyles as a dependency.
I think it would be better to write getToggledStyles with a ternary operator where cx is used, what do you think?
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.
What about if we got rid of getToggledStyles()
completely across the codebase and used cx()
instead? Maybe we could do this in another PR.
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.
yeah if it's okay, I'll like to help to do this
components/Header.tsx
Outdated
href={props.href} | ||
class={cx( | ||
props.active ? ACTIVE_LINK_STYLES : LINK_STYLES, | ||
"relative text-gray-500 px-3 py-4 sm:py-2", |
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.
"relative text-gray-500 px-3 py-4 sm:py-2", | |
"relative text-gray-500 py-4 sm:py-2", |
Perhaps, we don't need any horizontal padding. WYDT?
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.
Looks great! |
components/Header.tsx
Outdated
href: "/account/notifications", | ||
ariaLabel: "Notifications", | ||
}, | ||
{ name: "Submit a project", href: "/submit", class: "sm:hidden" }, |
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.
{ name: "Submit a project", href: "/submit", class: "sm:hidden" }, | |
{ name: "Submit", href: "/submit", class: "sm:hidden" }, |
I'm happy to keep the inner text the same.
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'd prefer to keep it in the menu as it is now. Instead, perhaps we could keep its button styling to stand out. WDYT? |
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
@iuioiua OK, wdyt? |
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 looks amazing 😍
I'll merge. Let's have the |
Thank you! |
"Someone" broke the hamburger menu in #646. This fixes the issue and cleans things up by making the CSS a bit more direct: * I use https://tailwindcss.com/docs/hover-focus-and-other-states#styling-based-on-sibling-state to modify the `nav` directly. * I add IDs to the hamburger and X components, and then use https://tailwindcss.com/docs/hover-focus-and-other-states#using-arbitrary-variants to directly target them, in combination with peer. FYI @hashrock since this restores the great work you did in #374.
This pull request introduces a hamburger menu on mobile.
Close #345
Implementation notes:
before:
after: