Files
spacedrive/interface/components/AlertDialog.tsx
Brendan Allan 795bb18d18 [ENG-1007] Per-page onboarding forms (#1256)
* useMultiZodForm

* fix imports

* handle obStore.data undefined

---------

Co-authored-by: Utku <74243531+utkubakir@users.noreply.github.com>
2023-08-29 10:58:39 +00:00

56 lines
1.6 KiB
TypeScript

import { Clipboard } from 'phosphor-react';
import { ReactNode } from 'react';
import { useZodForm } from '@sd/client';
import { Button, Dialog, Input, UseDialogProps, dialogManager, useDialog } from '@sd/ui';
interface Props extends UseDialogProps {
title: string; // dialog title
description?: string; // description of the dialog
children?: ReactNode; // dialog content
value?: string; // value to be displayed as text or in an input box
label?: string; // button label
inputBox?: boolean; // whether the dialog should display the `value` in a disabled input box or as text
cancelBtn?: boolean; // whether the dialog should have a cancel button
}
const AlertDialog = (props: Props) => {
// maybe a copy-to-clipboard button would be beneficial too
return (
<Dialog
title={props.title}
form={useZodForm()}
dialog={useDialog(props)}
ctaLabel={props.label !== undefined ? props.label : 'Done'}
cancelBtn={props.cancelBtn}
onCancelled={false}
>
{props.description && <div className="mb-3 text-sm">{props.description}</div>}
{props.children}
{props.inputBox ? (
<Input
value={props.value}
disabled
className="mt-3"
right={
<Button
type="button"
onClick={() => {
props.value && navigator.clipboard.writeText(props.value);
}}
size="icon"
>
<Clipboard className="h-4 w-4" />
</Button>
}
/>
) : (
<div className="text-sm">{props.value}</div>
)}
</Dialog>
);
};
export function showAlertDialog(props: Omit<Props & { children?: ReactNode }, 'id'>) {
dialogManager.create((dp) => <AlertDialog {...dp} {...props} />);
}