Class: Oversee::Resources::Errors

Inherits:
Base
  • Object
show all
Defined in:
app/components/oversee/resources/errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource: nil, errors: nil, content: nil, **options) ⇒ Errors



4
5
6
7
8
9
# File 'app/components/oversee/resources/errors.rb', line 4

def initialize(resource: nil, errors: nil, content: nil, **options)
  @resource = resource
  @errors = errors
  @content = content
  @options = options
end

Instance Method Details

#view_templateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/components/oversee/resources/errors.rb', line 11

def view_template
  if @content || @resource&.errors&.any?
    div(class: container_class) do
      div(class: "inline-flex items-center gap-1.5 bg-red-600 py-1 px-2 text-xs text-white") do
        # render Phlex::TablerIcons::ExclamationCircle.new(class: "size-5", stroke_width: 1.75)
        h3(class: "text-sm font-medium") { plain @content || "Something went wrong!" }
      end
      if displayed_errors.present?
        div(class: "mt-4 border-l-2 border-red-600 p-2") do
          ul(class: "space-y-1 text-sm text-gray-700") do
            displayed_errors.each do |message|
              li { "— #{message}" }
            end
          end
        end
      end
    end
  end
end