PhoenixKitComments.Web.CommentsComponent (PhoenixKitComments v0.2.1)

Copy Markdown View Source

Reusable LiveComponent for displaying and managing comments on any resource.

Usage

<.live_component
  module={PhoenixKitComments.Web.CommentsComponent}
  id={"comments-#{@post.uuid}"}
  resource_type="post"
  resource_uuid={@post.uuid}
  current_user={@current_user}
/>

Required Attrs

  • resource_type - String identifying the resource type (e.g., "post")
  • resource_uuid - UUID of the resource
  • current_user - Current authenticated user struct
  • id - Unique component ID

Optional Attrs

  • enabled - Whether comments are enabled (default: true)
  • show_likes - Show like/dislike buttons (default: false)
  • title - Section title (default: "Comments")

Slots

  • :form_extras - Custom markup rendered inside the new-comment form. Use it to inject parent-project inputs whose names are metadata[<key>]; their values are merged into comment.metadata on submit. The "giphy" key is reserved for the built-in Giphy picker.

    <:form_extras>
      <input type="color" name="metadata[box_color]" value="#ff5555" />
    </:form_extras>

Parent Notifications

After create/delete, sends to the parent LiveView:

{:comments_updated, %{resource_type: "post", resource_uuid: uuid, action: :created | :deleted}}

Summary

Functions

render(assigns)

Callback implementation for Phoenix.LiveComponent.render/1.

render_comment(assigns)

Attributes

  • comment (:map) (required)
  • current_user (:map) (required)
  • myself (:any) (required)
  • editing_uuid (:string) - Defaults to nil.
  • editing_content (:string) - Defaults to "".