Class: Charming::Presentation::Components::EmptyState
- Inherits:
-
Charming::Presentation::Component
- Object
- View
- Charming::Presentation::Component
- Charming::Presentation::Components::EmptyState
- Defined in:
- lib/charming/presentation/components/empty_state.rb
Overview
EmptyState is a placeholder component for screens with no content. Renders one of three states: a default “nothing to show” message, a “loading…” message, or an error message with optional help text.
Instance Method Summary collapse
-
#initialize(message: "Nothing to show.", loading: false, loading_message: "Loading...", error: nil, error_message: nil, help: nil, theme: nil) ⇒ EmptyState
constructor
message is shown in the default state.
-
#render ⇒ Object
Renders the appropriate state as styled text: loading → loading message, error → error message + help, otherwise the default message.
Methods inherited from View
Constructor Details
#initialize(message: "Nothing to show.", loading: false, loading_message: "Loading...", error: nil, error_message: nil, help: nil, theme: nil) ⇒ EmptyState
message is shown in the default state. loading switches to the loading message (overrides message). loading_message is the string rendered in the loading state. error and error_message switch to the error state (the string form takes precedence). help is an optional muted line shown below the error message.
14 15 16 17 18 19 20 21 22 |
# File 'lib/charming/presentation/components/empty_state.rb', line 14 def initialize(message: "Nothing to show.", loading: false, loading_message: "Loading...", error: nil, error_message: nil, help: nil, theme: nil) super(theme: theme) @message = @loading = loading @loading_message = @error = error @error_message = @help = help end |
Instance Method Details
#render ⇒ Object
Renders the appropriate state as styled text: loading → loading message, error →error message + help, otherwise the default message.
26 27 28 29 30 31 |
# File 'lib/charming/presentation/components/empty_state.rb', line 26 def render return loading_state if @loading return error_state if error? text @message, style: theme.muted end |