optics_view_components 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile +4 -2
- data/Gemfile.lock +186 -0
- data/app/components/optics/application_view_component.rb +113 -0
- data/app/components/optics/application_view_component_preview.rb +5 -0
- data/app/components/optics/button/component.rb +55 -0
- data/app/components/optics/button/preview.rb +34 -0
- data/app/components/optics/icon/component.rb +59 -0
- data/app/components/optics/icon/preview.rb +31 -0
- data/demo/.ruby-version +1 -0
- data/demo/Gemfile +21 -0
- data/demo/Gemfile.lock +198 -0
- data/demo/Procfile.dev +2 -0
- data/demo/README.md +24 -0
- data/demo/Rakefile +8 -0
- data/demo/app/assets/builds/.keep +0 -0
- data/demo/app/assets/config/manifest.js +3 -0
- data/demo/app/assets/images/.keep +0 -0
- data/demo/app/assets/stylesheets/application.sass.scss +2 -0
- data/demo/app/controllers/application_controller.rb +4 -0
- data/demo/app/controllers/concerns/.keep +0 -0
- data/demo/app/controllers/home_controller.rb +4 -0
- data/demo/app/helpers/application_helper.rb +4 -0
- data/demo/app/javascript/application.js +3 -0
- data/demo/app/javascript/controllers/application.js +9 -0
- data/demo/app/javascript/controllers/index.js +11 -0
- data/demo/app/views/home/index.html.erb +3 -0
- data/demo/app/views/layouts/application.html.erb +15 -0
- data/demo/bin/bundle +113 -0
- data/demo/bin/dev +8 -0
- data/demo/bin/importmap +5 -0
- data/demo/bin/rails +6 -0
- data/demo/bin/rake +6 -0
- data/demo/bin/setup +35 -0
- data/demo/config/application.rb +36 -0
- data/demo/config/boot.rb +6 -0
- data/demo/config/cable.yml +10 -0
- data/demo/config/credentials.yml.enc +1 -0
- data/demo/config/database.yml +25 -0
- data/demo/config/environment.rb +7 -0
- data/demo/config/environments/development.rb +63 -0
- data/demo/config/environments/production.rb +89 -0
- data/demo/config/environments/test.rb +59 -0
- data/demo/config/importmap.rb +9 -0
- data/demo/config/initializers/assets.rb +14 -0
- data/demo/config/initializers/content_security_policy.rb +26 -0
- data/demo/config/initializers/filter_parameter_logging.rb +10 -0
- data/demo/config/initializers/inflections.rb +17 -0
- data/demo/config/initializers/permissions_policy.rb +12 -0
- data/demo/config/locales/en.yml +33 -0
- data/demo/config/puma.rb +45 -0
- data/demo/config/routes.rb +8 -0
- data/demo/config/storage.yml +34 -0
- data/demo/config.ru +8 -0
- data/demo/lib/assets/.keep +0 -0
- data/demo/lib/tasks/.keep +0 -0
- data/demo/log/.keep +0 -0
- data/demo/package.json +9 -0
- data/demo/public/404.html +67 -0
- data/demo/public/422.html +67 -0
- data/demo/public/500.html +66 -0
- data/demo/public/favicon.ico +0 -0
- data/demo/yarn.lock +157 -0
- data/lib/optics/view_components/engine.rb +19 -0
- data/lib/optics/view_components/version.rb +1 -1
- data/lib/optics/view_components.rb +4 -2
- metadata +155 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a06b9454efef278cd56ab9a178e0aa4567f01db54119ad83e7d972c5a2fa232f
|
4
|
+
data.tar.gz: 3f0d0d5559526ba23baa50e88a4c84c4a38870e602013db702f1588be94d67e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 872cb462157bc5b9bcf7e610aafdb91eb2a125c042e7e9049ed38ced9f0750e54e6c8da305c8b568663bea3b3b56b72e0c8902df14758a8cfced1d3baefb8688
|
7
|
+
data.tar.gz: c66b0e6b482134588976015aaabdec6997c763b54460d28215b03cfb31524eda90c2825b4f4488559a84b40707f035191fa1f31450d4fbed449dbb2fad9f7f36
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -5,8 +5,10 @@ source 'https://rubygems.org'
|
|
5
5
|
# Specify your gem's dependencies in optics_view_components.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem '
|
8
|
+
gem 'rails', '~> 7.0'
|
9
9
|
|
10
|
+
gem 'bootsnap', require: false
|
11
|
+
gem 'rake', '~> 13.0'
|
10
12
|
gem 'rspec', '~> 3.0'
|
11
|
-
|
12
13
|
gem 'rubocop', '~> 1.21'
|
14
|
+
gem 'view_component'
|
data/Gemfile.lock
CHANGED
@@ -2,16 +2,165 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
optics_view_components (0.1.0)
|
5
|
+
view_component (> 2.0, < 4.0)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
10
|
+
actioncable (7.0.4.3)
|
11
|
+
actionpack (= 7.0.4.3)
|
12
|
+
activesupport (= 7.0.4.3)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailbox (7.0.4.3)
|
16
|
+
actionpack (= 7.0.4.3)
|
17
|
+
activejob (= 7.0.4.3)
|
18
|
+
activerecord (= 7.0.4.3)
|
19
|
+
activestorage (= 7.0.4.3)
|
20
|
+
activesupport (= 7.0.4.3)
|
21
|
+
mail (>= 2.7.1)
|
22
|
+
net-imap
|
23
|
+
net-pop
|
24
|
+
net-smtp
|
25
|
+
actionmailer (7.0.4.3)
|
26
|
+
actionpack (= 7.0.4.3)
|
27
|
+
actionview (= 7.0.4.3)
|
28
|
+
activejob (= 7.0.4.3)
|
29
|
+
activesupport (= 7.0.4.3)
|
30
|
+
mail (~> 2.5, >= 2.5.4)
|
31
|
+
net-imap
|
32
|
+
net-pop
|
33
|
+
net-smtp
|
34
|
+
rails-dom-testing (~> 2.0)
|
35
|
+
actionpack (7.0.4.3)
|
36
|
+
actionview (= 7.0.4.3)
|
37
|
+
activesupport (= 7.0.4.3)
|
38
|
+
rack (~> 2.0, >= 2.2.0)
|
39
|
+
rack-test (>= 0.6.3)
|
40
|
+
rails-dom-testing (~> 2.0)
|
41
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
42
|
+
actiontext (7.0.4.3)
|
43
|
+
actionpack (= 7.0.4.3)
|
44
|
+
activerecord (= 7.0.4.3)
|
45
|
+
activestorage (= 7.0.4.3)
|
46
|
+
activesupport (= 7.0.4.3)
|
47
|
+
globalid (>= 0.6.0)
|
48
|
+
nokogiri (>= 1.8.5)
|
49
|
+
actionview (7.0.4.3)
|
50
|
+
activesupport (= 7.0.4.3)
|
51
|
+
builder (~> 3.1)
|
52
|
+
erubi (~> 1.4)
|
53
|
+
rails-dom-testing (~> 2.0)
|
54
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
55
|
+
activejob (7.0.4.3)
|
56
|
+
activesupport (= 7.0.4.3)
|
57
|
+
globalid (>= 0.3.6)
|
58
|
+
activemodel (7.0.4.3)
|
59
|
+
activesupport (= 7.0.4.3)
|
60
|
+
activerecord (7.0.4.3)
|
61
|
+
activemodel (= 7.0.4.3)
|
62
|
+
activesupport (= 7.0.4.3)
|
63
|
+
activestorage (7.0.4.3)
|
64
|
+
actionpack (= 7.0.4.3)
|
65
|
+
activejob (= 7.0.4.3)
|
66
|
+
activerecord (= 7.0.4.3)
|
67
|
+
activesupport (= 7.0.4.3)
|
68
|
+
marcel (~> 1.0)
|
69
|
+
mini_mime (>= 1.1.0)
|
70
|
+
activesupport (7.0.4.3)
|
71
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
72
|
+
i18n (>= 1.6, < 2)
|
73
|
+
minitest (>= 5.1)
|
74
|
+
tzinfo (~> 2.0)
|
75
|
+
addressable (2.8.4)
|
76
|
+
public_suffix (>= 2.0.2, < 6.0)
|
9
77
|
ast (2.4.2)
|
78
|
+
bootsnap (1.16.0)
|
79
|
+
msgpack (~> 1.2)
|
80
|
+
builder (3.2.4)
|
81
|
+
capybara (3.39.1)
|
82
|
+
addressable
|
83
|
+
matrix
|
84
|
+
mini_mime (>= 0.1.3)
|
85
|
+
nokogiri (~> 1.8)
|
86
|
+
rack (>= 1.6.0)
|
87
|
+
rack-test (>= 0.6.3)
|
88
|
+
regexp_parser (>= 1.5, < 3.0)
|
89
|
+
xpath (~> 3.2)
|
90
|
+
coderay (1.1.3)
|
91
|
+
concurrent-ruby (1.2.2)
|
92
|
+
crass (1.0.6)
|
93
|
+
date (3.3.3)
|
10
94
|
diff-lcs (1.5.0)
|
95
|
+
erubi (1.12.0)
|
96
|
+
globalid (1.1.0)
|
97
|
+
activesupport (>= 5.0)
|
98
|
+
i18n (1.13.0)
|
99
|
+
concurrent-ruby (~> 1.0)
|
11
100
|
json (2.6.3)
|
101
|
+
loofah (2.21.3)
|
102
|
+
crass (~> 1.0.2)
|
103
|
+
nokogiri (>= 1.12.0)
|
104
|
+
mail (2.8.1)
|
105
|
+
mini_mime (>= 0.1.1)
|
106
|
+
net-imap
|
107
|
+
net-pop
|
108
|
+
net-smtp
|
109
|
+
marcel (1.0.2)
|
110
|
+
matrix (0.4.2)
|
111
|
+
method_source (1.0.0)
|
112
|
+
mini_mime (1.1.2)
|
113
|
+
minitest (5.18.0)
|
114
|
+
msgpack (1.7.1)
|
115
|
+
net-imap (0.3.4)
|
116
|
+
date
|
117
|
+
net-protocol
|
118
|
+
net-pop (0.1.2)
|
119
|
+
net-protocol
|
120
|
+
net-protocol (0.2.1)
|
121
|
+
timeout
|
122
|
+
net-smtp (0.3.3)
|
123
|
+
net-protocol
|
124
|
+
nio4r (2.5.9)
|
125
|
+
nokogiri (1.15.1-x86_64-linux)
|
126
|
+
racc (~> 1.4)
|
12
127
|
parallel (1.23.0)
|
13
128
|
parser (3.2.2.1)
|
14
129
|
ast (~> 2.4.1)
|
130
|
+
pry (0.14.2)
|
131
|
+
coderay (~> 1.1)
|
132
|
+
method_source (~> 1.0)
|
133
|
+
public_suffix (5.0.1)
|
134
|
+
racc (1.6.2)
|
135
|
+
rack (2.2.7)
|
136
|
+
rack-test (2.1.0)
|
137
|
+
rack (>= 1.3)
|
138
|
+
rails (7.0.4.3)
|
139
|
+
actioncable (= 7.0.4.3)
|
140
|
+
actionmailbox (= 7.0.4.3)
|
141
|
+
actionmailer (= 7.0.4.3)
|
142
|
+
actionpack (= 7.0.4.3)
|
143
|
+
actiontext (= 7.0.4.3)
|
144
|
+
actionview (= 7.0.4.3)
|
145
|
+
activejob (= 7.0.4.3)
|
146
|
+
activemodel (= 7.0.4.3)
|
147
|
+
activerecord (= 7.0.4.3)
|
148
|
+
activestorage (= 7.0.4.3)
|
149
|
+
activesupport (= 7.0.4.3)
|
150
|
+
bundler (>= 1.15.0)
|
151
|
+
railties (= 7.0.4.3)
|
152
|
+
rails-dom-testing (2.0.3)
|
153
|
+
activesupport (>= 4.2.0)
|
154
|
+
nokogiri (>= 1.6)
|
155
|
+
rails-html-sanitizer (1.5.0)
|
156
|
+
loofah (~> 2.19, >= 2.19.1)
|
157
|
+
railties (7.0.4.3)
|
158
|
+
actionpack (= 7.0.4.3)
|
159
|
+
activesupport (= 7.0.4.3)
|
160
|
+
method_source
|
161
|
+
rake (>= 12.2)
|
162
|
+
thor (~> 1.0)
|
163
|
+
zeitwerk (~> 2.5)
|
15
164
|
rainbow (3.1.1)
|
16
165
|
rake (13.0.6)
|
17
166
|
regexp_parser (2.8.0)
|
@@ -28,6 +177,14 @@ GEM
|
|
28
177
|
rspec-mocks (3.12.5)
|
29
178
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
179
|
rspec-support (~> 3.12.0)
|
180
|
+
rspec-rails (6.0.2)
|
181
|
+
actionpack (>= 6.1)
|
182
|
+
activesupport (>= 6.1)
|
183
|
+
railties (>= 6.1)
|
184
|
+
rspec-core (~> 3.12)
|
185
|
+
rspec-expectations (~> 3.12)
|
186
|
+
rspec-mocks (~> 3.12)
|
187
|
+
rspec-support (~> 3.12)
|
31
188
|
rspec-support (3.12.0)
|
32
189
|
rubocop (1.51.0)
|
33
190
|
json (~> 2.3)
|
@@ -42,16 +199,45 @@ GEM
|
|
42
199
|
rubocop-ast (1.28.1)
|
43
200
|
parser (>= 3.2.1.0)
|
44
201
|
ruby-progressbar (1.13.0)
|
202
|
+
sprockets (4.2.0)
|
203
|
+
concurrent-ruby (~> 1.0)
|
204
|
+
rack (>= 2.2.4, < 4)
|
205
|
+
sprockets-rails (3.4.2)
|
206
|
+
actionpack (>= 5.2)
|
207
|
+
activesupport (>= 5.2)
|
208
|
+
sprockets (>= 3.0.0)
|
209
|
+
thor (1.2.2)
|
210
|
+
timeout (0.3.2)
|
211
|
+
tzinfo (2.0.6)
|
212
|
+
concurrent-ruby (~> 1.0)
|
45
213
|
unicode-display_width (2.4.2)
|
214
|
+
view_component (3.0.0)
|
215
|
+
activesupport (>= 5.2.0, < 8.0)
|
216
|
+
concurrent-ruby (~> 1.0)
|
217
|
+
method_source (~> 1.0)
|
218
|
+
websocket-driver (0.7.5)
|
219
|
+
websocket-extensions (>= 0.1.0)
|
220
|
+
websocket-extensions (0.1.5)
|
221
|
+
xpath (3.2.0)
|
222
|
+
nokogiri (~> 1.8)
|
223
|
+
zeitwerk (2.6.8)
|
46
224
|
|
47
225
|
PLATFORMS
|
48
226
|
x86_64-linux
|
49
227
|
|
50
228
|
DEPENDENCIES
|
229
|
+
bootsnap
|
230
|
+
capybara
|
51
231
|
optics_view_components!
|
232
|
+
pry
|
233
|
+
rails (~> 7.0)
|
52
234
|
rake (~> 13.0)
|
53
235
|
rspec (~> 3.0)
|
236
|
+
rspec-rails
|
54
237
|
rubocop (~> 1.21)
|
238
|
+
sprockets
|
239
|
+
sprockets-rails
|
240
|
+
view_component
|
55
241
|
|
56
242
|
BUNDLED WITH
|
57
243
|
2.4.10
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Optics::ApplicationViewComponent < ViewComponent::Base
|
4
|
+
class_attribute :optional_attributes, default: {}
|
5
|
+
class_attribute :required_attributes, default: {}
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# To allow DB queries, put this in the class definition:
|
9
|
+
# self.allow_db_queries = true
|
10
|
+
attr_accessor :allow_db_queries
|
11
|
+
alias allow_db_queries? allow_db_queries
|
12
|
+
|
13
|
+
def requires(parameter, default: nil)
|
14
|
+
required_attributes[parameter] = default
|
15
|
+
|
16
|
+
attr_reader parameter
|
17
|
+
end
|
18
|
+
|
19
|
+
def accepts(parameter, default: nil)
|
20
|
+
optional_attributes[parameter] = default
|
21
|
+
|
22
|
+
attr_reader parameter
|
23
|
+
end
|
24
|
+
|
25
|
+
def inherited(subclass)
|
26
|
+
subclass.optional_attributes = optional_attributes.dup
|
27
|
+
subclass.required_attributes = required_attributes.dup
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(**attributes)
|
33
|
+
initialize_instance_variables(required_attributes, attributes) do |key, _default|
|
34
|
+
raise ArgumentError, "Missing keyword: :#{key}"
|
35
|
+
end
|
36
|
+
|
37
|
+
initialize_instance_variables(optional_attributes, attributes) do |key, default|
|
38
|
+
instance_variable_set("@#{key}", default)
|
39
|
+
end
|
40
|
+
|
41
|
+
@attributes = attributes.except(*optional_attributes.keys, *required_attributes.keys)
|
42
|
+
end
|
43
|
+
|
44
|
+
def class_for(name)
|
45
|
+
"c--#{identifier}--#{name}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def container_class
|
49
|
+
"c--#{identifier}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def class_names_for(*args)
|
53
|
+
class_names(*args).map { |name| class_for(name) }.join(' ')
|
54
|
+
end
|
55
|
+
|
56
|
+
# Inspired by https://github.com/primer/view_components/blob/v0.1.9/app/lib/primer/class_name_helper.rb#L9
|
57
|
+
def class_names(*args) # rubocop:disable Metrics/MethodLength
|
58
|
+
[].tap do |classes|
|
59
|
+
args.each do |class_name|
|
60
|
+
case class_name
|
61
|
+
when String
|
62
|
+
classes << class_name
|
63
|
+
when Hash
|
64
|
+
class_name.each do |key, val|
|
65
|
+
classes << key if val
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
classes.compact!
|
71
|
+
classes.uniq!
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Used by Stimulus. E.g. data-controller=identifier => data-controller='dynamic-form--field'
|
76
|
+
def identifier
|
77
|
+
@identifier ||= self.class.name.sub('::Component', '').underscore.gsub('_', '-').gsub('/', '--')
|
78
|
+
end
|
79
|
+
|
80
|
+
# Helper for Stimulus data attributes
|
81
|
+
def data_for(method:, target:)
|
82
|
+
data_method(method).merge(data_target(target))
|
83
|
+
end
|
84
|
+
|
85
|
+
# Helper for Stimulus controller method
|
86
|
+
def data_method(method, event: 'click')
|
87
|
+
{ action: "#{event}->#{identifier}##{method}" }
|
88
|
+
end
|
89
|
+
|
90
|
+
# Helper for Stimulus controller target
|
91
|
+
def data_target(target)
|
92
|
+
{ "#{identifier}": { target: } }
|
93
|
+
end
|
94
|
+
|
95
|
+
# Helper for Stimulus controller value
|
96
|
+
def data_values(values)
|
97
|
+
values.transform_keys do |key|
|
98
|
+
"#{identifier}-#{key}-value"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def initialize_instance_variables(configured_attributes, attributes)
|
105
|
+
configured_attributes.each do |key, default|
|
106
|
+
if attributes.key?(key)
|
107
|
+
instance_variable_set("@#{key}", attributes[key])
|
108
|
+
else
|
109
|
+
yield(key, default)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Optics
|
4
|
+
module Button
|
5
|
+
class Component < ApplicationViewComponent
|
6
|
+
SIZES = %w[small medium large].freeze
|
7
|
+
STYLES = %w[default primary secondary delete].freeze
|
8
|
+
|
9
|
+
renders_one :leading_icon, lambda { |name:, size: 'normal'|
|
10
|
+
Optics::Icon::Component.new(name:, size:)
|
11
|
+
}
|
12
|
+
|
13
|
+
accepts :label
|
14
|
+
accepts :border, default: true
|
15
|
+
accepts :icon, default: false
|
16
|
+
accepts :size, default: 'medium'
|
17
|
+
accepts :variant, default: 'default'
|
18
|
+
accepts :url
|
19
|
+
|
20
|
+
def call
|
21
|
+
build_button do
|
22
|
+
leading_icon
|
23
|
+
label
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_button(&)
|
28
|
+
return link_to(url, class: classes, **@attributes, &) if url
|
29
|
+
|
30
|
+
tag.button(class: classes, **@attributes, &)
|
31
|
+
end
|
32
|
+
|
33
|
+
def button_class
|
34
|
+
return 'btn' if variant == 'default'
|
35
|
+
|
36
|
+
"btn-#{variant}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def classes
|
40
|
+
class_names(
|
41
|
+
button_class,
|
42
|
+
size_class,
|
43
|
+
'btn--icon': icon,
|
44
|
+
'btn--no-border': !border
|
45
|
+
).join(' ')
|
46
|
+
end
|
47
|
+
|
48
|
+
def size_class
|
49
|
+
return if size == 'medium'
|
50
|
+
|
51
|
+
"btn--#{size}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Optics
|
4
|
+
module Button
|
5
|
+
class Preview < ApplicationViewComponentPreview
|
6
|
+
# @param border toggle
|
7
|
+
# @param icon toggle
|
8
|
+
# @param id text
|
9
|
+
# @param label text
|
10
|
+
# @param size select {{ ::Button::Component::SIZES }}
|
11
|
+
# @param variant select {{ ::Button::Component::STYLES }}
|
12
|
+
# @param url text
|
13
|
+
def default( # rubocop:disable Metrics/ParameterLists
|
14
|
+
border: true,
|
15
|
+
icon: false,
|
16
|
+
id: nil,
|
17
|
+
label: 'Default',
|
18
|
+
size: 'normal',
|
19
|
+
variant: 'default',
|
20
|
+
url: nil
|
21
|
+
)
|
22
|
+
render(Button::Component.new(
|
23
|
+
border:,
|
24
|
+
icon:,
|
25
|
+
id:,
|
26
|
+
label:,
|
27
|
+
size:,
|
28
|
+
variant:,
|
29
|
+
url:,
|
30
|
+
))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Optics
|
4
|
+
module Icon
|
5
|
+
class Component < ApplicationViewComponent
|
6
|
+
SIZES = %w[normal large x-large].freeze
|
7
|
+
WEIGHTS = %w[light normal semi-bold bold].freeze
|
8
|
+
EMPHASES = %w[low normal high].freeze
|
9
|
+
|
10
|
+
requires :name
|
11
|
+
accepts :data
|
12
|
+
accepts :emphasis, default: 'normal'
|
13
|
+
accepts :filled, default: false
|
14
|
+
accepts :size, default: 'normal'
|
15
|
+
accepts :title
|
16
|
+
accepts :weight, default: 'normal'
|
17
|
+
|
18
|
+
def call
|
19
|
+
content_tag(
|
20
|
+
:span,
|
21
|
+
class: classes,
|
22
|
+
'aria-label': title,
|
23
|
+
title:,
|
24
|
+
data:
|
25
|
+
) do
|
26
|
+
name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def classes
|
31
|
+
class_names(
|
32
|
+
'material-symbols-outlined',
|
33
|
+
size_class,
|
34
|
+
weight_class,
|
35
|
+
emphasis_class,
|
36
|
+
'icon--filled': filled
|
37
|
+
).join(' ')
|
38
|
+
end
|
39
|
+
|
40
|
+
def size_class
|
41
|
+
return if size == 'normal'
|
42
|
+
|
43
|
+
"icon--#{size}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def weight_class
|
47
|
+
return if weight == 'normal'
|
48
|
+
|
49
|
+
"icon--weight-#{weight}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def emphasis_class
|
53
|
+
return if emphasis == 'normal'
|
54
|
+
|
55
|
+
"icon--#{emphasis}-emphasis"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Icon
|
4
|
+
class Preview < ViewComponent::Preview
|
5
|
+
# @param emphasis select {{ ::Icon::Component::EMPHASES }}
|
6
|
+
# @param filled toggle
|
7
|
+
# @param name
|
8
|
+
# @param size select {{ ::Icon::Component::SIZES }}
|
9
|
+
# @param title
|
10
|
+
# @param weight select {{ ::Icon::Component::WEIGHTS }}
|
11
|
+
def default( # rubocop:disable Metrics/ParameterLists
|
12
|
+
emphasis: 'normal',
|
13
|
+
filled: false,
|
14
|
+
name: 'settings',
|
15
|
+
size: 'normal',
|
16
|
+
title: nil,
|
17
|
+
weight: 'normal'
|
18
|
+
)
|
19
|
+
render(
|
20
|
+
Icon::Component.new(
|
21
|
+
emphasis:,
|
22
|
+
filled:,
|
23
|
+
name:,
|
24
|
+
size:,
|
25
|
+
title:,
|
26
|
+
weight:
|
27
|
+
)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/demo/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/demo/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gem 'rails', '~> 7.0.4', '>= 7.0.4.3'
|
6
|
+
|
7
|
+
gem 'bootsnap', require: false
|
8
|
+
gem 'cssbundling-rails', '~> 1.1'
|
9
|
+
gem 'puma', '~> 6.0'
|
10
|
+
gem 'sprockets-rails'
|
11
|
+
|
12
|
+
gem 'optics_view_components', path: '../'
|
13
|
+
|
14
|
+
group :development, :test do
|
15
|
+
gem 'debug', platforms: %i[mri mingw x64_mingw]
|
16
|
+
end
|
17
|
+
|
18
|
+
group :development do
|
19
|
+
gem 'web-console'
|
20
|
+
end
|
21
|
+
|