Class: Ariadne::CommentComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/ariadne/comment_component.rb

Overview

Defines a submittable form for adding comments to a conversation.

attribute, which will be used to label the tabs for screen readers.

Constant Summary collapse

DEFAULT_TAG =
:div
TAG_OPTIONS =
[DEFAULT_TAG].freeze
DEFAULT_CLASSES =
"ariadne-border-gray-300 ariadne-border ariadne-shadow ariadne-py-5 ariadne-px-5 ariadne-rounded-md "

Constants inherited from Component

Ariadne::Component::BASE_HIDDEN_CLASS, Ariadne::Component::BASE_MAIN_CLASSES, Ariadne::Component::BASE_WRAPPER_CLASSES, Ariadne::Component::INVALID_ARIA_LABEL_TAGS

Constants included from ActionViewExtensions::FormHelper

ActionViewExtensions::FormHelper::DEFAULT_FORM_CLASSES

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::INTEGER_TYPES, FetchOrFallbackHelper::InvalidValueError, FetchOrFallbackHelper::TRUE_OR_FALSE

Instance Method Summary collapse

Methods included from ActionViewExtensions::FormHelper

#ariadne_form_with

Methods included from ClassNameHelper

#class_names

Methods included from LoggerHelper

#logger, #silence_deprecations?, #silence_warnings?

Methods included from FetchOrFallbackHelper

#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_raise, #fetch_or_raise_boolean, #fetch_or_raise_integer

Constructor Details

#initialize(url:, method: :post, sr_label:, classes: "", attributes: {}) ⇒ CommentComponent

Returns a new instance of CommentComponent.

Examples:

Default


<%= render(Ariadne::CommentComponent.new(url: "/messages", method: :post, sr_label: "Select delivery time")) do |comment| %>
  <% comment.public_tab(selected: true, text: "Reply to sender") %>
  <% comment.public_submit { "Send" } %>
  <% comment.internal_tab(text: "Internal comment") %>
  <% comment.internal_submit { "Send" } %>
<% end %>

Parameters:

  • url (String)

    The URL to take action against.

  • method (String) (defaults to: :post)

    The method to use when submitting the form.

  • sr_label (String)

    A label to introduce these tabs for screen readers.

  • classes (String) (defaults to: "")

    <%= link_to_classes_docs %>

  • attributes (Hash) (defaults to: {})

    <%= link_to_attributes_docs %>



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/components/ariadne/comment_component.rb', line 55

def initialize(url:, method: :post, sr_label:, classes: "", attributes: {})
  @tag = DEFAULT_TAG
  @classes = class_names(
    DEFAULT_CLASSES,
    classes,
  )
  @url = url
  @method = method
  @sr_label = sr_label

  @tab_idx = -1
  @attributes = attributes
end