Skip to content

Commit

Permalink
Add closable option to modal ui component
Browse files Browse the repository at this point in the history
That way we can disdplay the modal on an edit/new route but prevent
the modal from being closed by the user.
  • Loading branch information
tvdeyen committed Dec 23, 2024
1 parent 3a05eaf commit 6df1a03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
20 changes: 12 additions & 8 deletions admin/app/components/solidus_admin/ui/modal/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
**@attributes
) %>
>
<a href="<%= @close_path %>" aria-hidden="true" class="cursor-default fixed inset-0 bg-full-black/50 overflow-y-auto"></a>
<% if @closable %>
<a href="<%= @close_path %>" aria-hidden="true" class="cursor-default fixed inset-0 bg-full-black/50 overflow-y-auto"></a>
<% end %>
<div class="fixed inset-0 z-10 pointer-events-none flex min-h-full justify-center p-4 text-center items-center">
<div class="min-w-[40rem] max-h-screen pointer-events-auto cursor-auto relative transform overflow-auto rounded-lg bg-white text-left shadow-xl max-w-lg divide-y divide-gray-100">

<header class="flex items-center justify-between p-4 sticky top-0 bg-inherit">
<h3 class="text-xl font-semibold text-gray-900">
<%= @title %>
</h3>
<form method="dialog">
<%= render component('ui/button').new(
icon: 'close-line',
scheme: :ghost,
title: t('.close'),
) %>
</form>
<% if @closable %>
<form method="dialog">
<%= render component('ui/button').new(
icon: 'close-line',
scheme: :ghost,
title: t('.close'),
) %>
</form>
<% end %>
</header>

<div class="p-4 overflow-auto">
Expand Down
3 changes: 2 additions & 1 deletion admin/app/components/solidus_admin/ui/modal/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
class SolidusAdmin::UI::Modal::Component < SolidusAdmin::BaseComponent
renders_one :actions

def initialize(title:, close_path: nil, open: false, **attributes)
def initialize(title:, close_path: nil, closable: true, open: false, **attributes)
@title = title
@close_path = close_path
@closable = closable
@attributes = attributes
@attributes[:open] = open
end
Expand Down

0 comments on commit 6df1a03

Please sign in to comment.