Skip to content

Commit

Permalink
Add the preview for the sidebar admin component
Browse files Browse the repository at this point in the history
We inject a tweaked item component to avoid rendering actual links in
the embedded preview.

We'll leave the preview of active state of the main navigation to the
item component preview.

Ref. #5221
  • Loading branch information
waiting-for-dev authored and elia committed Sep 29, 2023
1 parent 4b69036 commit 7fa58b8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require "solidus_admin/main_nav_item"

# @component "sidebar"
class SolidusAdmin::Sidebar::ComponentPreview < ViewComponent::Preview
include SolidusAdmin::Preview

class ItemComponent < SolidusAdmin::Sidebar::Item::Component
def path
"#"
end

def active?
false
end
end

# @param store_name text
# @param store_url url
# @param logo_path text { description: "Asset path to the store logo" }
def overview(store_name: "Solidus store", store_url: "https://example.com", logo_path: SolidusAdmin::Config.logo_path)
store = Struct.new(:name, :url).new(store_name, store_url)

render_with_template(
locals: {
logo_path: logo_path,
store: store,
item_component: ItemComponent
}
)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="w-[17.78rem]">
<%= render current_component.new(
store: store,
logo_path: logo_path,
item_component: item_component
) %>
</div>
4 changes: 4 additions & 0 deletions admin/spec/components/solidus_admin/sidebar/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
require "spec_helper"

RSpec.describe SolidusAdmin::Sidebar::Component, type: :component do
it "renders the overview preview" do
render_preview(:overview)
end

it "renders the solidus logo" do
component = described_class.new(
store: build(:store),
Expand Down

0 comments on commit 7fa58b8

Please sign in to comment.