sdr_view_components 0.3.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 +4 -4
- data/README.md +21 -0
- data/Rakefile +1 -1
- data/app/assets/sdr_view_components.css +22 -0
- data/app/components/sdr_view_components/elements/toast_component.html.erb +2 -6
- data/app/components/sdr_view_components/elements/toast_component.rb +13 -2
- data/app/javascript/sdr_view_components/toast_controller.js +7 -0
- data/lib/sdr_view_components/engine.rb +1 -0
- data/lib/sdr_view_components/version.rb +1 -1
- data/spec/components/previews/sdr_view_components/elements/toast_component_preview/disappearing.html.erb +5 -0
- data/spec/components/previews/sdr_view_components/elements/toast_component_preview.rb +4 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4925b643ff3bbb773d0583382c635d876b270fe449561a106b0766fc85865938
|
|
4
|
+
data.tar.gz: d226b6b48db3c1ca228633f9e6c3c78a53beb4ea6336e9c41c980bc425871a3e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/Rakefile
CHANGED
|
@@ -116,3 +116,25 @@ table.table-data th {
|
|
|
116
116
|
cursor: default;
|
|
117
117
|
opacity: .5;
|
|
118
118
|
}
|
|
119
|
+
|
|
120
|
+
/* Toasts */
|
|
121
|
+
@keyframes fade-out {
|
|
122
|
+
0% {
|
|
123
|
+
opacity: 1;
|
|
124
|
+
max-height: 200px;
|
|
125
|
+
visibility: visible;
|
|
126
|
+
}
|
|
127
|
+
79% { opacity: 1; }
|
|
128
|
+
80% { max-height: 200px; }
|
|
129
|
+
|
|
130
|
+
100% {
|
|
131
|
+
opacity: 0;
|
|
132
|
+
max-height: 0;
|
|
133
|
+
visibility: hidden;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.toast-disappear {
|
|
138
|
+
animation: fade-out 5s ease-in forwards;
|
|
139
|
+
}
|
|
140
|
+
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
class="toast align-items-center show"
|
|
3
|
-
role="alert"
|
|
4
|
-
aria-live="assertive"
|
|
5
|
-
aria-atomic="true">
|
|
1
|
+
<%= tag.div class: classes, role: 'alert', aria: { live: 'assertive', atomic: 'true' }, data: do %>
|
|
6
2
|
<%= tag.div class: toast_body_classes do %>
|
|
7
3
|
<div class="d-flex">
|
|
8
4
|
<div
|
|
@@ -29,4 +25,4 @@
|
|
|
29
25
|
</div>
|
|
30
26
|
</div>
|
|
31
27
|
<% end %>
|
|
32
|
-
|
|
28
|
+
<% end %>
|
|
@@ -3,21 +3,32 @@
|
|
|
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
|
-
def initialize(title:, text: nil, close_text: nil, variant: :black)
|
|
9
|
+
def initialize(title:, text: nil, close_text: nil, variant: :black, disappearing: false)
|
|
8
10
|
@title = title
|
|
9
11
|
@text = text
|
|
10
12
|
@close_text = close_text
|
|
11
13
|
@variant = variant
|
|
14
|
+
@disappearing = disappearing
|
|
12
15
|
super()
|
|
13
16
|
end
|
|
14
17
|
|
|
15
|
-
attr_reader :title, :text, :close_text, :variant
|
|
18
|
+
attr_reader :title, :text, :close_text, :variant, :disappearing
|
|
19
|
+
|
|
20
|
+
def classes
|
|
21
|
+
merge_classes('toast align-items-center show', ('toast-disappear' if disappearing))
|
|
22
|
+
end
|
|
16
23
|
|
|
17
24
|
def toast_body_classes
|
|
18
25
|
merge_classes([background_color], %w[toast-body text-white])
|
|
19
26
|
end
|
|
20
27
|
|
|
28
|
+
def data
|
|
29
|
+
{ controller: 'sdr-toast' } if disappearing
|
|
30
|
+
end
|
|
31
|
+
|
|
21
32
|
def background_color
|
|
22
33
|
case variant
|
|
23
34
|
when :red
|
|
@@ -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
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<%= render SdrViewComponents::Elements::ToastComponent.new(title: 'Alert!', text: 'Non-Disappearing Toast text') %>
|
|
2
|
+
|
|
3
|
+
<%= render SdrViewComponents::Elements::ToastComponent.new(title: 'Alert!', text: 'Disappearing Toast text. Wait 5 secs.', disappearing: true, variant: :green) %>
|
|
4
|
+
|
|
5
|
+
<%= render SdrViewComponents::Elements::ToastComponent.new(title: 'Alert!', text: 'Non-Disappearing Toast text') %>
|
|
@@ -21,6 +21,10 @@ 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.
|
|
26
|
+
def disappearing; end
|
|
27
|
+
|
|
24
28
|
def with_close_text
|
|
25
29
|
render SdrViewComponents::Elements::ToastComponent.new(title: 'Alert!', text: 'Black Toast text', close_text: 'Undo')
|
|
26
30
|
end
|
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
|
+
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
|
|
@@ -190,6 +191,7 @@ files:
|
|
|
190
191
|
- spec/components/previews/sdr_view_components/elements/tabs/tab_list_component_preview/underline_variant.html.erb
|
|
191
192
|
- spec/components/previews/sdr_view_components/elements/tabs/tab_list_component_preview/with_header.html.erb
|
|
192
193
|
- spec/components/previews/sdr_view_components/elements/toast_component_preview.rb
|
|
194
|
+
- spec/components/previews/sdr_view_components/elements/toast_component_preview/disappearing.html.erb
|
|
193
195
|
- spec/components/previews/sdr_view_components/elements/tooltip_component_preview.rb
|
|
194
196
|
- spec/components/previews/sdr_view_components/elements/tooltip_component_preview/default.html.erb
|
|
195
197
|
- spec/components/previews/sdr_view_components/forms/basic/basic_checkbox_component_preview.rb
|