# SPDX-FileCopyrightText: 2025 James Harton
#
# SPDX-License-Identifier: Apache-2.0
defmodule BB.LiveView.Components do
@moduledoc """
Shared UI components for the BB Dashboard.
Provides reusable function components for building the dashboard interface.
"""
use Phoenix.Component
@doc """
Renders a widget card with header and body.
## Examples
<.widget title="Safety">
Widget content here
<.widget title="Joints" loading={true}>
Loading...
"""
attr(:title, :string, required: true)
attr(:loading, :boolean, default: false)
attr(:class, :string, default: nil)
slot(:inner_block, required: true)
slot(:actions)
def widget(assigns) do
~H"""
"""
end
@doc """
Renders a loading spinner.
"""
def spinner(assigns) do
~H"""
"""
end
@doc """
Renders a status badge.
## Examples
<.badge variant="success">Armed
<.badge variant="danger">Error
"""
attr(:variant, :string, default: "muted", values: ~w(success warning danger muted))
slot(:inner_block, required: true)
def badge(assigns) do
~H"""
{render_slot(@inner_block)}
"""
end
@doc """
Renders a button.
## Examples
<.button>Click me
<.button variant="primary" disabled={true}>Submit
"""
attr(:type, :string, default: "button")
attr(:variant, :string, default: "outline", values: ~w(primary danger outline))
attr(:disabled, :boolean, default: false)
attr(:class, :string, default: nil)
attr(:rest, :global)
slot(:inner_block, required: true)
def button(assigns) do
~H"""
{render_slot(@inner_block)}
"""
end
@doc """
Renders an empty state message.
## Examples
<.empty_state message="No events yet" />
"""
attr(:message, :string, required: true)
attr(:icon, :string, default: nil)
def empty_state(assigns) do
~H"""
"""
end
@doc """
Renders an error message.
## Examples
<.error_message message="Failed to load robot data" />
"""
attr(:message, :string, required: true)
def error_message(assigns) do
~H"""
!
{@message}
"""
end
end