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

Replace custom modal implementation with turbo/stimulus #3001

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion app/components/blacklight/document/action_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def link_to_modal_control
url,
id: @id,
class: @link_classes,
data: {}.merge(({ blacklight_modal: "trigger", turbo: false } if @action.modal != false) || {})
data: {}.merge(({ action: 'blacklight--modal#open', 'turbo-frame': 'modal' } if @action.modal != false) || {})
end

def render_partial
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/facet_field_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div class="more_facets">
<%= link_to t("more_#{@facet_field.key}_html", scope: 'blacklight.search.facets', default: :more_html, field_name: @facet_field.label),
@facet_field.modal_path,
data: { blacklight_modal: 'trigger', turbo: false } %>
data: { action: 'blacklight--modal#open', 'turbo-frame': 'modal' } %>
</div>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="more_facets">
<%= link_to t("more_#{@facet_field.key}_html", scope: 'blacklight.search.facets', default: :more_html, field_name: @facet_field.label),
@facet_field.modal_path,
data: { blacklight_modal: 'trigger' } %>
data: { action: 'blacklight--modal#open', 'turbo-frame': 'modal' } %>
</div>
<% end %>
<% end %>
Expand Down
42 changes: 22 additions & 20 deletions app/components/blacklight/system/modal_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<div data-blacklight-modal="container">
<%= prefix %>
<turbo-frame id="modal">
<div data-blacklight-modal="container">
<%= prefix %>

<div class="modal-header">
<%= header || (capture do %>
<h1 class="modal-title"><%= title %></h1>
<% end) %>

<button type="button" class="blacklight-modal-close btn-close close" data-bl-dismiss="modal" aria-label="<%= t('blacklight.modal.close') %>">
<span aria-hidden="true" class="visually-hidden">&times;</span>
</button>
</div>
<div class="modal-header">
<%= header || (capture do %>
<h1 class="modal-title"><%= title %></h1>
<% end) %>

<%= body || (capture do %>
<div class="modal-body">
<%= content %>
<button type="button" class="blacklight-modal-close btn-close close" data-action="blacklight--modal#close" aria-label="<%= t('blacklight.modal.close') %>">
<span aria-hidden="true" class="visually-hidden">&times;</span>
</button>
</div>
<% end) %>

<% if footer.present? %>
<div class="modal-footer">
<%= footer %>
</div>
<% end %>
<%= body || (capture do %>
<div class="modal-body">
<%= content %>
</div>
<% end) %>

<% if footer.present? %>
<div class="modal-footer">
<%= footer %>
</div>
<% end %>
</div>
</div>
2 changes: 0 additions & 2 deletions app/javascript/blacklight/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import BookmarkToggle from 'blacklight/bookmark_toggle'
import ButtonFocus from 'blacklight/button_focus'
import Modal from 'blacklight/modal'
import SearchContext from 'blacklight/search_context'
import Core from 'blacklight/core'

export default {
BookmarkToggle,
ButtonFocus,
Modal,
SearchContext,
Core,
onLoad: Core.onLoad
Expand Down
166 changes: 0 additions & 166 deletions app/javascript/blacklight/modal.js

This file was deleted.

60 changes: 0 additions & 60 deletions app/javascript/blacklight/modalForm.js

This file was deleted.

17 changes: 17 additions & 0 deletions app/javascript/controllers/blacklight/modal_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ['content', 'modal']

connect() {
this.contentTarget.innerHTML = '<turbo-frame id="modal"></turbo-frame>';
}

open() {
this.modalTarget.showModal();
}

close() {
this.modalTarget.close();
}
}
2 changes: 1 addition & 1 deletion app/views/catalog/facet.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<%= render partial: 'facet_index_navigation' if @facet.index_range && @display_facet.index? %>

<div class="facet-extended-list">
<div class="facet-extended-list" target="_top">
<%= render Blacklight::FacetComponent.new(display_facet: @display_facet,
blacklight_config: blacklight_config,
layout: false) %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/blacklight/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<%= javascript_importmap_tags %>
<% elsif defined? Propshaft %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
<% else %>
<% else %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
<%= javascript_include_tag "blacklight/blacklight", type: 'module' %>
<% end %>
Expand All @@ -30,7 +30,7 @@
import githubAutoCompleteElement from 'https://cdn.skypack.dev/@github/auto-complete-element';
</script>
</head>
<body class="<%= render_body_class %>">
<body class="<%= render_body_class %>" data-controller="blacklight--modal">
<nav id="skip-link" role="navigation" aria-label="<%= t('blacklight.skip_links.label') %>">
<%= link_to t('blacklight.skip_links.search_field'), '#search_field', class: 'element-invisible element-focusable rounded-bottom py-2 px-3', data: { turbolinks: 'false' } %>
<%= link_to t('blacklight.skip_links.main_content'), '#main-container', class: 'element-invisible element-focusable rounded-bottom py-2 px-3', data: { turbolinks: 'false' } %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/shared/_modal.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dialog id="blacklight-modal" class="modal" data-turbo="false">
<dialog id="blacklight-modal" class="modal" data-blacklight--modal-target="modal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-content" data-blacklight--modal-target="content">
</div>
</div>
</dialog>
1 change: 1 addition & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

pin_all_from File.expand_path("../app/javascript/blacklight", __dir__), under: "blacklight"
pin_all_from File.expand_path("../app/javascript/controllers", __dir__), under: "controllers"
4 changes: 4 additions & 0 deletions lib/generators/blacklight/assets/propshaft_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def add_package_assets
CONTENT
end
end

def install_stimulus_controllers
rake "stimulus:manifest:update"
end
end
end
end
Loading