Skip to content

Commit e056aa2

Browse files
committed
feat: add optional type prop to ChoiceOptions to distinguish when rendering
1 parent cf6daad commit e056aa2

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ The `ConfirmComponentHost` accepts the following props:
9595

9696
| Property | Required | Description |
9797
| --- | --- | --- |
98-
| renderAlert | yes | Provide a function which renders the alert component. See [renderAlert](#renderAlert) |
99-
| renderConfirm | yes | Provide a function which renders the confirmation component. See [renderConfirm](#renderConfirm) |
100-
| renderChoice | no | Provide a function which renders the choice component. See [renderChoice](#renderChoice) |
98+
| renderAlert | yes | Provide a function which renders the alert component. See [renderAlert](#renderalert) |
99+
| renderConfirm | yes | Provide a function which renders the confirmation component. See [renderConfirm](#renderconfirm) |
100+
| renderChoice | no | Provide a function which renders the choice component. See [renderChoice](#renderchoice) |
101101
| strings | no | Takes an object to provide default values for `yes`, `no`, and `cancel` button captions. Use this to localize these texts. |
102102
| alertDurations | no | You can provide an object to set the durations of an alert for each severity in ms. The defaults are: info: 3000, success: 3000, warning: 10000, error: 10000. |
103103

@@ -136,6 +136,7 @@ The `ConfirmComponentHost` accepts the following props:
136136
| isOpen | Is the choice dialog opened? |
137137
| title | The optional title of the choice. |
138138
| options | The list of selectable options to show. |
139+
| type | The optional type of the options to distinguish when rendering. |
139140
| cancelCaption | The caption of the action to cancel the choice. |
140141
| onConfirm | Call this function when a choice is selected. |
141142
| onCancel | Call this function when the choice is cancelled. |
@@ -172,6 +173,7 @@ To show a choice to the user, use the `choose` function. It takes one options pa
172173
| --- | --- | --- |
173174
| title | no | The title of the choice. |
174175
| options | yes | The possible choices. |
176+
| type | no | The optional type of the options to distinguish when rendering. |
175177
| cancelCaption | no | The caption of the cancel action. If not provided the `cancel` property of `strings` is used. The default is "Cancel". |
176178

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

src/Component.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ interface State {
2020
isOpen: boolean,
2121
title: string | undefined,
2222
options: Service.Option [],
23+
type?: string,
2324
cancelCaption: string,
2425
callback: (result: Service.Option | null) => void,
2526
},
@@ -97,6 +98,7 @@ class ConfirmComponentHost extends React.Component<Props, State> {
9798
isOpen: false,
9899
title: undefined,
99100
options: [],
101+
type: undefined,
100102
cancelCaption: "",
101103
callback () {
102104
// blank
@@ -217,6 +219,7 @@ class ConfirmComponentHost extends React.Component<Props, State> {
217219
isOpen: true,
218220
title: props.title,
219221
options: props.options,
222+
type: props.type,
220223
cancelCaption: props.cancelCaption ?? strings?.cancel ?? "Cancel",
221224
callback,
222225
},

src/Service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ interface ChooseOptions<TData extends Option = Option> {
4040
* The list of selectable options.
4141
*/
4242
options: TData [],
43+
/**
44+
* The optional type of the options to distinguish when rendering.
45+
* @type {string}
46+
*/
47+
type?: string,
4348
/**
4449
* The optional caption of the cancel action.
4550
*/

tests/Service.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ describe("Service", () => {
117117
const chooseOptions: ChooseOptions = {
118118
title: "Title",
119119
options,
120+
type: "default",
120121
};
121122

122123
// act

0 commit comments

Comments
 (0)