Skip to content

Commit

Permalink
Add form previews
Browse files Browse the repository at this point in the history
  • Loading branch information
unabris committed Oct 6, 2024
1 parent ae42e66 commit 21f2c02
Show file tree
Hide file tree
Showing 32 changed files with 553 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

&-link {
margin-left: 30px;
padding: 6px 0;
padding: 6px 0 !important;
}
}
5 changes: 0 additions & 5 deletions site/app/controllers/home_controller.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :boolean,
as: :boolean,
required:,
label: label ? nil : false,
disabled:,
error: error ? t('simple_form.errors.boolean') : false %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :check_boxes,
as: :check_boxes,
collection: [[0, 'Email'], [1, 'Phone (SMS)'], [2, 'Push notification']],
label_method: :second,
value_method: :first,
label: label ? nil : false,
checked: 0,
disabled:,
required:,
error: error ? t('simple_form.errors.check_boxes') : false %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :radio_buttons,
as: :radio_buttons,
collection: [[0, 'Email'], [1, 'Phone (SMS)'], [2, 'Push notification']],
label_method: :second,
value_method: :first,
label: label ? nil : false,
checked: 0,
disabled:,
required:,
error: error ? t('simple_form.errors.radio_buttons') : false %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :country,
as: :country,
required:,
label: label ? nil : false,
hint: hint ? nil : false,
prompt: prompt ? :translate : false,
disabled:,
error: error ? t('simple_form.errors.country') : false,
selected: error ? t('simple_form.values.country') : false %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :select,
collection: collection_for(:select),
required:,
label: label ? nil : false,
hint: hint ? nil : false,
prompt: prompt ? :translate : false,
disabled:,
error: error ? t('simple_form.errors.select') : false,
selected: disabled || error ? t('simple_form.values.select') : false %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :decimal,
as: :decimal,
required:,
label: label ? nil : false,
hint: hint ? nil : false,
placeholder: placeholder ? nil : false,
disabled:,
error: error ? t('simple_form.errors.decimal') : false,
input_html: { value: disabled || error ? t('simple_form.values.decimal') : false } %>
<% end %>
11 changes: 11 additions & 0 deletions site/app/views/lookbook/previews/forms/text_inputs/_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :email,
as: :email,
required:,
label: label ? nil : false,
hint: hint ? nil : false,
placeholder: placeholder ? nil : false,
disabled:,
error: error ? t('simple_form.errors.email') : false,
input_html: { value: disabled || error ? t('simple_form.values.email') : false } %>
<% end %>
11 changes: 11 additions & 0 deletions site/app/views/lookbook/previews/forms/text_inputs/_float.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :float,
as: :float,
required:,
label: label ? nil : false,
hint: hint ? nil : false,
placeholder: placeholder ? nil : false,
disabled:,
error: error ? t('simple_form.errors.float') : false,
input_html: { value: disabled || error ? t('simple_form.values.float') : false } %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :integer,
as: :integer,
required:,
label: label ? nil : false,
hint: hint ? nil : false,
placeholder: placeholder ? nil : false,
disabled:,
error: error ? t('simple_form.errors.integer') : false,
input_html: { value: disabled || error ? t('simple_form.values.integer') : false } %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :password,
as: :password,
required:,
label: label ? nil : false,
hint: hint ? nil : false,
placeholder: placeholder ? nil : false,
disabled:,
error: error ? t('simple_form.errors.password') : false,
input_html: { value: disabled || error ? t('simple_form.values.password') : false } %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :string,
as: :string,
required:,
label: label ? nil : false,
hint: hint ? nil : false,
placeholder: placeholder ? nil : false,
disabled:,
error: error ? t('simple_form.errors.string') : false,
input_html: { value: disabled || error ? t('simple_form.values.string') : false } %>
<% end %>
11 changes: 11 additions & 0 deletions site/app/views/lookbook/previews/forms/text_inputs/_tel.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :tel,
as: :tel,
required:,
label: label ? nil : false,
hint: hint ? nil : false,
placeholder: placeholder ? nil : false,
disabled:,
error: error ? t('simple_form.errors.tel') : false,
input_html: { value: disabled || error ? t('simple_form.values.tel') : false } %>
<% end %>
11 changes: 11 additions & 0 deletions site/app/views/lookbook/previews/forms/text_inputs/_url.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= simple_fields_for nil do |f| %>
<%= f.input :url,
as: :url,
required:,
label: label ? nil : false,
hint: hint ? nil : false,
placeholder: placeholder ? nil : false,
disabled:,
error: error ? t('simple_form.errors.url') : false,
input_html: { value: disabled || error ? t('simple_form.values.url') : false } %>
<% end %>
22 changes: 0 additions & 22 deletions site/app/views/pwa/manifest.json.erb

This file was deleted.

26 changes: 0 additions & 26 deletions site/app/views/pwa/service-worker.js

This file was deleted.

9 changes: 3 additions & 6 deletions site/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ module Site
class Application < Rails::Application
config.load_defaults Rails::VERSION::STRING.to_f

# For compatibility with applications that use this config
config.action_controller.include_all_helpers = false

# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.
# Common ones are `templates`, `generators`, or `middleware`, for example.
Expand All @@ -51,7 +48,8 @@ def fetch_asset_files(data)
end
end

asset_panel_config = {
Lookbook.define_panel(
'assets',
label: 'Assets',
partial: 'lookbook/panels/assets',
hotkey: 'a',
Expand All @@ -64,8 +62,7 @@ def fetch_asset_files(data)

{ assets: }
end
}
Lookbook.define_panel('assets', asset_panel_config)
)

config.lookbook.project_name = "Beyond Essence v#{BeyondEssence::VERSION}"
config.lookbook.component_paths = [BeyondEssence::Engine.root.join('app/components')]
Expand Down
97 changes: 67 additions & 30 deletions site/config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,68 @@
# Files in the config/locales directory are used for internationalization and
# are automatically loaded by Rails. If you want to use locales other than
# English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t "hello"
#
# In views, this is aliased to just `t`:
#
# <%= t("hello") %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more about the API, please read the Rails Internationalization guide
# at https://guides.rubyonrails.org/i18n.html.
#
# Be aware that YAML interprets the following case-insensitive strings as
# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings
# must be quoted to be interpreted as strings. For example:
#
# en:
# "yes": yup
# enabled: "ON"

en:
hello: "Hello world"
simple_form:
errors:
boolean: 'You must accept the terms and conditions.'
check_boxes: 'Not a valid option.'
country: 'Not a valid country.'
email: 'Enter a valid email.'
float: 'Enter a valid height.'
decimal: 'Enter a valid price.'
integer: 'Enter a valid age.'
password: 'Enter a valid password.'
radio_buttons: 'Not a valid option.'
select: 'Not a valid gender.'
string: 'Enter a valid name.'
tel: 'Enter a valid phone number.'
url: 'Enter a valid URL.'
values:
country: 'ES'
email: 'you@example'
float: '3.67'
decimal: '1234.56'
integer: '30.5'
password: 'password'
select: 'female'
string: 'John'
tel: '123456789'
url: 'https:/example.com'
labels:
defaults:
boolean: 'Accept terms and conditions'
check_boxes: 'Notifications'
country: 'Country'
decimal: 'Price'
email: 'Email'
float: 'Height'
integer: 'Age'
password: 'Password'
radio_buttons: 'Notifications'
select: 'Gender'
string: 'Name'
tel: 'Phone number'
url: 'Website URL'
hints:
defaults:
country: 'Choose the country where you reside or operate.'
decimal: 'Enter the amount in dollars and cents (e.g., 1234.56).'
email: 'Make sure to include "@" and a domain name (e.g., ".com", ".org").'
float: 'Enter the height in meters and centimeters (e.g., 1.75).'
integer: 'Age should be a whole number without any decimal points.'
password: 'Password must be at least 8 characters long and contain a mix of letters and numbers.'
select: 'Choose a gender with which you identify.'
string: 'Enter your first name and last name.'
tel: 'Please include your country code.'
url: 'Include http:// or https:// in the URL.'
placeholders:
defaults:
decimal: '1234.56'
email: 'you@example.com'
float: '1.75'
integer: '30'
password: 'Password123!'
string: 'John Doe'
tel: '+1234567890'
url: 'https://www.example.com'
prompts:
defaults:
country: 'Select your country'
select: 'Select your gender'
23 changes: 23 additions & 0 deletions spec/components/previews/forms/boolean_inputs/boolean_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Forms
module BooleanInputs
#
# @display wrapper card
#
class BooleanPreview < Lookbook::Preview
#
# @param required toggle
# @param label toggle
# @param disabled toggle
# @param error toggle
#
def base(required: true,
label: true,
disabled: false,
error: false)
render 'lookbook/previews/forms/boolean_inputs/boolean', required:, disabled:, label:, error:
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Forms
module CollectionInputs
#
# @display wrapper card
#
class CheckBoxesPreview < Lookbook::Preview
#
# @param required toggle
# @param label toggle
# @param disabled toggle
# @param error toggle
#
def base(required: true,
label: true,
disabled: false,
error: false)
render 'lookbook/previews/forms/collection_inputs/check_boxes', required:, disabled:, label:, error:
end
end
end
end
Loading

0 comments on commit 21f2c02

Please sign in to comment.