Shared Dock, PublishButton, DiscardButton, DiscardDraftDialog for the flow and dashboard editors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 22:04:34 +02:00
co-authored by Claude Opus 5.5
parent 8d158169e5
commit 72b4cf3556
4 changed files with 277 additions and 233 deletions
+196
View File
@@ -0,0 +1,196 @@
import { Check, WifiOff, X } from "lucide-react"
import { motion } from "motion/react"
import type { ReactNode } from "react"
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
import { FluksioLoader } from "@/components/ui/fluksio-loader"
import { Separator } from "@/components/ui/separator"
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip"
import { slideUp, transitions } from "@/lib/motion"
import { cn } from "@/lib/utils"
/**
* The action bar floating at the bottom of an editor canvas, flow or dashboard.
*
* Capped and wrapping: the canvas shell clips, so an uncapped row would put the
* buttons at its ends out of reach on a phone rather than merely look wrong.
* See DESIGN-GUIDELINES.md → Responsive.
*/
export function Dock({
className,
children,
}: {
className?: string
children: ReactNode
}) {
return (
<motion.div
variants={slideUp}
initial="hidden"
animate="visible"
exit="exit"
transition={transitions.emphasized}
className={cn(
"pointer-events-auto flex max-w-[calc(100vw-2rem)] flex-wrap items-center justify-center gap-1 rounded-full border border-border bg-card/80 px-1.5 py-1 shadow-e2 backdrop-blur-md pb-[max(0.25rem,env(safe-area-inset-bottom))]",
className,
)}
>
{children}
</motion.div>
)
}
/** Groups the dock's buttons; a phone wraps instead. */
export function DockSeparator() {
return (
<Separator orientation="vertical" className="mx-0.5 !h-5 hidden md:block" />
)
}
/**
* Saved state and publish are one control: the glyph never moves, it simply
* stops being something you can press once there is nothing left to put live.
* A button that appears and disappears moved everything beside it just as the
* work was finished.
*/
export function PublishButton({
label,
testId,
hasDraft,
saving,
publishing,
offline = false,
draftHint,
onPublish,
}: {
label: string
testId: string
hasDraft: boolean
saving: boolean
publishing: boolean
/** The engine is out of reach, so there is nothing to publish to. */
offline?: boolean
/** What the tooltip says while there is a saved draft waiting. */
draftHint: string
onPublish: () => void
}) {
return (
<Tooltip>
<TooltipTrigger asChild>
<span>
<Button
variant="ghost"
size="icon-touch"
className="text-muted-foreground"
onClick={onPublish}
disabled={!hasDraft || publishing || saving || offline}
aria-label={label}
data-testid={testId}
>
{offline ? (
<WifiOff className="size-3.5" />
) : saving || publishing ? (
<FluksioLoader className="size-3.5" />
) : (
<Check className="size-3.5" />
)}
</Button>
</span>
</TooltipTrigger>
<TooltipContent>
{offline
? "Reconnecting to the engine"
: publishing
? "Publishing"
: saving
? "Saving"
: hasDraft
? draftHint
: "All changes saved"}
</TooltipContent>
</Tooltip>
)
}
/** Sits next to publish, and only while there is something to throw away. */
export function DiscardButton({
testId,
onClick,
}: {
testId: string
onClick: () => void
}) {
return (
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon-touch"
className="text-muted-foreground"
onClick={onClick}
aria-label="Discard the unpublished changes"
data-testid={testId}
>
<X />
</Button>
</TooltipTrigger>
<TooltipContent>Discard the unpublished changes</TooltipContent>
</Tooltip>
)
}
/** The confirmation behind `DiscardButton`; `children` says what goes back. */
export function DiscardDraftDialog({
open,
onOpenChange,
pending,
testId,
onConfirm,
children,
}: {
open: boolean
onOpenChange: (open: boolean) => void
pending: boolean
testId: string
onConfirm: () => void
children: ReactNode
}) {
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Discard the unpublished changes?</DialogTitle>
<DialogDescription>{children}</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Keep editing
</Button>
<Button
variant="destructive"
disabled={pending}
onClick={() => {
onOpenChange(false)
onConfirm()
}}
data-testid={testId}
>
Discard changes
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}