diff --git a/app/components/navbar/component.html.erb b/app/components/navbar/component.html.erb index 08a8800..ef4f22d 100644 --- a/app/components/navbar/component.html.erb +++ b/app/components/navbar/component.html.erb @@ -1,10 +1,5 @@
<%= content %> -
diff --git a/app/components/navbar/component.rb b/app/components/navbar/component.rb index e94840d..a7fb4b3 100644 --- a/app/components/navbar/component.rb +++ b/app/components/navbar/component.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class Navbar::Component < ApplicationViewComponent - renders_many :right_sections - def dark_mode_switch render(Navbar::DarkModeSwitch::Component.new) end @@ -14,4 +12,8 @@ def account_selector def separator render(Navbar::Separator::Component.new) end + + def item(**) + render(Navbar::Item::Component.new(**)) + end end diff --git a/app/components/navbar/item/component.html.erb b/app/components/navbar/item/component.html.erb new file mode 100644 index 0000000..aeb4052 --- /dev/null +++ b/app/components/navbar/item/component.html.erb @@ -0,0 +1,4 @@ +<%= link_to path, class: is_active? ? "font-bold text-primary" : "" do %> + <% if icon %><% end %> + <%= label || content %> +<% end %> diff --git a/app/components/navbar/item/component.rb b/app/components/navbar/item/component.rb new file mode 100644 index 0000000..afb378a --- /dev/null +++ b/app/components/navbar/item/component.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class Navbar::Item::Component < ApplicationViewComponent + option :label, optional: true + option :icon, optional: true + option :path + option :active, optional: true, default: false + + def is_active? + current_page?(path) || active + end +end diff --git a/app/components/navbar/item/preview.rb b/app/components/navbar/item/preview.rb new file mode 100644 index 0000000..3df7b0a --- /dev/null +++ b/app/components/navbar/item/preview.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class Navbar::Item::Preview < ApplicationViewComponentPreview + # You can specify the container class for the default template + # self.container_class = "w-1/2 border border-gray-300" + + def default + end +end diff --git a/app/views/partials/navigations/_protected.html.erb b/app/views/partials/navigations/_protected.html.erb index f903e86..1144dff 100644 --- a/app/views/partials/navigations/_protected.html.erb +++ b/app/views/partials/navigations/_protected.html.erb @@ -1,14 +1,10 @@ -<%= link_to t(".dashboard"), dashboard_path, class: "font-bold text-primary" %> +<%= navbar.item(icon: "fa fa-dashboard", label: t(".dashboard"), path: dashboard_path) %> -<% navbar.with_right_section do %> + diff --git a/app/views/partials/navigations/_public.html.erb b/app/views/partials/navigations/_public.html.erb index 27931b3..b197daf 100644 --- a/app/views/partials/navigations/_public.html.erb +++ b/app/views/partials/navigations/_public.html.erb @@ -1,11 +1,7 @@ - <%= link_to "Home", root_path, class: "font-bold text-primary" %> - <%= link_to "Features", "#", class: "hover:text-primary" %> - <%= link_to "Pricing", "#", class: "hover:text-primary" %> - <%= link_to "About us", "#", class: "hover:text-primary" %> - <%= link_to "Contact", "#", class: "hover:text-primary" %> +<%= navbar.item(icon: "fa fa-house", label: t(".home"), path: root_path) %> - <% navbar.with_right_section do %> - <%= link_to "Sign in", new_user_session_path, class: "hover:text-primary" %> - <%= link_to "Create account", new_user_registration_path, class: "hover:text-primary" %> - <%= navbar.dark_mode_switch %> - <% end %> + diff --git a/config/locales/kiqr.en.yml b/config/locales/kiqr.en.yml index fdeeb29..e0c4a69 100644 --- a/config/locales/kiqr.en.yml +++ b/config/locales/kiqr.en.yml @@ -42,6 +42,10 @@ en: navigations: protected: dashboard: "Dashboard" + public: + home: "Home" + sign_in: "Sign in" + register: "Create account" settings: account_settings: "Account settings" user_settings: "Login & security"