# frozen_string_literal: true module Ariadne # Add a general description of component here # Add additional usage considerations or best practices that may aid the user to use the component correctly. # @accessibility Add any accessibility considerations class PanelBarComponent < Ariadne::Component DEFAULT_TAG = :ol TAG_OPTIONS = [DEFAULT_TAG].freeze DEFAULT_CLASSES = "ariadne-border ariadne-border-gray-300 ariadne-rounded-md ariadne-divide-y ariadne-divide-gray-300 md:ariadne-flex md:ariadne-divide-y-0" renders_many :panels, "PanelItem" # @example Default # # <%= render(Ariadne::PanelBarComponent.new) { "Example" } %> # # @param tag [Symbol, String] The rendered tag name. # @param classes [String] <%= link_to_classes_docs %> # @param attributes [Hash] <%= link_to_attributes_docs %> def initialize(classes: "", attributes: {}) @tag = DEFAULT_TAG @classes = merge_class_names( DEFAULT_CLASSES, classes, ) @attributes = attributes @attributes[:role] ||= "list" end # def render? # items.any? # end # This component is part of `PanelBarComponent` and should not be # used as a standalone component. class PanelItem < Ariadne::Component DEFAULT_ITEM_CLASSES = "ariadne-relative md:ariadne-flex-1 md:ariadne-flex" DEFAULT_WRAPPER_CLASSES = "group ariadne-flex ariadne-items-center ariadne-w-full" # TODO: fix this renders_one :icon, lambda { |static_content = nil, &block| next static_content if static_content.present? view_context.capture { block&.call } } renders_one :label, lambda { |static_content = nil, &block| next static_content if static_content.present? view_context.capture { block&.call } } attr_reader :link, :classes, :attributes def initialize(link: {}, classes: "", attributes: {}) @link = link if @link.present? @link["classes"] = merge_class_names(DEFAULT_WRAPPER_CLASSES, @link["classes"]) end @classes = merge_class_names(DEFAULT_ITEM_CLASSES, classes) @attributes = attributes end def selected? @selected end def linked? @link.present? end def call render(Ariadne::BaseComponent.new(tag: :div, classes: @classes, attributes: @attributes)) end end end end