diff --git a/admin/app/components/solidus_admin/ui/forms/fieldset/component.erb b/admin/app/components/solidus_admin/ui/forms/fieldset/component.erb deleted file mode 100644 index 7b05c129a8f..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/fieldset/component.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%= tag.fieldset(**fieldset_html_attributes) do %> - <%= legend_and_toggletip_tags %> - <%= content %> -<% end %> diff --git a/admin/app/components/solidus_admin/ui/forms/fieldset/component.rb b/admin/app/components/solidus_admin/ui/forms/fieldset/component.rb deleted file mode 100644 index 17a32b6710a..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/fieldset/component.rb +++ /dev/null @@ -1,64 +0,0 @@ -# frozen_string_literal: true - -class SolidusAdmin::UI::Forms::Fieldset::Component < SolidusAdmin::BaseComponent - # @param legend [String, nil] The legend of the fieldset. - # @param fieldset_attributes [Hash] Attributes to pass to the fieldset tag. - # @param legend_attributes [Hash, nil] Attributes to pass to the legend tag. - # @param toggletip_attributes [Hash, nil] Attributes to pass to a toggletip - # component that will be rendered after the legend. - def initialize( - legend: nil, - attributes: {}, - legend_attributes: {}, - toggletip_attributes: {} - ) - @legend = legend - @attributes = attributes - @legend_attributes = legend_attributes - @toggletip_attributes = toggletip_attributes - end - - def fieldset_html_attributes - { - class: fieldset_classes, - **@attributes.except(:class) - } - end - - def fieldset_classes - %w[p-6 mb-6 border border-gray-100 rounded-lg] + Array(@attributes[:class]).compact - end - - def legend_and_toggletip_tags - return "" unless @legend || @toggletip_attributes.any? - - tag.div(class: "flex mb-4") do - legend_tag + toggletip_tag - end - end - - def legend_tag - return "".html_safe unless @legend - - tag.legend(@legend, **legend_html_attributes) - end - - def legend_html_attributes - { - class: legend_classes, - **@legend_attributes.except(:class) - } - end - - def legend_classes - %w[body-title mr-2] + Array(@legend_attributes[:class]).compact - end - - def toggletip_tag - return "" unless @toggletip_attributes.any? - - tag.div do - render component("ui/toggletip").new(**@toggletip_attributes) - end - end -end diff --git a/admin/app/components/solidus_admin/ui/forms/form/component.erb b/admin/app/components/solidus_admin/ui/forms/form/component.erb deleted file mode 100644 index 7ea4458e700..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/form/component.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= form_with(**@attributes) do |builder| %> - <%= render_elements(@elements, builder) %> -<% end %> diff --git a/admin/app/components/solidus_admin/ui/forms/form/component.rb b/admin/app/components/solidus_admin/ui/forms/form/component.rb deleted file mode 100644 index ca5e2b51742..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/form/component.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -class SolidusAdmin::UI::Forms::Form::Component < SolidusAdmin::BaseComponent - # @param elements [Array<#call(form, builder)>] Builders of renderable - # elements within a form context. They need to implement `#call(form, - # builder)`, where the arguments are an instance of this class and an - # instance of `ActionView::Helpers::FormBuilder`. The method needs to return - # something responding to `#render_in(view_context)`. See the following - # classes for examples: - # - {SolidusAdmin::Form::Elements::Field} - # - {SolidusAdmin::Form::Elements::Fieldset} - # - {SolidusAdmin::Form::Elements::Component} - # - {SolidusAdmin::Form::Elements::HTML} - # @param attributes [Hash] Attributes to pass to the Rails `form_with` helper, - # which is used to render the form. - def initialize(elements:, **attributes) - @elements = elements - @attributes = attributes - end - - # @return [Hash{Symbol => SolidusAdmin::BaseComponent}] Hash of component - # classes dependencies given on initialization. - def dependencies - { - fieldset: component("ui/forms/fieldset"), - text_field: component("ui/forms/text_field"), - text_area: component("ui/forms/text_area") - } - end - - # @api private - def render_elements(elements, builder) - safe_join( - elements.map do |element| - render_element(element, builder) - end - ) - end - - # @api private - def render_element(element, builder) - render element.call(self, builder) - end -end diff --git a/admin/app/components/solidus_admin/ui/forms/guidance/component.rb b/admin/app/components/solidus_admin/ui/forms/guidance/component.rb deleted file mode 100644 index 67d88cb189a..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/guidance/component.rb +++ /dev/null @@ -1,70 +0,0 @@ -# frozen_string_literal: true - -# @api private -class SolidusAdmin::UI::Forms::Guidance::Component < SolidusAdmin::BaseComponent - def initialize(field:, builder:, hint:, errors:, disabled: false) - @field = field - @builder = builder - @hint = hint - @disabled = disabled - @errors = errors || @builder.object&.errors || raise(ArgumentError, <<~MSG - When the form builder is not bound to a model instance, you must pass an - errors Hash (`{ field_name: [errors] }`) to the component. - MSG - ) - end - - def call - return "" unless needed? - - tag.div(class: "mt-2") do - hint_tag + error_tag - end - end - - def hint_tag - return "".html_safe unless @hint - - tag.p(id: hint_id, class: "body-tiny #{hint_text_color_class}") do - @hint - end - end - - def hint_text_color_class - @disabled ? "text-gray-300" : "text-gray-500" - end - - def hint_id - "#{prefix}_hint" - end - - def error_tag - return "".html_safe unless errors? - - tag.p(id: error_id, class: "body-tiny text-red-400") do - @errors[@field].map do |error| - tag.span(class: "block") { error.capitalize } - end.reduce(&:+) - end - end - - def errors? - @errors[@field].present? - end - - def error_id - "#{prefix}_error" - end - - def prefix - "#{@builder.object_name}_#{@field}" - end - - def aria_describedby - "#{hint_id if @hint} #{error_id if errors?}" - end - - def needed? - @hint || errors? - end -end diff --git a/admin/app/components/solidus_admin/ui/forms/label/component.rb b/admin/app/components/solidus_admin/ui/forms/label/component.rb deleted file mode 100644 index 072042cc811..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/label/component.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -# @api private -class SolidusAdmin::UI::Forms::Label::Component < SolidusAdmin::BaseComponent - def initialize(field:, builder:) - @field = field - @builder = builder - end - - def call - @builder.label(@field, class: "block mb-0.5 body-tiny-bold") - end -end diff --git a/admin/lib/solidus_admin/form/element/component.rb b/admin/lib/solidus_admin/form/element/component.rb deleted file mode 100644 index c46751808ab..00000000000 --- a/admin/lib/solidus_admin/form/element/component.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module SolidusAdmin - module Form - module Element - # Builds an arbitrary component in a form context. - # - # This class can be used to render an arbitrary components in a form. - # - # This is useful when there's the need to render a component that's not - # strictly related to a form definition, but still needs to be within the - # form tags. - class Component - # @param component [ViewComponent::Base] the component instance to - # render. - def initialize(component:) - @component = component - end - - # @api private - def call(_form, _builder) - @component - end - end - end - end -end diff --git a/admin/lib/solidus_admin/form/element/field.rb b/admin/lib/solidus_admin/form/element/field.rb deleted file mode 100644 index 9b54f22679e..00000000000 --- a/admin/lib/solidus_admin/form/element/field.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -module SolidusAdmin - module Form - module Element - # Builds a form field component. - # - # This class encapsulates a form field definition and its resolution to a - # component. - class Field - # @param component [Symbol, ViewComponent::Base] the component to be - # used when rendering. It can be a component class (which needs to - # accept the `builder:` parameter on initialization) or a Symbol. When - # the latter, it's used to infer the one configured in the form - # instance. For instance, for a `:text_field` type, the component used - # will be the one given to the form component as the - # `text_field_component` keyword argument on initialization. - # @param attributes [Hash] attributes to pass to the field component. - def initialize(component:, **attributes) - @component = component - @attributes = attributes - end - - # @api private - def call(form, builder) - component_class(form).new( - builder: builder, - **@attributes - ) - end - - private - - def component_class(form) - case @component - when Symbol - form.dependencies[@component] - else - @component - end - end - end - end - end -end diff --git a/admin/lib/solidus_admin/form/element/fieldset.rb b/admin/lib/solidus_admin/form/element/fieldset.rb deleted file mode 100644 index 08f01e4674d..00000000000 --- a/admin/lib/solidus_admin/form/element/fieldset.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -module SolidusAdmin - module Form - module Element - # Builds a form fieldset component. - # - # This class encapsulates a form fieldset definition and its resolution to - # a component. - class Fieldset - # @param elements [Array<#call(form, builder)>] See - # {SolidusAdmin::UI::Forms::Form::Component#initialize}. - # @param component [ViewComponent::Base, nil] the component to be - # used when rendering. When `nil`, the component configured in the form - # `fieldset_component` keyword argument on initialization is used. - # @param attributes [Hash] Attributes to pass to the fieldset - # component. - def initialize(elements:, component: nil, **attributes) - @elements = elements - @component = component - @attributes = attributes - end - - # @api private - def call(form, builder) - component_class(form).new( - **@attributes - ).with_content( - render_elements(form, builder) - ) - end - - private - - def component_class(form) - @component || form.dependencies[:fieldset] - end - - def render_elements(form, builder) - return "" if @elements.empty? - - form.render_elements(@elements, builder) - end - end - end - end -end diff --git a/admin/lib/solidus_admin/form/element/html.rb b/admin/lib/solidus_admin/form/element/html.rb deleted file mode 100644 index e9c681507b2..00000000000 --- a/admin/lib/solidus_admin/form/element/html.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -module SolidusAdmin - module Form - module Element - # Builds arbitrary HTML in a form. - # - # This class can be used to render arbitrary content in a form. - # - # This is useful when there's the need to render content that's not - # strictly related to a form definition, but still needs to be within the - # form tags. If the content is a component, it's better to use - # {SolidusAdmin::Form::Element::Component} instead. - class HTML - # @param html [String] the HTML to render. - def initialize(html:) - @html = html - end - - # @api private - def call(_form, _builder) - self - end - - # @api private - def render_in(_view_context) - @html - end - end - end - end -end diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview.rb b/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview.rb deleted file mode 100644 index 98ba84cb3f7..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -# @component "ui/forms/fieldset" -class SolidusAdmin::UI::Forms::Fieldset::ComponentPreview < ViewComponent::Preview - include SolidusAdmin::Preview - - # The fieldset component is used to render a set of fields in a form. - # - # Most commonly, it'll be used indirectly through the definition given to a - # [form component](../form/overview). - # - # For standalone usage, it wraps the yielded content in a fieldset tag: - # - # ```erb - # <%= render components('ui/forms/fieldset').new do %> - # <%= # ... %> - # <% end %> - # ``` - # - # The legend of the fieldset can be set with the `legend` option: - # - # ```erb - # <%= render components('ui/forms/fieldset').new( - # legend: "My fieldset" - # ) do %> - # <%= # ... %> - # <% end %> - # ``` - # - # Lastly, a toggletip can be added to the legend with the - # `toggletip_attributes`, which will be passed to the [toggletip - # component](../../toggletip): - # - # ```erb - # <%= render components('ui/forms/fieldset').new( - # legend: "My fieldset", - # toggletip_attributes: { - # text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", - # position: :right - # } - # ) do %> - # <%= # ... %> - # <% end %> - # ``` - def overview - end -end diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview/overview.html.erb deleted file mode 100644 index 8376955d631..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview/overview.html.erb +++ /dev/null @@ -1,48 +0,0 @@ -<%= form_with(url: "#", scope: :overview, method: :get, class: "w-full") do |form| %> -
Whatever HTML you want
".html_safe - # ) - # ] - # ) - # %> - # ``` - def overview - render_with_template( - locals: { - elements: elements - } - ) - end - - private - - def elements - [ - field_element, - fieldset_element, - component_element, - html_element - ] - end - - def field_element - SolidusAdmin::Form::Element::Field.new( - component: :text_field, - field: :name, - placeholder: "SolidusAdmin::Form::Element::Field", - errors: {} - ) - end - - def fieldset_element - SolidusAdmin::Form::Element::Fieldset.new( - elements: [ - SolidusAdmin::Form::Element::Field.new( - component: :text_field, - field: :name, - placeholder: "SolidusAdmin::Form::Element::Field", - errors: {} - ) - ], - legend: "SolidusAdmin::Form::Element::Fieldset" - ) - end - - def component_element - SolidusAdmin::Form::Element::Component.new( - component: Class.new(SolidusAdmin::BaseComponent) do - def self.name - "MyCustomComponent" - end - - def call - tag.p(class: "body-text-bold mb-2 italic") { "SolidusAdmin::Form::Element::Component" } - end - end.new - ) - end - - def html_element - SolidusAdmin::Form::Element::HTML.new( - html: "SolidusAdmin::Form::Element::HTML
".html_safe - ) - end -end diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/form/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/forms/form/component_preview/overview.html.erb deleted file mode 100644 index 40dee9a8220..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/form/component_preview/overview.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -