Skip to content

Commit

Permalink
Add support for legacy icon styles
Browse files Browse the repository at this point in the history
If a module or extension uses old fontawesome icon styles
it now returns the correct style class for remixicons.
  • Loading branch information
tvdeyen committed Jan 11, 2024
1 parent ddb55df commit d30b54e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
17 changes: 16 additions & 1 deletion app/helpers/alchemy/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def warning(message, text = nil)
# @return [String]
def render_icon(icon_name, options = {})
options = {style: "line", fixed_width: true}.merge(options)
style = options[:style] && "-#{options[:style]}"
style = options[:style] && "-#{ri_style(options[:style])}"
classes = [
"icon",
"ri-#{ri_icon(icon_name)}#{style}",
Expand Down Expand Up @@ -134,5 +134,20 @@ def ri_icon(icon_name)
icon_name
end
end

# Returns the Remix icon style for given style
#
# @param style [String] The style name
# @return [String] The RemixIcon style
def ri_style(style)
case style.to_s
when "solid", "fill"
"fill"
when "line", "regular"
"line"
else
style
end
end
end
end
26 changes: 25 additions & 1 deletion spec/helpers/alchemy/base_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Alchemy

let(:options) { {} }

it "renders a solid remix icon with fixed width and line style" do
it "renders a remix icon with fixed width and line style" do
is_expected.to have_css "i.icon.ri-information-line.ri-fw"
end

Expand All @@ -21,6 +21,30 @@ module Alchemy
end
end

context "with style set to solid" do
let(:options) { {style: "solid"} }

it "renders a filled remix icon" do
is_expected.to have_css 'i[class*="-fill"]'
end
end

context "with style set to regular" do
let(:options) { {style: "regular"} }

it "renders a line remix icon" do
is_expected.to have_css 'i[class*="-line"]'
end
end

context "with style set to m" do
let(:options) { {style: "m"} }

it "renders a line remix icon" do
is_expected.to have_css 'i[class*="-m"]'
end
end

context "with fixed_width set to false" do
let(:options) { {fixed_width: false} }

Expand Down

0 comments on commit d30b54e

Please sign in to comment.