-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract a thumbnail component from product images
- Loading branch information
Showing
5 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
admin/app/components/solidus_admin/ui/thumbnail/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::UI::Thumbnail::Component < SolidusAdmin::BaseComponent | ||
SIZES = { | ||
s: 'h-6 w-6', | ||
m: 'h-10 w-10', | ||
l: 'h-20 w-20', | ||
}.freeze | ||
|
||
def initialize(size: :m, **attributes) | ||
@size = size | ||
@attributes = attributes | ||
end | ||
|
||
def call | ||
tag.div( | ||
tag.img( | ||
**@attributes, | ||
class: "object-contain h-full w-full", | ||
), | ||
class: " | ||
#{SIZES[@size]} | ||
rounded border border-gray-100 | ||
bg-white overflow-hidden | ||
#{@attributes[:class]} | ||
" | ||
) | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
admin/spec/components/previews/solidus_admin/ui/thumbnail/component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# @component "ui/thumbnail" | ||
class SolidusAdmin::UI::Thumbnail::ComponentPreview < ViewComponent::Preview | ||
include SolidusAdmin::Preview | ||
|
||
def overview | ||
render_with_template | ||
end | ||
|
||
# @param size select { choices: [s, m, l] } | ||
# @param src text | ||
def playground(size: :m, src: "https://picsum.photos/200/300") | ||
render component("ui/thumbnail").new(size: size.to_sym, src: src) | ||
end | ||
end |
45 changes: 45 additions & 0 deletions
45
...n/spec/components/previews/solidus_admin/ui/thumbnail/component_preview/overview.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
Empty | ||
</h6> | ||
<% current_component::SIZES.keys.each do |size| %> | ||
(size: <%= size.inspect %>) | ||
<%= render current_component.new(size: size) %> | ||
<% end %> | ||
</div> | ||
|
||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
Square | ||
</h6> | ||
|
||
<% current_component::SIZES.keys.each do |size| %> | ||
(size: <%= size.inspect %>) | ||
<%= render current_component.new(size: size, src: "https://placekitten.com/200/200") %> | ||
<%= render current_component.new(size: size, src: "https://placekitten.com/20/20") %> | ||
<% end %> | ||
</div> | ||
|
||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
Portrait | ||
</h6> | ||
|
||
<% current_component::SIZES.keys.each do |size| %> | ||
(size: <%= size.inspect %>) | ||
<%= render current_component.new(size: size, src: "https://placekitten.com/200/286") %> | ||
<%= render current_component.new(size: size, src: "https://placekitten.com/20/28") %> | ||
<% end %> | ||
</div> | ||
|
||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
Landscape | ||
</h6> | ||
|
||
<% current_component::SIZES.keys.each do |size| %> | ||
(size: <%= size.inspect %>) | ||
<%= render current_component.new(size: size, src: "https://placekitten.com/280/200") %> | ||
<%= render current_component.new(size: size, src: "https://placekitten.com/28/20") %> | ||
<% end %> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
admin/spec/components/solidus_admin/ui/thumbnail/component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe SolidusAdmin::UI::Thumbnail::Component, type: :component do | ||
it "renders the overview preview" do | ||
render_preview(:overview) | ||
end | ||
end |