Files
spacedrive/interface/components/AlertDialog.tsx
Ericson "Fogo" Soares 187ec933f4 [ENG-770 / ENG-773] Copy/paste / Explorer context menu duplicate (#992)
* Fixing copy, cut and paste

* Bug on duplicating files without extensions

* Fix paste only ignoring the location origin when validating relative paths
 - Add Error handling to all context menu actions
 - Hide FS actions in Overview and MediaView
 - Remove redundant useExplorerSearchParams
 - Add default schema to the Zod param hooks

* Hide FS actions in all Explorers but location ones
 - Fix react warnings in RenameTextBox
 - Fix ReactTextBox not selecting the whole file name, instead of just up to file extension
 - Fix react warning due to inputing missing onChange

* basic show jobs for cut, copy and delete in job manager

* tweaks

* Fixing some warnings and minor tweaks

* Rust fmt

* Fix cut between locations on Linux

* Change how routes retrieve route params
 - Replace useZodRouteParams with useLoader
 - Define all schemas in the router file instead of in the route Component
 - Parse schema in loader to avoid requiring the route Components having to import the schema from the router file

* Remove default argument from useZodRouteParams

---------

Co-authored-by: Vítor Vasconcellos <vasconcellos.dev@gmail.com>
Co-authored-by: Jamie Pine <32987599+jamiepine@users.noreply.github.com>
Co-authored-by: James Pine <ijamespine@me.com>
2023-06-22 23:41:29 +00:00

54 lines
1.5 KiB
TypeScript

import { Clipboard } from 'phosphor-react';
import { ReactNode } from 'react';
import { Button, Dialog, Input, UseDialogProps, dialogManager, useDialog } from '@sd/ui';
import { useZodForm } from '@sd/ui/src/forms';
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
}
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'}
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} />);
}