# frozen_string_literal: true module PandaCms module Admin class HeadingComponent < ViewComponent::Base renders_many :buttons, PandaCms::Admin::ButtonComponent def initialize(text:, level: 2, icon: "", additional_styles: "") @text = text @level = level @icon = icon @additional_styles = additional_styles @additional_styles = @additional_styles.split(" ") if @additional_styles.is_a?(String) end def call output = "" output += content_tag(:div, @text, class: "grow") if buttons? output += content_tag(:span, class: "actions flex gap-x-2") do safe_join(buttons, "") end end output = output.html_safe if @level == 1 content_tag(:h1, output, class: ["flex", "text-2xl", "font-medium", "text-gray-900", @additional_styles]) elsif @level == 2 content_tag(:h2, output, class: ["flex", "text-xl", "font-medium", "text-gray-800", @additional_styles]) elsif @level == 3 content_tag(:h3, output, class: ["flex", "text-xl", "font-bold", "text-gray-700", @additional_styles]) end end end end end