1+ import type { ConfirmDialogOptions , ConfirmDialogVariant } from "@t3tools/contracts" ;
2+
13export type ConfirmDialogState =
24 | { readonly status : "idle" }
3- | { readonly status : "confirming" ; readonly message : string }
4- | { readonly status : "closing" ; readonly message : string } ;
5+ | {
6+ readonly status : "confirming" ;
7+ readonly message : string ;
8+ readonly variant : ConfirmDialogVariant ;
9+ }
10+ | {
11+ readonly status : "closing" ;
12+ readonly message : string ;
13+ readonly variant : ConfirmDialogVariant ;
14+ } ;
515
616type PendingConfirmation = {
717 readonly message : string ;
18+ readonly variant : ConfirmDialogVariant ;
819 readonly resolve : ( confirmed : boolean ) => void ;
920} ;
1021
@@ -66,18 +77,25 @@ export function registerConfirmDialogHost(): () => void {
6677 * Requests a themed confirmation when a host is mounted. An undefined result
6778 * means no themed host is currently available.
6879 */
69- export function requestConfirmDialog ( message : string ) : Promise < boolean > | undefined {
80+ export function requestConfirmDialog (
81+ message : string ,
82+ options ?: ConfirmDialogOptions ,
83+ ) : Promise < boolean > | undefined {
7084 if ( registeredHostCount === 0 ) return undefined ;
7185
7286 const confirmation = new Promise < boolean > ( ( resolve ) => {
73- const pending = { message, resolve } satisfies PendingConfirmation ;
87+ const pending = {
88+ message,
89+ variant : options ?. variant ?? "default" ,
90+ resolve,
91+ } satisfies PendingConfirmation ;
7492 if ( activeConfirmation || state . status === "closing" ) {
7593 queuedConfirmations . push ( pending ) ;
7694 return ;
7795 }
7896
7997 activeConfirmation = pending ;
80- publish ( { status : "confirming" , message } ) ;
98+ publish ( { status : "confirming" , message, variant : pending . variant } ) ;
8199 } ) ;
82100
83101 return confirmation ;
@@ -89,7 +107,7 @@ export function respondToConfirmDialog(confirmed: boolean): void {
89107 const confirmation = activeConfirmation ;
90108 activeConfirmation = null ;
91109 confirmation . resolve ( confirmed ) ;
92- publish ( { status : "closing" , message : state . message } ) ;
110+ publish ( { status : "closing" , message : state . message , variant : state . variant } ) ;
93111}
94112
95113export function completeConfirmDialogClose ( ) : void {
@@ -102,7 +120,7 @@ export function completeConfirmDialogClose(): void {
102120 }
103121
104122 activeConfirmation = next ;
105- publish ( { status : "confirming" , message : next . message } ) ;
123+ publish ( { status : "confirming" , message : next . message , variant : next . variant } ) ;
106124}
107125
108126export function resetConfirmDialogForTests ( ) : void {
0 commit comments