vident-view_component 1.0.0.alpha1 → 1.0.0.alpha3

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: 9a0cd9fafe18012c95fc9f952e6a0601eaa51bc7b3d3d813d0b34a3cdc9a0d8f
4
- data.tar.gz: 37a26c0415fd55cdb67516e49dd393a19b0214a77178f1ab2d0c563910a800d4
3
+ metadata.gz: 6008f5d78b7230589329a8b2a634767a2f54defd2fc9e3358548b3b641ef99b7
4
+ data.tar.gz: 7456a6c1f34c58cfce0477b623a12025e12665739f8f338687643cf5bea2b578
5
5
  SHA512:
6
- metadata.gz: b3ffb9e5a400c02d98cb94fb21f8e4b62cb6af93c5adcf7798954919da69a4218c00262fb573dc41a18bcd221cee82a01af2283b4225fc0176732ec7785b4180
7
- data.tar.gz: 86549c4a08aa6ca775f1501c7bcc561c25fc08e6210a01ea648bc9454ada7fa82ce7be8dbc3db9f2e01af06d282677d47c8687da9a865773c1eaf5dcf3646fb1
6
+ metadata.gz: c289ba2437da177d898f6bce6f7275495153aca16b8ada22c57ea046a32f8341b858f0099224b698c6e4607a2ed735991c5992ee3cab75c1ed173eb4cbc89752
7
+ data.tar.gz: fa6d53c82825e7a9be5f000265310521b803543b974a5784082438d3bd44b6b3162e512ff12147ab1646859f99759b9c6a0c4038d7c8f859f575d41546b7810a
data/CHANGELOG.md CHANGED
@@ -5,7 +5,25 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
- ## [1.0.0.alpha1] - 2025-07-04
8
+ ## [1.0.0.alpha3] - 2025-07-21
9
+
10
+ ### Breaking
11
+ - `element_classes` is now `root_element_classes` to make more consistent with the other root element methods.
12
+
13
+ ### Added
14
+
15
+ -`.prop_names` and `#prop_values` methods to `Vident::Component` to return the names and values of the component's properties.
16
+
17
+ ## [1.0.0.alpha2] - 2025-07-08
18
+
19
+ ### Breaking
20
+ - `nil` values in Stimulus values are ok, but `nil` for an action/target/outlet makes no sense so is ignored.
21
+
22
+ ### Fixed
23
+
24
+ - `stimulus_scoped_event` must return a Symbol to work with `stimulus_action` and `stimulus_target` methods etc.
25
+
26
+ ## [1.0.0.alpha1] - 2025-07-08
9
27
 
10
28
  This release is a major overhaul of the Vident library, and introduces a new API for defining components and Stimulus attributes. The new API is designed to be more consistent and easier to use.
11
29
 
data/README.md CHANGED
@@ -76,27 +76,32 @@ class ButtonComponent < Vident::ViewComponent::Base
76
76
 
77
77
  # Configure Stimulus integration
78
78
  stimulus do
79
- actions [:click, :handle_click]
80
- # Static values
81
- values loading_duration: 1000
79
+ # Setup actions, including with proc to evaluate on instance
80
+ actions [:click, :handle_click],
81
+ -> { [stimulus_scoped_event(:my_custom_event), :handle_this] if should_handle_this? }
82
82
  # Map the clicked_count prop as a Stimulus value
83
83
  values_from_props :clicked_count
84
84
  # Dynamic values using procs (evaluated in component context)
85
- values item_count: -> { @items.count }
86
- values api_url: -> { Rails.application.routes.url_helpers.api_items_path }
85
+ values item_count: -> { @items.count },
86
+ api_url: -> { Rails.application.routes.url_helpers.api_items_path },
87
+ loading_duration: 1000 # or set static values
87
88
  # Static and dynamic classes
88
- classes loading: "opacity-50 cursor-wait"
89
- classes size: -> { @items.count > 10 ? "large" : "small" }
89
+ classes loading: "opacity-50 cursor-wait",
90
+ size: -> { @items.count > 10 ? "large" : "small" }
90
91
  end
91
92
 
92
93
  def call
93
- root_element do
94
- @text
94
+ root_element do |component|
95
+ # Wire up targets etc
96
+ component.tag(:span, stimulus_target: :status) do
97
+ @text
98
+ end
95
99
  end
96
100
  end
97
101
 
98
102
  private
99
103
 
104
+ # Configure your components root HTML element
100
105
  def root_element_attributes
101
106
  {
102
107
  element_tag: @url ? :a : :button,
@@ -104,7 +109,8 @@ class ButtonComponent < Vident::ViewComponent::Base
104
109
  }
105
110
  end
106
111
 
107
- def element_classes
112
+ # optionally add logic to determine initial classes
113
+ def root_element_classes
108
114
  base_classes = "btn"
109
115
  case @style
110
116
  when :primary
@@ -130,14 +136,19 @@ export default class extends Controller {
130
136
  loadingDuration: Number
131
137
  }
132
138
  static classes = ["loading"]
139
+ static targets = ["status"]
133
140
 
134
141
  handleClick(event) {
135
142
  // Increment counter
136
143
  this.clickedCountValue++
137
144
 
145
+ // Store original text
146
+ const originalText = this.statusTarget.textContent
147
+
138
148
  // Add loading state
139
149
  this.element.classList.add(this.loadingClass)
140
150
  this.element.disabled = true
151
+ this.statusTarget.textContent = "Loading..."
141
152
 
142
153
  // Use the loading duration from the component
143
154
  setTimeout(() => {
@@ -145,7 +156,7 @@ export default class extends Controller {
145
156
  this.element.disabled = false
146
157
 
147
158
  // Update text to show count
148
- this.element.textContent = `${this.element.textContent} (${this.clickedCountValue})`
159
+ this.statusTarget.textContent = `${originalText} (${this.clickedCountValue})`
149
160
  }, this.loadingDurationValue)
150
161
  }
151
162
  }
@@ -178,7 +189,7 @@ The rendered HTML includes all Stimulus data attributes:
178
189
  data-button-component-loading-duration-value="1000"
179
190
  data-button-component-loading-class="opacity-50 cursor-wait"
180
191
  id="button-component-123">
181
- Save
192
+ <span data-button-component-target="status">Save</span>
182
193
  </button>
183
194
 
184
195
  <!-- Second button with pre-set count -->
@@ -189,7 +200,7 @@ The rendered HTML includes all Stimulus data attributes:
189
200
  data-button-component-loading-duration-value="1000"
190
201
  data-button-component-loading-class="opacity-50 cursor-wait"
191
202
  id="button-component-456">
192
- Submit
203
+ <span data-button-component-target="status">Submit</span>
193
204
  </button>
194
205
  ```
195
206
 
@@ -218,6 +229,29 @@ class CardComponent < Vident::ViewComponent::Base
218
229
  end
219
230
  ```
220
231
 
232
+ ### Post-Initialization Hooks
233
+
234
+ Vident provides a hook for performing actions after component initialization:
235
+
236
+ ```ruby
237
+ class MyComponent < Vident::ViewComponent::Base
238
+ prop :data, Hash, default: -> { {} }
239
+
240
+ def after_component_initialize
241
+ @processed_data = process_data(@data)
242
+ end
243
+
244
+ private
245
+
246
+ def process_data(data)
247
+ # Your initialization logic here
248
+ data.transform_values(&:upcase)
249
+ end
250
+ end
251
+ ```
252
+
253
+ **Important**: If you decide to override Literal's `after_initialize`, you **must** call `super` first to ensure Vident's initialization completes properly. Alternatively, use `after_component_initialize` which doesn't require calling `super`.
254
+
221
255
  ### Built-in Properties
222
256
 
223
257
  Every Vident component includes these properties:
@@ -233,7 +267,7 @@ The `root_element` helper method renders your component's root element with all
233
267
 
234
268
  ```ruby
235
269
  # In your component class
236
- def element_classes
270
+ def root_element_classes
237
271
  ["card", featured? ? "card-featured" : nil]
238
272
  end
239
273
 
@@ -389,7 +423,7 @@ Vident provides helper methods to generate scoped event names for dispatching cu
389
423
  class MyComponent < Vident::ViewComponent::Base
390
424
  stimulus do
391
425
  # Define an action that responds to a scoped event
392
- actions [stimulus_scoped_event_on_window(:data_loaded), :handle_data_loaded]
426
+ actions -> { [stimulus_scoped_event_on_window(:data_loaded), :handle_data_loaded] }
393
427
  end
394
428
 
395
429
  def handle_click
@@ -589,7 +623,7 @@ class StyledComponent < Vident::ViewComponent::Base
589
623
  private
590
624
 
591
625
  # Classes on the root element
592
- def element_classes
626
+ def root_element_classes
593
627
  ["base-class", variant_class]
594
628
  end
595
629
 
@@ -623,7 +657,7 @@ class TailwindComponent < Vident::ViewComponent::Base
623
657
 
624
658
  private
625
659
 
626
- def element_classes
660
+ def root_element_classes
627
661
  # Conflicts with size_class will be resolved automatically
628
662
  "p-2 text-sm #{size_class}"
629
663
  end
@@ -41,10 +41,10 @@ module Vident
41
41
 
42
42
  SELF_CLOSING_TAGS = Set[:area, :base, :br, :col, :embed, :hr, :img, :input, :link, :meta, :param, :source, :track, :wbr].freeze
43
43
 
44
- def root_element(&block)
44
+ def root_element(**overrides, &block)
45
45
  tag_type = root_element_tag_type
46
46
  child_content = view_context.capture(self, &block) if block_given? # Evaluate before generating the outer tag options to ensure DSL methods are executed
47
- options = root_element_tag_options
47
+ options = resolve_root_element_attributes_before_render(overrides)
48
48
  if SELF_CLOSING_TAGS.include?(tag_type)
49
49
  view_context.tag(tag_type, options)
50
50
  else
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vident-view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha1
4
+ version: 1.0.0.alpha3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-07-08 00:00:00.000000000 Z
10
+ date: 2025-07-21 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: railties
@@ -55,14 +55,14 @@ dependencies:
55
55
  requirements:
56
56
  - - "~>"
57
57
  - !ruby/object:Gem::Version
58
- version: 1.0.0.alpha1
58
+ version: 1.0.0.alpha3
59
59
  type: :runtime
60
60
  prerelease: false
61
61
  version_requirements: !ruby/object:Gem::Requirement
62
62
  requirements:
63
63
  - - "~>"
64
64
  - !ruby/object:Gem::Version
65
- version: 1.0.0.alpha1
65
+ version: 1.0.0.alpha3
66
66
  - !ruby/object:Gem::Dependency
67
67
  name: view_component
68
68
  requirement: !ruby/object:Gem::Requirement