Skip to content

Commit 18abb5d

Browse files
committed
feat: add optional extra prop to ChooseOptions (#5)
1 parent b82987f commit 18abb5d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ You can use the `ConfirmComponentHost` in multiple places in your application. T
150150
| cancelCaption | The caption of the action to cancel the choice. |
151151
| onConfirm | Call this function when a choice is selected. |
152152
| onCancel | Call this function when the choice is cancelled. |
153+
| extra | Optional custom data. |
153154

154155
## How to use the `ConfirmService`
155156

@@ -185,6 +186,7 @@ To show a choice to the user, use the `choose` function. It takes one options pa
185186
| options | yes | The possible choices. |
186187
| type | no | The optional type of the options to distinguish when rendering. |
187188
| cancelCaption | no | The caption of the cancel action. If not provided the `cancel` property of `strings` is used. The default is "Cancel". |
189+
| extra | no | Optional custom data. |
188190

189191
This function returns a `Promise`. It will be resolved with the selected option and rejected if the choice is cancelled.
190192

src/Component.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ interface State {
2020
isOpen: boolean,
2121
title: string | undefined,
2222
options: Service.Option [],
23-
type?: string,
23+
type: string | undefined,
2424
cancelCaption: string,
25+
extra: unknown,
2526
callback: (result: Service.Option | null) => void,
2627
},
2728
}
@@ -50,6 +51,7 @@ interface ChoiceRenderProps {
5051
options: Service.Option [],
5152
type?: string,
5253
cancelCaption: string,
54+
extra: unknown,
5355
onConfirm: (option: Service.Option) => void,
5456
onCancel: () => void,
5557
}
@@ -103,6 +105,7 @@ class ConfirmComponentHost extends React.Component<Props, State> {
103105
options: [],
104106
type: undefined,
105107
cancelCaption: "",
108+
extra: undefined,
106109
callback () {
107110
// blank
108111
},
@@ -229,6 +232,7 @@ class ConfirmComponentHost extends React.Component<Props, State> {
229232
title: props.title,
230233
options: props.options,
231234
type: props.type,
235+
extra: props.extra,
232236
cancelCaption: props.cancelCaption ?? strings?.cancel ?? "Cancel",
233237
callback,
234238
},

src/Service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ interface ChooseOptions<TData extends Option = Option> {
6060
* The optional caption of the cancel action.
6161
*/
6262
cancelCaption?: string,
63+
/**
64+
* Optional custom data.
65+
*/
66+
extra?: unknown,
6367
}
6468

6569
interface Handlers {

0 commit comments

Comments
 (0)