-
-
Save skryukov/dbbd281b0f147e49a673bda0a2223bad to your computer and use it in GitHub Desktop.
[ViewComponent] html_option
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
# From https://evilmartians.com/chronicles/viewcomponent-in-the-wild-embracing-tailwindcss-classes-and-html-attributes | |
class ApplicationViewComponent < ViewComponentContrib::Base | |
# Move default attrs to a constants so we can re-use it | |
EMPTY_ATTRS = {}.freeze | |
class << self | |
def html_option(name, default: nil, **opts) | |
if default | |
opts[:type] = proc { default.merge(_1) } | |
end | |
# Assuming you have `extend Dry::Initializer` | |
option name, default: proc { EMPTY_ATTRS }, **opts | |
end | |
end | |
def dots(**) | |
tag.attributes(**) | |
end | |
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
asdadas | |
andas | |
defaultsd | |
asdadasa | |
ds |
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
foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment