Skip to content

Commit

Permalink
Add .media-grid-auto media grid for best-fit column layout
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz committed Jun 26, 2024
1 parent 16b537e commit 774264a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/assets/bundle/trestle/admin.css

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion frontend/css/components/_media-grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.media-grid {
@include list-unstyled;

--media-grid-aspect-ratio: #{math.div(4, 3)};
--media-grid-aspect-ratio: 4 / 3;
--media-grid-gap: #{$grid-gutter-width};
--media-grid-columns: 2;

Expand Down Expand Up @@ -85,3 +85,9 @@
--media-grid-columns: 3;
}
}

.media-grid-auto {
--media-grid-item-size: 240px;

grid-template-columns: repeat(auto-fill, minmax(var(--media-grid-item-size), 1fr));
}
24 changes: 20 additions & 4 deletions sandbox/app/views/admin/components/media/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@
</ul>
<% end %>
<%= container do |c| %>
<% c.sidebar class: "order-first" do %>
<h2>Media Grid <small>(Auto)</small></h2>
<p>Add <code>.media-grid-auto</code> and set the <code>--media-grid-item-size</code> CSS variable for best-fit layout.</p>
<p>This example also shows specifying a custom aspect ratio using the <code>--media-grid-aspect-ratio</code> CSS variable.</p>
<% end %>

<ul class="media-grid media-grid-auto" style="--media-grid-aspect-ratio: 16 / 9">
<% 12.times do |i| %>
<li>
<figure class="fill"><%= random_image(320, 200, "4-#{i}") %></figure>
</li>
<% end %>
</ul>
<% end %>
<%= container do |c| %>
<% c.sidebar class: "order-first" do %>
<h2>Gallery</h2>
Expand All @@ -61,8 +77,8 @@
<ul class="media-grid media-grid-sm" data-controller="gallery">
<% 12.times do |i| %>
<li>
<%= link_to random_image_url(1920, 1080, "4-#{i}"), data: { gallery_target: "image", width: 1920, height: 1080 } do %>
<figure class="fill zoom"><%= random_image(576, 324, "4-#{i}") %></figure>
<%= link_to random_image_url(1920, 1080, "5-#{i}"), data: { gallery_target: "image", width: 1920, height: 1080 } do %>
<figure class="fill zoom"><%= random_image(576, 324, "5-#{i}") %></figure>
<% end %>
</li>
<% end %>
Expand All @@ -73,8 +89,8 @@
<ul class="media-grid media-grid-sm">
<% 4.times do |i| %>
<li>
<%= link_to random_image_url(1920, 1080, "5-#{i}"), data: { controller: "lightbox", lightbox_animation_type_value: "fade", lightbox_animation_duration_value: 500, width: 1920, height: 1080 } do %>
<figure class="fill zoom"><%= random_image(576, 324, "5-#{i}") %></figure>
<%= link_to random_image_url(1920, 1080, "6-#{i}"), data: { controller: "lightbox", lightbox_animation_type_value: "fade", lightbox_animation_duration_value: 500, width: 1920, height: 1080 } do %>
<figure class="fill zoom"><%= random_image(576, 324, "6-#{i}") %></figure>
<% end %>
</li>
<% end %>
Expand Down

0 comments on commit 774264a

Please sign in to comment.