Skip to content

Commit

Permalink
refactor: add modal component overflow option (#3128)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev authored Aug 12, 2024
1 parent 9590a82 commit 98dc44d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/components/avo/modal_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
data-modal-target="modal"
>
<div aria-expanded="true" class="modal-overlay absolute w-full h-full bg-opacity-25 bg-gray-800 flex justify-center items-center" data-action="click->modal#close"></div>
<div aria-expanded="true" role="dialog" aria-modal="true" class="modal-body rounded-lg inset-auto bg-white flex z-50 relative shadow-modal overflow-auto <%= width_classes %> <%= height_classes %>">
<div aria-expanded="true" role="dialog" aria-modal="true" class="modal-body rounded-lg inset-auto bg-white flex z-50 relative shadow-modal <%= overflow_classes %> <%= width_classes %> <%= height_classes %>">
<div class="flex-1 flex flex-col justify-between">
<div>
<% if heading? %>
Expand Down
7 changes: 6 additions & 1 deletion app/components/avo/modal_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ class Avo::ModalComponent < Avo::BaseComponent
attr_reader :width
attr_reader :body_class

def initialize(width: :md, body_class: nil)
def initialize(width: :md, body_class: nil, overflow: :auto)
@width = width
@body_class = body_class
@overflow = overflow
end

def width_classes
Expand All @@ -24,4 +25,8 @@ def width_classes
def height_classes
"max-h-full min-h-1/4 max-h-11/12"
end

def overflow_classes
@overflow == :auto ? "overflow-auto" : ""
end
end
4 changes: 3 additions & 1 deletion spec/dummy/app/avo/resources/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def fields
field :location, as: :has_one
end

field :patrons, as: :has_many, through: :patronships,
field :patrons,
as: :has_many,
through: :patronships,
translation_key: "patrons",
attach_fields: -> {
if ENV["TEST_FILL_JOIN_RECORD"]
Expand Down
6 changes: 5 additions & 1 deletion spec/dummy/app/avo/resources/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def fields
end

field :admin, as: :has_one, linkable: true
field :team_members, as: :has_many, through: :memberships, translation_key: "avo.resource_translations.team_members"
field :team_members,
as: :has_many,
through: :memberships,
linkable: true,
reloadable: true
field :reviews, as: :has_many,
reloadable: -> {
current_user.is_admin?
Expand Down
4 changes: 2 additions & 2 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.0].define(version: 2024_04_10_120015) do
ActiveRecord::Schema[8.0].define(version: 2024_07_24_090242) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -171,7 +171,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "price_cents", default: 0, null: false
t.string "price_currency", default: "USD", null: false
t.string "price_currency", default: "'USD'::character varying", null: false
end

create_table "projects", force: :cascade do |t|
Expand Down

0 comments on commit 98dc44d

Please sign in to comment.