Skip to content

Result Card

ResultCard presents the outcome of an action: saved settings, failed submissions, empty flows, or follow-up next steps.

It is intentionally small, semantic, and HTMX-friendly. Success and info states use role="status"; warning and error states use role="alert".

Import

from faststrap import ResultCard, Button

Basic Usage

ResultCard(
    title="Settings saved",
    message="Your preferences have been updated.",
    status="success",
)

Error State

ResultCard(
    title="Could not save",
    message="Please review the highlighted fields and try again.",
    status="error",
)

With Action

ResultCard(
    title="Invite sent",
    message="We emailed the new team member.",
    status="success",
    action=Button("View team", href="/team", variant="primary"),
)

Parameters

Param Type Description
title str Main result title.
message str | None Optional supporting message.
status success | error | warning | info Semantic result state.
icon str | None Bootstrap icon name override.
action Any | None Optional action component.
compact bool Use tighter spacing.

faststrap.components.display.result_card.ResultCard(title, message=None, *, status='success', icon=None, action=None, compact=False, **kwargs)

Render a focused result surface for completed actions.

Source code in src/faststrap/components/display/result_card.py
@register(category="display")
@beta
def ResultCard(
    title: str,
    message: str | None = None,
    *,
    status: ResultStatus = "success",
    icon: str | None = None,
    action: Any | None = None,
    compact: bool = False,
    **kwargs: Any,
) -> Div:
    """Render a focused result surface for completed actions."""
    variant = RESULT_VARIANTS.get(status, "secondary")
    resolved_icon = icon if icon is not None else RESULT_ICONS.get(status)
    user_cls = kwargs.pop("cls", "")

    attrs: dict[str, Any] = {
        "cls": merge_classes(
            "faststrap-result-card card border-0 shadow-sm",
            f"border-start border-4 border-{variant}",
            user_cls,
        ),
        "role": "status" if status in {"success", "info", "neutral"} else "alert",
    }
    attrs.update(convert_attrs(kwargs))

    body_cls = "card-body"
    if compact:
        body_cls = merge_classes(body_cls, "py-3")

    content = []
    if resolved_icon:
        content.append(
            Div(
                Icon(resolved_icon, cls=f"text-{variant} fs-4", aria_hidden="true"),
                cls="flex-shrink-0",
            )
        )

    text_parts: list[Any] = [H5(title, cls="card-title mb-1")]
    if message:
        text_parts.append(P(message, cls="card-text text-muted mb-0"))
    if action:
        text_parts.append(Div(action, cls="mt-3"))

    content.append(Div(*text_parts, cls="min-w-0"))

    return Div(Div(Div(*content, cls="d-flex gap-3 align-items-start"), cls=body_cls), **attrs)