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

Feature: Add Lookbook to preview view components #236

Merged
merged 6 commits into from
Apr 21, 2023
Merged
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ gem 'rest-client'
gem 'stackprof', require: false
gem 'thin'
gem 'view_component', '~> 2.72'
gem "lookbook"
gem 'turnout'
gem 'will_paginate', '~> 3.0'

Expand Down
4 changes: 2 additions & 2 deletions app/components/card_message_component.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class CardMessageComponent < ViewComponent::Base
def initialize(title: nil ,message:, button_text: nil, type:)
def initialize(title: nil ,message:, button_text: nil, button_link: "/" ,type:)
@title = title
@message = message
@button_text = button_text
@type = type

@button_link = button_link
end

def no_title?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
- unless no_button?
- case @type
- when "success"
%a.card-message-button.card-message-button-success{:href => "/"}
%a.card-message-button.card-message-button-success{:href => @button_link}
= @button_text
- when "failure"
%a.card-message-button.card-message-button-failure{:href => "/"}
%a.card-message-button.card-message-button-failure{:href => @button_link}
= @button_text
12 changes: 12 additions & 0 deletions app/views/layouts/component_preview.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<title>Component Preview</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= stylesheet_link_tag "application" %>
</head>
<body style="margin: 20px">

<%= yield %> <!-- rendered preview will be injected here -->

</body>
</html>
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ class Application < Rails::Application
config.change_request = config_for :change_request

config.generators.template_engine = :haml

# Set the default layout to app/views/layouts/component_preview.html.erb
config.view_component.default_preview_layout = "component_preview"
end
end
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,6 @@
get '/visualize' => 'ontologies#visualize', :as => :visualize_concept, :constraints => { ontology: /[^\/?]+/, id: /[^\/?]+/, ontologyid: /[^\/?]+/, conceptid: /[^\/?]+/ }

get '/exhibit/:ontology/:id' => 'concepts#exhibit'


mount Lookbook::Engine, at: "/lookbook"
end
12 changes: 12 additions & 0 deletions test/components/previews/card_message_component_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CardMessageComponentPreview < ViewComponent::Preview

# @param message text
# @param button_text text
# @param type select [success, failure]
# @param button_link text

def default(message: "Here we can type a success or failure message to the user", button_text: "Do action", type: "success", button_link: "/" )
render(CardMessageComponent.new(message: message, button_text: button_text, type: type, button_link: button_link))
end

end
10 changes: 10 additions & 0 deletions test/components/previews/chips_component_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ChipsComponentPreview < ViewComponent::Preview

# @param name text
# @param value text

def default(name: "name", value: "value")
render(ChipsComponent.new(name: name, value: value))
end

end