-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add TailwinCSS 3 support #1762
Open
loqimean
wants to merge
6
commits into
heartcombo:main
Choose a base branch
from
loqimean:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add TailwinCSS 3 support #1762
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7539281
feat(project|lib|test) add TailwinCSS 3 support
loqimean fe620eb
return back changes
loqimean 7948436
Merge branch 'main' into main
loqimean 0641503
feat(lib/simple_form/tags.rb) add data attribute option for item wrapper
loqimean cad1bb9
feat: add missing space in the bottom of file input
loqimean 58cfb2f
Merge branch 'heartcombo:main' into main
loqimean 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 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 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
176 changes: 176 additions & 0 deletions
176
lib/generators/simple_form/templates/config/initializers/simple_form_tailwindcss.rb
This file contains 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,176 @@ | ||
# frozen_string_literal: true | ||
|
||
# Please do not make direct changes to this file! | ||
# The generator is written by author named 'loqimean' | ||
# All future development, tests, and organization should happen there. | ||
# Background history: https://github.com/heartcombo/simple_form/issues/1561 | ||
|
||
# Uncomment this and change the path if necessary to include your own | ||
# components. | ||
# See https://github.com/heartcombo/simple_form#custom-components | ||
# to know more about custom components. | ||
# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f } | ||
|
||
# Use this setup block to configure all options available in SimpleForm. | ||
SimpleForm.setup do |config| | ||
config.wrappers :vertical_form, tag: 'div', class: 'mb-3', error_class: 'form-group-invalid', | ||
valid_class: 'form-group-valid' do |b| | ||
b.use :html5 | ||
b.use :placeholder, class: 'text-gray-400' | ||
b.optional :maxlength | ||
b.optional :minlength | ||
b.optional :pattern | ||
b.optional :min_max | ||
b.optional :readonly | ||
b.use :label, class: 'ml-1 mb-2' | ||
b.use :input, | ||
class: 'mt-1 focus:ring-indigo-500 focus:border-indigo-500 ' \ | ||
'block w-full shadow-sm sm:text-sm border-gray-300 rounded-md', | ||
error_class: 'border-red-400 is-invalid mb-1', valid_class: 'is-valid' | ||
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback text-xs text-red-400' } | ||
b.use :hint, wrap_with: { tag: 'small', class: 'text-gray-400' } | ||
end | ||
|
||
# vertical input for radio buttons and check boxes | ||
config.wrappers :vertical_collection, item_wrapper_class: 'form-check', | ||
item_label_class: 'form-check-label', | ||
tag: 'fieldset', | ||
class: 'form-group mb-3', | ||
error_class: 'form-group-invalid', | ||
valid_class: 'form-group-valid' do |b| | ||
b.use :html5 | ||
b.optional :readonly | ||
b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba| | ||
ba.use :label_text, class: 'ml-3 block text-sm font-medium text-gray-700' | ||
end | ||
b.use :input, class: 'focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 mr-2', | ||
error_class: 'is-invalid border-red-400', | ||
valid_class: 'is-valid' | ||
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback text-xs text-red-400' } | ||
b.use :hint, wrap_with: { tag: 'small', class: 'text-gray-400' } | ||
end | ||
|
||
# vertical input for radio buttons and check boxes | ||
# config.wrappers :vertical_check_boxes_collection, item_wrapper_class: 'form-check', | ||
# item_label_class: 'form-check-label', | ||
# tag: 'fieldset', class: 'form-group mb-3', | ||
# error_class: 'form-group-invalid', | ||
# valid_class: 'form-group-valid' do |b| | ||
# b.use :html5 | ||
# b.optional :readonly | ||
# b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba| | ||
# ba.use :label_text, class: 'ml-3 block text-sm font-medium text-gray-700' | ||
# end | ||
# b.use :input, class: 'focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded mr-2', | ||
# error_class: 'is-invalid border-red-400', | ||
# valid_class: 'is-valid' | ||
# b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback text-xs text-red-400' } | ||
# b.use :hint, wrap_with: { tag: 'small', class: 'text-gray-400' } | ||
# end | ||
|
||
# horizontal input for inline radio buttons and check boxes | ||
config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline', | ||
item_label_class: 'form-check-label', | ||
tag: 'div', | ||
class: 'form-group flex flex-row-reverse w-fit mb-3', | ||
error_class: 'form-group-invalid', | ||
valid_class: 'form-group-valid' do |b| | ||
b.use :html5 | ||
b.optional :readonly | ||
b.use :label, class: 'pt-0 mb-2' | ||
b.wrapper :grid_wrapper, tag: 'div' do |ba| | ||
ba.use :input, class: 'focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded mr-2', | ||
error_class: 'is-invalid', valid_class: 'is-valid' | ||
ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback text-xs text-red-400' } | ||
ba.use :hint, wrap_with: { tag: 'small', class: 'text-gray-400' } | ||
end | ||
end | ||
|
||
# vertical multi select | ||
config.wrappers :vertical_multi_select, tag: 'div', class: 'mb-3', | ||
error_class: 'form-group-invalid', | ||
valid_class: 'form-group-valid' do |b| | ||
b.use :html5 | ||
b.optional :readonly | ||
b.use :label, class: 'mb-2' | ||
b.wrapper tag: 'div', class: 'flex flex-col md:flex-row gap-1 justify-between items-center' do |ba| | ||
ba.use :input, class: 'w-full min-w-fit mt-1 focus:ring-indigo-500 focus:border-indigo-500 block shadow-sm sm:text-sm border-gray-300 rounded-md', | ||
error_class: '!border-red-500', | ||
valid_class: 'is-valid' | ||
end | ||
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback text-xs text-red-400' } | ||
b.use :hint, wrap_with: { tag: 'small', class: 'text-gray-400' } | ||
end | ||
|
||
# vertical input for boolean | ||
config.wrappers :vertical_boolean, tag: 'fieldset', class: 'mb-3', | ||
error_class: 'form-group-invalid', | ||
valid_class: 'form-group-valid' do |b| | ||
b.use :html5 | ||
b.optional :readonly | ||
b.wrapper :form_check_wrapper, tag: 'div' do |bb| | ||
bb.use :input, class: 'focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded mr-2', | ||
error_class: '!border-red-500', | ||
valid_class: 'is-valid' | ||
bb.use :label, class: 'mb-2' | ||
end | ||
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback text-xs text-red-400' } | ||
b.use :hint, wrap_with: { tag: 'small', class: 'text-gray-400' } | ||
end | ||
|
||
# vertical file input | ||
config.wrappers :vertical_file, tag: 'div', | ||
class: 'form-group', | ||
error_class: 'form-group-invalid', | ||
valid_class: 'form-group-valid' do |b| | ||
b.use :html5 | ||
b.use :placeholder | ||
b.optional :maxlength | ||
b.optional :minlength | ||
b.optional :readonly | ||
b.use :label, class: 'mb-2' | ||
b.use :input, class: 'w-full min-w-fit mt-1 focus:ring-indigo-500 focus:border-indigo-500 block shadow-sm sm:text-sm border-gray-300 rounded-md border', | ||
error_class: 'border-red-400 is-invalid mb-1', | ||
valid_class: 'is-valid' | ||
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback text-xs text-red-400' } | ||
b.use :hint, wrap_with: { tag: 'small', class: 'text-gray-400' } | ||
end | ||
|
||
# Custom wrappers for input types. This should be a hash containing an input | ||
# type as key and the wrapper that will be used for all inputs with specified type. | ||
config.wrapper_mappings = { | ||
boolean: :vertical_boolean, | ||
check_boxes: :vertical_collection, | ||
date: :vertical_multi_select, | ||
file: :vertical_file, | ||
datetime: :vertical_multi_select, | ||
radio_buttons: :vertical_collection, | ||
time: :vertical_multi_select | ||
} | ||
|
||
# How the label text should be generated altogether with the required text. | ||
config.label_text = ->(label, required, _explicit_label) { "#{label} #{required}" } | ||
|
||
# CSS class for buttons | ||
config.button_class = 'rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer mb-1' | ||
|
||
# Set this to div to make the checkbox and radio properly work | ||
# otherwise simple_form adds a label tag instead of a div around | ||
# the nested label | ||
config.item_wrapper_tag = :div | ||
|
||
# CSS class to add for error notification helper. | ||
config.error_notification_class = 'bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded' | ||
|
||
# Method used to tidy up errors. Specify any Rails Array method. | ||
# :first lists the first message for each field. | ||
# :to_sentence to list all errors for each field. | ||
config.error_method = :to_sentence | ||
|
||
# The default wrapper to be used by the FormBuilder. | ||
config.default_wrapper = :vertical_form | ||
|
||
# add validation classes to `input_field` | ||
config.input_field_error_class = 'is-invalid' | ||
config.input_field_valid_class = 'is-valid' | ||
end |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @loqimean! Thanks for your contribution!
I noticed that we can use the following snippet at the
config/locales/simple_form.en.yml
file and override theabbr
propsbtw, you should add the simple_form.*.yml into the content array at the
tailwind.config.js
fileThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, nice idea, can you add it to the PR?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure will add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@loqimean I ended up creating a gem to install the tailwind theme and added the locale file automatically. (It also has support for bulma css)
JuanVqz/simple_form-theme#5