forked from maybe-finance/maybe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply default form styling (maybe-finance#272)
* Add and organise component stylesheets * Revert CSS folder and file structure * Add FormsHelper and FormBuilder to apply component classes * Refactor label args Co-authored-by: Jose Farias <[email protected]> Signed-off-by: Josh Brown <[email protected]> * Update form field styles * Apply form builder to all fields * Remove redundant style rules Some of these were either duplicative or had no effect. * Apply default submit button styles * Set default form class * Fix opacity of input when focused --------- Signed-off-by: Josh Brown <[email protected]> Co-authored-by: Jose Farias <[email protected]> Co-authored-by: Josh Pigford <[email protected]>
- Loading branch information
1 parent
f817499
commit df3e14a
Showing
11 changed files
with
131 additions
and
120 deletions.
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
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,58 @@ | ||
class ApplicationFormBuilder < ActionView::Helpers::FormBuilder | ||
def initialize(object_name, object, template, options) | ||
options[:html] ||= {} | ||
options[:html][:class] ||= "space-y-4" | ||
|
||
super(object_name, object, template, options) | ||
end | ||
|
||
(field_helpers - [ :label, :check_box, :radio_button, :fields_for, :fields, :hidden_field, :file_field ]).each do |selector| | ||
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 | ||
def #{selector}(method, options) | ||
default_options = { class: "form-field__input" } | ||
merged_options = default_options.merge(options) | ||
return super(method, merged_options) unless options[:label] | ||
@template.form_field_tag do | ||
label(method, *label_args(options)) + | ||
super(method, merged_options.except(:label)) | ||
end | ||
end | ||
RUBY_EVAL | ||
end | ||
|
||
def select(method, choices, options = {}, html_options = {}) | ||
default_options = { class: "form-field__input" } | ||
merged_options = default_options.merge(html_options) | ||
|
||
return super(method, choices, options, merged_options) unless options[:label] | ||
|
||
@template.form_field_tag do | ||
label(method, *label_args(options)) + | ||
super(method, choices, options, merged_options.except(:label)) | ||
end | ||
end | ||
|
||
def submit(value = nil, options = {}) | ||
value, options = nil, value if value.is_a?(Hash) | ||
default_options = { class: "form-field__submit" } | ||
merged_options = default_options.merge(options) | ||
super(value, merged_options) | ||
end | ||
|
||
private | ||
|
||
def label_args(options) | ||
case options[:label] | ||
when Array | ||
options[:label] | ||
when String | ||
[ options[:label], { class: "form-field__label" } ] | ||
when Hash | ||
[ nil, options[:label] ] | ||
else | ||
[ nil, { class: "form-field__label" } ] | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module FormsHelper | ||
def form_field_tag(&) | ||
tag.div class: "form-field", & | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
<div class="relative p-3 border border-[#141414]/8 bg-white rounded-xl focus-within:bg-white focus-within:shadow-none focus-within:border-gray-900 focus-within:ring-4 focus-within:ring-gray-100 focus-within:opacity-100 shadow-sm"> | ||
<label for="account_name" class="block text-sm font-medium opacity-50 focus-within:opacity-100">Type</label> | ||
<%= f.select :subtype, options_for_select([["Checking", "checking"], ["Savings", "savings"]], selected: ""), {}, class: "block w-full p-0 mt-1 bg-transparent border-none focus:outline-none focus:ring-0" %> | ||
</div> | ||
<%= f.select :subtype, options_for_select([["Checking", "checking"], ["Savings", "savings"]], selected: ""), { label: "Type" } %> |
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 |
---|---|---|
@@ -1,4 +1 @@ | ||
<div class="relative p-3 border border-[#141414]/8 bg-white rounded-xl focus-within:bg-white focus-within:shadow-none focus-within:border-gray-900 focus-within:ring-4 focus-within:ring-gray-100 focus-within:opacity-100 shadow-sm"> | ||
<label for="account_name" class="block text-sm font-medium opacity-50 focus-within:opacity-100">Type</label> | ||
<%= f.select :subtype, options_for_select(Account::Investment::SUBTYPES, selected: ""), {}, class: "block w-full p-0 mt-1 bg-transparent border-none focus:outline-none focus:ring-0" %> | ||
</div> | ||
<%= f.select :subtype, options_for_select(Account::Investment::SUBTYPES, selected: ""), { label: true } %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,10 @@ | |
header_title t('.title') | ||
%> | ||
|
||
<%= form_with url: password_reset_path, html: {class: 'space-y-6'} do |form| %> | ||
<%= form_with url: password_reset_path do |form| %> | ||
<%= auth_messages form %> | ||
|
||
<div class="relative border border-gray-100 bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100"> | ||
<%= form.label :email, class: 'p-4 pb-0 block text-sm font-medium text-gray-700' %> | ||
<%= form.email_field :email, autofocus: false, autocomplete: "email", required: 'required', placeholder: '[email protected]', class: 'p-4 pt-1 bg-transparent border-none opacity-50 focus:outline-none focus:ring-0 focus-within:opacity-100 w-full' %> | ||
</div> | ||
<%= form.email_field :email, label: true, autofocus: false, autocomplete: "email", required: 'required', placeholder: '[email protected]' %> | ||
|
||
<div> | ||
<%= form.submit t('.submit'), class: 'flex justify-center w-full px-4 py-3 text-sm font-medium text-white bg-black rounded-xl hover:bg-black focus:outline-none focus:ring-2 focus:ring-gray-200 shadow' %> | ||
</div> | ||
<%= form.submit t('.submit') %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,32 +2,18 @@ | |
header_title t('.title') | ||
%> | ||
|
||
<%= form_with model: @user, url: registration_path, html: {class: 'space-y-6'} do |form| %> | ||
<%= form_with model: @user, url: registration_path do |form| %> | ||
<%= auth_messages form %> | ||
|
||
<div class="relative border border-gray-100 bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100"> | ||
<%= form.label :email, class: 'p-4 pb-0 block text-sm font-medium text-gray-700' %> | ||
<%= form.email_field :email, autofocus: false, autocomplete: "email", required: 'required', placeholder: '[email protected]', class: 'p-4 pt-1 bg-transparent border-none opacity-50 focus:outline-none focus:ring-0 focus-within:opacity-100 w-full' %> | ||
</div> | ||
<%= form.email_field :email, autofocus: false, autocomplete: "email", required: 'required', placeholder: '[email protected]', label: true %> | ||
|
||
<div class="relative border border-gray-100 bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100"> | ||
<%= form.label :password, class: 'p-4 pb-0 block text-sm font-medium text-gray-700' %> | ||
<%= form.password_field :password, autocomplete: "new-password", required: 'required', class: 'p-4 pt-1 bg-transparent border-none opacity-50 focus:outline-none focus:ring-0 focus-within:opacity-100 w-full' %> | ||
</div> | ||
<%= form.password_field :password, autocomplete: "new-password", required: 'required', label: true %> | ||
|
||
<div class="relative border border-gray-100 bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100"> | ||
<%= form.label :password_confirmation, class: 'p-4 pb-0 block text-sm font-medium text-gray-700' %> | ||
<%= form.password_field :password_confirmation, autocomplete: "new-password", required: 'required', class: 'p-4 pt-1 bg-transparent border-none opacity-50 focus:outline-none focus:ring-0 focus-within:opacity-100 w-full' %> | ||
</div> | ||
<%= form.password_field :password_confirmation, autocomplete: "new-password", required: 'required', label: true %> | ||
|
||
<% if hosted_app? %> | ||
<div class="bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100 relative border border-gray-100"> | ||
<%= form.label :invite_code, class: 'p-4 pb-0 block text-sm font-medium text-gray-700' %> | ||
<%= form.password_field :invite_code, required: 'required', class: 'p-4 pt-1 bg-transparent border-none opacity-50 focus:outline-none focus:ring-0 focus-within:opacity-100 w-full' %> | ||
</div> | ||
<%= form.password_field :invite_code, required: 'required', label: true %> | ||
<% end %> | ||
|
||
<div> | ||
<%= form.submit class: 'cursor-pointer flex justify-center w-full px-4 py-3 text-sm font-medium text-white bg-black rounded-xl hover:bg-black focus:outline-none focus:ring-2 focus:ring-gray-200 shadow' %> | ||
</div> | ||
<%= form.submit %> | ||
<% 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