-
Notifications
You must be signed in to change notification settings - Fork 166
Reintroduce Lookbook for component previews #7115
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
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
34b1c65
Revert "Revert "Add view component previews using Lookbook" (#6004)"
aduth a6d4da9
Add changelog
aduth 5928f26
Move Lookbook/ViewComponent preview config to application.rb
aduth 7443e22
Add additional button variations
aduth 4ef49be
Fix border-box bug
aduth 2a25a88
Render default and component JavaScripts
aduth 6356607
Add Accordion component preview
aduth 8474949
Add Barcode component preview
aduth b0c62c7
Add Block Link component preview
aduth 4537889
Use custom preview controller for synchronous script enqueues
aduth c304b52
Add Clipboard Button component preview
aduth 02be2d9
Try handling CSP overrides in preview controller
aduth f17d286
Revert to referencing CSP from request
aduth 564fedb
Add countdown component preview
aduth c629b7f
Add icon component preview
aduth 99e7ee6
Add basic theming configuration for Lookbook
aduth 8561fc7
Update Lookbook and remove workaround for now-fixed bug
aduth dd4f16f
Revert (back) to current_content_security_policy
aduth 1e54b09
Set X-Frame-Options based on component preview config
aduth 612539f
Manage component CSP with Rack middleware
aduth 425d990
Fix download button space encoding
aduth fdf8bf0
Add preview for DownloadButton component
aduth cf2fff9
Temporary: Remove mounting
aduth fce4dba
Revert "Temporary: Remove mounting"
aduth f3a950c
Upgrade Lookbook to latest
aduth dc71883
Try loading on demand
aduth 1807e82
Require at config
aduth 460292f
Fix standalone MemorableDateComponent missing dependencies
aduth 0bfb987
Add MemorableDateComponent component preview
aduth 251c609
Add PasswordToggleComponent component preview
aduth 1a33473
Add PhoneInputComponent component preview
aduth aecd839
Add SpinnerButtonComponent component preview
aduth 5c805d5
Add StatusPageComponent component preview
aduth 5196680
Add StepIndicatorComponent component preview
aduth 570ca4d
Add TimeComponent component preview
aduth f3e40a0
Add TroubleshootingOptionsComponent component preview
aduth 76a07d3
Add ValidatedFieldComponent component preview
aduth ccac220
Swap "Kitchen Sink" and "Playground" with "Preview" and "Workbench"
aduth c8c3194
Move Lookbook gem back into alphabetized list
aduth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,9 @@ | ||
| class ComponentPreviewController < ViewComponentsController | ||
| include ActionView::Helpers::AssetTagHelper | ||
| helper Lookbook::PreviewHelper | ||
| include Lookbook::PreviewController | ||
| include ScriptHelper | ||
|
|
||
| helper_method :enqueue_component_scripts | ||
| alias_method :enqueue_component_scripts, :render_javascript_pack_once_tags | ||
| end |
This file contains hidden or 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 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <title>Component Preview</title> | ||
| <%= stylesheet_link_tag 'application', media: 'all' %> | ||
| </head> | ||
| <body class="padding-2"> | ||
| <% if params[:lookbook][:display][:form] == true %> | ||
| <form> | ||
| <%= yield %> | ||
| <%= render SubmitButtonComponent.new(class: 'margin-top-5') do %> | ||
| <%= t('forms.buttons.submit.default') %> | ||
| <% end %> | ||
| </form> | ||
| <% else %> | ||
| <%= yield %> | ||
| <% end %> | ||
| <%= javascript_packs_tag_once('application', prepend: true) %> | ||
| <%= render_javascript_pack_once_tags %> | ||
| </body> | ||
| </html> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
| class ComponentPreviewCsp | ||
| COMPONENT_REQUEST_PATH = /^\/components(\/|$)/ | ||
|
|
||
| def initialize(app) | ||
| @app = app | ||
| end | ||
|
|
||
| def call(env) | ||
| status, headers, body = @app.call(env) | ||
| request = Rack::Request.new(env) | ||
|
|
||
| if headers['Content-Security-Policy'].present? && request.path.match?(COMPONENT_REQUEST_PATH) | ||
| headers['Content-Security-Policy'] = headers['Content-Security-Policy']. | ||
| split(';'). | ||
| map(&:strip). | ||
| map do |directive| | ||
| directive. | ||
| sub(/^script-src .+/, "script-src * 'unsafe-eval' 'unsafe-inline'"). | ||
| sub(/^style-src .+/, "style-src * 'unsafe-inline'") | ||
| end. | ||
| join(';') | ||
| end | ||
|
|
||
| [status, headers, body] | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
| class AccordionComponentPreview < BaseComponentPreview | ||
| # @!group Preview | ||
| def default | ||
| render(AccordionComponent.new) do |c| | ||
| c.header { 'Header' } | ||
| 'Content' | ||
| end | ||
| end | ||
|
|
||
| def unbordered | ||
| render(AccordionComponent.new(bordered: false)) do |c| | ||
| c.header { 'Header' } | ||
| 'Content' | ||
| end | ||
| end | ||
| # @!endgroup | ||
|
|
||
| # @param header text | ||
| # @param content text | ||
| # @param bordered toggle | ||
| def workbench(header: 'Header', content: 'Content', bordered: true) | ||
| render(AccordionComponent.new(bordered: bordered)) do |c| | ||
| c.header { header } | ||
| content | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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,41 @@ | ||
| class AlertComponentPreview < BaseComponentPreview | ||
| # @!group Preview | ||
| def default | ||
| render(AlertComponent.new(message: 'A default message')) | ||
| end | ||
|
|
||
| def info | ||
| render(AlertComponent.new(message: 'An info message', type: :info)) | ||
| end | ||
|
|
||
| def success | ||
| render(AlertComponent.new(message: 'A success message', type: :success)) | ||
| end | ||
|
|
||
| def warning | ||
| render(AlertComponent.new(message: 'A warning message', type: :warning)) | ||
| end | ||
|
|
||
| def error | ||
| render(AlertComponent.new(message: 'An error message', type: :error)) | ||
| end | ||
|
|
||
| def emergency | ||
| render(AlertComponent.new(message: 'An emergency message', type: :emergency)) | ||
| end | ||
|
|
||
| def other | ||
| render(AlertComponent.new(message: 'An other message', type: :other)) | ||
| end | ||
|
|
||
| def with_custom_text_tag | ||
| render(AlertComponent.new(type: :success, message: 'A custom message', text_tag: 'div')) | ||
| end | ||
| # @!endgroup | ||
|
|
||
| # @param message text | ||
| # @param type select [info, success, warning, error, emergency, other] | ||
| def workbench(message: 'An important message', type: :info) | ||
| render(AlertComponent.new(message: message, type: type)) | ||
| end | ||
| end |
This file contains hidden or 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,13 @@ | ||
| class BarcodeComponentPreview < BaseComponentPreview | ||
| # @!group Preview | ||
| def default | ||
| render(BarcodeComponent.new(barcode_data: '1234567812345678', label: 'Barcode')) | ||
| end | ||
| # @!endgroup | ||
|
|
||
| # @param barcode_data text | ||
| # @param label text | ||
| def workbench(barcode_data: '1234567812345678', label: 'Barcode') | ||
| render(BarcodeComponent.new(barcode_data: barcode_data, label: label)) | ||
| end | ||
| end |
This file contains hidden or 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,26 @@ | ||
| class BaseComponentPreview < ViewComponent::Preview | ||
| private | ||
|
|
||
| def form_builder | ||
| @form_builder ||= SimpleForm::FormBuilder.new( | ||
| '', | ||
| form_instance, | ||
| ActionView::Base.new( | ||
| ActionView::LookupContext.new(ActionController::Base.view_paths), | ||
| {}, | ||
| nil, | ||
| ), | ||
| {}, | ||
| ) | ||
| end | ||
|
|
||
| def form_instance | ||
| nil | ||
| end | ||
|
|
||
| # rubocop:disable Layout/LineLength | ||
| def example_long_content | ||
| 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et tincidunt libero, quis eleifend dui. Quisque dui velit, euismod ac arcu in, vehicula suscipit dui. Vivamus sed justo justo. Nunc a feugiat libero. Nulla dapibus blandit nisl, ac ultrices sapien dapibus ut. Vivamus convallis elementum mi pulvinar elementum. Quisque at aliquet nibh. Donec sed magna ut ipsum auctor dapibus. Proin leo metus, placerat eu finibus sed, consequat eu urna. Nunc tristique purus sollicitudin, luctus nisi eu, commodo tortor. Praesent mattis dictum diam ac sodales.' | ||
| end | ||
| # rubocop:enable Layout/LineLength | ||
| end |
This file contains hidden or 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,18 @@ | ||
| class BlockLinkComponentPreview < BaseComponentPreview | ||
| # @!group Preview | ||
| def default | ||
| render(BlockLinkComponent.new(url: '', new_tab: false).with_content('Link text')) | ||
| end | ||
|
|
||
| def new_tab | ||
| render(BlockLinkComponent.new(url: '', new_tab: true).with_content('Link text')) | ||
| end | ||
| # @!endgroup | ||
|
|
||
| # @param content text | ||
| # @param url text | ||
| # @param new_tab toggle | ||
| def workbench(content: 'Link text', url: '', new_tab: false) | ||
| render(BlockLinkComponent.new(url: url, new_tab: new_tab).with_content(content)) | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.