-
Notifications
You must be signed in to change notification settings - Fork 0
Simple Form Segmented Control Input #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7a24b5d
Add segmented control input
Jeremy-Walton 013693b
Add spec for simple form and replace deprecated method
Jeremy-Walton 37838cc
Update Optics related inputs to specify their version number availabi…
Jeremy-Walton cf551f0
Bump version number
Jeremy-Walton 836a95c
Remove unnecessary option
Jeremy-Walton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| PATH | ||
| remote: . | ||
| specs: | ||
| rolemodel_rails (0.21.0) | ||
| rolemodel_rails (0.22.0) | ||
|
|
||
| GEM | ||
| remote: https://rubygems.org/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb
Jeremy-Walton marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # SegmentedControlInput is a custom input type for SimpleForm that renders a radio group as an optics (v2.2.0+) segmented control | ||
| # | ||
| # Options: | ||
| # :size (:small, :medium, :large) - renders the control at different sizes | ||
| # :full_width - renders the control to take the full width of its container | ||
| # | ||
| # Usage: | ||
| # <%= f.input :my_field, as: :segmented_control, collection: collection_options %> | ||
| # <%= f.input :my_field, as: :segmented_control, collection: collection_options, size: :small %> | ||
| # <%= f.input :my_field, as: :segmented_control, collection: collection_options, disabled: true %> | ||
| # <%= f.input :my_field, as: :segmented_control, collection: collection_options, full_width: true %> | ||
| class SegmentedControlInput < SimpleForm::Inputs::CollectionRadioButtonsInput | ||
| def input_type | ||
| 'radio_buttons' | ||
| end | ||
|
|
||
| def input_options | ||
| options = super | ||
| options[:item_wrapper_tag] = false | ||
| options[:collection_wrapper_tag] = 'div' | ||
| options[:collection_wrapper_class] = collection_wrapper_classes | ||
| options[:item_label_class] = 'segmented-control__label' | ||
| options | ||
| end | ||
|
|
||
| def input_html_options | ||
| super.tap do |options| | ||
| options[:class].delete('form-control') | ||
| end | ||
| end | ||
Jeremy-Walton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def input_html_classes | ||
| classes = super | ||
| classes.push('segmented-control__input') | ||
| classes | ||
Jeremy-Walton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| private | ||
|
|
||
| def collection_wrapper_classes | ||
| class_names( | ||
| 'segmented-control', | ||
| options[:class], | ||
| "segmented-control--#{options[:size]}": options[:size].present?, | ||
Jeremy-Walton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 'segmented-control--full-width': options[:full_width].present? | ||
| ) | ||
| end | ||
| end | ||
2 changes: 1 addition & 1 deletion
2
lib/generators/rolemodel/simple_form/templates/app/inputs/switch_checkbox_input.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module RolemodelRails | ||
| VERSION = '0.21.0' | ||
| VERSION = '0.22.0' | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| require 'spec_helper' | ||
|
|
||
| RSpec.describe Rolemodel::SimpleFormGenerator, type: :generator do | ||
| before { run_generator_against_test_app } | ||
|
|
||
| it 'generates a simple form initializer' do | ||
| assert_file 'config/initializers/simple_form.rb' | ||
| end | ||
|
|
||
| it 'generates custom input files' do | ||
| assert_file 'app/inputs/collection_check_boxes_input.rb' | ||
| assert_file 'app/inputs/collection_select_input.rb' | ||
| assert_file 'app/inputs/grouped_collection_select_input.rb' | ||
| assert_file 'app/inputs/segmented_control_input.rb' | ||
| assert_file 'app/inputs/switch_checkbox_input.rb' | ||
| assert_file 'app/inputs/tailored_select_input.rb' | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.