diff --git a/admin/app/components/solidus_admin/products/show/component.html.erb b/admin/app/components/solidus_admin/products/show/component.html.erb index f50a5a2af10..edde127bff7 100644 --- a/admin/app/components/solidus_admin/products/show/component.html.erb +++ b/admin/app/components/solidus_admin/products/show/component.html.erb @@ -36,18 +36,15 @@
<%= render component('ui/panel').new do %> - <%= render component("ui/forms/text_field").new(field: :name, builder: f) %> - <%= render component("ui/forms/text_field").new(field: :slug, builder: f) %> - <%= render component("ui/forms/text_area").new(field: :description, builder: f) %> + <%= render component("ui/forms/field").text_field(f, :name) %> + <%= render component("ui/forms/field").text_field(f, :slug) %> + <%= render component("ui/forms/field").text_area(f, :description) %> <% end %> <%= render component('ui/panel').new(title: 'SEO', title_hint: 'Search Engine Optimization') do %> - <%= render component("ui/forms/text_field").new(field: :meta_title, builder: f) %> - <%= render component("ui/forms/text_field").new( - field: :meta_description, - builder: f - ) %> - <%= render component("ui/forms/text_area").new(field: :meta_keywords, builder: f) %> + <%= render component("ui/forms/field").text_field(f, :meta_title) %> + <%= render component("ui/forms/field").text_field(f, :meta_description) %> + <%= render component("ui/forms/field").text_area(f, :meta_keywords) %> <% end %> <%= render component('ui/panel').new(title: "Media") do |panel| %> @@ -58,15 +55,15 @@ <% end %> <%= render component('ui/panel').new(title: 'Pricing') do %> - <%= render component("ui/forms/text_field").new(field: :price, builder: f) %> + <%= render component("ui/forms/field").text_field(f, :price) %>
- <%= render component("ui/forms/text_field").new(field: :cost_price, builder: f) %> - <%= render component("ui/forms/text_field").new(field: :cost_currency, builder: f) %> + <%= render component("ui/forms/field").text_field(f, :cost_price) %> + <%= render component("ui/forms/field").text_field(f, :cost_currency) %>
<% end %> <%= render component('ui/panel').new(title: 'Stock') do |panel| %> - <%= render component("ui/forms/text_field").new(field: :sku, builder: f) %> + <%= render component("ui/forms/field").text_field(f, :sku) %> <% panel.with_action( name: t(".manage_stock"), @@ -75,30 +72,28 @@ <% end %> <%= render component('ui/panel').new(title: 'Shipping') do %> - <%= render component("ui/forms/select").new( - field: :shipping_category_id, + <%= render component("ui/forms/field").select( + f, + :shipping_category_id, + [[t(".none"), nil]] + Spree::ShippingCategory.order(:name).pluck(:name, :id), tip: t(".hints.shipping_category_html"), - choices: - [[t(".none"), nil]] + Spree::ShippingCategory.order(:name).pluck(:name, :id), - builder: f ) %> - <%= render component("ui/forms/select").new( - field: :tax_category_id, + <%= render component("ui/forms/field").select( + f, + :tax_category_id, + [[t(".none"), nil]] + Spree::TaxCategory.order(:name).pluck(:name, :id), tip: t( ".hints.tax_category_html", default_tax_category: Spree::TaxCategory.default&.name ), - choices: - [[t(".none"), nil]] + Spree::TaxCategory.order(:name).pluck(:name, :id), - builder: f ) %> <% end %> <%= render component('ui/panel').new(title: "Options") do %> - <%= render component("ui/forms/select").new( - field: :option_type_ids, - choices: option_type_options, - builder: f, + <%= render component("ui/forms/field").select( + f, + :option_type_ids, + option_type_options, multiple: true, "size" => option_type_options.size, ) %> @@ -114,16 +109,8 @@
diff --git a/admin/app/components/solidus_admin/ui/forms/field/component.html.erb b/admin/app/components/solidus_admin/ui/forms/field/component.html.erb index fc0e7e22474..d91ea825ade 100644 --- a/admin/app/components/solidus_admin/ui/forms/field/component.html.erb +++ b/admin/app/components/solidus_admin/ui/forms/field/component.html.erb @@ -9,7 +9,11 @@ <%= render component('ui/toggletip').new(text: @tip) if @tip.present? %>
- <%= content %> + <% if @input_attributes %> + <%= render component('ui/forms/input').new(**@input_attributes) %> + <% else %> + <%= content %> + <% end %> <% if @hint.present? || @error.present? %>
<%= tag.span @hint if @hint.present? %> - <%= tag.span @error, class: "text-red-400" if @error.present? %> + <%= tag.span safe_join(@error, tag.br), class: "text-red-400" if @error.present? %>
<% end %> diff --git a/admin/app/components/solidus_admin/ui/forms/field/component.rb b/admin/app/components/solidus_admin/ui/forms/field/component.rb index 8303e330e42..d3c7998c0a3 100644 --- a/admin/app/components/solidus_admin/ui/forms/field/component.rb +++ b/admin/app/components/solidus_admin/ui/forms/field/component.rb @@ -1,11 +1,72 @@ # frozen_string_literal: true class SolidusAdmin::UI::Forms::Field::Component < SolidusAdmin::BaseComponent - def initialize(label:, hint: nil, tip: nil, error: nil, **attributes) + def initialize(label:, hint: nil, tip: nil, error: nil, input_attributes: nil, **attributes) @label = label @hint = hint @tip = tip - @error = error + @error = [error] if error.present? @attributes = attributes + @input_attributes = input_attributes + + raise ArgumentError, "provide either a block or input_attributes" if content && input_attributes + end + + def self.text_field(form, method, hint: nil, tip: nil, size: :m, **attributes) + errors = form.object.errors.messages_for(method).presence + + new( + label: form.object.class.human_attribute_name(method), + hint: hint, + tip: tip, + error: errors, + input_attributes: { + name: "#{form.object_name}[#{method}]", + tag: :input, + size: size, + value: form.object.public_send(method), + error: (errors.to_sentence.capitalize if errors), + **attributes, + } + ) + end + + def self.select(form, method, choices, hint: nil, tip: nil, size: :m, **attributes) + errors = form.object.errors.messages_for(method).presence + + new( + label: form.object.class.human_attribute_name(method), + hint: hint, + tip: tip, + error: errors, + input_attributes: { + name: "#{form.object_name}[#{method}]", + tag: :select, + choices: choices, + size: size, + value: form.object.public_send(method), + error: (errors.to_sentence.capitalize if errors), + **attributes, + } + ) + end + + def self.text_area(form, method, hint: nil, tip: nil, size: :m, **attributes) + errors = form.object.errors.messages_for(method).presence + + new( + label: form.object.class.human_attribute_name(method), + hint: hint, + tip: tip, + error: errors, + input_attributes: { + name: "#{form.object_name}[#{method}]", + size: size, + tag: :textarea, + value: form.object.public_send(method), + error: (errors.to_sentence.capitalize if errors), + **attributes, + } + ) end end diff --git a/admin/app/components/solidus_admin/ui/forms/select/component.js b/admin/app/components/solidus_admin/ui/forms/select/component.js deleted file mode 100644 index b8e937cdfb5..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/select/component.js +++ /dev/null @@ -1,33 +0,0 @@ -import { Controller } from '@hotwired/stimulus' - -export default class extends Controller { - static targets = ['select', 'arrow'] - static classes = ['regular', 'prompt', 'arrowPrompt'] - - connect () { - this.addClassToOptions() - this.refreshSelectClass() - } - - // Add class to all the options to avoid inheriting the select's styles - addClassToOptions () { - this.selectTarget.querySelectorAll('option').forEach((option) => { - if (option.value == '') { - option.classList.add(this.promptClass) - } else { - option.classList.add(this.regularClass) - } - }) - } - - // Make the select look like a placeholder when the prompt is selected - refreshSelectClass () { - if (this.selectTarget.options[this.selectTarget.selectedIndex].value == '') { - this.selectTarget.classList.add(this.promptClass) - this.arrowTarget.classList.add(this.arrowPromptClass) - } else { - this.selectTarget.classList.remove(this.promptClass) - this.arrowTarget.classList.remove(this.arrowPromptClass) - } - } -} diff --git a/admin/app/components/solidus_admin/ui/forms/select/component.rb b/admin/app/components/solidus_admin/ui/forms/select/component.rb deleted file mode 100644 index 83bc1753977..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/select/component.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -class SolidusAdmin::UI::Forms::Select::Component < SolidusAdmin::BaseComponent - SIZES = { - s: { - select: %w[leading-4 body-small], - arrow: %w[w-4 h-4] - }, - m: { - select: %w[leading-6 body-small], - arrow: %w[w-5 h-5] - }, - l: { - select: %w[leading-9 body-text], - arrow: %w[w-6 h-6] - } - }.freeze - - def initialize( - field:, - builder:, - size: :m, - choices: [], - hint: nil, - errors: nil, - tip: nil, - options: {}, - attributes: {} - ) - @field = field - @builder = builder - @size = size - @choices = choices - @hint = hint - @tip = tip - @options = options - @attributes = HashWithIndifferentAccess.new(attributes) - @errors = errors || @builder.object&.errors - end - - def call - @attributes[:class] = [ - %w[ - block px-3 py-1.5 w-full - appearance-none - text-black - bg-white border border-gray-300 rounded-sm - hover:border-gray-500 - focus:border-gray-500 focus:shadow-[0_0_0_2px_#bbb] focus-visible:outline-none - disabled:bg-gray-50 disabled:text-gray-300 - ], - SIZES.fetch(@size)[:select], - @attributes[:class], - ].compact.join(" ") - - render component("ui/forms/field").new( - label: @builder.object.class.human_attribute_name(@field), - hint: @hint, - tip: @tip, - error: helpers.safe_join(@errors.messages_for(@field), tag.br).presence, - **@attributes - ).with_content(@builder.select( - @field, - @choices, - @options, - "data-#{stimulus_id}-target" => "select", - "data-action" => "#{stimulus_id}#refreshSelectClass", - **@attributes, - )) - end -end diff --git a/admin/app/components/solidus_admin/ui/forms/text_area/component.rb b/admin/app/components/solidus_admin/ui/forms/text_area/component.rb deleted file mode 100644 index 7f749614084..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/text_area/component.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -class SolidusAdmin::UI::Forms::TextArea::Component < SolidusAdmin::BaseComponent - SIZES = { - s: %w[h-20 body-small], - m: %w[h-28 body-small], - l: %w[h-36 body-text] - }.freeze - - def initialize( - field:, - builder:, - size: :m, - hint: nil, - tip: nil, - errors: nil, - **attributes - ) - @field = field - @builder = builder - @size = size - @hint = hint - @tip = tip - @attributes = HashWithIndifferentAccess.new(attributes) - @errors = errors || @builder.object&.errors - end - - def call - @attributes[:class] = [ - %w[ - block px-3 py-4 w-full - text-black - bg-white border border-gray-300 rounded-sm - hover:border-gray-500 - placeholder:text-gray-400 - focus:border-gray-500 focus:shadow-[0_0_0_2px_#bbb] focus-visible:outline-none - disabled:bg-gray-50 disabled:text-gray-300 - ], - SIZES.fetch(@size), - (%w[border-red-400 text-red-400] if @errors.present?), - @attributes[:class], - ].compact.join(" ") - - render component("ui/forms/field").new( - label: @builder.object.class.human_attribute_name(@field), - hint: @hint, - tip: @tip, - error: helpers.safe_join(@errors.messages_for(@field), tag.br).presence, - **@attributes - ).with_content(@builder.text_area(@field, **@attributes)) - end -end diff --git a/admin/app/components/solidus_admin/ui/forms/text_field/component.rb b/admin/app/components/solidus_admin/ui/forms/text_field/component.rb deleted file mode 100644 index a36aa4584f8..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/text_field/component.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -class SolidusAdmin::UI::Forms::TextField::Component < SolidusAdmin::BaseComponent - SIZES = { - s: %w[leading-4 body-small], - m: %w[leading-6 body-small], - l: %w[leading-9 body-text] - }.freeze - - TYPES = { - color: :color_field, - date: :date_field, - datetime: :datetime_field, - email: :email_field, - month: :month_field, - number: :number_field, - password: :password_field, - phone: :phone_field, - range: :range_field, - search: :search_field, - text: :text_field, - time: :time_field, - url: :url_field, - week: :week_field - }.freeze - - def initialize( - field:, - builder:, - type: :text, - size: :m, - hint: nil, - errors: nil, - tip: nil, - **attributes - ) - @field = field - @builder = builder - @type = type - @size = size - @hint = hint - @type = type - @tip = tip - @attributes = HashWithIndifferentAccess.new(attributes) - @errors = errors || @builder.object&.errors - end - - def call - @attributes[:class] = [ - %w[ - form-input - block px-3 py-1.5 w-full - text-black - bg-white border border-gray-300 rounded-sm - hover:border-gray-500 - placeholder:text-gray-400 - focus:border-gray-500 focus:shadow-[0_0_0_2px_#bbb] focus-visible:outline-none - disabled:bg-gray-50 disabled:text-gray-300 - ], - SIZES.fetch(@size), - (%w[border-red-400 text-red-400] if @errors.present?), - @attributes[:class], - ].compact.join(" ") - - render component("ui/forms/field").new( - label: @builder.object.class.human_attribute_name(@field), - hint: @hint, - tip: @tip, - error: helpers.safe_join(@errors.messages_for(@field), tag.br).presence, - **@attributes - ).with_content(@builder.send( - TYPES.fetch(@type), - @field, - @attributes, - )) - end -end diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/select/component_preview.rb b/admin/spec/components/previews/solidus_admin/ui/forms/select/component_preview.rb deleted file mode 100644 index ce0fb2b1b1d..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/select/component_preview.rb +++ /dev/null @@ -1,85 +0,0 @@ -# frozen_string_literal: true - -# @component "ui/forms/select" -class SolidusAdmin::UI::Forms::Select::ComponentPreview < ViewComponent::Preview - include SolidusAdmin::Preview - - # The select component is used to render a select box in a form. - # - # See the [`ui/forms/text_field`](../text_field) component for usage - # instructions. - def overview - choices = [ - ["Option 1", "option_1"], - ["Option 2", "option_2"], - ["Option 3", "option_3"] - ] - hint = "Select one of the options" - render_with_template( - locals: { - sizes: current_component::SIZES.keys, - choices: choices, - variants: { - "with_prompt" => { - hint: nil, errors: {}, options: { prompt: "Select" }, attributes: {} - }, - "selected" => { - hint: nil, errors: {}, options: {}, attributes: {} - }, - "with_hint" => { - hint: hint, errors: {}, options: {}, attributes: {} - }, - "with_prompt_and_error" => { - hint: nil, errors: { "with_prompt_and_error" => ["can't be blank"] }, options: { prompt: "Select" }, attributes: {} - }, - "selected_with_error" => { - hint: nil, errors: { "selected_with_error" => ["is invalid"] }, options: {}, attributes: {} - }, - "with_hint_and_error" => { - hint: hint, errors: { "with_hint_and_error" => ["is invalid"] }, options: {}, attributes: {} - }, - "with_prompt_disabled" => { - hint: nil, errors: {}, options: { prompt: "Select" }, attributes: { disabled: true } - }, - "selected_disabled" => { - hint: nil, errors: {}, options: {}, attributes: { disabled: true } - }, - "with_hint_disabled" => { - hint: hint, errors: {}, options: {}, attributes: { disabled: true } - } - } - } - ) - end - - # @param size select { choices: [s, m, l] } - # @param choices text "Separate multiple choices with a comma" - # @param label text - # @param selected text - # @param hint text - # @param errors text "Separate multiple errors with a comma" - # @param prompt text - # @param disabled toggle - def playground( - size: :m, - choices: "Option 1, Option 2, Option 3", - label: "Choose:", - selected: "Option 1", - hint: nil, errors: "", - prompt: "Select", - disabled: false - ) - render_with_template( - locals: { - size: size.to_sym, - choices: choices.split(",").map(&:strip).map { [_1, _1.parameterize] }, - field: label, - selected: selected&.parameterize, - hint: hint, - errors: { label.dasherize => (errors.blank? ? [] : errors.split(",").map(&:strip)) }, - prompt: prompt, - disabled: disabled - } - ) - end -end diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/select/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/forms/select/component_preview/overview.html.erb deleted file mode 100644 index 0742875b22d..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/select/component_preview/overview.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<%= form_with(url: "#", scope: :overview, method: :get, class: "w-full") do |form| %> - - - - <% sizes.each do |size| %> - - <% end %> - - - - <% - variants.each_pair do |name, definition| %> - - <% sizes.each do |size| %> - - <% end %> - - <% end %> - -
<%= size.to_s.humanize %>
- <%= - render current_component.new( - builder: form, - field: name, - choices: choices, - size: size, - errors: definition[:errors], - hint: definition[:hint], - options: definition[:options], - attributes: definition[:attributes] - ) - %> -
-<% end %> diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/select/component_preview/playground.html.erb b/admin/spec/components/previews/solidus_admin/ui/forms/select/component_preview/playground.html.erb deleted file mode 100644 index cad37e0e02b..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/select/component_preview/playground.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<%= form_with(url: "#", scope: :playground, method: :get, class: "w-60") do |form| %> - <%= - render current_component.new( - builder: form, - size: size, - choices: choices, - field: field, - hint: hint, - errors: errors, - options: { - prompt: prompt, - selected: selected - }, - attributes: { - disabled: disabled - } - ) - %> -<% end %> diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/text_area/component_preview.rb b/admin/spec/components/previews/solidus_admin/ui/forms/text_area/component_preview.rb deleted file mode 100644 index cb7ce0cc416..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/text_area/component_preview.rb +++ /dev/null @@ -1,69 +0,0 @@ -# frozen_string_literal: true - -# @component "ui/forms/text_area" -class SolidusAdmin::UI::Forms::TextArea::ComponentPreview < ViewComponent::Preview - include SolidusAdmin::Preview - - # The text area component is used to render a textarea in a form. - # - # See the [`ui/forms/text_field`](../text_field) component for usage - # instructions. - def overview - dummy_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, urna eu aliquam ultricies, urna elit aliquam urna, eu aliquam urna elit euismod urna." - render_with_template( - locals: { - sizes: current_component::SIZES.keys, - variants: { - "empty" => { - value: nil, disabled: false, hint: nil, errors: {} - }, - "filled" => { - value: dummy_text, disabled: false, hint: nil, errors: {} - }, - "with_hint" => { - value: dummy_text, disabled: false, hint: "Max. 400 characters", errors: {} - }, - "empty_with_error" => { - value: nil, disabled: false, hint: nil, errors: { "empty_with_error" => ["can't be blank"] } - }, - "filled_with_error" => { - value: dummy_text, disabled: false, hint: nil, errors: { "filled_with_error" => ["is invalid"] } - }, - "with_hint_and_error" => { - value: dummy_text, disabled: false, hint: "Max. 400 characters", errors: { "with_hint_and_error" => ["is invalid"] } - }, - "empty_disabled" => { - value: nil, disabled: true, hint: nil, errors: {} - }, - "filled_disabled" => { - value: dummy_text, disabled: true, hint: nil, errors: {} - }, - "with_hint_disabled" => { - value: dummy_text, disabled: true, hint: "Max. 400 characters", errors: {} - } - } - } - ) - end - - # @param size select { choices: [s, m, l] } - # @param label text - # @param value text - # @param hint text - # @param errors text "Separate multiple errors with a comma" - # @param placeholder text - # @param disabled toggle - def playground(size: :m, label: "Description", value: nil, hint: nil, errors: "", placeholder: "Placeholder", disabled: false) - render_with_template( - locals: { - size: size.to_sym, - field: label, - value: value, - hint: hint, - errors: { label.dasherize => (errors.blank? ? [] : errors.split(",").map(&:strip)) }, - placeholder: placeholder, - disabled: disabled - } - ) - end -end diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/text_area/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/forms/text_area/component_preview/overview.html.erb deleted file mode 100644 index 8ded42897d1..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/text_area/component_preview/overview.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<%= form_with(url: "#", scope: :overview, method: :get, class: "w-full") do |form| %> - - - - <% sizes.each do |size| %> - - <% end %> - - - - <% - variants.each_pair do |name, definition| %> - - <% sizes.each do |size| %> - - <% end %> - - <% end %> - -
<%= size.to_s.humanize %>
- <%= - render current_component.new( - builder: form, - field: name, - size: size, - errors: definition[:errors], - hint: definition[:hint], - disabled: definition[:disabled], - placeholder: "Placeholder", - value: definition[:value] - ) - %> -
-<% end %> diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/text_area/component_preview/playground.html.erb b/admin/spec/components/previews/solidus_admin/ui/forms/text_area/component_preview/playground.html.erb deleted file mode 100644 index c12a2684850..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/text_area/component_preview/playground.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<%= form_with(url: "#", scope: :playground, method: :get, class: "w-60") do |form| %> - <%= - render current_component.new( - builder: form, - size: size, - field: field, - value: value, - hint: hint, - errors: errors, - placeholder: placeholder, - disabled: disabled - ) - %> -<% end %> diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/text_field/component_preview.rb b/admin/spec/components/previews/solidus_admin/ui/forms/text_field/component_preview.rb deleted file mode 100644 index 72d46308dd8..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/text_field/component_preview.rb +++ /dev/null @@ -1,105 +0,0 @@ -# frozen_string_literal: true - -# @component "ui/forms/text_field" -class SolidusAdmin::UI::Forms::TextField::ComponentPreview < ViewComponent::Preview - include SolidusAdmin::Preview - - # The text field component is used to render a text field in a form. - # - # Most commonly, it'll be used indirectly through the definition given to a - # [form component](../form/overview). - # - # For standalone usage, it must be used within the block context yielded in - # the [`form_with` - # ](https://api.rubyonrails.org/v5.1/classes/ActionView/Helpers/FormHelper.html#method-i-form_with) - # or - # [`form_for`](https://api.rubyonrails.org/v5.1/classes/ActionView/Helpers/FormHelper.html#method-i-form_for) - # helpers. - # - # When the form builder is not bound to a model instance, you must pass an - # errors Hash to the component. For example: - # - # ```erb - # <%= form_with(url: search_path, method: :get) do |form| %> - # <%= render components('ui/forms/text_field').new( - # builder: form, - # field: :q, - # errors: params[:q].present? ? {} : { - # q: ["can't be blank"] - # } - # ) %> - # <%= form.submit "Search" %> - # <% end %> - # ``` - # - # When the form builder is bound to a model instance, the component will - # automatically fetch the errors from the model. - # - # ```erb - # <%= form_with(model: @user) do |form| %> - # <%= render components('ui/forms/text_field').new( - # builder: form, - # field: :name - # ) %> - # <%= form.submit "Save" %> - # <% end %> - def overview - render_with_template( - locals: { - sizes: current_component::SIZES.keys, - variants: { - "empty" => { - value: nil, disabled: false, hint: nil, errors: {} - }, - "filled" => { - value: "Alice", disabled: false, hint: nil, errors: {} - }, - "with_hint" => { - value: "Alice", disabled: false, hint: "No special characters", errors: {} - }, - "empty_with_error" => { - value: nil, disabled: false, hint: nil, errors: { "empty_with_error" => ["can't be blank"] } - }, - "filled_with_error" => { - value: "Alice", disabled: false, hint: nil, errors: { "filled_with_error" => ["is invalid"] } - }, - "with_hint_and_error" => { - value: "Alice", disabled: false, hint: "No special characters", errors: { "with_hint_and_error" => ["is invalid"] } - }, - "empty_disabled" => { - value: nil, disabled: true, hint: nil, errors: {} - }, - "filled_disabled" => { - value: "Alice", disabled: true, hint: nil, errors: {} - }, - "with_hint_disabled" => { - value: "Alice", disabled: true, hint: "No special characters", errors: {} - } - } - } - ) - end - - # @param size select { choices: [s, m, l] } - # @param type select { choices: [color, date, datetime, email, month, number, password, phone, range, search, text, time, url, week] } - # @param label text - # @param value text - # @param hint text - # @param errors text "Separate multiple errors with a comma" - # @param placeholder text - # @param disabled toggle - def playground(size: :m, type: :text, label: "Name", value: nil, hint: nil, errors: "", placeholder: "Placeholder", disabled: false) - render_with_template( - locals: { - size: size.to_sym, - type: type.to_sym, - field: label, - value: value, - hint: hint, - errors: { label.dasherize => (errors.blank? ? [] : errors.split(",").map(&:strip)) }, - placeholder: placeholder, - disabled: disabled - } - ) - end -end diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/text_field/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/forms/text_field/component_preview/overview.html.erb deleted file mode 100644 index 200f131e93b..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/text_field/component_preview/overview.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<%= form_with(url: "#", scope: :overview, method: :get) do |form| %> - - - - <% sizes.each do |size| %> - - <% end %> - - - - <% - variants.each_pair do |name, definition| %> - - <% sizes.each do |size| %> - - <% end %> - - <% end %> - -
<%= size.to_s.humanize %>
- <%= - render current_component.new( - builder: form, - field: name, - size: size, - errors: definition[:errors], - hint: definition[:hint], - disabled: definition[:disabled], - placeholder: "Placeholder", - value: definition[:value] - ) - %> -
-<% end %> diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/text_field/component_preview/playground.html.erb b/admin/spec/components/previews/solidus_admin/ui/forms/text_field/component_preview/playground.html.erb deleted file mode 100644 index 76072bee203..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/text_field/component_preview/playground.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<%= form_with(url: "#", scope: :playground, method: :get, class: "w-56") do |form| %> - <%= - render current_component.new( - builder: form, - size: size, - type: type, - field: field, - value: value, - hint: hint, - errors: errors, - placeholder: placeholder, - disabled: disabled - ) - %> -<% end %> diff --git a/admin/spec/components/solidus_admin/ui/forms/select/component_spec.rb b/admin/spec/components/solidus_admin/ui/forms/select/component_spec.rb deleted file mode 100644 index 1cc630faec1..00000000000 --- a/admin/spec/components/solidus_admin/ui/forms/select/component_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe SolidusAdmin::UI::Forms::Select::Component, type: :component do - it "renders the overview preview" do - render_preview(:overview) - end - - it "renders the playground preview" do - render_preview(:playground) - end -end diff --git a/admin/spec/components/solidus_admin/ui/forms/text_area/component_spec.rb b/admin/spec/components/solidus_admin/ui/forms/text_area/component_spec.rb deleted file mode 100644 index af5e6f1bf09..00000000000 --- a/admin/spec/components/solidus_admin/ui/forms/text_area/component_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe SolidusAdmin::UI::Forms::TextArea::Component, type: :component do - it "renders the overview preview" do - render_preview(:overview) - end - - it "renders the playground preview" do - render_preview(:playground) - end -end diff --git a/admin/spec/components/solidus_admin/ui/forms/text_field/component_spec.rb b/admin/spec/components/solidus_admin/ui/forms/text_field/component_spec.rb deleted file mode 100644 index 2d89dabfe54..00000000000 --- a/admin/spec/components/solidus_admin/ui/forms/text_field/component_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe SolidusAdmin::UI::Forms::TextField::Component, type: :component do - it "renders the overview preview" do - render_preview(:overview) - end - - it "renders the playground preview" do - render_preview(:playground) - end -end