bs5_expandable_list_group 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -2
- data/app/components/bs5/expandable_list_group_component.html.erb +1 -1
- data/app/components/bs5/expandable_list_group_component.rb +13 -5
- data/app/components/bs5/expandable_list_item_component.html.erb +12 -12
- data/app/components/bs5/expandable_list_item_component.rb +20 -2
- data/lib/bs5_expandable_list_group/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53968aced77ec5891c98c1ecbcdfc9a7011a88b1d04893fdddc51f296eb6b4c5
|
4
|
+
data.tar.gz: 79820d54b461d866e1f12f1896942d8e7f27bcd2e04251da3df8d0bc178d5f4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9659802b3e4619a59bcc748ec5a5ded01e46ecae3b158ba304baf8837385ffdfa089792a8ec5632f7e009c6f223c19930609be6eff770c7015c4fb1bc15cf0d
|
7
|
+
data.tar.gz: 1d0771ec4518307e8b5b6ee7e28aec4fbd3f398d13f93537ddc5334a53beb82942a90423e99592e79967db262f430afc50c698f2a74705fc3c4b865260460618
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Bootstrap 5 expandable list group
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/bazzel/Bs5ExpandableListGroup.svg?branch=main)](https://travis-ci.org/bazzel/Bs5ExpandableListGroup)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/bs5_expandable_list_group.svg)](https://badge.fury.io/rb/bs5_expandable_list_group)
|
4
5
|
|
5
6
|
**Bootstrap 5 expandable list group** is a Ruby on Rails engine and gives you a simple API for creating expandable and stretchable list groups. A bit like [Bootstrap 5](https://getbootstrap.com/)'s [Accordion](https://getbootstrap.com/docs/5.0/components/accordion/), [Collapse](https://getbootstrap.com/docs/5.0/components/collapse/) and [List group](https://getbootstrap.com/docs/5.0/components/list-group/) components combined.
|
6
7
|
|
@@ -172,7 +173,7 @@ This will render just a [list group item](https://getbootstrap.com/docs/5.0/comp
|
|
172
173
|
<%= i.body { post.text } %>
|
173
174
|
<% end %>
|
174
175
|
<% end %>
|
175
|
-
<% if @
|
176
|
+
<% if @posts.next_page %>
|
176
177
|
<% c.item %>
|
177
178
|
<%= link_to_next_page @posts "Load more" %>
|
178
179
|
<% end %>
|
@@ -180,6 +181,27 @@ This will render just a [list group item](https://getbootstrap.com/docs/5.0/comp
|
|
180
181
|
<% end %>
|
181
182
|
```
|
182
183
|
|
184
|
+
### Wrap an item in an extra element
|
185
|
+
|
186
|
+
Every list item is a `div` with one or more CSS classes and, dependent on block passed, some `data` attributes and is not customizable (yet).
|
187
|
+
However, you can wrap a list item in a extra element by passing a `wrapper_html` option to the `item` method:
|
188
|
+
|
189
|
+
```erb
|
190
|
+
...
|
191
|
+
<% c.item(wrapper_html: { tag: :turbo_frame, id: dom_id(post) }) do |i| %>
|
192
|
+
<%= i.title do |t| %>
|
193
|
+
<%= t.collapsed { 'Collapsed title' } %>
|
194
|
+
<%= t.expanded { 'Expanded title' } %>
|
195
|
+
<% end %>
|
196
|
+
<%= i.body { ... } %>
|
197
|
+
<% end %>
|
198
|
+
```
|
199
|
+
|
200
|
+
All options passed to the item method are used as HTML attributes of the wrapper, expect for the following:
|
201
|
+
|
202
|
+
| name | default | description |
|
203
|
+
|---|---|---|
|
204
|
+
| `tag` | `:div` | A symbol or string of a valid HTML tag that is used for the tag of the wrapper |
|
183
205
|
|
184
206
|
### Passing options
|
185
207
|
|
@@ -187,12 +209,12 @@ The following options can be passed to `Bs5::ExpandableListGroupComponent.new`:
|
|
187
209
|
|
188
210
|
| name | default | description |
|
189
211
|
|---|---|---|
|
212
|
+
| `tag` | `:div` | A symbol or string of a valid HTML tag that is used for the tag of the list group |
|
190
213
|
| `id` | | is used to assign an id HTML attribute to the rendered container |
|
191
214
|
| `class` | | is added to the class attribute of the rendered container |
|
192
215
|
| `accordion` | `false` | Behaves as an Bootstrap [accordion](https://getbootstrap.com/docs/5.0/components/accordion/) by having only 1 item expanded |
|
193
216
|
| `expandable` | `false` | Expanded items are shown a little bit bigger as if they come out a bit|
|
194
217
|
|
195
|
-
|
196
218
|
Example:
|
197
219
|
|
198
220
|
```erb
|
@@ -201,6 +223,9 @@ Example:
|
|
201
223
|
<% end %>
|
202
224
|
```
|
203
225
|
|
226
|
+
Other options are used as HTML attributes of the list group element.
|
227
|
+
|
228
|
+
|
204
229
|
## Running tests
|
205
230
|
|
206
231
|
```bash
|
@@ -2,23 +2,27 @@
|
|
2
2
|
|
3
3
|
module Bs5
|
4
4
|
class ExpandableListGroupComponent < ViewComponent::Base
|
5
|
-
renders_many :items, lambda {
|
6
|
-
|
5
|
+
renders_many :items, lambda { |options = {}|
|
6
|
+
options.merge!(parent_id: id, stretchable: stretchable?)
|
7
|
+
ExpandableListItemComponent.new(**options)
|
7
8
|
}
|
8
9
|
|
9
|
-
attr_reader :accordion, :stretchable
|
10
|
+
attr_reader :options, :accordion, :stretchable, :tag_name
|
11
|
+
|
12
|
+
DEFAULT_TAG_NAME = :div
|
10
13
|
|
11
14
|
def initialize(options = {})
|
12
15
|
@accordion = options.delete(:accordion)
|
13
16
|
@stretchable = options.delete(:stretchable)
|
14
|
-
@id = options
|
17
|
+
@id = options.delete(:id)
|
18
|
+
@tag_name = options.delete(:tag) || DEFAULT_TAG_NAME
|
15
19
|
@options = options
|
16
20
|
end
|
17
21
|
|
18
22
|
private
|
19
23
|
|
20
24
|
def id
|
21
|
-
@id || "list-group-#{object_id}"
|
25
|
+
@id || (accordion? && "list-group-#{object_id}")
|
22
26
|
end
|
23
27
|
|
24
28
|
def component_class
|
@@ -27,6 +31,10 @@ module Bs5
|
|
27
31
|
class_names
|
28
32
|
end
|
29
33
|
|
34
|
+
def component_attributes
|
35
|
+
options.merge(id: id, class: component_class)
|
36
|
+
end
|
37
|
+
|
30
38
|
alias accordion? accordion
|
31
39
|
alias stretchable? stretchable
|
32
40
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
|
2
|
-
<% if simple_content? %>
|
3
|
-
|
4
|
-
<% else %>
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
<%= wrapper do %>
|
2
|
+
<% if simple_content? %>
|
3
|
+
<%= tag.div(content, class: "list-group-item") %>
|
4
|
+
<% else %>
|
5
|
+
<%= tag.div(class: "list-group-item expandable-item", data: component_data_options) do %>
|
6
|
+
<div class="expandable-item-header">
|
7
|
+
<%= title %>
|
8
|
+
<%= actions %>
|
9
|
+
</div>
|
10
|
+
<%= tag.div(id: target_id, class: "expandable-item-body collapse", data: body_data_options) do %>
|
11
|
+
<%= body %>
|
12
|
+
<% end %>
|
12
13
|
<% end %>
|
13
14
|
<% end %>
|
14
15
|
<% end %>
|
15
|
-
|
@@ -2,24 +2,42 @@
|
|
2
2
|
|
3
3
|
module Bs5
|
4
4
|
class ExpandableListItemComponent < ViewComponent::Base
|
5
|
+
DEFAULT_WRAPPER_TAG = :div
|
5
6
|
renders_one :title, lambda {
|
6
7
|
ExpandableListItemHeaderTitleComponent.new(target_id: target_id)
|
7
8
|
}
|
8
9
|
renders_one :actions, ExpandableListItemHeaderActionsComponent
|
9
10
|
renders_one :body
|
10
11
|
|
11
|
-
attr_reader :parent_id, :stretchable
|
12
|
+
attr_reader :parent_id, :stretchable, :wrapper_html
|
12
13
|
|
13
14
|
def initialize(options = {})
|
14
15
|
@parent_id = options.delete(:parent_id)
|
15
16
|
@stretchable = options.delete(:stretchable)
|
17
|
+
@wrapper_html = options.delete(:wrapper_html)
|
16
18
|
@options = options
|
17
19
|
end
|
18
20
|
|
19
21
|
private
|
20
22
|
|
23
|
+
def wrapper_html?
|
24
|
+
@wrapper_html.present?
|
25
|
+
end
|
26
|
+
|
27
|
+
def wrapper_tag
|
28
|
+
@wrapper_html.delete(:tag) || DEFAULT_WRAPPER_TAG
|
29
|
+
end
|
30
|
+
|
31
|
+
def wrapper(&block)
|
32
|
+
if wrapper_html?
|
33
|
+
tag.send(wrapper_tag, **wrapper_html, &block)
|
34
|
+
else
|
35
|
+
yield
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
21
39
|
def simple_content?
|
22
|
-
title.
|
40
|
+
title.blank? && body.blank? && actions.blank?
|
23
41
|
end
|
24
42
|
|
25
43
|
def target_id
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bs5_expandable_list_group
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Baselier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|