optics_view_components 0.1.7 → 0.1.8

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: db165928ba46774fcb8412d71cd02ae0c4e066e323bff171c7bedaae7f7e1cf9
4
+ data.tar.gz: 482b366146b1e0ff14e8cd2c6c5819e51374ae142bb969b7f520f8f68a5de220
5
5
  SHA512:
6
- metadata.gz: 87d76b46feb1fed4772bd7e6ca8efd36e1c3bb38cae8fb94325f676dfef1e38bb8b6ec9a897010d72dd7d154dd6638ce961e2a6245c45be0a170a8c036276fb9
7
- data.tar.gz: fafd24dd4f8738e53b012a0a82ce10b4a2c6e35c7ccbaa872316055641260d2c62c09cfbc8ce8e87c63578ea37566c23544fd4d06d57cf54c561e866958fa148
6
+ metadata.gz: e8783ca32282a2e8f8f45b97b443198be8507f65d1c48cc773fe6f4ddd5ef737bdfa3a865b7591101b57fbf700e9d1af96858443f1ad3883338713f662ad2b7d
7
+ data.tar.gz: e21dd5880c6d94568f53c3202b154e7702d809fe7535e31134b3aef6c9ee56c8ce06a60de87a1069fb4381b4ee993c4bf5bb56b2d2ec3442720a479a7838d4c9
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
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'
@@ -40,37 +40,29 @@ module Optics
40
40
 
41
41
  class Brand < ApplicationViewComponent
42
42
  accepts :url
43
- accepts :image_source
43
+ accepts :img_src
44
+ accepts :name
44
45
 
45
46
  def call
46
47
  link_to(url, class: 'sidebar__brand') do
47
- image_tag(image_source)
48
+ name || image_tag(img_src)
48
49
  end
49
50
  end
50
51
  end
51
52
 
52
53
  class SidebarContent < ApplicationViewComponent
53
- renders_many :buttons, Optics::Button::Component
54
-
55
54
  accepts :position, default: 'center'
56
-
55
+
57
56
  def call
58
- concat(
59
- content_tag(
60
- :div,
61
- class: classes
62
- ) do
63
- buttons.each do |button|
64
- concat button
65
- end
57
+ content_tag(:div, class: classes) do
58
+ content
66
59
  end
67
- )
68
60
  end
69
61
 
70
62
  def classes
71
63
  class_names(
72
64
  'sidebar__content',
73
- position_class,
65
+ position_class
74
66
  ).join(' ')
75
67
  end
76
68
 
@@ -80,12 +72,12 @@ module Optics
80
72
  end
81
73
 
82
74
  class LinksComponent < ApplicationViewComponent
83
- accepts :image_source
75
+ accepts :img_src
84
76
  accepts :url
85
77
 
86
78
  def call
87
79
  link_to(url, class: 'sidebar__brand') do
88
- image_tag(image_source)
80
+ image_tag(img_src)
89
81
  end
90
82
  end
91
83
  end
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
@@ -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
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.8'
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:, 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:, 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,7 +1,7 @@
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.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reed Law
@@ -178,8 +178,11 @@ files:
178
178
  - lib/optics/view_components.rb
179
179
  - lib/optics/view_components/engine.rb
180
180
  - lib/optics/view_components/version.rb
181
+ - previews/component_helper.rb
181
182
  - previews/optics/button_preview.rb
183
+ - previews/optics/button_preview/with_icon.html.erb
182
184
  - previews/optics/icon_preview.rb
185
+ - previews/optics/sidebar_preview.rb
183
186
  - sig/optics_view_components.rbs
184
187
  homepage: https://github.com/RoleModel/optics_view_components
185
188
  licenses: