Class: Charming::Components::Toast
- Inherits:
-
Charming::Component
- Object
- View
- Charming::Component
- Charming::Components::Toast
- Defined in:
- lib/charming/presentation/components/toast.rb
Overview
Toast is a small auto-dismissing notification panel, usually composited as an overlay anchored to a screen corner. Controllers manage its lifetime with the ‘show_toast` / `dismiss_toast` helpers (which pair it with a timer); the component itself just renders the styled box.
Toast.new(message: "Saved!", kind: :success)
kind picks the accent style: :info (default), :success, :warn, or :error.
Constant Summary collapse
- KINDS =
%i[info success warn error].freeze
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(message:, kind: :info, width: nil, theme: nil) ⇒ Toast
constructor
message is the toast text.
-
#render ⇒ Object
Renders the bordered toast box with a kind-colored border.
Methods inherited from Charming::Component
Methods inherited from View
Constructor Details
#initialize(message:, kind: :info, width: nil, theme: nil) ⇒ Toast
message is the toast text. kind is the visual accent. width optionally fixes the box width (otherwise it hugs the message).
20 21 22 23 24 25 |
# File 'lib/charming/presentation/components/toast.rb', line 20 def initialize(message:, kind: :info, width: nil, theme: nil) super(theme: theme) @message = .to_s @kind = KINDS.include?(kind) ? kind : :info @width = width end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
16 17 18 |
# File 'lib/charming/presentation/components/toast.rb', line 16 def kind @kind end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
16 17 18 |
# File 'lib/charming/presentation/components/toast.rb', line 16 def @message end |
Instance Method Details
#render ⇒ Object
Renders the bordered toast box with a kind-colored border.
28 29 30 |
# File 'lib/charming/presentation/components/toast.rb', line 28 def render box(, style: toast_style) end |