# typed: false # frozen_string_literal: true require "heroicons_helper" module Ariadne module UI module Heroicon # @example Default # <%= render(Ariadne::UI::Heroicon::Component.new(icon: :check, variant: HeroiconsHelper::Icon::VARIANT_OUTLINE)) %> # <%= render(Ariadne::UI::Heroicon::Component.new(icon: :check, variant: HeroiconsHelper::Icon::VARIANT_SOLID)) %> # # @example Medium # <%= render(Ariadne::UI::Heroicon::Component.new(icon: :"user-group", variant: HeroiconsHelper::Icon::VARIANT_OUTLINE, size: :md)) %> # # @example Helper # <%= ariadne_heroicon(icon: :check, variant: HeroiconsHelper::Icon::VARIANT_OUTLINE) %> # # @param tag [Symbol, String] The rendered tag name # @param classes [String] <%= link_to_classes_docs %> # @param icon [Symbol, String] Name of <%= link_to_heroicons %> to use. # @param variant [String] <%= one_of(HeroiconsHelper::Icon::VALID_VARIANTS, sort: false) %> # @param size [Symbol] <%= one_of(Ariadne::UI::Heroicon::Component::SIZE_MAPPINGS, sort: false) %> class Component < Ariadne::BaseComponent option :icon option :variant option :size, default: -> { :md } include IconHelper include HeroiconsHelper accepts_html_attributes do |html_attrs| html_attrs[:class] = Ariadne::ViewComponents.tailwind_merger.merge([@heroicon.attributes["class"], style(size: @size), html_attrs[:class]].join(" ")) end def initialize(**options) super check_icon_presence!(icon, variant) @heroicon = heroicon(@icon, variant: @variant) end def svg_attributes tag.attributes(html_attrs.except(:class).merge(@heroicon.attributes.except("class", "aria-hidden"))) end def inner ActiveSupport::SafeBuffer.new(@heroicon.path) end style do variants do size do xs { ["ariadne-w-4", "ariadne-h-4"] } sm { ["ariadne-w-5", "ariadne-h-5"] } md { ["ariadne-w-6", "ariadne-h-6"] } lg { ["ariadne-w-10", "ariadne-h-10"] } xl { ["ariadne-w-12", "ariadne-h-12"] } end end end end end end end