Skip to content

Commit

Permalink
Adds ability to include module for an icon helper
Browse files Browse the repository at this point in the history
  • Loading branch information
nolantait committed Mar 4, 2024
1 parent 38a293e commit d0c48c0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ require "protos-icon"
render Protos::Icon.heroicon("academic-cap", variant: :mini)
```

Or you can include the module in a class and render them as an element:

```ruby
class MyComponent < Phlex::HTML
include Protos::Icon

def template
div(class: "w-6 h-6") do
icon("academic-cap", variant: :mini)
end
end
end
```

This will call render on the icon component and output it directly to the
component.

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run
Expand Down
4 changes: 4 additions & 0 deletions lib/protos/icon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ def self.lookup(name, variant: :solid)
def self.heroicon(name, variant: :solid)
Heroicons.new(name, variant:)
end

def icon(...)
render Protos::Icon.heroicon(...)
end
end
end
15 changes: 15 additions & 0 deletions spec/protos/icon_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# frozen_string_literal: true

TestComponent = Class.new(Phlex::HTML) do
include Protos::Icon

def template
icon("academic-cap", variant: :mini)
end
end

RSpec.describe Protos::Icon do
it "has a version number" do
expect(Protos::Icon::VERSION).not_to be nil
Expand All @@ -12,4 +20,11 @@
output = component.call
expect(output).to eq(svg)
end

it "can be included in a component" do
component = TestComponent.new
output = component.call

expect(output.start_with?("<svg")).to be true
end
end

0 comments on commit d0c48c0

Please sign in to comment.