Skip to content

Commit 71367e5

Browse files
authored
Merge pull request #18 from matestack/next_release
2.1.0 Release
2 parents cef240f + b97dc6b commit 71367e5

File tree

28 files changed

+10868
-656
lines changed

28 files changed

+10868
-656
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## v2.1.0 Release - 2021-06-29
4+
5+
### Improvements
6+
7+
- Added flexible column rendering via slots #17
8+
- Added nested form support
9+
- Added textarea component #6
10+
11+
### Bugfixes
12+
13+
- Enable disabled for select and switch #16
14+
- use step, min, max option for all input type, enabling float number input #15
15+
316
## v2.0.1 Release - 2021-04-12
417

518
### Bugfixes

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ gemspec
2323

2424
gem 'rails', '6.1.2'
2525

26-
2726
gem 'rspec-rails', '~> 4.0.2'
2827
gem 'capybara'
2928
gem 'webpacker', '~> 5.0'

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
PATH
22
remote: .
33
specs:
4-
matestack-ui-bootstrap (2.0.0)
5-
matestack-ui-core (~> 2.0)
4+
matestack-ui-bootstrap (2.1.0)
5+
matestack-ui-core (~> 2.1)
66

77
GEM
88
remote: https://rubygems.org/
@@ -113,7 +113,7 @@ GEM
113113
mini_mime (>= 0.1.1)
114114
marcel (0.3.3)
115115
mimemagic (~> 0.3.2)
116-
matestack-ui-core (2.0.0)
116+
matestack-ui-core (2.1.0)
117117
rails (>= 5.2)
118118
method_source (1.0.0)
119119
mimemagic (0.3.10)

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ services:
4949
RAILS_ENV: test
5050
links:
5151
- postgres_test
52+
depends_on:
53+
- postgres_test
5254
ports:
5355
- "33123:33123"
5456
volumes:

docs/api/components/smart_collection.md

Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Docs in progress! Please review the examples.
1010

1111
## Examples
1212

13-
### Example 1: Table rendering with custom row actions
13+
### Table rendering with custom row actions
1414

1515
```ruby
1616
def response
@@ -72,7 +72,7 @@ def customer_delete_action_config customer
7272
end
7373
```
7474

75-
### Example 2: Table rendering with joined model and formatted col data rendering
75+
### Table rendering with joined model and formatted col data rendering
7676

7777
```ruby
7878
def response
@@ -119,7 +119,101 @@ def table_item_actions order
119119
end
120120
```
121121

122-
### Example 3: Custom collection rendering
122+
### Table rendering formatted col data rendering access the whole row instance object
123+
124+
```ruby
125+
def response
126+
#...
127+
bs_smart_collection collection_config
128+
#...
129+
end
130+
131+
def collection_config
132+
{
133+
id: 'orders',
134+
items: Order.all,
135+
paginate: 10,
136+
rerender_on: "success",
137+
columns: {
138+
self: {
139+
heading: 'Price in €',
140+
format: -> (order){ "#{order.price_in_euro}" },
141+
}
142+
}
143+
}
144+
end
145+
```
146+
147+
### Table rendering formatted col data rendering access the whole row instance object in multiple columns
148+
149+
```ruby
150+
def response
151+
#...
152+
bs_smart_collection collection_config
153+
#...
154+
end
155+
156+
def collection_config
157+
{
158+
id: 'orders',
159+
items: Order.all,
160+
paginate: 10,
161+
rerender_on: "success",
162+
# the columns hash can only have a key once, fix by specifying the attribute name
163+
columns: {
164+
price_in_euro: {
165+
heading: 'Price in €',
166+
format: -> (column_data){ "#{column_data}" },
167+
},
168+
price_in_euro_again: {
169+
attribute: :price_in_euro, # fix by specifying the attribute name
170+
heading: 'Price in €',
171+
format: -> (column_data){ "#{column_data}" },
172+
},
173+
self: {
174+
heading: 'Price in €',
175+
format: -> (order){ "#{order.price_in_euro}" },
176+
},
177+
self_again: {
178+
attribute: :self, # fix by specifying the attribute name
179+
heading: 'Price in €',
180+
format: -> (order){ "#{order.price_in_euro}" },
181+
}
182+
}
183+
}
184+
end
185+
```
186+
187+
### Table rendering via slot enabling flexible column content composition
188+
189+
```ruby
190+
def response
191+
#...
192+
bs_smart_collection collection_config
193+
#...
194+
end
195+
196+
def collection_config
197+
{
198+
id: 'orders',
199+
items: Order.all,
200+
paginate: 10,
201+
rerender_on: "success",
202+
columns: {
203+
price_in_euro: {
204+
heading: 'Price in € accessed via row object',
205+
slot: method(:price_in_euro_column_slot) # slots ALWAYS get the whole row object passed in!
206+
}
207+
}
208+
}
209+
end
210+
211+
def price_in_euro_column_slot order
212+
bs_badge order.price_in_euro # or whatever you want to do with all kinds of components
213+
end
214+
```
215+
216+
### Custom collection rendering
123217

124218
```ruby
125219
def response
@@ -183,4 +277,3 @@ def product_delete_action_config product
183277
}
184278
end
185279
```
186-

docs/api/form/input.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,72 +15,77 @@ Renders a Bootstrap input field.
1515
* `browse_button_text` - Expects a string and sets the text to be displayed in the "browse" button for the `:file` input
1616
* `placeholder` - Expects a string to be displayed as a placeholder for whatever the user decides to choose for the `:file` input. Defaults to "Choose file"
1717
* `variant` - Expects a symbol to change the size of the select menu, you can use either `:sm` or `:lg`
18-
* `min` - Sets the corresponding HTML attribute for the `:range` input type
19-
* `max` - Sets the corresponding HTML attribute for the `:range` input type
20-
* `step` - Sets the corresponding HTML attribute for the `:range` input type
18+
* `min` - Sets the corresponding HTML attribute
19+
* `max` - Sets the corresponding HTML attribute
20+
* `step` - Sets the corresponding HTML attribute
2121
* `show_value` - Expects a boolean. Defaults to `false`, if set to `true` it displays the current value for the corresponding `:range` input type field
2222

2323
## Examples
2424

25-
### Example 1: Basic usage
25+
### Basic usage for text input
2626

2727
```ruby
2828
bs_form_input key: :foo, type: :text
2929
```
3030

31-
### Example 2: Basic usage with label and form text
31+
### Basic usage for float number input
32+
33+
```ruby
34+
bs_form_input key: :foo, type: :number, step: 0.01
35+
```
36+
37+
### Basic usage with label and form text
3238

3339
```ruby
3440
bs_form_input key: :foo, type: :text, label: "Input field", form_text: "some notes"
3541
```
3642

37-
### Example 3: Basic usage as disabled input
43+
### Basic usage as disabled input
3844

3945
```ruby
4046
bs_form_input key: :foo, type: :text, disabled: true
4147
```
4248

4349
returns
4450

45-
### Example 4: Basic usage with custom class
51+
### Basic usage with custom class
4652

4753
```ruby
4854
bs_form_input key: :foo, type: :text, class: "some-class"
4955
```
5056

51-
### Example 5: Basic usage with placeholder
57+
### Basic usage with placeholder
5258

5359
```ruby
5460
bs_form_input key: :foo, type: :text, placeholder: "fill!"
5561
```
5662

57-
### Example 6: Basic usage as range input
63+
### Basic usage as range input
5864

5965
```ruby
6066
bs_form_input key: :some_range_input, type: :range, max: 10
6167
```
6268

63-
### Example 7: Using range input with show\_value and non-default steps
69+
### Using range input with show\_value and non-default steps
6470

6571
```ruby
6672
bs_form_input key: :some_range_input, type: :range, step: 2, max: 10, show_value: true
6773
```
6874

69-
### Example 8: Basic usage as file input
75+
### Basic usage as file input
7076

7177
```ruby
7278
bs_form_input key: :some_single_file_input, type: :file
7379
```
7480

75-
### Example 9: File input with non-default size and optional form\_text
81+
### File input with non-default size and optional form\_text
7682

7783
```ruby
7884
bs_form_input variant: :lg, form_text: "just some notes", key: :some_single_file_input, type: :file
7985
```
8086

81-
### Example 10: Multi-file input with placeholder and browse\_button\_text
87+
### Multi-file input with placeholder and browse\_button\_text
8288

8389
```ruby
8490
bs_form_input placeholder: "Select a file", browse_button_text: "Click", key: :some_multi_file_input, type: :file, multiple: true
8591
```
86-

lib/matestack/ui/bootstrap/content/smart_collection/content.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ def table_footer
6969

7070
def cell(data, key, value)
7171
td class: cell_class(value) do
72-
plain cell_text(data, key, value)
72+
if value.is_a?(Hash) && value[:slot]
73+
value[:slot].call(data)
74+
else
75+
plain cell_text(data, key, value)
76+
end
7377
end
7478
end
7579

@@ -81,8 +85,17 @@ def cell_class(value)
8185
end
8286

8387
def cell_text(data, key, value)
84-
text = data.instance_eval(key.to_s)
85-
text = value[:format].call(text) if value.is_a?(Hash) && value[:format]
88+
if value.is_a?(Hash)
89+
if value[:attribute].present?
90+
text = data.instance_eval(value[:attribute].to_s)
91+
else
92+
text = data.instance_eval(key.to_s)
93+
end
94+
text = value[:format].call(text) if value[:format].present?
95+
else
96+
text = data.instance_eval(key.to_s)
97+
end
98+
8699
text
87100
end
88101

lib/matestack/ui/bootstrap/form/checkbox.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Matestack::Ui::Bootstrap::Form::Checkbox < Matestack::Ui::VueJs::Component
1010

1111
def response
1212
div class: "matestack-ui-bootstrap-form-checkbox" do
13-
label input_label, class: "form-label", for: attribute_key if input_label && multiple?
13+
label input_label, class: "form-label", ":for": id if input_label && multiple?
1414
render_options
1515
render_errors
1616
render_form_text unless context.form_text.nil? # otherwise renders empty div
@@ -19,6 +19,15 @@ def response
1919

2020
private
2121

22+
def bootstrap_attributes
23+
classes = 'form-check-input'
24+
classes = [options[:class], classes].join(' ')
25+
{
26+
class: classes,
27+
disabled: context.disabled
28+
}
29+
end
30+
2231
def multiple?
2332
checkbox_options.present?
2433
end
@@ -28,15 +37,15 @@ def render_options
2837
if multiple?
2938
checkbox_options.to_a.each do |item|
3039
checkbox_wrapper do
31-
input options.merge(checkbox_attributes(item)).merge(class: 'form-check-input')
40+
input options.merge(checkbox_attributes(item)).merge(bootstrap_attributes)
3241
bootstrap_label text: item_label(item), for_input: item_id(item)
3342
end
3443
end
3544
# checked/unchecked checkbox (true/false checkbox)
3645
else
3746
checkbox_wrapper do
3847
input true_false_checkbox_attributes.merge(type: :hidden, id: nil, value: 0)
39-
input true_false_checkbox_attributes.merge(type: :checkbox, id: item_id(1), class: 'form-check-input')
48+
input true_false_checkbox_attributes.merge(type: :checkbox, ":id": item_id(1)).merge(bootstrap_attributes)
4049

4150
bootstrap_label text: input_label, for_input: item_id(1)
4251
end
@@ -53,7 +62,7 @@ def checkbox_wrapper(options = {}, &block)
5362
end
5463

5564
def bootstrap_label(text:, for_input:)
56-
label text, for: for_input, class: 'form-check-label'
65+
label text, ":for": for_input, class: 'form-check-label'
5766
end
5867

5968
def render_errors
@@ -73,7 +82,7 @@ def checkbox_options
7382
end
7483

7584
def render_form_text
76-
div id: "form_text_for_#{attribute_key}", class: "form-text" do
85+
div class: "form-text form-text-for-#{attribute_key}" do
7786
plain context.form_text
7887
end
7988
end

0 commit comments

Comments
 (0)