Class: PhlexKit::Marker
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::Marker
- Defined in:
- app/components/phlex_kit/marker/marker.rb
Overview
Conversation annotation, ported from shadcn/ui's Marker (an AI-chat-era
addition): an inline status line, bordered system-note row, or labeled
separator. Compose Marker(variant:) > [MarkerIcon +] MarkerContent.
href: renders an , as: :button a
Constant Summary collapse
- VARIANTS =
{ default: nil, border: "border", separator: "separator" }.freeze
- AS_TAGS =
The elements this component knows how to render (href: forces ); unknown values used to fall through silently to
— fail loud instead.%i[div button].freeze
Instance Method Summary collapse
-
#initialize(variant: :default, href: nil, as: :div, type: :button, **attrs) ⇒ Marker
constructor
type: is a named kwarg (not a mix default) because
mixwould fuse a caller type: "submit" with the generated "button" into an invalid two-token value the browser resolves back to submit. - #view_template ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(variant: :default, href: nil, as: :div, type: :button, **attrs) ⇒ Marker
type: is a named kwarg (not a mix default) because
mixwould fuse a caller type: "submit" with the generated "button" into an invalid two-token value the browser resolves back to submit.16 17 18 19 20 21 22 23 24 25 26 27 28
# File 'app/components/phlex_kit/marker/marker.rb', line 16 def initialize(variant: :default, href: nil, as: :div, type: :button, **attrs) @variant = variant.to_sym @href = href @as = as.to_sym unless AS_TAGS.include?(@as) raise ArgumentError, "unknown Marker as: #{@as.inspect} (use one of #{AS_TAGS.join(", ")})" end if @href && @as != :div raise ArgumentError, "Marker href: renders an <a> — it can't combine with as: #{@as.inspect}" end @type = type @attrs = attrs end
Instance Method Details
#view_template ⇒ Object
30 31 32 33 34 35 36 37 38 39
# File 'app/components/phlex_kit/marker/marker.rb', line 30 def view_template(&) classes = [ "pk-marker", fetch_option(VARIANTS, @variant, :variant) ].compact.join(" ") if @href a(**mix({ class: classes, href: @href }, @attrs), &) elsif @as == :button (**mix({ class: classes, type: @type }, @attrs), &) else div(**mix({ class: classes }, @attrs), &) end end