lookbook 1.0.0.beta.1 → 1.0.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +180 -40
  3. data/app/components/lookbook/{component.rb → base_component.rb} +1 -1
  4. data/app/components/lookbook/button/component.rb +1 -1
  5. data/app/components/lookbook/button_group/component.rb +1 -1
  6. data/app/components/lookbook/code/component.rb +1 -1
  7. data/app/components/lookbook/copy_button/component.html.erb +1 -1
  8. data/app/components/lookbook/copy_button/component.rb +1 -1
  9. data/app/components/lookbook/dimensions_display/component.rb +1 -1
  10. data/app/components/lookbook/embed/component.html.erb +6 -5
  11. data/app/components/lookbook/embed/component.rb +1 -1
  12. data/app/components/lookbook/filter/component.html.erb +1 -1
  13. data/app/components/lookbook/filter/component.rb +1 -1
  14. data/app/components/lookbook/header/component.html.erb +6 -11
  15. data/app/components/lookbook/header/component.rb +6 -1
  16. data/app/components/lookbook/icon/component.rb +1 -1
  17. data/app/components/lookbook/nav/component.rb +1 -1
  18. data/app/components/lookbook/nav/item/component.html.erb +2 -2
  19. data/app/components/lookbook/nav/item/component.rb +1 -1
  20. data/app/components/lookbook/page_tabs/component.rb +1 -1
  21. data/app/components/lookbook/params_editor/component.rb +1 -1
  22. data/app/components/lookbook/params_editor/field/component.rb +1 -1
  23. data/app/components/lookbook/prose/component.rb +1 -1
  24. data/app/components/lookbook/split_layout/component.rb +1 -1
  25. data/app/components/lookbook/tab_panels/component.rb +1 -1
  26. data/app/components/lookbook/tab_panels/panel/component.rb +2 -2
  27. data/app/components/lookbook/tabs/component.js +6 -6
  28. data/app/components/lookbook/tabs/component.rb +1 -1
  29. data/app/components/lookbook/tabs/dropdown_tab/component.rb +1 -1
  30. data/app/components/lookbook/tabs/tab/component.rb +1 -1
  31. data/app/components/lookbook/toolbar/component.rb +1 -1
  32. data/app/components/lookbook/viewport/component.rb +1 -1
  33. data/app/controllers/lookbook/application_controller.rb +1 -1
  34. data/app/controllers/lookbook/pages_controller.rb +1 -1
  35. data/app/controllers/lookbook/previews_controller.rb +27 -32
  36. data/app/helpers/lookbook/application_helper.rb +8 -2
  37. data/app/helpers/lookbook/component_helper.rb +4 -0
  38. data/app/helpers/lookbook/page_helper.rb +2 -2
  39. data/app/views/layouts/lookbook/application.html.erb +5 -3
  40. data/app/views/layouts/lookbook/page.html.erb +2 -2
  41. data/app/views/layouts/lookbook/shell.html.erb +2 -48
  42. data/app/views/layouts/lookbook/skeleton.html.erb +7 -1
  43. data/app/views/lookbook/404.html.erb +1 -1
  44. data/app/views/lookbook/index.html.erb +1 -1
  45. data/app/views/lookbook/pages/show.html.erb +8 -8
  46. data/app/views/lookbook/previews/panels/_notes.html.erb +1 -1
  47. data/app/views/lookbook/previews/panels/_preview.html.erb +1 -1
  48. data/app/views/lookbook/previews/show.html.erb +4 -4
  49. data/config/routes.rb +6 -6
  50. data/lib/lookbook/collection.rb +1 -1
  51. data/lib/lookbook/component.rb +31 -0
  52. data/lib/lookbook/config.rb +94 -41
  53. data/lib/lookbook/engine.rb +72 -12
  54. data/lib/lookbook/page.rb +3 -3
  55. data/lib/lookbook/parser.rb +1 -4
  56. data/lib/lookbook/preview.rb +25 -8
  57. data/lib/lookbook/preview_example.rb +2 -2
  58. data/lib/lookbook/preview_group.rb +1 -1
  59. data/lib/lookbook/source_inspector.rb +10 -0
  60. data/lib/lookbook/utils.rb +2 -2
  61. data/lib/lookbook/version.rb +1 -1
  62. data/lib/lookbook.rb +1 -12
  63. data/public/lookbook-assets/css/lookbook.css +24 -28
  64. data/public/lookbook-assets/css/lookbook.css.map +1 -1
  65. data/public/lookbook-assets/js/lookbook.js +50 -49
  66. data/public/lookbook-assets/js/lookbook.js.map +1 -1
  67. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5efc30f722f9fff6377285d5b4e06a5f62e20e0a202eb19966ab6a7701999db2
4
- data.tar.gz: 4987e68865cf8ddfdc68838bfc1497c71118898c0607d0c5dd9701ccc754d406
3
+ metadata.gz: d5ea17315afaadd8b53a97bd7e3a5cb41c9c1098f5f4a67984d702386b1033b3
4
+ data.tar.gz: 3d2c07669fc5b7bd812429c010d2e79bc3bf0d6de4edc27c8f3da978d3780d7f
5
5
  SHA512:
6
- metadata.gz: 27b85921801c7e88510e69ae88a0b6b093f9da9252910130b5ee7edbc89ecb9149a8b7d0a6c60b6993904e73448e64150a2756a936eeb1e3f61a4ab7d2acc40b
7
- data.tar.gz: 68d236bd6baba5c456cc090cd2faed45ef02300ba2d0913eae9d2087b0572d140653df035a65a28d29baf435459f67ea86aa1cb7142634c5154324540ac56e1f
6
+ metadata.gz: e9b2b50f8b9054c4e3ee9bff900c7326062721cad676b3708b2ff42e79e8a2178f35314284a01339faeca6a9350258bfe490fc75b058a7294875c30d5c103aae
7
+ data.tar.gz: 331ca602732e745d03a883a62e4e5e7ee0eacce7d55fc2fce74c47ea7661aaf2b42ef0b486e3a7b9ddc44b85192dcedbc2d7b4e30b9cd32ca4ec11e0a87b811e
data/README.md CHANGED
@@ -11,6 +11,7 @@ The main goals of the v1.0 release are:
11
11
  - [x] Rebuild app UI using ViewComponent components
12
12
  - [x] Improve usability of the small screen/mobile layout
13
13
  - [x] Add support for some limited UI color theme customisation
14
+ - [x] Add support for custom inspector panels
14
15
  - [x] Remove the `experimental` flag from the [Pages](https://github.com/allmarkedup/lookbook#pages)
15
16
  - [x] Improve the development/debugging setup, and allow previewing Lookbook's own components in Lookbook :-)
16
17
  - [ ] Improve the test setup and test coverage, switch to RSpec **[in progress]**
@@ -29,25 +30,21 @@ The bulk of the v1.0 'new feature' development work is now mostly complete, alth
29
30
 
30
31
  **If you are an existing Lookbook user** I'd greatly appreciate if you can kick the tyres on the v1.0 beta and open an issue with any bug reports, suggestions or feedback you might have.
31
32
 
32
- ### Main areas/points for testing:
33
+ ### Main areas/points for testing/feedback:
33
34
 
34
35
  - Existing Lookbook setups should continue to work **with no changes required**
35
- - There have been a number of small UI changes - do any of them negatively affect your experience of using Lookbook?
36
- - The Pages feature should work without opting in to any experimental features.
37
- - It's now possible to pick from one of a small set of pre-defined UI themes (finer-grained customisation coming soon!). [See below](#ui-theming) for details. Any thoughts on this?
36
+ - It's now possible to pick from one of a small set of pre-defined **UI themes** (plus finer-grained customisation coming soon). [See below](#ui-theming) for details.
37
+ - You can now [extend Lookbook](#extending-lookbook) to more closely customise it to your needs - testing and feedback around this area would be a great help!
38
38
 
39
- > However absolutely any thoughts, comments or bug reports (even if unrelated to the specific areas above) would be much appreciated!
39
+ > Any thoughts, comments or bug reports (even if unrelated to the specific areas above) would be much appreciated!
40
40
 
41
- ## New features
42
41
 
43
- There are a number of new features that are planned for inclusion in the v1.0 release. They are:
42
+ ## UI theming
44
43
 
45
- ### UI theming
46
-
47
- Lookbook now ships with a small set of pre-defined UI themes, which can be set using the `ui_theme` config option:
44
+ Lookbook v1.0 ships with a small set of pre-defined UI themes, which can be set using the `ui_theme` config option:
48
45
 
49
46
  ```ruby
50
- # config/application.rb (or similar)
47
+ # config/application.rb
51
48
  config.lookbook.ui_theme = "blue"
52
49
  ```
53
50
 
@@ -59,25 +56,174 @@ Currently available themes are:
59
56
 
60
57
  > More themes and finer-grained customisation of theme colours is coming soon!
61
58
 
62
- ### Inspector panels customisation
59
+ ## Extending Lookbook
60
+
61
+ > Opening up Lookbook to more in-depth customisation is a work in progress and any feedback or use-case examples would be greatly appreciated!
62
+
63
+ * [Lifecycle Hooks](#lifecycle-hooks)
64
+ * [Adding inspector panels](#adding-inspector-panels)
65
+ * [Removing inspector panels](#removing-inspector-panels)
66
+
67
+ ### Lifecycle hooks
68
+
69
+ A number of lifecycle hooks are available for use in triggering actions outside of Lookbook.
70
+
71
+ All hook callback blocks are yielded a `Lookbook` instance as the first argument. Some hooks additionally supply other arguments, see below for details.
72
+
73
+ #### `:after_initialize`
74
+
75
+ This is run once Lookbook has been set up and the initial parsing of files has been completed.
76
+
77
+ ```ruby
78
+ Lookbook.after_initialize do |app|
79
+ puts "Lookbook version #{app.version} has started"
80
+ puts "There are #{app.previews.size} previews and #{app.pages.size} pages"
81
+ # other code here...
82
+ end
83
+ ```
84
+
85
+ #### `:after_change`
86
+
87
+ Run each time a change is detected to a file that Lookbook is watching, unless listening for changes has been disabled in the config.
88
+
89
+ Receives a hash as the second argument with `:modified`, `:added`, and `:removed` properties, each of which is an array of affected file paths.
90
+
91
+ ```ruby
92
+ Lookbook.after_change do |app, changes|
93
+ puts "Modified files: #{changes.modified.join("\n")}"
94
+ puts "Added files: #{changes.added.join("\n")}"
95
+ puts "Removed files: #{changes.removed.join("\n")}"
96
+ end
97
+ ```
98
+
99
+ #### `:before_exit`
100
+
101
+ Run when the current process exits, after Lookbook has stopped any listeners.
102
+
103
+ ```ruby
104
+ Lookbook.after_initialize do |app|
105
+ puts "Shutting down..."
106
+ end
107
+ ```
108
+
109
+ ### Adding inspector panels
110
+
111
+ It's now possible to add custom inspector panels/tabs to Lookbook using the `:define_panel` method:
112
+
113
+ ```ruby
114
+ Lookbook.define_panel(<name>, <opts>)
115
+ ```
116
+
117
+ * `<name>`: A unique name for the panel
118
+ * `<opts>`: A `Hash` of options (see below for details)
119
+
120
+ For example, a very simple 'info' panel could be created as follows:
121
+
122
+ ```ruby
123
+ # config/application.rb
124
+ Lookbook.define_panel(:info, {
125
+ label: "Extra Info",
126
+ partial: "panels/info"
127
+ })
128
+ ```
129
+
130
+ ```erb
131
+ <!-- views/panels/_info.html.erb -->
132
+ <div>
133
+ <h2>Some information</h2>
134
+ <ul>
135
+ <li>You are looking at the '<%= preview.label %>' preview</li>
136
+ <li>The preview file path is: '<%= preview.full_path %>'<li>
137
+ <li>There are <%= examples.size %> examples in this preview<li>
138
+ </ul>
139
+ </div>
140
+ ```
141
+
142
+ #### Panel templates
143
+
144
+ The panel partial template will have access to any `locals` defined in the [panel options](#panel-options), plus the following variables:
145
+
146
+ #### `panel`
147
+
148
+ The resolved panel options object (see below for details)
149
+
150
+ ```erb
151
+ <h2><%= panel.label =></h2>
152
+ ```
153
+
154
+ #### `preview`
155
+
156
+ An object representing the current preview:
157
+
158
+ * `preview.id`
159
+ * `preview.label`
160
+ * `preview.full_path`
161
+ * `preview.url_path`
162
+ * ...
163
+
164
+ #### `examples`
165
+
166
+ An array of objects representing the individual examples being rendered in the current preview. (For non-grouped previews, this array will always only have one item.)
167
+
168
+ Each example has the following properties:
169
+
170
+ * `example.output` - the rendered preview example output (String)
171
+ * `example.source` - the example source code (String)
172
+ * `example.source_lang` - a hash of information about the source language (Ruby or HTML/ERB, depending on whether the example uses a preview template)
173
+ * `example.id`
174
+ * `example.label`
175
+ * `example.full_path`
176
+ * `example.url_path`
177
+ * ...
178
+
179
+
180
+ #### `components`
181
+
182
+ An array of objects representing the components that are rendered in the preview. The components are 'guessed' from the Preview class name but if that doesn't work then they can be manually specified via annotations.
183
+
184
+ Each component object has the following properties:
63
185
 
64
- It is now possible to add, remove or customise tabbed panels in the preview inspector by editing the `lookbook.inspector_panels` configuration option.
186
+ * `component.name`
187
+ * `component.full_path`
188
+ * `component.dir_path`
189
+ * `component.template_path`
190
+ * `component.inline?`
65
191
 
66
- By default Lookbook comes with **five** panels split between two resizable panes:
192
+ To manually specify one or more components in the preview class, you can use the `@component` tag at the class level:
67
193
 
68
- 1. The `main` pane - by default includes the `preview` and `output` (HTML) panels
69
- 2. The `drawer` pane - by default includes the `source`, `notes` and `params` panels
194
+ ```ruby
195
+ # @component Elements::BigDangerButton
196
+ class ButtonComponentPreview < ViewComponent::Preview
197
+
198
+ def default
199
+ render Elements::BigDangerButton.new do
200
+ "Click here"
201
+ end
202
+ end
203
+
204
+ end
205
+ ```
206
+
207
+ #### `context`
208
+
209
+ An object containing data about the request context:
210
+
211
+ * `context.preview_params`
212
+ * `context.path`
213
+
214
+ #### `app`
70
215
 
71
- These can be hidden, moved, reordered and/or added to as your project requires.
216
+ The main `Lookbook` app instance.
72
217
 
73
- #### Panel config overview
218
+ * `app.previews` - Array of preview objects
219
+ * `app.pages` - Array of page objects
220
+ * `app.logger` - Logger instance
74
221
 
75
- Panels are defined as a hash with the following properties (all of which are actually optional):
222
+ #### Panel options
76
223
 
77
224
  ```ruby
78
225
  {
79
226
  label: "New Panel",
80
- pane: :drawer,
81
227
  position: 1,
82
228
  partial: "path/to/view_partial",
83
229
  content: "Some **markdown** content",
@@ -85,11 +231,11 @@ Panels are defined as a hash with the following properties (all of which are act
85
231
  disabled: false,
86
232
  show: true,
87
233
  copy: "Content to be copied",
234
+ locals: {}
88
235
  }
89
236
  ```
90
237
 
91
238
  * `label`: the text to be displayed in the tab
92
- * `pane`: the panel location, either `:drawer` or `:main` (`:drawer` is the default)
93
239
  * `position`: used for ordering the tabs
94
240
  * `partial`: the path to the view template partial used to render the panel
95
241
  * `content`: the default partial renders and displays the contents of this (markdown supported)
@@ -99,7 +245,8 @@ Panels are defined as a hash with the following properties (all of which are act
99
245
  * `copy`: if present, the panel will display a copy button that copies the value of this property to the clipboard when clicked
100
246
  * `locals`: a `Hash` of local variables that will be made available to the partial when rendering the panel
101
247
 
102
- All panel config values can be provided either as a **simple static value** or as a **lambda function** which will receive a hash of data relating to the current preview/example. For example:
248
+
249
+ All panel option values can be provided either as a **simple static value** or as a **lambda function** which will receive a hash of data relating to the currently active preview/example. For example:
103
250
 
104
251
  ```ruby
105
252
  {
@@ -108,32 +255,25 @@ All panel config values can be provided either as a **simple static value** or a
108
255
  }
109
256
  ```
110
257
 
111
- > **Work in progress!** There is more documentation to come on the data hash passed to lambdas.
258
+ The `data` hash contains the same set of objects that are passed to the panel partial template:
112
259
 
113
- #### Removing panels
260
+ * `data.preview`
261
+ * `data.examples`
262
+ * `data.components`
263
+ * `data.context`
264
+ * `data.app`
114
265
 
115
- To remove a pane entirely from the UI, just set it's value to false in your `application.rb` (or wherever you do your configuration):
266
+ **See the [panel templates section above]((#panel-templates)) for more details.**
116
267
 
117
- ```ruby
118
- config.lookbook.inspector_panels.notes = false # remove the notes panel
119
- ```
268
+ ### Removing inspector panels
120
269
 
121
- #### Customising existing panels
122
-
123
- Existing panel configuration can be amended as needed. For example, to change the label on one of the default panels:
270
+ To remove a panel entirely from the UI you can use the `Lookbook.remove_panel` method:
124
271
 
125
272
  ```ruby
126
- config.lookbook.inspector_panels.notes.label = "Instructions"
127
-
128
- # or use block-style config
129
- config.lookbook.inspector_panels do |panels|
130
- panels.notes.label = "Instructions"
131
- end
273
+ # config/application.rb
274
+ Lookbook.remove_panel(:notes)
132
275
  ```
133
276
 
134
-
135
-
136
-
137
277
  ## 🛠 Workbench
138
278
 
139
279
  As of this release, Lookbook's UI is itself built using ViewComponent components. To help with development it is possible to preview these components (in a Lookbook instance!) by running the included 'Workbench" app, as follows:
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Component < ViewComponent::Base
2
+ class BaseComponent < ViewComponent::Base
3
3
  include Lookbook::ComponentHelper
4
4
 
5
5
  def initialize(alpine_data: [], **html_attrs)
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Button::Component < Lookbook::Component
2
+ class Button::Component < Lookbook::BaseComponent
3
3
  renders_one :icon, Lookbook::Icon::Component
4
4
  renders_one :dropdown
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class ButtonGroup::Component < Lookbook::Component
2
+ class ButtonGroup::Component < Lookbook::BaseComponent
3
3
  renders_many :buttons, ->(copy: nil, **attrs, &block) do
4
4
  attrs[:size] = @size
5
5
  instance = if copy.present?
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Code::Component < Lookbook::Component
2
+ class Code::Component < Lookbook::BaseComponent
3
3
  include Lookbook::OutputHelper
4
4
 
5
5
  def initialize(
@@ -4,7 +4,7 @@
4
4
  x_data: prepare_alpine_data,
5
5
  "@click.prevent": "copyToClipboard" do |button| %>
6
6
  <% button.icon name: @icon, size: icon_size, x_show: "!copied", cloak: true %>
7
- <%= render_component :icon, name: :check, size: icon_size, class: "text-green-500", x_show: "copied", cloak: true %>
7
+ <%= icon :check, size: icon_size, class: "text-green-500", x_show: "copied", cloak: true %>
8
8
  <% if content %>
9
9
  <div x-ref="copyTarget" class="hidden"><%== content %></div>
10
10
  <% end %>
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class CopyButton::Component < Lookbook::Component
2
+ class CopyButton::Component < Lookbook::BaseComponent
3
3
  def initialize(target: nil, icon: :code, **attrs)
4
4
  @icon = icon
5
5
  @target = target
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class DimensionsDisplay::Component < Lookbook::Component
2
+ class DimensionsDisplay::Component < Lookbook::BaseComponent
3
3
  def initialize(target:, **html_attrs)
4
4
  @target = target
5
5
  super(**html_attrs)
@@ -10,10 +10,10 @@
10
10
  <% toolbar.section align: :right, divide: :left do %>
11
11
  <%= render_component :button_group do |group| %>
12
12
  <% group.button icon: :eye,
13
- href: helpers.lookbook.inspect_path(@example.path, @params),
13
+ href: helpers.lookbook_inspect_path(@example.path, @params),
14
14
  tooltip: "View in Inspector" %>
15
15
  <% group.button icon: :external_link,
16
- href: helpers.lookbook.inspect_path(@example.path, @params),
16
+ href: helpers.lookbook_inspect_path(@example.path, @params),
17
17
  tooltip: "Open in new window",
18
18
  target: "_blank" %>
19
19
  <% end %>
@@ -25,9 +25,10 @@
25
25
  @viewport:loaded="loadResizer"
26
26
  @dom:update-complete="loadResizer"
27
27
  @viewport:resize-progress="resizeIframe"
28
- @viewport:resize-complete="resizeIframe">
28
+ @viewport:resize-complete="resizeIframe"
29
+ @tabs:change.window="resizeIframe">
29
30
  <%= render_component :viewport,
30
- src: helpers.lookbook.preview_path(@example.path, @params.merge(lookbook_embed: true)),
31
+ src: helpers.lookbook_preview_path(@example.path, @params.merge(lookbook_embed: true)),
31
32
  alpine_data: "store",
32
33
  resize_height: false,
33
34
  max_height: @max_height,
@@ -38,7 +39,7 @@
38
39
  <% else %>
39
40
  <%= render_component_tag class: "bg-white flex flex-col items-center justify-center border-2 border-dashed border-gray-200 p-6 rounded-md not-prose" do %>
40
41
  <div class="px-4 text-center">
41
- <%= render_component :icon, name: :alert_triangle, size: 6, class: "text-red-300 mx-auto" %>
42
+ <%= icon :alert_triangle, size: 6, class: "text-red-300 mx-auto" %>
42
43
  <div class="mt-2 max-w-xs">
43
44
  <h5 class="text-base">Preview not found</h5>
44
45
  <p class="mt-1 opacity-50 text-sm">
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Embed::Component < Lookbook::Component
2
+ class Embed::Component < Lookbook::BaseComponent
3
3
  def initialize(id:, example:, params: {}, opts: {}, max_height: nil, **html_attrs)
4
4
  @id = id
5
5
  @example = example
@@ -11,7 +11,7 @@
11
11
  @keydown.f.stop.prevent.window="focus"
12
12
  @keydown.stop>
13
13
  <button class="text-lookbook-button-text hover:text-lookbook-button-text-hover focus:ring-0 focus:outline-none absolute top-1/2 right-3 -translate-y-1/2" @click="clear" :class="{hidden: !active}">
14
- <%= render_component :icon, name: :x, size: 3 %>
14
+ <%= icon :x, size: 3 %>
15
15
  </button>
16
16
  </div>
17
17
  <% end %>
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Filter::Component < Lookbook::Component
2
+ class Filter::Component < Lookbook::BaseComponent
3
3
  def initialize(store: nil, placeholder: "Type to filter&hellip;", **html_attrs)
4
4
  @model = store.nil? ? "{}" : "#{store}.raw"
5
5
  @placeholder = placeholder
@@ -12,7 +12,7 @@
12
12
 
13
13
  <% toolbar.section padded: false, align: :right, class: "flex items-center" do %>
14
14
  <%= render_component :button_group do |group| %>
15
- <% if Rails.env.development? %>
15
+ <% if @debug_menu %>
16
16
  <% group.button icon: :help_circle, class: "opacity-50 hover:opacity-100 transition !text-lookbook-header-text" do |button| %>
17
17
  <% button.dropdown do %>
18
18
  <%= tag.div class: "divide-y divide-lookbook-divider min-w-[180px]" do %>
@@ -24,15 +24,10 @@
24
24
  x-data="clipboardComponent"
25
25
  @click.prevent.stop="copyToClipboard('#debug-data')">
26
26
  <span x-show="copied" x-cloak>
27
- <%= render_component :icon,
28
- name: :check,
29
- size: 2.5,
30
- class: "text-green-600" %>
27
+ <%= icon :check, size: 2.5, class: "text-green-600" %>
31
28
  </span>
32
29
  <span x-show="!copied">
33
- <%= render_component :icon,
34
- name: :clipboard,
35
- size: 2.5 %>
30
+ <%= icon :clipboard, size: 2.5 %>
36
31
  </span>
37
32
  <span class="ml-2">Copy debug data</span>
38
33
  </a>
@@ -41,7 +36,7 @@
41
36
  <a href="#"
42
37
  class="text-xs flex items-center hover:underline"
43
38
  @click.stop="localStorage.clear(); window.location.reload();">
44
- <%= render_component :icon, name: :refresh_cw, size: 2.5 %>
39
+ <%= icon :refresh_cw, size: 2.5 %>
45
40
  <span class="ml-2">Reset local storage</span>
46
41
  </a>
47
42
  </li>
@@ -52,10 +47,10 @@
52
47
  <span class="mr-6">v<%= Lookbook::VERSION %></span>
53
48
  <div class="flex items-center space-x-2">
54
49
  <!-- a href="https://github.com/allmarkedup/lookbook" target="_blank" class="ml-auto opacity-70" title="Documentation">
55
- <%= render_component :icon, name: :book, size: 3 %>
50
+ <%= icon :book, size: 3 %>
56
51
  </a -->
57
52
  <a href="https://github.com/allmarkedup/lookbook" target="_blank" class="ml-auto opacity-70" title="Github">
58
- <%= render_component :icon, name: :github, size: 3 %>
53
+ <%= icon :github, size: 3 %>
59
54
  </a>
60
55
  </div>
61
56
  </div>
@@ -1,7 +1,12 @@
1
1
  module Lookbook
2
- class Header::Component < Lookbook::Component
2
+ class Header::Component < Lookbook::BaseComponent
3
3
  renders_one :branding
4
4
 
5
+ def initialize(debug_menu: false, **html_attrs)
6
+ @debug_menu = debug_menu
7
+ super(**html_attrs)
8
+ end
9
+
5
10
  def landing_path
6
11
  helpers.landing_path if defined? helpers.landing_path
7
12
  end
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Icon::Component < Lookbook::Component
2
+ class Icon::Component < Lookbook::BaseComponent
3
3
  def initialize(name:, size: 4, **html_attrs)
4
4
  @icon_name = name.is_a?(Symbol) ? name.to_s.tr("_", "-").to_json : name
5
5
  @size = size || 4
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Nav::Component < Lookbook::Component
2
+ class Nav::Component < Lookbook::BaseComponent
3
3
  renders_one :filter, Lookbook::Filter::Component
4
4
 
5
5
  def initialize(
@@ -6,11 +6,11 @@
6
6
  style: "padding-left: #{left_pad}px",
7
7
  x_bind: "bindings.#{href.present? ? "link" : "toggle"}" do %>
8
8
  <div class="relative flex items-center">
9
- <%= render_component :icon, name: nil,
9
+ <%= icon nil,
10
10
  size: 3,
11
11
  class: "mr-1 text-lookbook-nav-toggle absolute -left-4",
12
12
  x_effect: "iconName = open ? 'chevron-down' : 'chevron-right'" if children? %>
13
- <%= render_component :icon, name: nav_icon(@item), size: 3.5, class: "mr-1.5 text-lookbook-nav-icon" %>
13
+ <%= icon nav_icon(@item), size: 3.5, class: "mr-1.5 text-lookbook-nav-icon" %>
14
14
  <span><%= label %></span>
15
15
  </div>
16
16
  <% end %>
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Nav::Item::Component < Lookbook::Component
2
+ class Nav::Item::Component < Lookbook::BaseComponent
3
3
  ICONS = {
4
4
  page: :file,
5
5
  page_collection: :folder,
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class PageTabs::Component < Lookbook::Component
2
+ class PageTabs::Component < Lookbook::BaseComponent
3
3
  renders_many :tabs, ->(**attrs, &block) do
4
4
  @tabs ||= []
5
5
  attrs[:content] = capture(&block)
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class ParamsEditor::Component < Lookbook::Component
2
+ class ParamsEditor::Component < Lookbook::BaseComponent
3
3
  renders_many :fields, Lookbook::ParamsEditor::Field::Component
4
4
 
5
5
  protected
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class ParamsEditor::Field::Component < Lookbook::Component
2
+ class ParamsEditor::Field::Component < Lookbook::BaseComponent
3
3
  def initialize(input:, name:, default: nil, value: nil, input_type: nil, type: nil, options: nil, **html_attrs)
4
4
  @input = input
5
5
  @name = name
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Prose::Component < Lookbook::Component
2
+ class Prose::Component < Lookbook::BaseComponent
3
3
  include Lookbook::OutputHelper
4
4
 
5
5
  def initialize(size: :md, markdown: true, **html_attrs)
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class SplitLayout::Component < Lookbook::Component
2
+ class SplitLayout::Component < Lookbook::BaseComponent
3
3
  renders_many :panes, Lookbook::TagComponent
4
4
 
5
5
  protected
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class TabPanels::Component < Lookbook::Component
2
+ class TabPanels::Component < Lookbook::BaseComponent
3
3
  renders_many :panels, ->(**attrs) do
4
4
  @panel_counter += 1
5
5
  attrs[:name] ||= "tab-#{@panel_counter}"
@@ -1,8 +1,8 @@
1
1
  module Lookbook
2
- class TabPanels::Panel::Component < Lookbook::Component
2
+ class TabPanels::Panel::Component < Lookbook::BaseComponent
3
3
  def initialize(name:, id: nil, **html_attrs)
4
4
  @name = name
5
- @id = id || name
5
+ @id = "#{id || "panel-#{name}"}"
6
6
  super(**html_attrs)
7
7
  end
8
8
  end
@@ -16,7 +16,7 @@ export default function tabsComponent(store) {
16
16
  },
17
17
 
18
18
  get tabs() {
19
- return Array.from(this.$refs.tabs.children);
19
+ return this.$refs.tabs ? Array.from(this.$refs.tabs.children) : [];
20
20
  },
21
21
 
22
22
  get dropdownTabs() {
@@ -45,7 +45,7 @@ export default function tabsComponent(store) {
45
45
  const initialTab = initial
46
46
  ? this.tabs.find((t) => this._getRef(t) === initial)
47
47
  : this.tabs[0];
48
- this.selectTab(initialTab);
48
+ this.selectTab(initialTab, true);
49
49
 
50
50
  this.parentObserver = observeSize(
51
51
  this.$root.parentElement,
@@ -64,13 +64,10 @@ export default function tabsComponent(store) {
64
64
  }
65
65
 
66
66
  if (width === this.$root.offsetWidth) {
67
- console.log("uep");
68
67
  this.visibleTabsCount = this.tabs.length;
69
68
  return;
70
69
  }
71
70
 
72
- console.log(width);
73
-
74
71
  let sumTabWidths = 60;
75
72
  let triggerLeft = 20;
76
73
  let visibleTabsCount = 0;
@@ -87,9 +84,12 @@ export default function tabsComponent(store) {
87
84
  this._lastMeasuredWidth = width;
88
85
  },
89
86
 
90
- selectTab(el) {
87
+ selectTab(el, initial = false) {
91
88
  this.store.activeTab = this._getRef(el);
92
89
  dropdown.hide();
90
+ if (!initial) {
91
+ this.$dispatch("tabs:change", { tabs: this });
92
+ }
93
93
  },
94
94
 
95
95
  isSelected(el) {
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Tabs::Component < Lookbook::Component
2
+ class Tabs::Component < Lookbook::BaseComponent
3
3
  renders_many :tabs, ->(**attrs) do
4
4
  @tab_counter += 1
5
5
  attrs[:name] ||= "tab-#{@tab_counter}"
@@ -1,5 +1,5 @@
1
1
  module Lookbook
2
- class Tabs::DropdownTab::Component < Lookbook::Component
2
+ class Tabs::DropdownTab::Component < Lookbook::BaseComponent
3
3
  def initialize(name:, label: nil, hotkey: nil, disabled: nil, position: 0, theme: :toolbar, **html_attrs)
4
4
  @name = name
5
5
  @label = label