Sha256: b7ef6eefe229bd4a61dc893d240fd44612ec76706e9990b9a518428118b76747

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module Ariadne
  # Defines a submittble form for adding comments to a conversation.
  class CommentComponent < Ariadne::Component
    DEFAULT_TAG = :form
    TAG_OPTIONS = [DEFAULT_TAG].freeze

    DEFAULT_CLASSES = ""

    DEFAULT_TAB_CLASSES = "text-gray-500 hover:text-gray-900 bg-white hover:bg-gray-100 px-3 py-1.5 border border-transparent text-sm font-medium rounded-md"
    renders_many :tabs, lambda { |classes: "", attributes: {}|
      actual_classes = class_names(DEFAULT_TAB_CLASSES, classes)
      @tab_idx += 1
      attributes[:id] = "comment-tabs-tab-#{@tab_idx}"
      attributes[:"aria-controls"] = "comment-tabs-panel-#{@tab_idx}"
      attributes[:role] = "tab"
      attributes[:type] = "button"

      Ariadne::BaseComponent.new(tag: :button, classes: actual_classes, attributes: attributes)
    }

    renders_one :submit, lambda { |classes: "", attributes: {}|
      Ariadne::ButtonComponent.new(type: Ariadne::BaseButton::TYPE_SUBMIT, classes: classes, attributes: attributes)
    }

    # @example Default
    #
    #   <%= render(Ariadne::CommentComponent.new(action: "#")) { "Example" } %>
    #
    # @param action [String] The action to take when the form is submitted.
    # @param classes [String] <%= link_to_classes_docs %>
    # @param attributes [Hash] <%= link_to_attributes_docs %>
    def initialize(action:, classes: "", attributes: {})
      @tag = DEFAULT_TAG
      @classes = class_names(
        DEFAULT_CLASSES,
        classes
      )

      @tab_idx = 0
      @attributes = attributes.merge(action: action)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.6 app/components/ariadne/comment_component.rb
ariadne_view_components-0.0.5 app/components/ariadne/comment_component.rb