# frozen_string_literal: true module FComponents module IconsHelper VALID_STYLES = { solid: 'fa-solid', regular: 'fa-regular', light: 'fa-light', thin: 'fa-thin', duotone: 'fa-duotone', brands: 'fa-brands' }.freeze # Public: Creates a Font Awesome icon tag # # Examples: # # fa_icon('home') # #=> # # fa_icon('user', style: :regular) # #=> # # fa_icon('github', style: :brands) # #=> # # fa_icon('eye', class: 'strong space-x-2', text: 'my text') # #=> my text # # Parameters: # @param name [String] The icon name (e.g., 'home', 'user') # @param options [Hash] Additional options # - :style [Symbol] The icon style (:solid, :regular, :brands, etc.) # - :class [String] Additional CSS classes # - :text [String] Text to display after the icon # # Returns: # @return [String] Safe HTML for rendering def fa_icon(name, options = {}) style = options.delete(:style) { :solid } style_class = VALID_STYLES[style] || VALID_STYLES[:solid] icon_class = "fa-#{name}" custom_classes = options[:class].presence options[:class] = [style_class, icon_class, custom_classes].compact.join(' ') f_icon(options) end # Internal: Creates the tag with the appropriate classes and adds text if necessary # # Parameters: # @param options [Hash] Options for the tag # # Returns: # @return [String] Safe HTML for rendering def f_icon(options) text = options.delete(:text) tag = content_tag(:i, nil, options) tag << " #{text}" if text.present? tag end end end