Class: PhlexKit::Attachment

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/attachment/attachment.rb

Overview

File chip, ported from shadcn/ui's Attachment: media (icon or image), name + metadata, optional actions, upload state and a full-card trigger. state: drives styling — :uploading/:processing shimmer the title, :error goes destructive; size: (:default/:sm/:xs) and orientation: (:horizontal/:vertical) shape the card. Lay several out in an AttachmentGroup (scrollable, snapping, edge-faded row). .pk-attachment* (attachment.css).

Constant Summary collapse

STATES =
{ idle: "idle", uploading: "uploading", processing: "processing", error: "error", done: "done" }.freeze
SIZES =
{ default: nil, sm: "sm", xs: "xs" }.freeze
ORIENTATIONS =
{ horizontal: nil, vertical: "vertical" }.freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(state: :done, size: :default, orientation: :horizontal, **attrs) ⇒ Attachment

Returns a new instance of Attachment.



14
15
16
17
18
19
# File 'app/components/phlex_kit/attachment/attachment.rb', line 14

def initialize(state: :done, size: :default, orientation: :horizontal, **attrs)
  @state = state.to_sym
  @size = size.to_sym
  @orientation = orientation.to_sym
  @attrs = attrs
end

Instance Method Details

#view_templateObject



21
22
23
24
25
26
# File 'app/components/phlex_kit/attachment/attachment.rb', line 21

def view_template(&)
  div(**mix({
    class: [ "pk-attachment", fetch_option(SIZES, @size, :size), fetch_option(ORIENTATIONS, @orientation, :orientation) ].compact.join(" "),
    data: { state: fetch_option(STATES, @state, :state) }
  }, @attrs), &)
end