@luscii-healthtech/web-ui 2.16.1 → 2.16.2

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.
@@ -1,5 +1,7 @@
1
1
  import React from "react";
2
- import { ConfirmationDialogProps } from "./types/ConfirmationDialog.types";
2
+ import { ConfirmationDialogChoice, ConfirmationDialogProps } from "./types/ConfirmationDialog.types";
3
3
  export declare const ConfirmationDialogChoices: React.FC<{
4
4
  choices: ConfirmationDialogProps["choices"];
5
+ onChoiceChangeCallback?: (choice: ConfirmationDialogChoice) => void;
6
+ selectedChoice?: ConfirmationDialogChoice;
5
7
  }>;
@@ -19,7 +19,7 @@ export interface ConfirmationDialogProps {
19
19
  texts: ConfirmationDialogTexts;
20
20
  isOpen: boolean;
21
21
  onCancel: () => void;
22
- onConfirm: () => void;
22
+ onConfirm: (choice?: ConfirmationDialogChoice) => void;
23
23
  isProcessing?: boolean;
24
24
  withTitle?: {
25
25
  title: string;
@@ -2701,13 +2701,9 @@ var RadioGroupV2 = /*#__PURE__*/React__default.forwardRef(function (props, ref)
2701
2701
  });
2702
2702
 
2703
2703
  var ConfirmationDialogChoices = function ConfirmationDialogChoices(props) {
2704
- var choices = props.choices;
2705
-
2706
- var _useState = React.useState(choices == null ? void 0 : choices.options.find(function (choice) {
2707
- return choice.value === choices.defaultChoice;
2708
- })),
2709
- selectedChoice = _useState[0],
2710
- setSelectedChoice = _useState[1];
2704
+ var choices = props.choices,
2705
+ onChoiceChangeCallback = props.onChoiceChangeCallback,
2706
+ selectedChoice = props.selectedChoice;
2711
2707
 
2712
2708
  if (!choices) {
2713
2709
  return null;
@@ -2720,10 +2716,7 @@ var ConfirmationDialogChoices = function ConfirmationDialogChoices(props) {
2720
2716
  value: choice.value,
2721
2717
  info: choice.description,
2722
2718
  onChange: function onChange() {
2723
- var _props$choices;
2724
-
2725
- (_props$choices = props.choices) == null ? void 0 : _props$choices.onChoiceChange(choice);
2726
- setSelectedChoice(choice);
2719
+ onChoiceChangeCallback == null ? void 0 : onChoiceChangeCallback(choice);
2727
2720
  }
2728
2721
  };
2729
2722
  });
@@ -2738,12 +2731,34 @@ var ConfirmationDialogChoices = function ConfirmationDialogChoices(props) {
2738
2731
  };
2739
2732
 
2740
2733
  var ConfirmationDialog = function ConfirmationDialog(props) {
2734
+ var choices = props.choices;
2735
+
2736
+ var _useState = React.useState(choices == null ? void 0 : choices.options.find(function (choice) {
2737
+ return choice.value === choices.defaultChoice;
2738
+ })),
2739
+ selectedChoice = _useState[0],
2740
+ setSelectedChoice = _useState[1];
2741
+
2741
2742
  var handleOnCloseClick = function handleOnCloseClick() {
2742
2743
  if (!props.isProcessing) {
2743
2744
  props.onCancel();
2744
2745
  }
2745
2746
  };
2746
2747
 
2748
+ var onChoiceChange = function onChoiceChange(choice) {
2749
+ setSelectedChoice(choice);
2750
+
2751
+ if (choice) {
2752
+ var _props$choices;
2753
+
2754
+ (_props$choices = props.choices) == null ? void 0 : _props$choices.onChoiceChange(choice);
2755
+ }
2756
+ };
2757
+
2758
+ var onConfirmHandler = function onConfirmHandler() {
2759
+ props.onConfirm(selectedChoice);
2760
+ };
2761
+
2747
2762
  var modalButtons = [/*#__PURE__*/React__default.createElement(SecondaryButton, {
2748
2763
  key: "confirmation-dialog-button-cancel",
2749
2764
  "data-test-id": "button-cancel",
@@ -2755,7 +2770,7 @@ var ConfirmationDialog = function ConfirmationDialog(props) {
2755
2770
  className: "ml-2.5",
2756
2771
  "data-test-id": "button-confirm",
2757
2772
  text: props.texts.confirmLabel,
2758
- onClick: props.onConfirm,
2773
+ onClick: onConfirmHandler,
2759
2774
  isPending: props.isProcessing
2760
2775
  })];
2761
2776
  return /*#__PURE__*/React__default.createElement(ModalWithButtons, {
@@ -2774,7 +2789,9 @@ var ConfirmationDialog = function ConfirmationDialog(props) {
2774
2789
  text: props.texts.message,
2775
2790
  containsDangerousHtml: true
2776
2791
  }), /*#__PURE__*/React__default.createElement(ConfirmationDialogChoices, {
2777
- choices: props.choices
2792
+ choices: props.choices,
2793
+ onChoiceChangeCallback: onChoiceChange,
2794
+ selectedChoice: selectedChoice
2778
2795
  })));
2779
2796
  };
2780
2797