Skip to content

Commit

Permalink
Merge pull request #18 from matestack/next_release
Browse files Browse the repository at this point in the history
2.1.0 Release
  • Loading branch information
jonasjabari authored Jun 29, 2021
2 parents cef240f + b97dc6b commit 71367e5
Show file tree
Hide file tree
Showing 28 changed files with 10,868 additions and 656 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## v2.1.0 Release - 2021-06-29

### Improvements

- Added flexible column rendering via slots #17
- Added nested form support
- Added textarea component #6

### Bugfixes

- Enable disabled for select and switch #16
- use step, min, max option for all input type, enabling float number input #15

## v2.0.1 Release - 2021-04-12

### Bugfixes
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ gemspec

gem 'rails', '6.1.2'


gem 'rspec-rails', '~> 4.0.2'
gem 'capybara'
gem 'webpacker', '~> 5.0'
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PATH
remote: .
specs:
matestack-ui-bootstrap (2.0.0)
matestack-ui-core (~> 2.0)
matestack-ui-bootstrap (2.1.0)
matestack-ui-core (~> 2.1)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -113,7 +113,7 @@ GEM
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
matestack-ui-core (2.0.0)
matestack-ui-core (2.1.0)
rails (>= 5.2)
method_source (1.0.0)
mimemagic (0.3.10)
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ services:
RAILS_ENV: test
links:
- postgres_test
depends_on:
- postgres_test
ports:
- "33123:33123"
volumes:
Expand Down
101 changes: 97 additions & 4 deletions docs/api/components/smart_collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Docs in progress! Please review the examples.

## Examples

### Example 1: Table rendering with custom row actions
### Table rendering with custom row actions

```ruby
def response
Expand Down Expand Up @@ -72,7 +72,7 @@ def customer_delete_action_config customer
end
```

### Example 2: Table rendering with joined model and formatted col data rendering
### Table rendering with joined model and formatted col data rendering

```ruby
def response
Expand Down Expand Up @@ -119,7 +119,101 @@ def table_item_actions order
end
```

### Example 3: Custom collection rendering
### Table rendering formatted col data rendering access the whole row instance object

```ruby
def response
#...
bs_smart_collection collection_config
#...
end

def collection_config
{
id: 'orders',
items: Order.all,
paginate: 10,
rerender_on: "success",
columns: {
self: {
heading: 'Price in €',
format: -> (order){ "#{order.price_in_euro}" },
}
}
}
end
```

### Table rendering formatted col data rendering access the whole row instance object in multiple columns

```ruby
def response
#...
bs_smart_collection collection_config
#...
end

def collection_config
{
id: 'orders',
items: Order.all,
paginate: 10,
rerender_on: "success",
# the columns hash can only have a key once, fix by specifying the attribute name
columns: {
price_in_euro: {
heading: 'Price in €',
format: -> (column_data){ "#{column_data}" },
},
price_in_euro_again: {
attribute: :price_in_euro, # fix by specifying the attribute name
heading: 'Price in €',
format: -> (column_data){ "#{column_data}" },
},
self: {
heading: 'Price in €',
format: -> (order){ "#{order.price_in_euro}" },
},
self_again: {
attribute: :self, # fix by specifying the attribute name
heading: 'Price in €',
format: -> (order){ "#{order.price_in_euro}" },
}
}
}
end
```

### Table rendering via slot enabling flexible column content composition

```ruby
def response
#...
bs_smart_collection collection_config
#...
end

def collection_config
{
id: 'orders',
items: Order.all,
paginate: 10,
rerender_on: "success",
columns: {
price_in_euro: {
heading: 'Price in € accessed via row object',
slot: method(:price_in_euro_column_slot) # slots ALWAYS get the whole row object passed in!
}
}
}
end

def price_in_euro_column_slot order
bs_badge order.price_in_euro # or whatever you want to do with all kinds of components
end
```

### Custom collection rendering

```ruby
def response
Expand Down Expand Up @@ -183,4 +277,3 @@ def product_delete_action_config product
}
end
```

33 changes: 19 additions & 14 deletions docs/api/form/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,72 +15,77 @@ Renders a Bootstrap input field.
* `browse_button_text` - Expects a string and sets the text to be displayed in the "browse" button for the `:file` input
* `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"
* `variant` - Expects a symbol to change the size of the select menu, you can use either `:sm` or `:lg`
* `min` - Sets the corresponding HTML attribute for the `:range` input type
* `max` - Sets the corresponding HTML attribute for the `:range` input type
* `step` - Sets the corresponding HTML attribute for the `:range` input type
* `min` - Sets the corresponding HTML attribute
* `max` - Sets the corresponding HTML attribute
* `step` - Sets the corresponding HTML attribute
* `show_value` - Expects a boolean. Defaults to `false`, if set to `true` it displays the current value for the corresponding `:range` input type field

## Examples

### Example 1: Basic usage
### Basic usage for text input

```ruby
bs_form_input key: :foo, type: :text
```

### Example 2: Basic usage with label and form text
### Basic usage for float number input

```ruby
bs_form_input key: :foo, type: :number, step: 0.01
```

### Basic usage with label and form text

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

### Example 3: Basic usage as disabled input
### Basic usage as disabled input

```ruby
bs_form_input key: :foo, type: :text, disabled: true
```

returns

### Example 4: Basic usage with custom class
### Basic usage with custom class

```ruby
bs_form_input key: :foo, type: :text, class: "some-class"
```

### Example 5: Basic usage with placeholder
### Basic usage with placeholder

```ruby
bs_form_input key: :foo, type: :text, placeholder: "fill!"
```

### Example 6: Basic usage as range input
### Basic usage as range input

```ruby
bs_form_input key: :some_range_input, type: :range, max: 10
```

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

```ruby
bs_form_input key: :some_range_input, type: :range, step: 2, max: 10, show_value: true
```

### Example 8: Basic usage as file input
### Basic usage as file input

```ruby
bs_form_input key: :some_single_file_input, type: :file
```

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

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

### Example 10: Multi-file input with placeholder and browse\_button\_text
### Multi-file input with placeholder and browse\_button\_text

```ruby
bs_form_input placeholder: "Select a file", browse_button_text: "Click", key: :some_multi_file_input, type: :file, multiple: true
```

19 changes: 16 additions & 3 deletions lib/matestack/ui/bootstrap/content/smart_collection/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ def table_footer

def cell(data, key, value)
td class: cell_class(value) do
plain cell_text(data, key, value)
if value.is_a?(Hash) && value[:slot]
value[:slot].call(data)
else
plain cell_text(data, key, value)
end
end
end

Expand All @@ -81,8 +85,17 @@ def cell_class(value)
end

def cell_text(data, key, value)
text = data.instance_eval(key.to_s)
text = value[:format].call(text) if value.is_a?(Hash) && value[:format]
if value.is_a?(Hash)
if value[:attribute].present?
text = data.instance_eval(value[:attribute].to_s)
else
text = data.instance_eval(key.to_s)
end
text = value[:format].call(text) if value[:format].present?
else
text = data.instance_eval(key.to_s)
end

text
end

Expand Down
19 changes: 14 additions & 5 deletions lib/matestack/ui/bootstrap/form/checkbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Matestack::Ui::Bootstrap::Form::Checkbox < Matestack::Ui::VueJs::Component

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

private

def bootstrap_attributes
classes = 'form-check-input'
classes = [options[:class], classes].join(' ')
{
class: classes,
disabled: context.disabled
}
end

def multiple?
checkbox_options.present?
end
Expand All @@ -28,15 +37,15 @@ def render_options
if multiple?
checkbox_options.to_a.each do |item|
checkbox_wrapper do
input options.merge(checkbox_attributes(item)).merge(class: 'form-check-input')
input options.merge(checkbox_attributes(item)).merge(bootstrap_attributes)
bootstrap_label text: item_label(item), for_input: item_id(item)
end
end
# checked/unchecked checkbox (true/false checkbox)
else
checkbox_wrapper do
input true_false_checkbox_attributes.merge(type: :hidden, id: nil, value: 0)
input true_false_checkbox_attributes.merge(type: :checkbox, id: item_id(1), class: 'form-check-input')
input true_false_checkbox_attributes.merge(type: :checkbox, ":id": item_id(1)).merge(bootstrap_attributes)

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

def bootstrap_label(text:, for_input:)
label text, for: for_input, class: 'form-check-label'
label text, ":for": for_input, class: 'form-check-label'
end

def render_errors
Expand All @@ -73,7 +82,7 @@ def checkbox_options
end

def render_form_text
div id: "form_text_for_#{attribute_key}", class: "form-text" do
div class: "form-text form-text-for-#{attribute_key}" do
plain context.form_text
end
end
Expand Down
Loading

0 comments on commit 71367e5

Please sign in to comment.