Last active
February 3, 2022 17:03
-
-
Save boardfish/cd998a3975ac9a332966e3ba9346dde4 to your computer and use it in GitHub Desktop.
Basic <picture> component
This file contains hidden or 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
<%= render PictureComponent.new do |c| %> | |
<% c.source(srcset: 'http://placehold.it/500', media: '(min-width: 800px)') %> | |
<% c.img(srcset: 'http://placehold.it/300', alt: 'Placeholder image') %> | |
<% end %> |
This file contains hidden or 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
<picture> | |
<% sources.each do |source| %> | |
<%= source %> | |
<% end %> | |
<%= img %> | |
</picture> |
This file contains hidden or 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
# frozen_string_literal: true | |
class PictureComponent < ApplicationComponent | |
renders_many :sources, ->(**params) { tag.source(**params) } | |
renders_one :img, ->(**params) { tag.img(**params) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment