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

fix(portal): sidebar active item state #2119

Merged
merged 15 commits into from
Sep 25, 2023
Merged

Conversation

jamilbk
Copy link
Member

@jamilbk jamilbk commented Sep 22, 2023

Adds active_path to determine whether or not to highlight a sidebar item.

Leaving as draft for now to allow @devsnaked to contribute. Edit: Will use this PR as the base for @devsnaked's upcoming changes

Edit: fixes #2065

@vercel
Copy link

vercel bot commented Sep 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
firezone ⬜️ Ignored (Inspect) Visit Preview Sep 25, 2023 8:03pm

@jamilbk jamilbk force-pushed the jamilbk-fix/sidebar-active-state branch from 6718d7c to 46234a4 Compare September 22, 2023 19:53
@jamilbk jamilbk self-assigned this Sep 22, 2023
@@ -170,7 +173,8 @@ defmodule Web.NavigationComponents do

attr :id, :string, required: true, doc: "ID of the nav group container"
attr :icon, :string, required: true
# attr :navigate, :string, required: true
attr :active_path, :string, required: true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should call it current_path?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

@@ -154,6 +156,7 @@ defmodule Web.NavigationComponents do
flex items-center p-2
text-base font-medium text-gray-900
rounded-lg
#{if String.starts_with?(@active_path, @navigate), do: @active_class, else: ""}
hover:bg-gray-100
dark:text-white dark:hover:bg-gray-700 group]}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think for state changes we should move them out of ~H and do something like:

activity_class = 
  if String.starts_with?(assigns.current_path, assigns.navigate) do
    assigns.active_class
  end

assigns = assign(assigns, activity_class: activity_class)

And then to make classes more readable we can leverage list of strings instead of sigil (I noticed Elixir formatted makes some weird moves with it so was trying to avoid it in new code):

~H"""
... class={[
  "flex items-center p-2",
  "text-base font-medium text-gray-900",
  "rounded-lg",
  @activity_class
]}
"""

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 Will get this feedback applied

Copy link
Collaborator

@AndrewDryga AndrewDryga Sep 25, 2023

Choose a reason for hiding this comment

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

Or we can do like Phoenix team does:

class={[
  "flex items-center p-2",
  "text-base font-medium text-gray-900",
  "rounded-lg",
  String.starts_with?(@current_path, @navigate) && @active_class,
]}

Copy link
Member Author

@jamilbk jamilbk Sep 25, 2023

Choose a reason for hiding this comment

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

I think the second one might end up being cleaner because we need the particular navigate attribute for each item inside the comprehension

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

@jamilbk
Copy link
Member Author

jamilbk commented Sep 25, 2023

@AndrewDryga fixed.

@jamilbk jamilbk added this pull request to the merge queue Sep 25, 2023
Merged via the queue into main with commit 41bbf7e Sep 25, 2023
29 checks passed
@jamilbk jamilbk deleted the jamilbk-fix/sidebar-active-state branch September 25, 2023 21:51
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.

Sidebar fixes
2 participants