Skip to documentation
Design system / Sources & standards
Current repository source
overviewEditableField.tsx
src/components/editions/overviewEditableField.tsx
This view contains the escaped source read during the deployment build. Code and policy text are unchanged. Markdown is shown as source, not rendered as a document. A new deployment refreshes the content.
"use client";
import type { ReactNode } from "react";
import { Button } from "@/components/ui/button";
import { InlineEditTrigger } from "@/components/ui/inlineEditTrigger";
import { useEditTriggerFocus } from "@/hooks/useEditTriggerFocus";
import { cn } from "@/lib/utils";
/** Edition-owned molecule: replace one displayed value at its original position.
* Owners supply the input, draft, authorization and mutation lifecycle. */
export function OverviewEditableField({ actionLabel, value, editing, saving, disabled, title, heading = false, saveLabel, onStart, onSave, onCancel, children, className, containerClassName }: {
actionLabel: string; value: ReactNode; editing: boolean; saving: boolean; disabled?: boolean;
title?: string; heading?: boolean; saveLabel: string; onStart: () => void;
onSave: () => void | Promise<unknown>; onCancel: () => void; children: ReactNode; className?: string; containerClassName?: string;
}) {
const trigger = useEditTriggerFocus(editing);
const display = <InlineEditTrigger ref={trigger} className={cn("max-w-full", className)} aria-label={actionLabel} disabled={disabled || saving} title={title} onClick={onStart}>
<span data-slot={heading ? "overview-title" : undefined} className="min-w-0 break-words">{value}</span>
</InlineEditTrigger>;
return <div data-slot="overview-editable-field" data-edit-label={actionLabel} className={cn("min-w-0", containerClassName)}>
{heading ? <h1 aria-label={typeof value === "string" ? value : undefined} className={cn("min-w-0 break-words text-lg font-semibold", editing && "sr-only")}>{editing ? value : display}</h1> : !editing ? display : null}
{editing ? <form aria-label={actionLabel} aria-busy={saving} className="min-w-0 space-y-2" onSubmit={event => { event.preventDefault(); if (!saving) void onSave(); }} onKeyDown={event => {
if (saving) return;
if (event.key === "Escape") { event.preventDefault(); onCancel(); }
else if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) { event.preventDefault(); event.currentTarget.requestSubmit(); }
}}>
{children}
<div className="flex flex-wrap gap-2"><Button type="submit" size="sm" disabled={saving}>{saving ? "Saving..." : saveLabel}</Button><Button type="button" variant="outline" size="sm" disabled={saving} onClick={onCancel}>Cancel</Button></div>
</form> : null}
</div>;
}
All sources and standards