sdr_view_components 0.4.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a3b49086535a4be91b25b4f4a5b68f51c72fd2478f5fc72d54c2b77afe5f7cf
4
- data.tar.gz: dff1e70705204abaf6202df28826379dd8993d584445506e39f905250fed4795
3
+ metadata.gz: 4925b643ff3bbb773d0583382c635d876b270fe449561a106b0766fc85865938
4
+ data.tar.gz: d226b6b48db3c1ca228633f9e6c3c78a53beb4ea6336e9c41c980bc425871a3e
5
5
  SHA512:
6
- metadata.gz: a34d248d460b3af61fdb39db821d45620e5444defed6de2505f260cce700b3c6babb9000d10063b98e59a52a171b2df7ca0162bbac8476648efa28b2ee008993
7
- data.tar.gz: ed9d2ef885985c68e38f640ce30a67382be3cb9f258ac3d03946d896fdcaa651f09acd7059482b3a7f006163730748375a712f498e89832bd87dbe838a293292
6
+ metadata.gz: d2ed8d3c294e718797978c170bbf247d9721122f0b8811da747b0ab1d71d6b724b074562e872adbf090d4b5f049400da88f922dfff4ec5f0d81d9524e961915a
7
+ data.tar.gz: 1c8464a8b72bb93c65068cb3b3ab5f47f10e691c5c286757368ac1f87c116adb34ef1f21dcebfe0d3905b304e1f5b021af0169bad069ca47e1fac95893755754
data/README.md CHANGED
@@ -25,6 +25,27 @@ This set of components relies on the component library stylesheets, add:
25
25
 
26
26
  with the most recent date tagged release to your `application.html.erb` layout file.
27
27
 
28
+ ## JavaScript
29
+
30
+ Some components require JavaScript. The gem ships Stimulus controllers under `app/javascript/sdr_view_components/` and registers that path with the asset pipeline automatically.
31
+
32
+ Here is an example of how to add a Stimulus controller:
33
+
34
+ The disappearing toast uses `sdr_view_components/toast_controller` to remove itself from the DOM after its fade-out animation completes.
35
+
36
+ Add to `config/importmap.rb`:
37
+ ```ruby
38
+ pin "sdr_view_components/toast_controller", to: "sdr_view_components/toast_controller.js"
39
+ ```
40
+
41
+ Register the controller in `app/javascript/controllers/index.js`:
42
+ ```javascript
43
+ import { application } from "controllers/application"
44
+ import ToastController from "sdr_view_components/toast_controller"
45
+
46
+ application.register("sdr-toast", ToastController)
47
+ ```
48
+
28
49
  ## Usage
29
50
 
30
51
  ### Form components
@@ -1,4 +1,4 @@
1
- <%= tag.div class: classes, role: 'alert', aria: { live: 'assertive', atomic: 'true' } do %>
1
+ <%= tag.div class: classes, role: 'alert', aria: { live: 'assertive', atomic: 'true' }, data: do %>
2
2
  <%= tag.div class: toast_body_classes do %>
3
3
  <div class="d-flex">
4
4
  <div
@@ -3,6 +3,8 @@
3
3
  module SdrViewComponents
4
4
  module Elements
5
5
  # Component for rendering a toast element.
6
+ # The disappearing toast uses `sdr_view_components/toast_controller` to remove itself from the DOM after its
7
+ # fade-out animation completes.
6
8
  class ToastComponent < BaseComponent
7
9
  def initialize(title:, text: nil, close_text: nil, variant: :black, disappearing: false)
8
10
  @title = title
@@ -23,6 +25,10 @@ module SdrViewComponents
23
25
  merge_classes([background_color], %w[toast-body text-white])
24
26
  end
25
27
 
28
+ def data
29
+ { controller: 'sdr-toast' } if disappearing
30
+ end
31
+
26
32
  def background_color
27
33
  case variant
28
34
  when :red
@@ -0,0 +1,7 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ connect() {
5
+ this.element.addEventListener("animationend", () => this.element.remove(), { once: true })
6
+ }
7
+ }
@@ -26,6 +26,7 @@ module SdrViewComponents
26
26
  initializer 'sdr_view_components.assets' do |app|
27
27
  app.config.assets.paths << Engine.root.join('app', 'assets').to_s
28
28
  app.config.assets.paths << Engine.root.join('app', 'assets', 'stylesheets').to_s
29
+ app.config.assets.paths << Engine.root.join('app', 'javascript').to_s
29
30
  end
30
31
 
31
32
  initializer 'sdr_view_components.helpers' do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrViewComponents
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  end
@@ -21,6 +21,8 @@ module SdrViewComponents
21
21
  end
22
22
  # @!endgroup
23
23
 
24
+ # The disappearing toast uses `sdr_view_components/toast_controller` to remove itself from the DOM after its
25
+ # fade-out animation completes.
24
26
  def disappearing; end
25
27
 
26
28
  def with_close_text
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdr_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Collier
@@ -158,6 +158,7 @@ files:
158
158
  - app/components/sdr_view_components/tables/row_component.html.erb
159
159
  - app/components/sdr_view_components/tables/row_component.rb
160
160
  - app/components/sdr_view_components/tables/table_component.rb
161
+ - app/javascript/sdr_view_components/toast_controller.js
161
162
  - app/views/layouts/lookbook.html.erb
162
163
  - config/routes.rb
163
164
  - lib/sdr_view_components.rb