Class: PhlexKit::Alert

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

Overview

Callout box, ported from ruby_ui's RubyUI::Alert. Presentational, no JS. A variant: selector (same shape as PhlexKit::Button) tints the box; compose with AlertTitle + AlertDescription:

render PhlexKit::Alert.new(variant: :success) do
render PhlexKit::AlertTitle.new { "Saved" }
render PhlexKit::AlertDescription.new { "Your changes are live." }
end

ruby_ui's variants (nil / warning / success / destructive) map onto the palette tokens in vanilla CSS (alert.css). VARIANTS.fetch fails loud.

Constant Summary collapse

VARIANTS =

variant => extra class appended after the base ui-alert (nil = neutral).

{
  default: nil,
  warning: "warning",
  success: "success",
  destructive: "destructive"
}.freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(variant: :default, **attrs) ⇒ Alert

Returns a new instance of Alert.



22
23
24
25
# File 'app/components/phlex_kit/alert/alert.rb', line 22

def initialize(variant: :default, **attrs)
  @variant = variant.to_sym
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



27
28
29
# File 'app/components/phlex_kit/alert/alert.rb', line 27

def view_template(&block)
  div(**mix({ class: classes }, @attrs), &block)
end