forked from solidusio/solidus
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add component preview for the sidebar item component
We mock the url helpers so the dummy route we use points to the current page. At the same time, we change the item component to get the fullpath on initialization so we can mock and set the active state from outside. Closes solidusio#5221
- Loading branch information
1 parent
016b325
commit c7f9965
Showing
6 changed files
with
82 additions
and
6 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
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
45 changes: 45 additions & 0 deletions
45
admin/spec/components/previews/solidus_admin/sidebar/item/component_preview.rb
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,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require "solidus_admin/main_nav_item" | ||
|
||
# @component "sidebar/item" | ||
class SolidusAdmin::Sidebar::Item::ComponentPreview < ViewComponent::Preview | ||
include SolidusAdmin::Preview | ||
|
||
DUMMY_ROUTE = :foo_path | ||
|
||
DUMMY_PATH = "#" | ||
|
||
# @param active toggle { description: "Whether the item is active" } | ||
# @param key text { description: "ID also used for i18n" } | ||
# @param icon text { description: "RemixIcon name (https://remixicon.com/)" } | ||
def overview(active: false, key: "orders", icon: "inbox-line") | ||
item = SolidusAdmin::MainNavItem.new( | ||
key: key, | ||
icon: icon, | ||
position: 1, | ||
route: DUMMY_ROUTE | ||
) | ||
|
||
render_with_template( | ||
locals: { | ||
item: item, | ||
url_helpers: url_helpers, | ||
fullpath: fullpath(active) | ||
} | ||
) | ||
end | ||
|
||
private | ||
|
||
# solidus_admin.foo_path => "#" | ||
def url_helpers | ||
Struct.new(:solidus_admin).new( | ||
Struct.new(DUMMY_ROUTE).new(DUMMY_PATH) | ||
) | ||
end | ||
|
||
def fullpath(active) | ||
active ? DUMMY_PATH : "" | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
...n/spec/components/previews/solidus_admin/sidebar/item/component_preview/overview.html.erb
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,7 @@ | ||
<ul class="w-[17.78rem]"> | ||
<%= render current_component.new( | ||
item: item, | ||
url_helpers: url_helpers, | ||
fullpath: fullpath | ||
) %> | ||
</ul> |
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