import * as React from "react"
import { cn } from "@/registry/lib/utils"
// @use-when a row of buttons that answer one thing together: a primary and the
// quieter ones beside it under a result, at the end of a panel, in a drawer or
// sheet footer, or under a form that does not use Field's submit gap. It owns
// the gap and the wrap on a phone. Not Lockup, whose action sits under its own
// heading and copy; not TableToolbar, which scopes a table; not DialogFooter,
// which already lays out a dialog's buttons.
/**
* The order and the variants are the rule this part exists to hold, so every
* screen says it the same way:
*
* - ONE primary (`variant="default"`), never two. The rest are quieter:
* `soft` for a real alternative, `ghost` for a way out ("Cancel",
* "Start over"). A destructive action is `destructive` and still the only
* loud one.
* - The primary sits at the row's OUTER edge, where the eye ends: last in an
* `align="end"` row (a footer, read left to right toward the corner), first
* in an `align="start"` row (under a result, read from where the text
* starts). The way out sits furthest from it.
* - One size for the whole row. A smaller button beside a larger one reads as
* a different kind of control, not a quieter one.
*
* The row wraps rather than squeezing: on a phone a long label drops to the
* next line at the same gap, and keeps its alignment. Children render in the
* order given; the part never reorders them, because the DOM order is the tab
* order and must match what is seen.
*/
function ActionRow({
align = "start",
className,
style,
...props
}: React.ComponentProps<"div"> & {
/** `start` (default) under content that reads from the left, `end` in a
* footer or at the end of a panel. Sets which edge the primary goes on. */
align?: "start" | "end"
}) {
return (
<div
data-slot="action-row"
data-align={align}
className={cn(
"flex flex-wrap items-center",
align === "end" && "justify-end",
className
)}
// `actions`: the same 8px rung stacked secondary buttons take, one
// button to the next in either direction, and the gap a wrapped line
// keeps from the one above it.
style={{ ...style, gap: "var(--spacing-rhythm-actions)" }}
{...props}
/>
)
}
export { ActionRow }