Module: MaquinaComponents::EmptyHelper

Defined in:
app/helpers/maquina_components/empty_helper.rb

Overview

Empty Helper

Provides convenient methods for creating empty state components.

Examples:

Simple empty state

<%= empty_state title: "No projects", description: "Get started by creating one.", icon: :folder_open %>

With action button

<%= empty_state title: "No projects", icon: :folder_open do %>
  <%= link_to "Create Project", new_project_path, data: { component: "button", variant: "primary" } %>
<% end %>

Full control with partials

<%= render "components/empty", variant: :outline do %>
  <%= render "components/empty/header" do %>
    <%= render "components/empty/media", icon: :search %>
    <%= render "components/empty/title", text: "No results" %>
  <% end %>
<% end %>

Instance Method Summary collapse

Instance Method Details

#empty_list_state(resource_name:, new_path: nil, icon: :folder_open, size: :default) ⇒ String

Renders an empty state for lists/tables

Parameters:

  • resource_name (String)

    Name of the resource (e.g., "projects", "users")

  • new_path (String, nil) (defaults to: nil)

    Path to create new resource

  • icon (Symbol) (defaults to: :folder_open)

    Icon to display

  • size (Symbol) (defaults to: :default)

    Size variant

Returns:

  • (String)

    Rendered HTML



89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/helpers/maquina_components/empty_helper.rb', line 89

def empty_list_state(resource_name:, new_path: nil, icon: :folder_open, size: :default)
  empty_state(
    title: "No #{resource_name} yet",
    description: "Get started by creating your first #{resource_name.singularize}.",
    icon: icon,
    size: size
  ) do
    if new_path
      link_to "Create #{resource_name.singularize.titleize}", new_path, data: {component: "button", variant: "primary"}
    end
  end
end

#empty_search_state(query: nil, reset_path: nil, size: :default) ⇒ String

Renders an empty state for search results

Parameters:

  • query (String, nil) (defaults to: nil)

    The search query (for display)

  • reset_path (String, nil) (defaults to: nil)

    Path to reset/clear search

  • size (Symbol) (defaults to: :default)

    Size variant

Returns:

  • (String)

    Rendered HTML



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/helpers/maquina_components/empty_helper.rb', line 63

def empty_search_state(query: nil, reset_path: nil, size: :default)
  description = if query.present?
    "No results found for \"#{query}\". Try a different search term."
  else
    "No results found. Try adjusting your search."
  end

  empty_state(
    title: "No results",
    description: description,
    icon: :search,
    size: size
  ) do
    if reset_path
      link_to "Clear search", reset_path, data: {component: "button", variant: "outline", size: "sm"}
    end
  end
end

#empty_state(title:, description: nil, icon: nil, variant: :default, size: :default, css_classes: "", **html_options) { ... } ⇒ String

Renders an empty state component with a simple API

Parameters:

  • title (String)

    The title text

  • description (String, nil) (defaults to: nil)

    Optional description text

  • icon (Symbol, nil) (defaults to: nil)

    Icon name (uses icon_for helper)

  • variant (Symbol) (defaults to: :default)

    Visual style (:default, :outline)

  • size (Symbol) (defaults to: :default)

    Size variant (:default, :compact)

  • css_classes (String) (defaults to: "")

    Additional CSS classes

  • html_options (Hash)

    Additional HTML attributes

Yields:

  • Optional block for action content (buttons, links)

Returns:

  • (String)

    Rendered HTML



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/maquina_components/empty_helper.rb', line 36

def empty_state(title:, description: nil, icon: nil, variant: :default, size: :default, css_classes: "", **html_options, &block)
  render "components/empty", variant: variant, size: size, css_classes: css_classes, **html_options do
    parts = []

    # Build header
    header_content = []
    header_content << render("components/empty/media", icon: icon) if icon
    header_content << render("components/empty/title", text: title)
    header_content << render("components/empty/description", text: description) if description

    parts << render("components/empty/header") { safe_join(header_content) }

    # Add content/actions if block given
    if block
      parts << render("components/empty/content") { capture(&block) }
    end

    safe_join(parts)
  end
end