react-confirm-alert 3.0.6 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +56 -89
- package/dist/index.esm.js +1058 -0
- package/dist/package.json +1 -0
- package/index.d.ts +2 -31
- package/lib/index.js +1071 -295
- package/package.json +36 -40
- package/src/react-confirm-alert.css +64 -54
- package/style.css +127 -0
- package/typings/Dialog.d.ts +27 -0
- package/typings/DialogFrame.d.ts +28 -0
- package/typings/DialogHost.d.ts +17 -0
- package/typings/DialogStack.d.ts +5 -0
- package/typings/api.d.ts +21 -0
- package/typings/classNames.d.ts +16 -0
- package/typings/compat.d.ts +48 -0
- package/typings/fallbackRoot.d.ts +4 -0
- package/typings/index.d.ts +9 -0
- package/typings/lifecycle.d.ts +7 -0
- package/typings/page.d.ts +2 -0
- package/typings/store.d.ts +59 -0
- package/typings/types.d.ts +138 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, ComponentType, InputHTMLAttributes, KeyboardEvent, ReactNode } from 'react';
|
|
2
|
+
export type DialogId = string & {
|
|
3
|
+
readonly __brand: 'DialogId';
|
|
4
|
+
};
|
|
5
|
+
export type Strategy = 'stack' | 'queue' | 'replace';
|
|
6
|
+
export interface ButtonContext<R> {
|
|
7
|
+
close: (value: R) => void;
|
|
8
|
+
dismiss: () => void;
|
|
9
|
+
/** aborted when the dialog closes from elsewhere while this button waits */
|
|
10
|
+
signal: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
export interface DialogButton<R> extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'value' | 'children'> {
|
|
13
|
+
label: ReactNode;
|
|
14
|
+
value?: R | undefined;
|
|
15
|
+
variant?: 'primary' | 'secondary' | 'danger' | undefined;
|
|
16
|
+
/** return false to stay open; return a Promise to show the button as busy until it settles */
|
|
17
|
+
onClick?: ((ctx: ButtonContext<R>) => void | false | Promise<void | false>) | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface DialogRenderProps<R> {
|
|
20
|
+
id: DialogId;
|
|
21
|
+
titleId: string;
|
|
22
|
+
descriptionId: string;
|
|
23
|
+
title?: ReactNode | undefined;
|
|
24
|
+
message?: ReactNode | undefined;
|
|
25
|
+
buttons: readonly DialogButton<R>[];
|
|
26
|
+
close: (value: R) => void;
|
|
27
|
+
dismiss: () => void;
|
|
28
|
+
/** alias of dismiss, so v3 customUI code keeps working */
|
|
29
|
+
onClose: () => void;
|
|
30
|
+
}
|
|
31
|
+
export type DialogSlot = 'dialog' | 'panel' | 'body' | 'title' | 'message' | 'actions' | 'button' | 'field' | 'label' | 'input' | 'error';
|
|
32
|
+
export type DialogClassNames = Partial<Record<DialogSlot, string>>;
|
|
33
|
+
export interface StyleOptions {
|
|
34
|
+
/** leave out the v3 class names; only classNames, data attributes and ARIA remain */
|
|
35
|
+
unstyled?: boolean | undefined;
|
|
36
|
+
/** added to each slot's classes, after the app defaults */
|
|
37
|
+
classNames?: DialogClassNames | undefined;
|
|
38
|
+
}
|
|
39
|
+
export interface DialogDefaults extends StyleOptions {
|
|
40
|
+
closeOnEscape?: boolean | undefined;
|
|
41
|
+
closeOnClickOutside?: boolean | undefined;
|
|
42
|
+
strategy?: Strategy | undefined;
|
|
43
|
+
modal?: boolean | undefined;
|
|
44
|
+
/** default true: body gets react-confirm-alert-body-element while a dialog is open */
|
|
45
|
+
lockScroll?: boolean | undefined;
|
|
46
|
+
labels?: {
|
|
47
|
+
ok?: ReactNode;
|
|
48
|
+
confirm?: ReactNode;
|
|
49
|
+
cancel?: ReactNode;
|
|
50
|
+
submit?: ReactNode;
|
|
51
|
+
} | undefined;
|
|
52
|
+
/** separate defaults for confirmAlert, which otherwise keeps v3 behavior */
|
|
53
|
+
confirmAlert?: (StyleOptions & {
|
|
54
|
+
modal?: boolean | undefined;
|
|
55
|
+
strategy?: Strategy | undefined;
|
|
56
|
+
}) | undefined;
|
|
57
|
+
}
|
|
58
|
+
/** Attributes on the frame, for CSS and Tailwind data-* variants. A type only, kept in step by tests. */
|
|
59
|
+
export interface DialogDataAttributes {
|
|
60
|
+
'data-rca': '';
|
|
61
|
+
'data-state': 'open' | 'closing';
|
|
62
|
+
'data-kind': DialogKind;
|
|
63
|
+
'data-tone': 'default' | 'danger';
|
|
64
|
+
'data-busy'?: '';
|
|
65
|
+
'data-depth': `${number}`;
|
|
66
|
+
'data-topmost'?: '';
|
|
67
|
+
}
|
|
68
|
+
export interface SlotDataAttributes {
|
|
69
|
+
'data-slot': DialogSlot;
|
|
70
|
+
}
|
|
71
|
+
export interface ButtonDataAttributes extends SlotDataAttributes {
|
|
72
|
+
'data-variant': 'primary' | 'secondary' | 'danger';
|
|
73
|
+
'data-busy'?: '';
|
|
74
|
+
}
|
|
75
|
+
export interface BaseOptions extends StyleOptions {
|
|
76
|
+
title?: ReactNode | undefined;
|
|
77
|
+
message?: ReactNode | undefined;
|
|
78
|
+
closeOnEscape?: boolean | undefined;
|
|
79
|
+
closeOnClickOutside?: boolean | undefined;
|
|
80
|
+
strategy?: Strategy | undefined;
|
|
81
|
+
modal?: boolean | undefined;
|
|
82
|
+
signal?: AbortSignal | undefined;
|
|
83
|
+
onKeyDown?: ((event: KeyboardEvent<HTMLElement>, close: () => void) => void) | undefined;
|
|
84
|
+
afterClose?: (() => void) | undefined;
|
|
85
|
+
}
|
|
86
|
+
export interface AlertOptions extends BaseOptions {
|
|
87
|
+
kind: 'alert';
|
|
88
|
+
okLabel?: ReactNode | undefined;
|
|
89
|
+
}
|
|
90
|
+
export interface ConfirmOptions extends BaseOptions {
|
|
91
|
+
kind: 'confirm';
|
|
92
|
+
confirmLabel?: ReactNode | undefined;
|
|
93
|
+
cancelLabel?: ReactNode | undefined;
|
|
94
|
+
/** danger moves the initial focus to the cancel button */
|
|
95
|
+
tone?: 'default' | 'danger' | undefined;
|
|
96
|
+
onConfirm?: ((ctx: {
|
|
97
|
+
signal: AbortSignal;
|
|
98
|
+
}) => void | Promise<void>) | undefined;
|
|
99
|
+
}
|
|
100
|
+
export interface PromptOptions extends BaseOptions {
|
|
101
|
+
kind: 'prompt';
|
|
102
|
+
label?: ReactNode | undefined;
|
|
103
|
+
defaultValue?: string | undefined;
|
|
104
|
+
inputProps?: Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'defaultValue'> | undefined;
|
|
105
|
+
/** return a message to keep the dialog open and show it under the input */
|
|
106
|
+
validate?: ((value: string) => string | null | Promise<string | null>) | undefined;
|
|
107
|
+
submitLabel?: ReactNode | undefined;
|
|
108
|
+
cancelLabel?: ReactNode | undefined;
|
|
109
|
+
}
|
|
110
|
+
export interface CustomOptions<R> extends BaseOptions {
|
|
111
|
+
kind: 'custom';
|
|
112
|
+
render: ComponentType<DialogRenderProps<R>>;
|
|
113
|
+
buttons?: readonly DialogButton<R>[] | undefined;
|
|
114
|
+
}
|
|
115
|
+
export type DialogKind = 'alert' | 'confirm' | 'prompt' | 'custom';
|
|
116
|
+
/** what the store keeps: every kind renders through `render` */
|
|
117
|
+
export interface EntryOptions extends BaseOptions {
|
|
118
|
+
kind: DialogKind;
|
|
119
|
+
render: ComponentType<DialogRenderProps<any>>;
|
|
120
|
+
buttons?: readonly DialogButton<any>[] | undefined;
|
|
121
|
+
/** @internal class names from the v3 API, added to the frame */
|
|
122
|
+
overlayClassName?: string | undefined;
|
|
123
|
+
/** @internal v3 callback for a click on the overlay */
|
|
124
|
+
onClickOutside?: (() => void) | undefined;
|
|
125
|
+
/** @internal the v3 API: Escape from document keydown, blur on body.children[0] */
|
|
126
|
+
legacy?: boolean | undefined;
|
|
127
|
+
/** @internal confirm's tone, shown as data-tone on the frame */
|
|
128
|
+
tone?: 'default' | 'danger' | undefined;
|
|
129
|
+
/** @internal v3 callback, runs before afterClose when the dialog unmounts */
|
|
130
|
+
willUnmount?: (() => void) | undefined;
|
|
131
|
+
}
|
|
132
|
+
export interface DialogHandle<R> {
|
|
133
|
+
readonly id: DialogId;
|
|
134
|
+
readonly result: Promise<R | undefined>;
|
|
135
|
+
close: (value: R) => void;
|
|
136
|
+
dismiss: () => void;
|
|
137
|
+
update: (patch: Partial<Omit<CustomOptions<R>, 'kind'>>) => void;
|
|
138
|
+
}
|