Skip to content

Commit 6c0f18d

Browse files
committed
Document the use of confirmationFactory.custom()
Closes #331
1 parent aded4fd commit 6c0f18d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/javascript/components_confirmation.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,36 @@ if (result) {
100100
console.log("The user has requested to delete the object.");
101101
}
102102
```
103+
104+
## Custom Confirmation Prompts
105+
106+
The `custom()` permits a custom confirmation dialog with a user-defined dialog content.
107+
108+
```ts
109+
const result = await confirmationFactory()
110+
.custom(theQuestionToAsk)
111+
.message(someLengthyExplanation);
112+
if (result) {
113+
console.log("The user has confirmed the dialog.");
114+
}
115+
```
116+
117+
### Use Custom HTML in the Dialog Body
118+
119+
Some dialogs require additional input elements, for example, the prompt to remove an element has an optional text field for a reason.
120+
121+
```ts
122+
const { result, dialog } = await confirmationFactory()
123+
.custom(theQuestionToAsk)
124+
.withFormElements((dialog) => {
125+
const p = document.createElement("<p>Hello World</p>");
126+
dialog.content.append(p);
127+
});
128+
if (result) {
129+
console.log("The user has confirmed the dialog.");
130+
console.log(
131+
"The DOM of the dialog can be accessed through `dialog.content`",
132+
dialog.content
133+
);
134+
}
135+
```

0 commit comments

Comments
 (0)