@dynamic-framework/ui-react 2.1.0 → 2.1.1

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.
package/dist/index.js CHANGED
@@ -1128,6 +1128,9 @@ function DCollapse({ id, className, style, Component, hasSeparator = false, defa
1128
1128
  return next;
1129
1129
  });
1130
1130
  };
1131
+ React.useEffect(() => {
1132
+ setCollapsed(defaultCollapsed);
1133
+ }, [defaultCollapsed]);
1131
1134
  const { iconMap: { chevronDown, chevronUp, }, } = useDContext();
1132
1135
  const iconOpen = React.useMemo(() => iconOpenProp || chevronDown, [chevronDown, iconOpenProp]);
1133
1136
  const iconClose = React.useMemo(() => iconCloseProp || chevronUp, [chevronUp, iconCloseProp]);
@@ -1858,7 +1861,7 @@ function DInputSwitch({ id: idProp, label, ariaLabel, name, checked, disabled, i
1858
1861
  setInternalIsChecked(value);
1859
1862
  onChange === null || onChange === void 0 ? void 0 : onChange(value);
1860
1863
  }, [onChange]);
1861
- return (jsxRuntime.jsxs("div", Object.assign({ className: classNames('form-check', className) }, dataAttributes, { children: [jsxRuntime.jsx("input", { id: id, name: name, onChange: readonly ? () => false : changeHandler, className: classNames('form-check-input', {
1864
+ return (jsxRuntime.jsxs("div", Object.assign({ className: classNames('form-check form-switch', className) }, dataAttributes, { children: [jsxRuntime.jsx("input", { id: id, name: name, onChange: readonly ? () => false : changeHandler, className: classNames('form-check-input', {
1862
1865
  'is-invalid': invalid,
1863
1866
  'is-valid': valid,
1864
1867
  }, inputClassName), style: style, type: "checkbox", role: "switch", checked: internalIsChecked, disabled: disabled, "aria-label": ariaLabel }), label && (jsxRuntime.jsx("label", { className: "form-check-label", htmlFor: id, children: label }))] })));
@@ -2609,6 +2612,75 @@ function DVoucher({ amount, amountDetails, icon = 'CircleCheckBig', color = 'suc
2609
2612
  }, children: jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "d-voucher-header", children: [jsxRuntime.jsx(DIcon, { icon: icon, color: color }), jsxRuntime.jsxs("div", { className: "text-center", children: [jsxRuntime.jsx("h3", { className: "mb-2", children: title }), jsxRuntime.jsx("p", { className: "m-0", children: message })] })] }), amount && (jsxRuntime.jsxs("div", { className: "d-voucher-amount", children: [jsxRuntime.jsx("div", { className: classNames('text-center fw-bold fs-3', amountDetails ? 'mb-1' : 'm-0'), children: amount }), amountDetails] })), jsxRuntime.jsx("hr", { className: "my-4" }), children, jsxRuntime.jsx("hr", { className: "my-4" }), jsxRuntime.jsxs("div", { className: "d-voucher-footer", children: [jsxRuntime.jsx(DButton, { onClick: handleShare, iconStart: "Share2", text: shareText, variant: "outline", size: "sm" }), jsxRuntime.jsx(DButton, { onClick: handleDownload, iconStart: "Download", text: downloadText, variant: "outline", size: "sm" })] })] }) }));
2610
2613
  }
2611
2614
 
2615
+ function useCountdown(seconds) {
2616
+ const [secondsLeft, setSecondsLeft] = React.useState(seconds);
2617
+ const [isActive, setIsActive] = React.useState(true);
2618
+ const resetCountdown = React.useCallback((newSeconds = seconds) => {
2619
+ setIsActive(false);
2620
+ setSecondsLeft(newSeconds);
2621
+ }, [seconds]);
2622
+ const restartCountdown = React.useCallback(() => {
2623
+ resetCountdown(seconds);
2624
+ setIsActive(true);
2625
+ }, [resetCountdown, seconds]);
2626
+ React.useEffect(() => {
2627
+ if (!isActive) {
2628
+ return () => { };
2629
+ }
2630
+ const interval = setInterval(() => {
2631
+ setSecondsLeft((prevSeconds) => {
2632
+ const newSeconds = prevSeconds - 1;
2633
+ if (newSeconds <= 0) {
2634
+ clearInterval(interval);
2635
+ setIsActive(false);
2636
+ return 0;
2637
+ }
2638
+ return newSeconds;
2639
+ });
2640
+ }, 1000);
2641
+ return () => clearInterval(interval);
2642
+ }, [isActive]);
2643
+ return { secondsLeft, restartCountdown };
2644
+ }
2645
+
2646
+ const defaultMessage = (secs) => (secs > 0
2647
+ ? `Didn't get any code? Resend in: ${secs}s`
2648
+ : "Didn't get any code?");
2649
+ function OtpCountdown({ seconds, resendText, message, }) {
2650
+ const { secondsLeft, restartCountdown } = useCountdown(seconds);
2651
+ return (jsxRuntime.jsxs("div", { className: "d-flex gap-2 align-items-center", children: [jsxRuntime.jsx("p", { className: "mb-0", children: message ? message(secondsLeft) : defaultMessage(secondsLeft) }), jsxRuntime.jsx(DButton, { text: resendText, variant: "link", disabled: secondsLeft > 0, onClick: restartCountdown })] }));
2652
+ }
2653
+
2654
+ const TEXT_PROPS = {
2655
+ resend: 'Resend',
2656
+ resendText: 'Resend code',
2657
+ submit: 'Authorize and continue',
2658
+ title: 'We will send you a 6-digit code to your associated phone number so you can continue with your request.',
2659
+ contact: (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("span", { children: "Problems with your digital token? Contact us" }), ' ', jsxRuntime.jsx("a", { href: "https://www.modyo.com", className: "link-primary text-nowrap", target: "_blank", rel: "noreferrer", children: "Contact us" })] })),
2660
+ };
2661
+ function DOtp({ className, action, isLoading, otpSize = 6, texts = TEXT_PROPS, seconds = 15, }) {
2662
+ const [otp, setOtp] = React.useState('');
2663
+ const [invalid, setInvalid] = React.useState(false);
2664
+ const handler = React.useCallback(async () => {
2665
+ if (otp.length < otpSize) {
2666
+ setInvalid(true);
2667
+ return;
2668
+ }
2669
+ setInvalid(false);
2670
+ await action();
2671
+ }, [
2672
+ otp.length,
2673
+ action,
2674
+ otpSize,
2675
+ ]);
2676
+ return (jsxRuntime.jsxs("div", { className: className, children: [jsxRuntime.jsx("p", { children: texts.title }), jsxRuntime.jsxs("div", { className: "d-flex flex-column gap-6 pb-4 px-3", children: [jsxRuntime.jsxs("div", { className: "d-flex flex-column gap-6", children: [jsxRuntime.jsx(DInputPin, { className: "modal-otp-pin", characters: otpSize, onChange: (e) => setOtp(e), invalid: invalid && otp.length < otpSize, placeholder: "0" }), jsxRuntime.jsx(OtpCountdown, { seconds: seconds, resendText: texts.resend })] }), jsxRuntime.jsx("hr", { className: "m-0" }), jsxRuntime.jsxs("div", { className: "d-flex flex-column flex-lg-row gap-4 align-items-center", children: [jsxRuntime.jsx(DButton, { text: texts.submit, onClick: () => {
2677
+ handler().catch((err) => {
2678
+ // eslint-disable-next-line no-console
2679
+ console.error('Error in DOtp action:', err);
2680
+ });
2681
+ }, loading: isLoading }), jsxRuntime.jsx("p", { className: "small ms-lg-auto mb-0", children: texts.contact })] })] })] }));
2682
+ }
2683
+
2612
2684
  exports.DAlert = DAlert;
2613
2685
  exports.DAvatar = DAvatar;
2614
2686
  exports.DBadge = DBadge;
@@ -2655,6 +2727,7 @@ exports.DOffcanvas = DOffcanvas;
2655
2727
  exports.DOffcanvasBody = DOffcanvasBody;
2656
2728
  exports.DOffcanvasFooter = DOffcanvasFooter;
2657
2729
  exports.DOffcanvasHeader = DOffcanvasHeader;
2730
+ exports.DOtp = DOtp;
2658
2731
  exports.DPaginator = DPaginator;
2659
2732
  exports.DPasswordStrengthMeter = DPasswordStrengthMeter;
2660
2733
  exports.DPopover = DPopover;