Class: Charming::Presentation::Components::Modal

Inherits:
Charming::Presentation::Component show all
Defined in:
lib/charming/presentation/components/modal.rb

Overview

Modal is a centered, boxed overlay with an optional title, help line, and body content. The body may be a string, View, or Component; when it responds to ‘render`, its output is used. The result is wrapped in a UI::Style border with padding.

Instance Method Summary collapse

Methods inherited from View

#focused?, #layout_assigns

Constructor Details

#initialize(content:, title: nil, help: nil, width: 52, style: nil, theme: nil) ⇒ Modal

content is the modal body. title (optional) is rendered centered at the top. help (optional) is rendered as a muted footer line. width is the modal’s total width. style overrides the default ‘theme.modal` style.



13
14
15
16
17
18
19
20
# File 'lib/charming/presentation/components/modal.rb', line 13

def initialize(content:, title: nil, help: nil, width: 52, style: nil, theme: nil)
  super(theme: theme)
  @content = content
  @title = title
  @help = help
  @width = width
  @style = style
end

Instance Method Details

#renderObject

Renders the modal as a bordered, padded string with the title and help lines stacked above the content.



24
25
26
# File 'lib/charming/presentation/components/modal.rb', line 24

def render
  box(column(*lines, gap: 1), style: modal_style)
end