Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom icons #38

Open
marckohlbrugge opened this issue May 20, 2023 · 0 comments
Open

Allow custom icons #38

marckohlbrugge opened this issue May 20, 2023 · 0 comments

Comments

@marckohlbrugge
Copy link

marckohlbrugge commented May 20, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant