Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skryukov/dbbd281b0f147e49a673bda0a2223bad to your computer and use it in GitHub Desktop.
Save skryukov/dbbd281b0f147e49a673bda0a2223bad to your computer and use it in GitHub Desktop.
[ViewComponent] html_option
# 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
asdadas
andas
defaultsd
asdadasa
ds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment