optics_view_components 0.1.7 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5194f25da267f185510137dd9cb5cda150d6da2ea4bea6dcdbe2353360b460ba
4
- data.tar.gz: c856c408ca950243a0b00bf080c93c8a1d182f7a1bcb87df35084522c82c78d4
3
+ metadata.gz: 6288af3ac32f24e288467c22bea1cac3ced752a18d7cd7ff817cc927b57f3c06
4
+ data.tar.gz: 9cb97927ebe42807ae5990d3bc5eda34ace45842569d744994cdab0a726e8ee6
5
5
  SHA512:
6
- metadata.gz: 87d76b46feb1fed4772bd7e6ca8efd36e1c3bb38cae8fb94325f676dfef1e38bb8b6ec9a897010d72dd7d154dd6638ce961e2a6245c45be0a170a8c036276fb9
7
- data.tar.gz: fafd24dd4f8738e53b012a0a82ce10b4a2c6e35c7ccbaa872316055641260d2c62c09cfbc8ce8e87c63578ea37566c23544fd4d06d57cf54c561e866958fa148
6
+ metadata.gz: 82352039a648222ccb8721c529569cd7b1adbdc416b6e86d34c1ee611f724a9b6170f4b70843edbc3d4677af59509f1d1dfa870fc2e2b58bfc2af0991aef4661
7
+ data.tar.gz: 9295d7c6b41b3148bb14bd1ce9569686c90fc9d246c48ac083952feb4b43064b7e73aad9ad8eb003fbc5add4808035c8ff278bccc40b33bddcab90f83f877dc1
data/Gemfile CHANGED
@@ -9,6 +9,8 @@ gem 'rails', '~> 7.0'
9
9
 
10
10
  gem 'bootsnap', require: false
11
11
  gem 'lookbook'
12
+ gem 'puma', '~> 6.3'
13
+ gem 'sprockets-rails'
12
14
  gem 'rake', '~> 13.0'
13
15
  gem 'rspec', '~> 3.0'
14
16
  gem 'rubocop', '~> 1.21'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- optics_view_components (0.1.3)
4
+ optics_view_components (0.1.8)
5
5
  view_component (> 2.0, < 4.0)
6
6
 
7
7
  GEM
@@ -138,6 +138,8 @@ GEM
138
138
  net-smtp (0.3.3)
139
139
  net-protocol
140
140
  nio4r (2.5.9)
141
+ nokogiri (1.15.1-arm64-darwin)
142
+ racc (~> 1.4)
141
143
  nokogiri (1.15.1-x86_64-linux)
142
144
  racc (~> 1.4)
143
145
  parallel (1.23.0)
@@ -147,6 +149,8 @@ GEM
147
149
  coderay (~> 1.1)
148
150
  method_source (~> 1.0)
149
151
  public_suffix (5.0.1)
152
+ puma (6.3.1)
153
+ nio4r (~> 2.0)
150
154
  racc (1.6.2)
151
155
  rack (2.2.7)
152
156
  rack-test (2.1.0)
@@ -242,6 +246,7 @@ GEM
242
246
  zeitwerk (2.6.8)
243
247
 
244
248
  PLATFORMS
249
+ arm64-darwin-21
245
250
  x86_64-linux
246
251
 
247
252
  DEPENDENCIES
@@ -250,6 +255,7 @@ DEPENDENCIES
250
255
  lookbook
251
256
  optics_view_components!
252
257
  pry
258
+ puma (~> 6.3)
253
259
  rails (~> 7.0)
254
260
  rake (~> 13.0)
255
261
  rspec (~> 3.0)
data/Procfile ADDED
@@ -0,0 +1 @@
1
+ web: bundle exec rackup -p ${PORT:-5000} config.ru
data/README.md CHANGED
@@ -38,6 +38,18 @@ Add to `config/application.rb`:
38
38
  config.view_component.preview_paths << Optics::ViewComponents::Engine.root.join('previews')
39
39
  ```
40
40
 
41
+ If you need a custom layout add:
42
+ ```
43
+ config.view_component.default_preview_layout = 'preview'
44
+ ```
45
+
46
+ To use the shorthand `component 'optics/icon'` syntax, add this to `app/helpers/application_helper.rb`:
47
+ ```
48
+ def component(name, *args, **kwargs, &)
49
+ render(name.camelize.constantize::Component.new(*args, **kwargs), &)
50
+ end
51
+ ```
52
+
41
53
  ## Development
42
54
 
43
55
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -6,30 +6,27 @@ module Optics
6
6
  SIZES = %w[small medium large].freeze
7
7
  STYLES = %w[default primary secondary delete].freeze
8
8
 
9
- renders_one :leading_icon, lambda { |name:, size: 'normal'|
10
- Optics::Icon::Component.new(name:, size:)
11
- }
12
-
13
9
  accepts :label
10
+ accepts :active, default: false
14
11
  accepts :border, default: true
12
+ accepts :disabled, default: false
15
13
  accepts :icon, default: false
14
+ accepts :icon_with_label, default: false
15
+ accepts :pill, default: false
16
16
  accepts :size, default: 'medium'
17
17
  accepts :variant, default: 'default'
18
18
  accepts :url
19
19
 
20
20
  def call
21
21
  build_button do
22
- capture do
23
- concat leading_icon
24
- concat label
25
- end
22
+ content || label
26
23
  end
27
24
  end
28
25
 
29
26
  def build_button(&)
30
- return link_to(url, class: classes, **@attributes.except(:class), &) if url
27
+ return link_to(url, class: classes, **@attributes.except(:class), &) if url && !disabled
31
28
 
32
- tag.button(class: classes, **@attributes.except(:class), &)
29
+ tag.button(class: classes, disabled:, **@attributes.except(:class), &)
33
30
  end
34
31
 
35
32
  def button_class
@@ -43,8 +40,12 @@ module Optics
43
40
  @attributes[:class],
44
41
  button_class,
45
42
  size_class,
43
+ 'btn--active': active,
44
+ 'btn--disabled': disabled,
46
45
  'btn--icon': icon,
47
- 'btn--no-border': !border
46
+ 'btn--icon-with-label': icon_with_label,
47
+ 'btn--no-border': !border,
48
+ 'btn--pill': pill
48
49
  ).join(' ')
49
50
  end
50
51
 
@@ -3,7 +3,7 @@
3
3
  module Optics
4
4
  module Sidebar
5
5
  class Component < ApplicationViewComponent
6
- VARIANTS = %w[drawer compact rail]
6
+ VARIANTS = %w[drawer compact rail].freeze
7
7
 
8
8
  renders_one :brand, 'Brand'
9
9
  renders_many :sidebar_contents, 'SidebarContent'
@@ -41,36 +41,29 @@ module Optics
41
41
  class Brand < ApplicationViewComponent
42
42
  accepts :url
43
43
  accepts :image_source
44
+ accepts :image_label
45
+ accepts :name
44
46
 
45
47
  def call
46
48
  link_to(url, class: 'sidebar__brand') do
47
- image_tag(image_source)
49
+ name || image_tag(image_source, alt: image_label)
48
50
  end
49
51
  end
50
52
  end
51
53
 
52
54
  class SidebarContent < ApplicationViewComponent
53
- renders_many :buttons, Optics::Button::Component
54
-
55
55
  accepts :position, default: 'center'
56
-
56
+
57
57
  def call
58
- concat(
59
- content_tag(
60
- :div,
61
- class: classes
62
- ) do
63
- buttons.each do |button|
64
- concat button
65
- end
58
+ content_tag(:div, class: classes) do
59
+ content
66
60
  end
67
- )
68
61
  end
69
62
 
70
63
  def classes
71
64
  class_names(
72
65
  'sidebar__content',
73
- position_class,
66
+ position_class
74
67
  ).join(' ')
75
68
  end
76
69
 
@@ -80,12 +73,12 @@ module Optics
80
73
  end
81
74
 
82
75
  class LinksComponent < ApplicationViewComponent
83
- accepts :image_source
76
+ accepts :img_src
84
77
  accepts :url
85
78
 
86
79
  def call
87
80
  link_to(url, class: 'sidebar__brand') do
88
- image_tag(image_source)
81
+ image_tag(img_src)
89
82
  end
90
83
  end
91
84
  end
data/config.ru ADDED
@@ -0,0 +1,3 @@
1
+ require './demo/config/environment'
2
+ run Demo::Application
3
+
data/demo/Gemfile CHANGED
@@ -6,7 +6,7 @@ gem 'rails', '~> 7.0.4', '>= 7.0.4.3'
6
6
 
7
7
  gem 'bootsnap', require: false
8
8
  gem 'cssbundling-rails', '~> 1.1'
9
- gem 'puma', '~> 6.0'
9
+ gem 'puma', '~> 6.3'
10
10
  gem 'sprockets-rails'
11
11
 
12
12
  gem 'lookbook'
data/demo/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- optics_view_components (0.1.3)
4
+ optics_view_components (0.1.8)
5
5
  view_component (> 2.0, < 4.0)
6
6
 
7
7
  GEM
@@ -133,10 +133,12 @@ GEM
133
133
  net-smtp (0.3.3)
134
134
  net-protocol
135
135
  nio4r (2.5.9)
136
- nokogiri (1.15.1-x86_64-linux)
136
+ nokogiri (1.15.3-arm64-darwin)
137
+ racc (~> 1.4)
138
+ nokogiri (1.15.3-x86_64-linux)
137
139
  racc (~> 1.4)
138
140
  public_suffix (5.0.1)
139
- puma (6.2.2)
141
+ puma (6.3.1)
140
142
  nio4r (~> 2.0)
141
143
  racc (1.6.2)
142
144
  rack (2.2.7)
@@ -200,6 +202,7 @@ GEM
200
202
  zeitwerk (2.6.8)
201
203
 
202
204
  PLATFORMS
205
+ arm64-darwin-22
203
206
  x86_64-linux
204
207
 
205
208
  DEPENDENCIES
@@ -208,7 +211,7 @@ DEPENDENCIES
208
211
  debug
209
212
  lookbook
210
213
  optics_view_components!
211
- puma (~> 6.0)
214
+ puma (~> 6.3)
212
215
  rails (~> 7.0.4, >= 7.0.4.3)
213
216
  sprockets-rails
214
217
  web-console
@@ -1,4 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApplicationHelper
4
+ def component(name, *args, **kwargs, &)
5
+ render(name.camelize.constantize::Component.new(*args, **kwargs), &)
6
+ end
4
7
  end
@@ -25,8 +25,9 @@ module Demo
25
25
  config.load_defaults 7.0
26
26
 
27
27
  config.view_component.default_preview_layout = 'preview'
28
- config.view_component.preview_paths << Rails.root.join('..', 'previews')
28
+ config.view_component.preview_paths = [Optics::ViewComponents::Engine.root.join('previews')]
29
29
  config.lookbook.project_name = "Optics ViewComponents v#{Optics::ViewComponents::VERSION}"
30
30
  config.lookbook.component_paths = [Optics::ViewComponents::Engine.root.join('app', 'components')]
31
+ config.view_component.show_previews = true
31
32
  end
32
33
  end
data/demo/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "dependencies": {
3
- "@rolemodel/optics": "^0.3.1",
4
- "sass": "^1.62.1"
3
+ "@rolemodel/optics": "^0.4.2",
4
+ "sass": "^1.63.6"
5
5
  },
6
6
  "scripts": {
7
7
  "build:css": "sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
data/demo/yarn.lock CHANGED
@@ -2,25 +2,12 @@
2
2
  # yarn lockfile v1
3
3
 
4
4
 
5
- "@orchidjs/sifter@^1.0.3":
6
- version "1.0.3"
7
- resolved "https://registry.yarnpkg.com/@orchidjs/sifter/-/sifter-1.0.3.tgz#43f42519472282eb632d0a1589184f044d64129b"
8
- integrity sha512-zCZbwKegHytfsPm8Amcfh7v/4vHqTAaOu6xFswBYcn8nznBOuseu6COB2ON7ez0tFV0mKL0nRNnCiZZA+lU9/g==
9
- dependencies:
10
- "@orchidjs/unicode-variants" "^1.0.4"
11
-
12
- "@orchidjs/unicode-variants@^1.0.4":
13
- version "1.0.4"
14
- resolved "https://registry.yarnpkg.com/@orchidjs/unicode-variants/-/unicode-variants-1.0.4.tgz#6d2f812e3b19545bba2d81caffff1204de9a6a58"
15
- integrity sha512-NvVBRnZNE+dugiXERFsET1JlKZfM5lJDEpSMilKW4bToYJ7pxf0Zne78xyXB2ny2c2aHfJ6WLnz1AaTNHAmQeQ==
16
-
17
- "@rolemodel/optics@^0.3.1":
18
- version "0.3.1"
19
- resolved "https://registry.yarnpkg.com/@rolemodel/optics/-/optics-0.3.1.tgz#87a8f3733d8fc3e59d26f3c484e3a308cffd1f54"
20
- integrity sha512-/bbYc63WH8Yp/PWJ8jew/O1mYqKYqTIw7ixWViEDt/XM4AG8WYZZV+WUvMBUrff5k8kM6M8ZZVLkmaDple8e/Q==
5
+ "@rolemodel/optics@^0.4.2":
6
+ version "0.4.2"
7
+ resolved "https://registry.yarnpkg.com/@rolemodel/optics/-/optics-0.4.2.tgz#c8cadfa37091a4d97e81f5ff8662af1b74505af5"
8
+ integrity sha512-yppM7DbMF5AmWQ4g21N5fLufwtmef9pmlTGlLPgUtMgVDBGZmoz0BiRf6VjUsAXNRmvgqCK/g+YrT1kyEtQE1A==
21
9
  dependencies:
22
10
  modern-css-reset "^1.4.0"
23
- tom-select "^2.0.0"
24
11
 
25
12
  anymatch@~3.1.2:
26
13
  version "3.1.3"
@@ -127,10 +114,10 @@ readdirp@~3.6.0:
127
114
  dependencies:
128
115
  picomatch "^2.2.1"
129
116
 
130
- sass@^1.62.1:
131
- version "1.62.1"
132
- resolved "https://registry.yarnpkg.com/sass/-/sass-1.62.1.tgz#caa8d6bf098935bc92fc73fa169fb3790cacd029"
133
- integrity sha512-NHpxIzN29MXvWiuswfc1W3I0N8SXBd8UR26WntmDlRYf0bSADnwnOjsyMZ3lMezSlArD33Vs3YFhp7dWvL770A==
117
+ sass@^1.63.6:
118
+ version "1.63.6"
119
+ resolved "https://registry.yarnpkg.com/sass/-/sass-1.63.6.tgz#481610e612902e0c31c46b46cf2dad66943283ea"
120
+ integrity sha512-MJuxGMHzaOW7ipp+1KdELtqKbfAWbH7OLIdoSMnVe3EXPMTmxTmlaZDCTsgIpPCs3w99lLo9/zDKkOrJuT5byw==
134
121
  dependencies:
135
122
  chokidar ">=3.0.0 <4.0.0"
136
123
  immutable "^4.0.0"
@@ -147,11 +134,3 @@ to-regex-range@^5.0.1:
147
134
  integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==
148
135
  dependencies:
149
136
  is-number "^7.0.0"
150
-
151
- tom-select@^2.0.0:
152
- version "2.2.2"
153
- resolved "https://registry.yarnpkg.com/tom-select/-/tom-select-2.2.2.tgz#8e5f9296e6d80254feccb57f0986bd6c44d126e2"
154
- integrity sha512-igGah1yY6yhrnN2h/Ky8I5muw/nE/YQxIsEZoYu5qaA4bsRibvKto3s8QZZosKpOd0uO8fNYhRfAwgHB4IAYew==
155
- dependencies:
156
- "@orchidjs/sifter" "^1.0.3"
157
- "@orchidjs/unicode-variants" "^1.0.4"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Optics
4
4
  module ViewComponents
5
- VERSION = '0.1.7'
5
+ VERSION = '0.1.9'
6
6
  end
7
7
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ComponentHelper
4
+ def component(name, *args, **kwargs, &)
5
+ render(name.camelize.constantize::Component.new(*args, **kwargs), &)
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ <%= component('optics/button', active:, border:, disabled:, icon:, icon_with_label:, id:, pill:, size:, variant:, url:) do |component| %>
2
+ <%= component('optics/icon', name: 'home') %>
3
+ Button
4
+ <% end %>
@@ -2,31 +2,59 @@
2
2
 
3
3
  module Optics
4
4
  class ButtonPreview < ViewComponent::Preview
5
+ include ComponentHelper
6
+
7
+ # @param active toggle
5
8
  # @param border toggle
9
+ # @param disabled toggle
6
10
  # @param icon toggle
11
+ # @param icon_with_label toggle
7
12
  # @param id text
8
13
  # @param label text
14
+ # @param pill toggle
9
15
  # @param size select {{ Optics::Button::Component::SIZES }}
10
16
  # @param variant select {{ Optics::Button::Component::STYLES }}
11
17
  # @param url text
12
18
  def default( # rubocop:disable Metrics/ParameterLists
13
- border: true,
14
- icon: false,
15
- id: nil,
16
- label: 'Default',
17
- size: 'normal',
18
- variant: 'default',
19
- url: nil
20
- )
21
- render(Optics::Button::Component.new(
22
- border:,
23
- icon:,
24
- id:,
25
- label:,
26
- size:,
27
- variant:,
28
- url:
29
- ))
19
+ active: false,
20
+ border: true,
21
+ disabled: false,
22
+ icon: false,
23
+ icon_with_label: false,
24
+ id: nil,
25
+ label: 'Default',
26
+ pill: false,
27
+ size: 'medium',
28
+ variant: 'default',
29
+ url: nil
30
+ )
31
+ component 'optics/button', active:, border:, disabled:, icon:, icon_with_label:, id:, label:, pill:, size:,
32
+ variant:, url:
33
+ end
34
+
35
+ # @param active toggle
36
+ # @param border toggle
37
+ # @param disabled toggle
38
+ # @param icon toggle
39
+ # @param icon_with_label toggle
40
+ # @param id text
41
+ # @param pill toggle
42
+ # @param size select {{ Optics::Button::Component::SIZES }}
43
+ # @param variant select {{ Optics::Button::Component::STYLES }}
44
+ # @param url text
45
+ def with_icon( # rubocop:disable Metrics/ParameterLists
46
+ active: false,
47
+ border: true,
48
+ disabled: false,
49
+ icon: false,
50
+ icon_with_label: false,
51
+ id: nil,
52
+ pill: false,
53
+ size: 'medium',
54
+ variant: 'default',
55
+ url: nil
56
+ )
57
+ render_with_template(locals: { active:, border:, disabled:, icon:, icon_with_label:, id:, pill:, size:, variant:, url: })
30
58
  end
31
59
  end
32
60
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Optics
4
4
  class IconPreview < ViewComponent::Preview
5
+ include ComponentHelper
6
+
5
7
  # @param emphasis select {{ Optics::Icon::Component::EMPHASES }}
6
8
  # @param filled toggle
7
9
  # @param name
@@ -9,23 +11,14 @@ module Optics
9
11
  # @param title
10
12
  # @param weight select {{ Optics::Icon::Component::WEIGHTS }}
11
13
  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
- Optics::Icon::Component.new(
21
- emphasis:,
22
- filled:,
23
- name:,
24
- size:,
25
- title:,
26
- weight:
27
- )
28
- )
14
+ emphasis: 'normal',
15
+ filled: false,
16
+ name: 'settings',
17
+ size: 'normal',
18
+ title: nil,
19
+ weight: 'normal'
20
+ )
21
+ component('optics/icon', emphasis:, filled:, name:, size:, title:, weight:)
29
22
  end
30
23
  end
31
24
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Optics
4
+ class SidebarPreview < ViewComponent::Preview
5
+ include ComponentHelper
6
+
7
+ # @param responsive toggle
8
+ # @param variant select {{ Optics::Sidebar::Component::VARIANTS }}
9
+ def default(
10
+ responsive: true,
11
+ variant: 'drawer'
12
+ )
13
+ component('optics/sidebar', responsive:, variant:) do |sidebar|
14
+ sidebar.with_brand(name: 'Optics', url: 'https://www.example.com')
15
+ end
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optics_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reed Law
8
+ - Wes Rich
9
+ - Jeremy Walton
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2023-07-19 00:00:00.000000000 Z
13
+ date: 2023-10-16 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: view_component
@@ -112,7 +114,8 @@ files:
112
114
  - CHANGELOG.md
113
115
  - Gemfile
114
116
  - Gemfile.lock
115
- - LICENSE.txt
117
+ - LICENSE
118
+ - Procfile
116
119
  - README.md
117
120
  - Rakefile
118
121
  - app/components/optics/application_view_component.rb
@@ -120,6 +123,7 @@ files:
120
123
  - app/components/optics/button/component.rb
121
124
  - app/components/optics/icon/component.rb
122
125
  - app/components/optics/sidebar/component.rb
126
+ - config.ru
123
127
  - demo/.ruby-version
124
128
  - demo/Gemfile
125
129
  - demo/Gemfile.lock
@@ -178,8 +182,11 @@ files:
178
182
  - lib/optics/view_components.rb
179
183
  - lib/optics/view_components/engine.rb
180
184
  - lib/optics/view_components/version.rb
185
+ - previews/component_helper.rb
181
186
  - previews/optics/button_preview.rb
187
+ - previews/optics/button_preview/with_icon.html.erb
182
188
  - previews/optics/icon_preview.rb
189
+ - previews/optics/sidebar_preview.rb
183
190
  - sig/optics_view_components.rbs
184
191
  homepage: https://github.com/RoleModel/optics_view_components
185
192
  licenses:
File without changes