heroicon 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -4
- data/app/assets/images/heroicon/outline/academic-cap.svg +2 -2
- data/app/assets/images/heroicon/outline/arrow-sm-down.svg +3 -0
- data/app/assets/images/heroicon/outline/arrow-sm-left.svg +3 -0
- data/app/assets/images/heroicon/outline/arrow-sm-right.svg +3 -0
- data/app/assets/images/heroicon/outline/arrow-sm-up.svg +3 -0
- data/app/assets/images/heroicon/outline/truck.svg +1 -1
- data/app/assets/images/heroicon/solid/arrow-sm-down.svg +3 -0
- data/app/assets/images/heroicon/solid/arrow-sm-left.svg +3 -0
- data/app/assets/images/heroicon/solid/arrow-sm-right.svg +3 -0
- data/app/assets/images/heroicon/solid/arrow-sm-up.svg +3 -0
- data/app/helpers/heroicon/application_helper.rb +7 -2
- data/lib/generators/heroicon/templates/heroicon.rb.tt +5 -0
- data/lib/heroicon/configuration.rb +4 -1
- data/lib/heroicon/icon.rb +44 -3
- data/lib/heroicon/version.rb +1 -1
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b1da2f6a254f8d75998ee51b23dae5e795f1b020c2a4558aa765f99b5b0c290
|
4
|
+
data.tar.gz: df21e11c2767a743614d7ee5a01f95bd32aec73ea3445a409ed8462166f9cd6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0525f055760da3fb88e91f688ac16511cc9d15a434f46708e8134b95fd9e0b1727684ed5e11f7ac567a7b144d1e2feffe363b623af4e495ceb368688d43b193c
|
7
|
+
data.tar.gz: bf4faf542d32e2b246d2bfae07fd71fb99adaa01d06b7eed63f2904e3502ebd113b77c7a1205a1ac3c2cbc99764ee2880df47923ce780b6ddc17f12ba38e238e
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Heroicon
|
2
|
+
|
2
3
|
[![Build Status](https://github.com/bharget/heroicon/workflows/CI/badge.svg)](https://github.com/bharget/heroicon/actions)
|
3
4
|
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
|
4
5
|
|
5
6
|
Ruby on Rails view helpers for the beautiful hand-crafted SVG icons, Heroicons.
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
Used in production at [Morning Brew ☕](https://www.morningbrew.com/?utm_source=bharget_github)
|
9
9
|
|
10
10
|
This gem has no official affiliation with Tailwind CSS or the Heroicon team (yet!). Check out their sites:
|
11
11
|
|
@@ -14,6 +14,7 @@ This gem has no official affiliation with Tailwind CSS or the Heroicon team (yet
|
|
14
14
|
- [Heroicons](https://heroicons.com/?utm_source=bharget_github)
|
15
15
|
|
16
16
|
## Installation
|
17
|
+
|
17
18
|
Add this line to your application's Gemfile:
|
18
19
|
|
19
20
|
```ruby
|
@@ -21,11 +22,13 @@ gem "heroicon"
|
|
21
22
|
```
|
22
23
|
|
23
24
|
And then execute:
|
25
|
+
|
24
26
|
```bash
|
25
27
|
$ bundle
|
26
28
|
```
|
27
29
|
|
28
30
|
Run the installer
|
31
|
+
|
29
32
|
```bash
|
30
33
|
$ rails g heroicon:install
|
31
34
|
```
|
@@ -38,7 +41,7 @@ To use a icon in your views, simply use the provided view helper with the name o
|
|
38
41
|
<%= heroicon "search" %>
|
39
42
|
```
|
40
43
|
|
41
|
-
Heroicon comes with two variants, `:outline` and `:solid`.
|
44
|
+
Heroicon comes with two variants, `:outline` and `:solid`. The default variant is `:solid`. This can be changed in `config/initializers/heroicon.rb`, which is generated during installation (See [Configuration](#configuration)). To overwrite this in the view, use
|
42
45
|
|
43
46
|
```rb
|
44
47
|
<%= heroicon "search", variant: :outline %>
|
@@ -50,7 +53,35 @@ You can also pass HTML options directly to the icon.
|
|
50
53
|
<%= heroicon "search", options: { class: "text-primary-500" } %>
|
51
54
|
```
|
52
55
|
|
53
|
-
Heroicon currently supports icons up to [`Version 0.
|
56
|
+
Heroicon currently supports icons up to [`Version 1.0.1`](https://github.com/tailwindlabs/heroicons/releases/tag/v1.0.1). If there is a icon that is missing, feel free to contribute by following our contributing guide below.
|
57
|
+
|
58
|
+
# Configuration
|
59
|
+
|
60
|
+
After running `rails g heroicon:install` in the installation step, a configuration file will be created at `config/initializers/heroicon.rb`.
|
61
|
+
|
62
|
+
Currently there are two configuration options:
|
63
|
+
|
64
|
+
- `variant`: The default variant to use if no variant is specified in the view.
|
65
|
+
- You can set this to either `:outline` or `:solid`. Defaults to `:solid`.
|
66
|
+
- `default_class`: A default class that gets applied to every icon.
|
67
|
+
- This accepts either a String to apply to every icon, or a Hash, which applies the class based on the variant of the icon (see the example below).
|
68
|
+
- You can disable this on a per-icon basis by passing `disable_default_class: true` in the options hash within the view.
|
69
|
+
- _Note: If you use the `default_class` option with PurgeCSS (or something similar), make sure you add the classes you want to use to the generated CSS file. For PurgeCSS, you may want to add `config/intializers/heroicon.rb` to the list of purged paths._
|
70
|
+
|
71
|
+
An example configuration looks like this:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
Heroicon.configure do |config|
|
75
|
+
config.variant = :solid
|
76
|
+
config.default_class = {solid: "h-5 w-5", outline: "h-6 w-6"}
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
Disabling the default class in the view:
|
81
|
+
|
82
|
+
```rb
|
83
|
+
<%= heroicon "search", options: { class: "custom-class" disable_default_class: true } %>
|
84
|
+
```
|
54
85
|
|
55
86
|
## Contributing
|
56
87
|
|
@@ -71,4 +102,5 @@ bundle exec rake test
|
|
71
102
|
```
|
72
103
|
|
73
104
|
## License
|
105
|
+
|
74
106
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
2
|
-
<path
|
3
|
-
<path
|
2
|
+
<path d="M12 14l9-5-9-5-9 5 9 5z"/>
|
3
|
+
<path d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z"/>
|
4
4
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14l9-5-9-5-9 5 9 5zm0 0l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14zm-4 6v-7.5l4-2.222"/>
|
5
5
|
</svg>
|
@@ -1,4 +1,4 @@
|
|
1
1
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
2
|
-
<path
|
2
|
+
<path d="M9 17a2 2 0 11-4 0 2 2 0 014 0zM19 17a2 2 0 11-4 0 2 2 0 014 0z"/>
|
3
3
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16V6a1 1 0 00-1-1H4a1 1 0 00-1 1v10a1 1 0 001 1h1m8-1a1 1 0 01-1 1H9m4-1V8a1 1 0 011-1h2.586a1 1 0 01.707.293l3.414 3.414a1 1 0 01.293.707V16a1 1 0 01-1 1h-1m-6-1a1 1 0 001 1h1M5 17a2 2 0 104 0m-4 0a2 2 0 114 0m6 0a2 2 0 104 0m-4 0a2 2 0 114 0"/>
|
4
4
|
</svg>
|
@@ -0,0 +1,3 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
2
|
+
<path fill-rule="evenodd" d="M14.707 10.293a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 111.414-1.414L9 12.586V5a1 1 0 012 0v7.586l2.293-2.293a1 1 0 011.414 0z" clip-rule="evenodd"/>
|
3
|
+
</svg>
|
@@ -0,0 +1,3 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
2
|
+
<path fill-rule="evenodd" d="M9.707 14.707a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 1.414L7.414 9H15a1 1 0 110 2H7.414l2.293 2.293a1 1 0 010 1.414z" clip-rule="evenodd"/>
|
3
|
+
</svg>
|
@@ -0,0 +1,3 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
2
|
+
<path fill-rule="evenodd" d="M10.293 5.293a1 1 0 011.414 0l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414-1.414L12.586 11H5a1 1 0 110-2h7.586l-2.293-2.293a1 1 0 010-1.414z" clip-rule="evenodd"/>
|
3
|
+
</svg>
|
@@ -0,0 +1,3 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
2
|
+
<path fill-rule="evenodd" d="M5.293 9.707a1 1 0 010-1.414l4-4a1 1 0 011.414 0l4 4a1 1 0 01-1.414 1.414L11 7.414V15a1 1 0 11-2 0V7.414L6.707 9.707a1 1 0 01-1.414 0z" clip-rule="evenodd"/>
|
3
|
+
</svg>
|
@@ -2,8 +2,13 @@
|
|
2
2
|
|
3
3
|
module Heroicon
|
4
4
|
module ApplicationHelper
|
5
|
-
def heroicon(name, variant: Heroicon.configuration.variant, options: {})
|
6
|
-
raw Heroicon::Icon.render(
|
5
|
+
def heroicon(name, variant: Heroicon.configuration.variant, options: {}, path_options: {})
|
6
|
+
raw Heroicon::Icon.render(
|
7
|
+
name: name,
|
8
|
+
variant: variant,
|
9
|
+
options: options,
|
10
|
+
path_options: path_options
|
11
|
+
)
|
7
12
|
end
|
8
13
|
end
|
9
14
|
end
|
@@ -2,4 +2,9 @@
|
|
2
2
|
|
3
3
|
Heroicon.configure do |config|
|
4
4
|
config.variant = :solid # Options are :solid and :outline
|
5
|
+
|
6
|
+
##
|
7
|
+
# You can set a default class, which will get applied to every icon with
|
8
|
+
# the given variant. To do so, un-comment the line below.
|
9
|
+
# config.default_class = {solid: "h-5 w-5", outline: "h-6 w-6"}
|
5
10
|
end
|
data/lib/heroicon/icon.rb
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
module Heroicon
|
4
4
|
class Icon
|
5
|
-
attr_reader :name, :variant, :options
|
5
|
+
attr_reader :name, :variant, :options, :path_options
|
6
6
|
|
7
|
-
def initialize(name:, variant:, options:)
|
7
|
+
def initialize(name:, variant:, options:, path_options:)
|
8
8
|
@name = name
|
9
9
|
@variant = safe_variant(variant)
|
10
10
|
@options = options
|
11
|
+
@path_options = path_options
|
11
12
|
end
|
12
13
|
|
13
14
|
def render
|
@@ -15,6 +16,16 @@ module Heroicon
|
|
15
16
|
|
16
17
|
doc = Nokogiri::HTML::DocumentFragment.parse(file)
|
17
18
|
svg = doc.at_css "svg"
|
19
|
+
|
20
|
+
path_options.each do |key, value|
|
21
|
+
attribute = key.to_s.dasherize
|
22
|
+
svg.css("path[#{attribute}]").each do |item|
|
23
|
+
item[attribute] = value.to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
prepend_default_class_name
|
28
|
+
|
18
29
|
options.each do |key, value|
|
19
30
|
svg[key.to_s] = value
|
20
31
|
end
|
@@ -24,6 +35,34 @@ module Heroicon
|
|
24
35
|
|
25
36
|
private
|
26
37
|
|
38
|
+
##
|
39
|
+
# Prepends the default CSS class name for an icon. You can provide a String, which will apply
|
40
|
+
# to all icons, or a Hash, which will apply to the specified variant.
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# Heroicon.configure do |config|
|
44
|
+
# config.default_class = { solid: "h-5 w-5", outline: "h-6 w-6" }
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# #=> <svg class="h-5 w-5">...</svg>
|
48
|
+
def prepend_default_class_name
|
49
|
+
return if disable_default_class?
|
50
|
+
|
51
|
+
default_class_config = Heroicon.configuration.default_class
|
52
|
+
|
53
|
+
default_class = if default_class_config.is_a?(String)
|
54
|
+
default_class_config
|
55
|
+
elsif default_class_config.is_a?(Hash)
|
56
|
+
default_class_config[variant]
|
57
|
+
end
|
58
|
+
|
59
|
+
options[:class] = "#{default_class} #{options[:class]}".strip if default_class.present?
|
60
|
+
end
|
61
|
+
|
62
|
+
def disable_default_class?
|
63
|
+
@disable_default_class ||= !!options.delete(:disable_default_class)
|
64
|
+
end
|
65
|
+
|
27
66
|
def safe_variant(provided_variant)
|
28
67
|
if %i[solid outline].include?(provided_variant.to_sym)
|
29
68
|
provided_variant
|
@@ -45,13 +84,15 @@ module Heroicon
|
|
45
84
|
def warning
|
46
85
|
return unless Rails.env.development?
|
47
86
|
|
48
|
-
<<-HTML
|
87
|
+
script = <<-HTML
|
49
88
|
<script type="text/javascript">
|
50
89
|
//<![CDATA[
|
51
90
|
console.warn("Heroicon: Failed to find heroicon: #{name}")
|
52
91
|
//]]>
|
53
92
|
</script>
|
54
93
|
HTML
|
94
|
+
|
95
|
+
script.strip
|
55
96
|
end
|
56
97
|
|
57
98
|
class << self
|
data/lib/heroicon/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroicon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Hargett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mocha
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Ruby on Rails view helpers for the beautiful hand-crafted SVG icons,
|
98
112
|
Heroicons.
|
99
113
|
email:
|
@@ -120,6 +134,10 @@ files:
|
|
120
134
|
- app/assets/images/heroicon/outline/arrow-narrow-right.svg
|
121
135
|
- app/assets/images/heroicon/outline/arrow-narrow-up.svg
|
122
136
|
- app/assets/images/heroicon/outline/arrow-right.svg
|
137
|
+
- app/assets/images/heroicon/outline/arrow-sm-down.svg
|
138
|
+
- app/assets/images/heroicon/outline/arrow-sm-left.svg
|
139
|
+
- app/assets/images/heroicon/outline/arrow-sm-right.svg
|
140
|
+
- app/assets/images/heroicon/outline/arrow-sm-up.svg
|
123
141
|
- app/assets/images/heroicon/outline/arrow-up.svg
|
124
142
|
- app/assets/images/heroicon/outline/arrows-expand.svg
|
125
143
|
- app/assets/images/heroicon/outline/at-symbol.svg
|
@@ -346,6 +364,10 @@ files:
|
|
346
364
|
- app/assets/images/heroicon/solid/arrow-narrow-right.svg
|
347
365
|
- app/assets/images/heroicon/solid/arrow-narrow-up.svg
|
348
366
|
- app/assets/images/heroicon/solid/arrow-right.svg
|
367
|
+
- app/assets/images/heroicon/solid/arrow-sm-down.svg
|
368
|
+
- app/assets/images/heroicon/solid/arrow-sm-left.svg
|
369
|
+
- app/assets/images/heroicon/solid/arrow-sm-right.svg
|
370
|
+
- app/assets/images/heroicon/solid/arrow-sm-up.svg
|
349
371
|
- app/assets/images/heroicon/solid/arrow-up.svg
|
350
372
|
- app/assets/images/heroicon/solid/arrows-expand.svg
|
351
373
|
- app/assets/images/heroicon/solid/at-symbol.svg
|