Sha256: a7b67a0e53e87e444e73619d509fcc5bbb5fe6ac78965eb6d28972da2e577033
Contents?: true
Size: 1.39 KB
Versions: 122
Compression:
Stored size: 1.39 KB
Contents
# frozen_string_literal: true module Ariadne # All Ariadne ViewComponents accept a standard set of options: classes, which match Tailwind CSS classes, and attributes, which match HTML attributes.. # # Under the hood, any-non class attributes is passed to Rails' [`tag`](https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-tag) # (for self-closing tags) or [`content_tag`](https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag). class BaseComponent < Ariadne::Component SELF_CLOSING_TAGS = [:area, :base, :br, :col, :embed, :hr, :img, :input, :link, :meta, :param, :source, :track, :wbr].freeze def initialize(tag:, classes: "", attributes: {}) @tag = tag @attributes = validate_attributes(tag: tag, attributes: attributes) || {} @attributes[:"data-ariadne-view-component"] = true classes = @attributes.fetch(:classes, "") if classes.blank? @classes = validate_merge_class_names(classes) || {} @content_tag_args = {} end def call options = @attributes.merge(@classes) if SELF_CLOSING_TAGS.include?(@tag) tag(@tag, options) else content_tag(@tag, content, options) end end private def validate_merge_class_names(classes) return if classes.blank? { class: Ariadne::ViewComponents.tailwind_merger.merge(classes) } end end end
Version data entries
122 entries across 122 versions & 1 rubygems
Version | Path |
---|---|
ariadne_view_components-0.0.35-arm64-darwin | app/components/ariadne/base_component.rb |
ariadne_view_components-0.0.35-aarch64-linux | app/components/ariadne/base_component.rb |