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

✨ Add icon to menu items #1799

Merged
merged 2 commits into from Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/components/avo/sidebar/item_switcher_component.html.erb
@@ -1,11 +1,11 @@
<% if item.is_a? Avo::Menu::Link %>
<%= render Avo::Sidebar::LinkComponent.new label: item.name, path: item.path, target: item.target, data: item.data %>
<%= render Avo::Sidebar::LinkComponent.new label: item.name, path: item.path, target: item.target, data: item.data, icon: item.icon %>
<% end %>
<% if item.is_a? Avo::Menu::Resource %>
<%= render Avo::Sidebar::LinkComponent.new label: item.navigation_label, path: helpers.resources_path(resource: resource), data: item.data %>
<%= render Avo::Sidebar::LinkComponent.new label: item.navigation_label, path: helpers.resources_path(resource: resource), data: item.data, icon: item.icon %>
<% end %>
<% if item.is_a? Avo::Menu::Dashboard %>
<%= render Avo::Sidebar::LinkComponent.new label: item.navigation_label, path: dashboard.navigation_path, data: item.data %>
<%= render Avo::Sidebar::LinkComponent.new label: item.navigation_label, path: dashboard.navigation_path, data: item.data, icon: item.icon %>
<% end %>
<% if item.is_a? Avo::Menu::Section %>
<%= render Avo::Sidebar::SectionComponent.new item: item %>
Expand Down
2 changes: 2 additions & 0 deletions app/components/avo/sidebar/link_component.html.erb
@@ -1,12 +1,14 @@
<% if path.present? %>
<%= send link_method, path, class: classes, active: active, target: target, data: data do %>
<%= helpers.svg icon, class: "h-4" if icon.present? %>
<%= label %>
<% if target == :_blank %>
<%= helpers.svg('heroicons/outline/external-link', class: 'self-center ml-auto h-3 mr-2') %>
<% end %>
<% end %>
<% else %>
<%= content_tag :div, class: classes, active: active, target: target, data: data do %>
<%= helpers.svg icon, class: "h-4" if icon.present? %>
<%= label %>
<% end %>
<% end %>
6 changes: 4 additions & 2 deletions app/components/avo/sidebar/link_component.rb
Expand Up @@ -6,13 +6,15 @@ class Avo::Sidebar::LinkComponent < ViewComponent::Base
attr_reader :label
attr_reader :path
attr_reader :data
attr_reader :icon

def initialize(label: nil, path: nil, active: :inclusive, target: nil, data: {})
def initialize(label: nil, path: nil, active: :inclusive, target: nil, data: {}, icon: nil)
@label = label
@path = path
@active = active
@target = target
@data = data
@icon = icon
end

def is_external?
Expand All @@ -28,6 +30,6 @@ def link_method
end

def classes
"px-4 pr-0 flex-1 flex mx-6 leading-none py-2 text-black rounded font-medium hover:bg-gray-100"
"px-4 pr-0 flex-1 flex mx-6 leading-none py-2 text-black rounded font-medium hover:bg-gray-100 gap-1"
end
end
4 changes: 2 additions & 2 deletions app/components/avo/sidebar_component.html.erb
Expand Up @@ -25,7 +25,7 @@

<div class="w-full space-y-1">
<% dashboards.sort_by { |r| r.navigation_label }.each do |dashboard| %>
<%= render Avo::Sidebar::LinkComponent.new label: dashboard.navigation_label, path: dashboard.navigation_path %>
<%= render Avo::Sidebar::LinkComponent.new label: dashboard.navigation_label, path: dashboard.navigation_path, icon: resource.icon %>
<% end %>
</div>
</div>
Expand All @@ -36,7 +36,7 @@

<div class="w-full space-y-1">
<% resources.sort_by { |r| r.navigation_label }.each do |resource| %>
<%= render Avo::Sidebar::LinkComponent.new label: resource.navigation_label, path: helpers.resources_path(resource: resource) %>
<%= render Avo::Sidebar::LinkComponent.new label: resource.navigation_label, path: helpers.resources_path(resource: resource), icon: resource.icon %>
<% end %>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions spec/dummy/config/initializers/avo.rb
Expand Up @@ -76,7 +76,7 @@
## == Menus ==
config.main_menu = -> do
section I18n.t("avo.dashboards"), icon: "dummy-adjustments.svg" do
dashboard :dashy, visible: -> { true }
dashboard :dashy, visible: -> { true }, icon: "bolt"
dashboard "Sales", visible: -> { true }

group "All dashboards", visible: false, collapsable: true do
Expand Down Expand Up @@ -114,7 +114,7 @@
group "Blog", collapsable: true do
# resource :z_posts
resource :posts
resource :comments
resource :comments, icon: "chat-bubble-bottom-center-text"
resource :photo_comments, visible: -> do
authorize current_user, Comment, "index?", policy_class: PhotoCommentPolicy, raise_exception: false
end
Expand Down