mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
refactor: add modern DialogActions component (#24856)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
"./test/**/*.ts",
|
||||
"./e2e/**/*.ts"
|
||||
],
|
||||
"tags": ["-lintignore"],
|
||||
"ignore": [
|
||||
"**/*Generated.ts",
|
||||
"src/api/chatModelOptions.ts",
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
*/
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { Dialog as DialogPrimitive } from "radix-ui";
|
||||
import { Button } from "#/components/Button/Button";
|
||||
import { Spinner } from "#/components/Spinner/Spinner";
|
||||
import { cn } from "#/utils/cn";
|
||||
|
||||
export const Dialog = DialogPrimitive.Root;
|
||||
@@ -106,6 +108,72 @@ export const DialogFooter: React.FC<React.ComponentPropsWithRef<"div">> = ({
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @lintignore I'll be using this right away in another PR, just trying to break things up
|
||||
*/
|
||||
export interface DialogActionsProps {
|
||||
/** Text to display in the confirm button */
|
||||
confirmText?: React.ReactNode;
|
||||
/** Whether or not confirm is loading, also disables cancel when true */
|
||||
confirmLoading?: boolean;
|
||||
/** Whether or not the submit button is disabled */
|
||||
confirmDisabled?: boolean;
|
||||
/** Whether the confirm button triggers a destructive action or not */
|
||||
confirmVariant?: React.ComponentProps<typeof Button>["variant"];
|
||||
/** Called when confirm is clicked */
|
||||
onConfirm?: () => void;
|
||||
|
||||
/** Text to display in the cancel button */
|
||||
cancelText?: string;
|
||||
/** Called when cancel is clicked */
|
||||
onCancel?: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quickly handles most modals actions, some combination of a cancel and confirm button
|
||||
* @lintignore I'll be using this right away in another PR, just trying to break things up
|
||||
*/
|
||||
export const DialogActions: React.FC<DialogActionsProps> = ({
|
||||
confirmText = "Confirm",
|
||||
confirmLoading = false,
|
||||
confirmDisabled = false,
|
||||
confirmVariant,
|
||||
onConfirm,
|
||||
|
||||
cancelText = "Cancel",
|
||||
onCancel,
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
{onCancel && (
|
||||
<Button
|
||||
disabled={confirmLoading}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onCancel();
|
||||
}}
|
||||
variant="outline"
|
||||
>
|
||||
{cancelText}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{onConfirm && (
|
||||
<Button
|
||||
variant={confirmVariant}
|
||||
disabled={confirmLoading || confirmDisabled}
|
||||
onClick={onConfirm}
|
||||
data-testid="confirm-button"
|
||||
type="submit"
|
||||
>
|
||||
<Spinner loading={confirmLoading} />
|
||||
{confirmText}
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const DialogTitle: React.FC<
|
||||
React.ComponentPropsWithRef<typeof DialogPrimitive.Title>
|
||||
> = ({ className, ...props }) => {
|
||||
|
||||
Reference in New Issue
Block a user