Class: PhlexKit::ToastRegion
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::ToastRegion
- Defined in:
- app/components/phlex_kit/toast/toast_region.rb
Overview
Toast region ("toaster"), ported from ruby_ui's RubyUI::ToastRegion. Renders the fixed, position-anchored
- stack plus hidden skeletons (one
per variant) and action/cancel/close slot templates. The phlex-kit--toaster
controller clones those to spawn toasts client-side — via
window.PhlexKit.toast(...), a "phlex-kit:toast" window event, or the toast
Turbo Stream action. Pass flash: to render server-side flash messages as
toasts on page load. Per-toast behaviour (timer, swipe) lives on each
PhlexKit::ToastItem. Tailwind → vanilla .pk-toast* (toast.css).
Constant Summary collapse
- SKELETON_VARIANTS =
%i[default success error warning info loading].freeze
- POSITIONS =
{ top_left: "top-left", top_center: "top-center", top_right: "top-right", bottom_left: "bottom-left", bottom_center: "bottom-center", bottom_right: "bottom-right" }.freeze
Instance Method Summary collapse
-
#initialize(position: :bottom_right, expand: false, max: 3, duration: 4000, gap: 14, offset: 24, theme: :system, rich_colors: false, close_button: false, hotkey: %w[alt t],, dir: :ltr, flash: nil, **attrs) ⇒ ToastRegion
constructor
A new instance of ToastRegion.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(position: :bottom_right, expand: false, max: 3, duration: 4000, gap: 14, offset: 24, theme: :system, rich_colors: false, close_button: false, hotkey: %w[alt t],, dir: :ltr, flash: nil, **attrs) ⇒ ToastRegion
Returns a new instance of ToastRegion.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/components/phlex_kit/toast/toast_region.rb', line 22 def initialize( position: :bottom_right, expand: false, max: 3, duration: 4000, gap: 14, offset: 24, theme: :system, rich_colors: false, close_button: false, hotkey: %w[alt t], dir: :ltr, flash: nil, **attrs ) @position = POSITIONS.fetch(position.to_sym) @expand = @max = max @duration = duration @gap = gap @offset = offset @theme = theme.to_sym @rich_colors = rich_colors @close_button = @hotkey = hotkey @dir = dir @flash = flash @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/components/phlex_kit/toast/toast_region.rb', line 52 def view_template(&block) div(**mix(region_attrs, @attrs)) do ol(id: "pk-toaster", class: "pk-toast-list") do render_flash if @flash yield(self) if block end SKELETON_VARIANTS.each { |variant| skeleton(variant) } slot_template("actionTpl") { render ToastAction.new(label: "") } slot_template("cancelTpl") { render ToastCancel.new(label: "") } slot_template("closeTpl") { render ToastClose.new } end end |