Skip to content

Commit 42f2112

Browse files
committed
Replace custom modal implementation with turbo/stimulus
1 parent c372237 commit 42f2112

File tree

11 files changed

+47
-256
lines changed

11 files changed

+47
-256
lines changed

app/components/blacklight/document/action_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def link_to_modal_control
3131
url,
3232
id: @id,
3333
class: @link_classes,
34-
data: {}.merge(({ blacklight_modal: "trigger", turbo: false } if @action.modal != false) || {})
34+
data: {}.merge(({ action: 'blacklight--modal#open', 'turbo-frame': 'modal' } if @action.modal != false) || {})
3535
end
3636

3737
def render_partial

app/components/blacklight/facet_field_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div class="more_facets">
2121
<%= link_to t("more_#{@facet_field.key}_html", scope: 'blacklight.search.facets', default: :more_html, field_name: @facet_field.label),
2222
@facet_field.modal_path,
23-
data: { blacklight_modal: 'trigger', turbo: false } %>
23+
data: { action: 'blacklight--modal#open', 'turbo-frame': 'modal' } %>
2424
</div>
2525
<% end %>
2626
</div>

app/components/blacklight/facet_field_list_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<div class="more_facets">
1313
<%= link_to t("more_#{@facet_field.key}_html", scope: 'blacklight.search.facets', default: :more_html, field_name: @facet_field.label),
1414
@facet_field.modal_path,
15-
data: { blacklight_modal: 'trigger' } %>
15+
data: { action: 'blacklight--modal#open', 'turbo-frame': 'modal' } %>
1616
</div>
1717
<% end %>
1818
<% end %>
Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
<div data-blacklight-modal="container">
2-
<%= prefix %>
1+
<turbo-frame id="modal">
2+
<div data-blacklight-modal="container">
3+
<%= prefix %>
34

4-
<div class="modal-header">
5-
<%= header || (capture do %>
6-
<h1 class="modal-title"><%= title %></h1>
7-
<% end) %>
8-
9-
<button type="button" class="blacklight-modal-close btn-close close" data-bl-dismiss="modal" aria-label="<%= t('blacklight.modal.close') %>">
10-
<span aria-hidden="true" class="visually-hidden">&times;</span>
11-
</button>
12-
</div>
5+
<div class="modal-header">
6+
<%= header || (capture do %>
7+
<h1 class="modal-title"><%= title %></h1>
8+
<% end) %>
139

14-
<%= body || (capture do %>
15-
<div class="modal-body">
16-
<%= content %>
10+
<button type="button" class="blacklight-modal-close btn-close close" data-action="blacklight--modal#close" aria-label="<%= t('blacklight.modal.close') %>">
11+
<span aria-hidden="true" class="visually-hidden">&times;</span>
12+
</button>
1713
</div>
18-
<% end) %>
1914

20-
<% if footer.present? %>
21-
<div class="modal-footer">
22-
<%= footer %>
23-
</div>
24-
<% end %>
15+
<%= body || (capture do %>
16+
<div class="modal-body">
17+
<%= content %>
18+
</div>
19+
<% end) %>
20+
21+
<% if footer.present? %>
22+
<div class="modal-footer">
23+
<%= footer %>
24+
</div>
25+
<% end %>
26+
</div>
2527
</div>

app/javascript/blacklight/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import ButtonFocus from 'blacklight/button_focus'
2-
import Modal from 'blacklight/modal'
32
import SearchContext from 'blacklight/search_context'
43
import Core from 'blacklight/core'
54

65
export default {
76
ButtonFocus,
8-
Modal,
97
SearchContext,
108
Core,
119
onLoad: Core.onLoad

app/javascript/blacklight/modal.js

Lines changed: 0 additions & 166 deletions
This file was deleted.

app/javascript/blacklight/modalForm.js

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Controller } from "@hotwired/stimulus"
2+
3+
export default class extends Controller {
4+
static targets = ['content', 'modal']
5+
6+
connect() {
7+
this.contentTarget.innerHTML = '<turbo-frame id="modal"></turbo-frame>';
8+
}
9+
10+
open() {
11+
this.modalTarget.showModal();
12+
}
13+
14+
close() {
15+
this.modalTarget.close();
16+
}
17+
}

app/views/catalog/facet.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

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

12-
<div class="facet-extended-list">
12+
<div class="facet-extended-list" target="_top">
1313
<%= render Blacklight::FacetComponent.new(display_facet: @display_facet,
1414
blacklight_config: blacklight_config,
1515
layout: false) %>

app/views/layouts/blacklight/base.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<%= javascript_importmap_tags %>
2020
<% elsif defined? Propshaft %>
2121
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
22-
<% else %>
22+
<% else %>
2323
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
2424
<%= javascript_include_tag "blacklight/blacklight", type: 'module' %>
2525
<% end %>
@@ -30,7 +30,7 @@
3030
import githubAutoCompleteElement from 'https://cdn.skypack.dev/@github/auto-complete-element';
3131
</script>
3232
</head>
33-
<body class="<%= render_body_class %>">
33+
<body class="<%= render_body_class %>" data-controller="blacklight--modal">
3434
<nav id="skip-link" role="navigation" aria-label="<%= t('blacklight.skip_links.label') %>">
3535
<%= link_to t('blacklight.skip_links.search_field'), '#search_field', class: 'element-invisible element-focusable rounded-bottom py-2 px-3', data: { turbolinks: 'false' } %>
3636
<%= link_to t('blacklight.skip_links.main_content'), '#main-container', class: 'element-invisible element-focusable rounded-bottom py-2 px-3', data: { turbolinks: 'false' } %>

app/views/shared/_modal.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<dialog id="blacklight-modal" class="modal" data-turbo="false">
1+
<dialog id="blacklight-modal" class="modal" data-blacklight--modal-target="modal">
22
<div class="modal-dialog modal-lg">
3-
<div class="modal-content">
3+
<div class="modal-content" data-blacklight--modal-target="content">
44
</div>
55
</div>
66
</dialog>

0 commit comments

Comments
 (0)