heroicon icon indicating copy to clipboard operation
heroicon copied to clipboard

Allow custom icons

Open marckohlbrugge opened this issue 1 year ago • 0 comments

Sometimes you may need an icon that's not included in Heroicons. It would be great if you could still use this gem for consistency throughout your codebase. Especially if you plan on closely following Heroicons' approach of having the three variants, etc.

I created the following monkey patch that first checks for a custom icon and falls back to the default icons. This way you can add new icons, and replace existing ones (although personally I'm unlikely to do that).

If there's interest I can create a PR for this that makes custom_path configurable.

module Heroicon
  class Icon
    def file_path
      custom_path = File.join(Rails.root, "app/assets/images/icons/heroicons/#{variant}/#{name}.svg")

      if File.exist?(custom_path)
        custom_path
      else
        File.join(Heroicon.root, "app/assets/images/heroicon/#{variant}/#{name}.svg")
      end
    end
  end
end

marckohlbrugge avatar May 20 '23 11:05 marckohlbrugge