Class: PhlexKit::Alert
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::Alert
- Defined in:
- app/components/phlex_kit/alert/alert.rb
Overview
Callout box, ported from ruby_ui's RubyUI::Alert and matched to shadcn/ui's
current alert. Presentational, no JS. A variant: selector (same shape as
PhlexKit::Button) tints the text; a leading svg child becomes the icon column
(CSS :has switches the grid); compose with AlertTitle + AlertDescription
(+ optional AlertAction pinned top-right):
render PhlexKit::Alert.new do
svg(...) { ... } # optional icon
render PhlexKit::AlertTitle.new { "Saved" }
render PhlexKit::AlertDescription.new { "Your changes are live." }
render PhlexKit::AlertAction.new { render PhlexKit::Button.new(size: :sm) { "Undo" } }
end
shadcn ships default/destructive; success/warning are kit extras kept from
ruby_ui, restyled to the same text-tint grammar. 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
-
#initialize(variant: :default, **attrs) ⇒ Alert
constructor
A new instance of Alert.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(variant: :default, **attrs) ⇒ Alert
Returns a new instance of Alert.
26 27 28 29 |
# File 'app/components/phlex_kit/alert/alert.rb', line 26 def initialize(variant: :default, **attrs) @variant = variant.to_sym @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
31 32 33 |
# File 'app/components/phlex_kit/alert/alert.rb', line 31 def view_template(&block) div(**mix({ class: classes, role: "alert" }, @attrs), &block) end |