-
-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Sam Williams <[email protected]>
- Loading branch information
Showing
23 changed files
with
411 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
$small: 640px; | ||
$medium: 1024px; | ||
$mobile: $medium; | ||
$large: 1200px; | ||
$large: 1200px; | ||
|
||
// If you adjust this breakpoint, you also need to adjust the breakpoint value in app/javascript/controllers/sidebar-controller.js | ||
$mobile: 768px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
$primary: #00447c; | ||
$red: #dc3545; | ||
|
||
// ======== Sidebar colors | ||
$sidebar-inactive: #9AA4CA; | ||
$sidebar-active: #365CF5; | ||
$sidebar-dark: #1A2142; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<li class="nav-item nav-item-has-children group-item" data-sidebar-target="groupList" data-controller="sidebar-group"> | ||
<a | ||
href="#0" | ||
class="<%= @class %>" | ||
data-bs-toggle="collapse" | ||
data-bs-target="#ddmenu_<%= @identifier %>" | ||
aria-controls="ddmenu_<%= @identifier %>" | ||
aria-expanded="true" | ||
aria-label="Toggle navigation" | ||
data-sidebar-group-target="title"> | ||
<span class="icon"> | ||
<i class="lni mr-10 lni-<%= @icon %>"></i> | ||
</span> | ||
<span data-sidebar-target="linkTitle"><%= @title %></span> | ||
</a> | ||
<ul id="ddmenu_<%= @identifier %>" class="collapse dropdown-nav" data-sidebar-group-target="list"> | ||
<% links.each do |link| %> | ||
<%= link %> | ||
<% end %> | ||
</ul> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class Sidebar::GroupComponent < ViewComponent::Base | ||
renders_many :links, Sidebar::LinkComponent | ||
|
||
# @param title [String] the title/label for the link | ||
# @param icon [String] the lni icon, pass just the name of the icon (ie. for lni-star --> icon: "star") | ||
# @param render_check [Boolean] whether or not to display the link | ||
def initialize(title:, icon:, render_check: true) | ||
@title = title | ||
@icon = icon | ||
@render_check = render_check | ||
@identifier = title.downcase.tr(" ", "-") | ||
@class = "#{@identifier} collapsed" | ||
end | ||
|
||
# If there are no links or all links fail their render_check, then don't render this group | ||
# @return [Boolean] | ||
def render? | ||
@render_check && !links.empty? && !links.select(&:render?).empty? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<li class="<%= @class %>" data-sidebar-group-target="link"> | ||
<%= link_to @path do %> | ||
<% if @icon %> | ||
<i class="lni mr-10 lni-<%= @icon %>"></i> | ||
<% end %> | ||
<span data-sidebar-target="linkTitle" class="sidebar-link"><%= @title %></span> | ||
<% end %> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
class Sidebar::LinkComponent < ViewComponent::Base | ||
include SidebarHelper | ||
|
||
# @param title [String] the title/label for the link | ||
# @param path [String] the path to navigate to | ||
# @param icon [String] the lni icon, pass just the name of the icon (ie. for lni-star --> icon: "star") | ||
# @param nav_item [Boolean] whether or not the link should have the nav-item class | ||
# @param render_check [Boolean] whether or not to display the link | ||
def initialize(title:, path:, icon: nil, nav_item: true, render_check: true) | ||
@title = title | ||
@icon = icon | ||
@path = path | ||
@nav_item = nav_item | ||
@render_check = render_check | ||
end | ||
|
||
# Must be moved to this method in order to use the SidebarHelper | ||
def before_render | ||
@class = @nav_item ? "nav-item #{active_class(@path)}" : "" | ||
end | ||
|
||
# @return [Boolean] | ||
def render? | ||
@render_check | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
static outlets = ['sidebar'] | ||
|
||
click () { | ||
// This simulates a click action on the sidebar-controller | ||
this.sidebarOutlet.click() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
static targets = ['sidebar', 'menu', 'logo', 'linkTitle', 'groupList'] | ||
static values = { | ||
open: Boolean, | ||
breakpoint: { type: Number, default: 768 } | ||
} | ||
|
||
static outlets = ['sidebar-group'] | ||
|
||
click () { | ||
this.openValue = !this.openValue | ||
this.toggleSidebar() | ||
if (this.isNotMobile()) { | ||
this.toggleLinks() | ||
const mainWrapper = document.querySelector('.main-wrapper') | ||
mainWrapper.classList.toggle('active') | ||
} else { | ||
this.toggleOverlay() | ||
} | ||
} | ||
|
||
hoverOn () { | ||
this.toggleHover() | ||
} | ||
|
||
hoverOff () { | ||
this.toggleHover() | ||
} | ||
|
||
toggleHover () { | ||
if (!this.openValue && this.isNotMobile()) { | ||
this.toggleSidebar() | ||
this.toggleLinks() | ||
} | ||
} | ||
|
||
toggleSidebar () { | ||
this.sidebarTarget.classList.toggle('active') | ||
} | ||
|
||
toggleLinks () { | ||
this.linkTitleTargets.forEach((target) => { | ||
target.classList.toggle('d-none') | ||
}) | ||
this.groupListTargets.forEach((list) => { | ||
list.classList.toggle('nav-item-has-children') | ||
}) | ||
this.logoTarget.classList.toggle('d-none') | ||
} | ||
|
||
toggleOverlay () { | ||
const overlay = document.querySelector('.overlay') | ||
overlay.classList.toggle('active') | ||
} | ||
|
||
isNotMobile () { | ||
return window.innerWidth >= this.breakpointValue | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
static targets = ['title', 'list', 'link'] | ||
|
||
connect () { | ||
this.toggleShow() | ||
} | ||
|
||
// Expands list if a link is active | ||
toggleShow () { | ||
this.linkTargets.forEach((link) => { | ||
if (link.classList.contains('active')) { | ||
this.titleTarget.classList.remove('collapsed') | ||
this.listTarget.classList.add('show') | ||
} | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.