80 lines
3.2 KiB
TypeScript
80 lines
3.2 KiB
TypeScript
// Shared chrome of the quick-action modals (header with icon/title/subtitle and
|
|
// close, body slot, footer with cancel + one primary action). Extracted from the
|
|
// project quick actions so any screen that offers the same kind of "one small
|
|
// thing, right here" action gets the same dialog instead of a lookalike.
|
|
//
|
|
// Pure/presentational: it owns no draft state and performs no navigation — the
|
|
// caller passes the body and decides what submitting means.
|
|
|
|
import type { ReactNode } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { FeatherCheck, FeatherX } from "@subframe/core";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Dialog } from "~/ui/components/Dialog";
|
|
import { IconButton } from "~/ui/components/IconButton";
|
|
import { IconWithBackground } from "~/ui/components/IconWithBackground";
|
|
|
|
export type QuickActionDialogProps = {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
icon: ReactNode;
|
|
iconVariant: "warning" | "information" | "success" | "neutral";
|
|
title: string;
|
|
subtitle: string;
|
|
submitLabel: string;
|
|
/** Defaults to the check the "erstellen" dialogs use. */
|
|
submitIcon?: ReactNode;
|
|
submitting: boolean;
|
|
submitDisabled?: boolean;
|
|
onSubmit: () => void;
|
|
uiId: string;
|
|
children: ReactNode;
|
|
};
|
|
|
|
export function QuickActionDialog(props: QuickActionDialogProps) {
|
|
const { t } = useTranslation();
|
|
return (
|
|
<Dialog open={props.open} onOpenChange={props.onOpenChange}>
|
|
{/* w-112 like every one of Davids four exports. */}
|
|
<Dialog.Content className="w-112 max-w-[92vw] p-4" data-ui-id={props.uiId}>
|
|
<div className="flex w-full flex-col items-start gap-5">
|
|
<div className="flex w-full items-start justify-between gap-3">
|
|
<div className="flex items-start gap-3">
|
|
<IconWithBackground variant={props.iconVariant} size="medium" icon={props.icon} />
|
|
<div className="flex flex-col items-start gap-1">
|
|
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">{props.title}</span>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{props.subtitle}</span>
|
|
</div>
|
|
</div>
|
|
<IconButton
|
|
variant="tertiary"
|
|
size="small"
|
|
icon={<FeatherX />}
|
|
onClick={() => props.onOpenChange(false)}
|
|
data-ui-id={`${props.uiId}.close`}
|
|
/>
|
|
</div>
|
|
<div className="flex w-full flex-col items-start gap-4">{props.children}</div>
|
|
<div className="flex w-full items-center justify-end gap-2">
|
|
<Button variant="tertiary" onClick={() => props.onOpenChange(false)} data-ui-id={`${props.uiId}.cancel`}>
|
|
{t("shared.cancel")}
|
|
</Button>
|
|
<Button
|
|
variant="primary"
|
|
icon={props.submitIcon ?? <FeatherCheck />}
|
|
loading={props.submitting}
|
|
disabled={props.submitDisabled}
|
|
onClick={props.onSubmit}
|
|
data-ui-id={`${props.uiId}.submit`}
|
|
>
|
|
{props.submitLabel}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
);
|
|
}
|
|
|
|
export default QuickActionDialog;
|