Skip to content
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

[WIP] Showcase Example for Field Partials #188

Merged
merged 11 commits into from
Aug 12, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% showcase.description do %>
When you're building forms, use Bullet Train's Field Partials for your form fields. They DRY-up all the presentation logic without needing a third-party dependency like Formtastic.
<br/>
<br/>
Read much more about them in the extensive <a href="https://bullettrain.co/docs/field-partials" target="_blank">developer documentation</a>.
<% end %>

<% form_with model: Scaffolding::CompletelyConcrete::TangibleThing.new, url: "#" do |form| %>
<% yield form %>
<% end %>

<%# To display further options use `showcase.options.x` as options with a block will clear the old options. See `_options.html.erb` for an example. %>
<% showcase.options do |o| %>
<% o.required :form, "Reference to the form object", type: "ActionView::Helpers::FormBuilder" %>
<% o.required :method, "Attribute of the model" %>
<% o.optional :options, "Options passed directly to the underlying Rails form field helper.", default: {} %>
<% o.optional :other_options, "Additional options for things like hiding labels, displaying specific error messages, etc.", default: {} %>
<% o.optional "other_options[:icon]", "Display an icon." %>
<% o.optional "other_options[:label]", "Display a specific field label." %>
<% o.optional "other_options[:hide_label]", "Hide the field label.", default: false %>
<% o.optional "other_options[:help]", "Display a specific help string." %>
<% o.optional "other_options[:error]", "Display a specific error string." %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Single Basic Button" do %>
<%= render "shared/fields/buttons", form: form, method: :button_value %>
<% end %>

<% showcase.sample "Multiple Buttons" do %>
<%= render "shared/fields/buttons", form: form, method: :multiple_button_values, multiple: true %>
<% end %>

<% showcase.sample "Boolean Button" do %>
<%= render "shared/fields/buttons", form: form, method: :boolean_button_value %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic", description: "Requires an `ENV['CLOUDINARY_URL']` is set to render anything." do %>
<%= "ENV['CLOUDINARY_URL'] hasn't been set." unless cloudinary_enabled? %>
<%= render 'shared/fields/cloudinary_image', form: form, method: :cloudinary_image_value %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/color_picker', form: form,
method: :color_picker_value,
options: {color_picker_options: t('scaffolding/completely_concrete/tangible_things.fields.color_picker_value.options')} %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/date_and_time_field', form: form, method: :created_at %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/date_field', form: form, method: :created_at %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/email_field', form: form, method: :email_field_value %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/emoji_field', form: form, method: :text_field_value %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/file_field', form: form, method: :file_field_value %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/number_field', form: form, method: :number_field_value %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Single Option" do %>
<%= render 'shared/fields/options', form: form, method: :option_value %>
<% end %>

<% showcase.sample "Multiple Option" do %>
<%= render 'shared/fields/options', form: form, method: :multiple_option_values, multiple: true, show_select_all_top: true %>
<% end %>
<% end %>

<% showcase.options.optional :multiple, "Whether to select single or multiple values", default: false %>
<% showcase.options.optional :show_select_all_top, "Whether to put the select all toggle before the options", default: false %>
<% showcase.options.optional :show_select_all_bottom, "Whether to put the select all toggle after the options", default: false %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/password_field', form: form, method: :password_field_value %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/phone_field', form: form, method: :phone_field_value %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Single Select" do %>
<%= render 'shared/fields/super_select', form: form, method: :super_select_value, other_options: {search: true} %>
<% end %>

<% showcase.sample "Multiple Select" do %>
<%= render 'shared/fields/super_select', form: form, method: :multiple_super_select_values, other_options: {search: true}, html_options: {multiple: true} %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/text_area', form: form, method: :text_area_value %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/text_field', form: form, method: :text_field_value %>
<% end %>

<% showcase.sample "With Icon" do %>
<%= render 'shared/fields/text_field', form: form, icon: 'Test', method: :text_field_value,
other_options: { label: 'New Label', hide_label: true, help: 'I am help text', error: "Error Text", icon: 'fal fa-sign-out ti ti-close' } %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render "showcase/previews/field_partials/about_field_partials", showcase: showcase do |form| %>
<% showcase.sample "Basic" do %>
<%= render 'shared/fields/trix_editor', form: form, method: :trix_editor_value %>
<% end %>
<% end %>