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 config option to change the order of section panels in the sidebar #553

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/controllers/lookbook/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def assign_instance_vars
@config = Lookbook.config
@engine = Lookbook.engine
@embed = !!params[:lookbook_embed]
@blank_slate = Engine.pages.none? && Engine.previews.none?
@sidebar_panels = sidebar_panels
@blank_slate = @sidebar_panels.none?
end

def raise_not_found(message = "Page not found")
Expand All @@ -71,6 +72,13 @@ def current_layout

private

def sidebar_panels
panels_config = Lookbook.config.preview_inspector.sidebar_panels.map(&:to_sym)
panels_config.select do |panel|
(panel == :pages && Engine.pages.any?) || (panel == :previews && Engine.previews.any?)
end
end

def get_status_code(err)
if err.respond_to?(:status)
err.status
Expand Down
78 changes: 41 additions & 37 deletions app/views/layouts/lookbook/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
project_name: @config.project_name,
project_logo: @config.project_logo %>

<% if @previews.any? || @pages.any? %>
<% unless @blank_slate %>

<%= lookbook_render :split_layout,
alpine_data: "$store.layout.main",
Expand All @@ -32,48 +32,52 @@
"x-on:click.outside": "closeMobileSidebar",
cloak: true do %>

<%= lookbook_render :split_layout,
alpine_data: "$store.layout.#{@pages.any? && @previews.any? ? "sidebar" : "singleSectionSidebar"}",
style: "height: calc(100vh - 2.5rem);" do |layout| %>
<% if @sidebar_panels.any? %>
<%= lookbook_render :split_layout,
alpine_data: "$store.layout.#{@sidebar_panels.many? ? "sidebar" : "singleSectionSidebar"}",
style: "height: calc(100vh - 2.5rem);" do |layout| %>

<% if @previews.any? %>
<% layout.with_pane class: "overflow-hidden" do %>
<%= lookbook_render :nav,
id: "previews-nav",
tree: @previews.to_tree,
alpine_data: "$store.nav.previews" do |nav| %>
<%= nav.with_toolbar do |toolbar| %>
<% toolbar.with_section padded: true do %>
<h4 class="pt-1"><%= @config.preview_collection_label %></h4>
<% end %>
<% toolbar.with_section align: :right, padded: false do %>
<%= lookbook_render :button_group, size: :xs do |group| %>
<% group.with_button icon: :minus_square,
tooltip: "Collapse all",
"x-on:click": "closeAll" %>
<% @sidebar_panels.each do |panel| %>
<% if panel == :previews && @previews.any? %>
<% layout.with_pane class: "overflow-hidden" do %>
<%= lookbook_render :nav,
id: "previews-nav",
tree: @previews.to_tree,
alpine_data: "$store.nav.previews" do |nav| %>
<%= nav.with_toolbar do |toolbar| %>
<% toolbar.with_section padded: true do %>
<h4 class="pt-1"><%= @config.preview_collection_label %></h4>
<% end %>
<% toolbar.with_section align: :right, padded: false do %>
<%= lookbook_render :button_group, size: :xs do |group| %>
<% group.with_button icon: :minus_square,
tooltip: "Collapse all",
"x-on:click": "closeAll" %>
<% end %>
<% end %>
<% end %>
<% nav.with_filter store: "$store.nav.previews.filter", placeholder: "Filter previews by name&hellip;" %>
<% end %>
<% end %>
<% nav.with_filter store: "$store.nav.previews.filter", placeholder: "Filter previews by name&hellip;" %>
<% end %>
<% end %>
<% end %>

<% if @pages.any? %>
<% layout.with_pane class: "overflow-hidden" do %>
<%= lookbook_render :nav,
id: "pages-nav",
tree: @pages.to_tree,
alpine_data: "$store.nav.pages" do |nav| %>
<%= nav.with_toolbar do |toolbar| %>
<% toolbar.with_section padded: true do %>
<h4 class="pt-1"><%= @config.page_collection_label %></h4>
<% end %>
<% toolbar.with_section align: :right, padded: false do %>
<%= lookbook_render :button_group, size: :xs do |group| %>
<% group.with_button icon: :minus_square,
tooltip: "Collapse all",
"x-on:click": "closeAll" %>
<% if panel == :pages && @pages.any? %>
<% layout.with_pane class: "overflow-hidden" do %>
<%= lookbook_render :nav,
id: "pages-nav",
tree: @pages.to_tree,
alpine_data: "$store.nav.pages" do |nav| %>
<%= nav.with_toolbar do |toolbar| %>
<% toolbar.with_section padded: true do %>
<h4 class="pt-1"><%= @config.page_collection_label %></h4>
<% end %>
<% toolbar.with_section align: :right, padded: false do %>
<%= lookbook_render :button_group, size: :xs do |group| %>
<% group.with_button icon: :minus_square,
tooltip: "Collapse all",
"x-on:click": "closeAll" %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
Expand Down
32 changes: 21 additions & 11 deletions app/views/lookbook/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
<%
sidebar_panels_config = @config.preview_inspector.sidebar_panels.map(&:to_sym)
%>

<%= render "lookbook/partials/blank_slate" do %>
<% if @blank_slate %>
<%= lookbook_render :message,
id: "welcome-message",
title: "Welcome to your Lookbook!",
icon: :logo do %>
<p>
There isn't much to see yet, but
<%= link_to "component previews",
"#{@config.links.docs}/guide/previews",
target: "_blank"
%>
and
<%= link_to "content pages",
"#{@config.links.docs}/guide/pages",
target: "_blank"
%>
will show up here as soon as they are added.
There isn't much to see yet<% if sidebar_panels_config.any? %>, but<% end %>
<% if sidebar_panels_config.include?(:previews) %>
<%= link_to "component previews",
"#{@config.links.docs}/guide/previews",
target: "_blank"
%>
<% end %>
<% if sidebar_panels_config.many? %>and<% end %>
<% if sidebar_panels_config.include?(:pages) %>
<%= link_to "content pages",
"#{@config.links.docs}/guide/pages",
target: "_blank"
%>
<% end %>
<% if sidebar_panels_config.any? %>
will show up here as soon as they are added.
<% end %>
</p>
<% end %>
<% else %>
Expand Down
1 change: 1 addition & 0 deletions config/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ shared:
preview_inspector:
main_panels: [preview, output]
drawer_panels: [source, notes, params, "*"]
sidebar_panels: [previews, pages]
preview_embeds:
enabled: true
policy: SAMEORIGIN
Expand Down
6 changes: 6 additions & 0 deletions docs/src/_data/config_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ previews:
example: config.lookbook.preview_inspector.drawer_panels = [:notes, :params]
description: List of panels to display in the preview inspector

- name: preview_inspector.sidebar_panels
types: Array
default: '[:previews, :pages]'
example: config.lookbook.preview_inspector.sidebar_panels = [:pages, :previews]
description: Controls the order and availability of the sidebar navigation panels.

- name: preview_embeds.enabled
types: Boolean
default: "true"
Expand Down
10 changes: 10 additions & 0 deletions docs/src/_guide/ui/other.md → docs/src/_guide/ui/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ title: Navigation
```
<% end %>

<%= render section("Sections order", id: "sections-order") do |s| %>

To change the order of the navigation sections in the sidebar, use the `preview_inspector.sidebar_panels` config option:

```ruby
# Display pages before previews in the sidebar
config.lookbook.preview_inspector.sidebar_panels = [:pages, :previews]
```
<% end %>

<%= render section("Scenario order", id: "scenario-order") do |s| %>
By default scenarios are listed in the navigation in the order in which they are defined in the preview class.

Expand Down