@dynamic-framework/ui-react 2.0.0-dev.21 → 2.0.0-dev.22

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.esm.js CHANGED
@@ -23,16 +23,51 @@ import { initReactI18next } from 'react-i18next';
23
23
 
24
24
  const PREFIX_BS = 'bs-';
25
25
 
26
+ /* eslint-disable no-lonely-if */
26
27
  function useDisableBodyScrollEffect(disable) {
27
28
  useEffect(() => {
28
- if (disable) {
29
+ let observer;
30
+ let timer;
31
+ const lock = () => {
32
+ const { clientWidth } = document.documentElement;
33
+ const { innerWidth } = window;
34
+ const scrollbarWidth = clientWidth ? innerWidth - clientWidth : 0;
29
35
  document.body.style.overflow = 'hidden';
30
- document.body.style.paddingRight = '0';
36
+ document.body.style.paddingRight = `${Math.max(0, scrollbarWidth)}px`;
37
+ };
38
+ const unlock = () => {
39
+ document.body.style.overflow = 'unset';
40
+ document.body.style.paddingRight = '0px';
41
+ };
42
+ if (disable) {
43
+ lock();
31
44
  }
32
45
  else {
33
- document.body.style.overflow = 'unset';
34
- document.body.style.paddingRight = 'unset';
46
+ // Wait until all portal elements are removed (exit animations done)
47
+ if (document.querySelector('.portal')) {
48
+ observer = new MutationObserver(() => {
49
+ if (!document.querySelector('.portal')) {
50
+ unlock();
51
+ observer === null || observer === void 0 ? void 0 : observer.disconnect();
52
+ }
53
+ });
54
+ observer.observe(document.body, { childList: true, subtree: true });
55
+ // Fallback in case observer misses changes
56
+ timer = window.setTimeout(() => {
57
+ unlock();
58
+ observer === null || observer === void 0 ? void 0 : observer.disconnect();
59
+ }, 3000);
60
+ }
61
+ else {
62
+ unlock();
63
+ }
35
64
  }
65
+ return () => {
66
+ if (observer)
67
+ observer.disconnect();
68
+ if (timer)
69
+ window.clearTimeout(timer);
70
+ };
36
71
  }, [disable]);
37
72
  }
38
73
 
@@ -966,7 +1001,7 @@ function DBoxFile(_a) {
966
1001
  }
967
1002
 
968
1003
  const DButton = forwardRef((props, ref) => {
969
- const { color = 'primary', size, variant, text, children, iconStart, iconStartFamilyClass, iconStartFamilyPrefix, iconStartMaterialStyle, iconEnd, iconEndFamilyClass, iconEndFamilyPrefix, iconEndMaterialStyle, loading = false, loadingText, loadingAriaLabel, disabled = false, className, style, dataAttributes, onClick, type = 'button' } = props, rest = __rest(props, ["color", "size", "variant", "text", "children", "iconStart", "iconStartFamilyClass", "iconStartFamilyPrefix", "iconStartMaterialStyle", "iconEnd", "iconEndFamilyClass", "iconEndFamilyPrefix", "iconEndMaterialStyle", "loading", "loadingText", "loadingAriaLabel", "disabled", "className", "style", "dataAttributes", "onClick", "type"]);
1004
+ const { color = 'primary', size, variant, text, children, iconStart, iconStartFamilyClass, iconStartFamilyPrefix, iconStartMaterialStyle, iconEnd, iconEndFamilyClass, iconEndFamilyPrefix, iconEndMaterialStyle, loading = false, loadingText, loadingAriaLabel, disabled = false, className, style, dataAttributes, onClick, type = 'button', target, rel } = props, rest = __rest(props, ["color", "size", "variant", "text", "children", "iconStart", "iconStartFamilyClass", "iconStartFamilyPrefix", "iconStartMaterialStyle", "iconEnd", "iconEndFamilyClass", "iconEndFamilyPrefix", "iconEndMaterialStyle", "loading", "loadingText", "loadingAriaLabel", "disabled", "className", "style", "dataAttributes", "onClick", "type", "target", "rel"]);
970
1005
  const [buttonWidth, setButtonWidth] = useState();
971
1006
  const buttonRef = useRef(null);
972
1007
  const isDisabled = useMemo(() => disabled || loading, [disabled, loading]);
@@ -1003,6 +1038,19 @@ const DButton = forwardRef((props, ref) => {
1003
1038
  }
1004
1039
  // eslint-disable-next-line react-hooks/exhaustive-deps
1005
1040
  }, [content, iconEnd, iconStart]);
1041
+ if (props.href) {
1042
+ return (jsxs("a", Object.assign({ href: props.href, target: target, rel: rel, ref: (node) => {
1043
+ buttonRef.current = node;
1044
+ if (typeof ref === 'function')
1045
+ ref(node);
1046
+ // eslint-disable-next-line max-len
1047
+ // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
1048
+ else if (ref)
1049
+ ref.current = node;
1050
+ }, className: classNames(classes, className), style: Object.assign(Object.assign({}, style), (loading && buttonWidth
1051
+ ? { minWidth: `${buttonWidth}px` }
1052
+ : undefined)), "aria-label": ariaLabel, "aria-busy": loading, "aria-disabled": isDisabled, onClick: handleClick }, dataAttributes, { children: [loading && (jsxs("span", { className: "btn-loading", children: [jsx("span", { className: "spinner-border spinner-border-sm", "aria-hidden": "true" }), loadingText && jsx("span", { role: "status", children: loadingText })] })), !loading && (jsxs(Fragment, { children: [iconStart && (jsx(DIcon, { icon: iconStart, familyClass: iconStartFamilyClass, familyPrefix: iconStartFamilyPrefix, materialStyle: iconStartMaterialStyle })), content, iconEnd && (jsx(DIcon, { icon: iconEnd, familyClass: iconEndFamilyClass, familyPrefix: iconEndFamilyPrefix, materialStyle: iconEndMaterialStyle }))] }))] })));
1053
+ }
1006
1054
  return (jsxs("button", Object.assign({ ref: (node) => {
1007
1055
  buttonRef.current = node;
1008
1056
  if (typeof ref === 'function')
@@ -1019,23 +1067,32 @@ const DButton = forwardRef((props, ref) => {
1019
1067
  });
1020
1068
  DButton.displayName = 'DButton';
1021
1069
 
1022
- function DButtonIcon({ id, icon, size, className, variant, state, loadingAriaLabel, iconMaterialStyle, ariaLabel, color = 'primary', type = 'button', loading = false, disabled = false, stopPropagationEnabled = true, style, iconFamilyClass, iconFamilyPrefix, dataAttributes, onClick, }) {
1070
+ function DButtonIcon({ id, icon, size, className, variant, state, loadingAriaLabel, iconMaterialStyle, ariaLabel, color = 'primary', type = 'button', loading = false, disabled = false, href, target, rel, stopPropagationEnabled = true, style, iconFamilyClass, iconFamilyPrefix, dataAttributes, onClick, }) {
1023
1071
  const generateClasses = useMemo(() => {
1024
1072
  const variantClass = variant
1025
1073
  ? `btn-${variant}-${color}`
1026
1074
  : `btn-${color}`;
1027
1075
  return Object.assign(Object.assign(Object.assign({ 'btn d-button-icon': true, [variantClass]: true }, size && { [`btn-${size}`]: true }), (state && state !== 'disabled') && { [state]: true }), { loading });
1028
1076
  }, [variant, color, size, state, loading]);
1077
+ const isDisabled = useMemo(() => (state === 'disabled' || loading || disabled), [state, loading, disabled]);
1029
1078
  const clickHandler = useCallback((event) => {
1030
1079
  if (stopPropagationEnabled) {
1031
1080
  event.stopPropagation();
1032
1081
  }
1082
+ if (isDisabled) {
1083
+ event.preventDefault();
1084
+ return;
1085
+ }
1033
1086
  onClick === null || onClick === void 0 ? void 0 : onClick(event);
1034
- }, [stopPropagationEnabled, onClick]);
1035
- const isDisabled = useMemo(() => (state === 'disabled' || loading || disabled), [state, loading, disabled]);
1087
+ }, [stopPropagationEnabled, onClick, isDisabled]);
1036
1088
  const newAriaLabel = useMemo(() => (loading
1037
1089
  ? (loadingAriaLabel || ariaLabel)
1038
1090
  : (ariaLabel)), [ariaLabel, loading, loadingAriaLabel]);
1091
+ if (href) {
1092
+ return (jsx("a", Object.assign({ href: href, target: target, rel: rel, className: classNames(generateClasses, className), style: style, onClick: clickHandler, "aria-label": newAriaLabel, "aria-disabled": isDisabled, id: id }, dataAttributes, { children: loading
1093
+ ? (jsx("span", { className: "spinner-border spinner-border-sm", role: "status", "aria-hidden": "true", children: jsx("span", { className: "visually-hidden", children: "Loading..." }) }))
1094
+ : (jsx(DIcon, { icon: icon, familyClass: iconFamilyClass, familyPrefix: iconFamilyPrefix, materialStyle: iconMaterialStyle })) })));
1095
+ }
1039
1096
  return (jsx("button", Object.assign({ className: classNames(generateClasses, className), style: style, type: type, disabled: isDisabled, onClick: clickHandler, "aria-label": newAriaLabel, id: id }, dataAttributes, { children: loading
1040
1097
  ? (jsx("span", { className: "spinner-border spinner-border-sm", role: "status", "aria-hidden": "true", children: jsx("span", { className: "visually-hidden", children: "Loading..." }) }))
1041
1098
  : (jsx(DIcon, { icon: icon, familyClass: iconFamilyClass, familyPrefix: iconFamilyPrefix, materialStyle: iconMaterialStyle })) })));
@@ -2418,7 +2475,7 @@ ForwardedDInputPhone.displayName = 'DInputPhone';
2418
2475
  const DEFAULT_IMAGE = 'https://cdn.modyo.cloud/uploads/06b434f7-b943-4f54-9543-84a904e189aa/original/Visa_Logo_1_.png';
2419
2476
  const CHIP_IMAGE = 'https://cdn.modyo.cloud/uploads/4660ad00-e5d8-477e-8919-52b53d0a26fb/original/chip-debit-svgrepo-com_1_.png';
2420
2477
  function DCreditCard({ brand = 'visa', name, number, holderText = 'Card Holder', logoImage, isChipVisible = true, className, isVertical = false, }) {
2421
- return (jsxs("div", { className: classNames('d-credit-card overflow-hidden text-white', 'position-relative rounded-3', 'd-none d-lg-flex', isVertical && 'is-vertical', className), children: [jsxs("div", { className: "d-credit-card-header", children: [jsx("img", { src: logoImage || DEFAULT_IMAGE, alt: brand, className: "d-credit-card-logo", width: 100 }), isChipVisible && (jsx("div", { className: "d-credit-card-chip p-2 rounded-2", children: jsx("img", { src: CHIP_IMAGE, alt: "chip", width: 30, className: "d-credit-card-chip-image" }) }))] }), jsxs("div", { className: "d-credit-card-details mt-auto d-none d-sm-block", children: [jsx("div", { className: "d-credit-card-number d-none d-sm-block mb-4", children: number }), jsx("small", { className: "d-block opacity-50", children: holderText }), jsx("span", { className: "name", children: name })] })] }));
2478
+ return (jsxs("div", { className: classNames('d-credit-card overflow-hidden text-white', 'position-relative rounded-3', 'd-flex', isVertical && 'is-vertical', className), children: [jsxs("div", { className: "d-credit-card-header", children: [jsx("img", { src: logoImage || DEFAULT_IMAGE, alt: brand, className: "d-credit-card-logo", width: 100 }), isChipVisible && (jsx("div", { className: "d-credit-card-chip p-2 rounded-2", children: jsx("img", { src: CHIP_IMAGE, alt: "chip", width: 30, className: "d-credit-card-chip-image" }) }))] }), jsxs("div", { className: "d-credit-card-details mt-auto d-none d-sm-block", children: [jsx("div", { className: "d-credit-card-number d-none d-sm-block mb-4", children: number }), jsx("small", { className: "d-block opacity-50", children: holderText }), jsx("span", { className: "name", children: name })] })] }));
2422
2479
  }
2423
2480
 
2424
2481
  const getItemClass = (action) => {
@@ -2560,7 +2617,7 @@ function useScreenshotWebShare() {
2560
2617
  };
2561
2618
  }
2562
2619
 
2563
- function DVoucher({ amount, amountDetails, icon = 'CircleCheckBig', color = 'success', title, onError, message, downloadText = 'Download', shareText = 'Share', children, }) {
2620
+ function DVoucher({ amount, amountDetails, icon, title, onError, message, downloadText = 'Download', shareText = 'Share', className, children, }) {
2564
2621
  const { shareRef, share } = useScreenshotWebShare();
2565
2622
  const { downloadRef, download } = useScreenshotDownload();
2566
2623
  const handleShare = () => {
@@ -2585,10 +2642,25 @@ function DVoucher({ amount, amountDetails, icon = 'CircleCheckBig', color = 'suc
2585
2642
  // Error already handled by onError
2586
2643
  });
2587
2644
  };
2588
- return (jsx("div", { className: "d-voucher", ref: (el) => {
2645
+ const defaultIconProps = {
2646
+ icon: 'CircleCheckBig',
2647
+ color: 'success',
2648
+ size: '2rem',
2649
+ hasCircle: true,
2650
+ };
2651
+ const resolvedIconProps = (() => {
2652
+ if (icon === false || icon == null)
2653
+ return null;
2654
+ if (typeof icon === 'string')
2655
+ return Object.assign(Object.assign({}, defaultIconProps), { icon });
2656
+ if (typeof icon === 'object')
2657
+ return Object.assign(Object.assign({}, defaultIconProps), icon);
2658
+ return defaultIconProps;
2659
+ })();
2660
+ return (jsx("div", { className: classNames('d-voucher', className), ref: (el) => {
2589
2661
  shareRef.current = el;
2590
2662
  downloadRef.current = el;
2591
- }, children: jsxs("div", { children: [jsxs("div", { className: "d-voucher-header", children: [jsx(DIcon, { icon: icon, color: color }), jsxs("div", { className: "text-center", children: [jsx("h3", { className: "mb-2", children: title }), jsx("p", { className: "m-0", children: message })] })] }), amount && (jsxs("div", { className: "d-voucher-amount", children: [jsx("div", { className: classNames('text-center fw-bold fs-3', amountDetails ? 'mb-1' : 'm-0'), children: amount }), amountDetails] })), jsx("hr", { className: "my-4" }), children, jsx("hr", { className: "my-4" }), jsxs("div", { className: "d-voucher-footer", children: [jsx(DButton, { onClick: handleShare, iconStart: "Share2", text: shareText, variant: "outline", size: "sm" }), jsx(DButton, { onClick: handleDownload, iconStart: "Download", text: downloadText, variant: "outline", size: "sm" })] })] }) }));
2663
+ }, children: jsxs("div", { children: [jsxs("div", { className: "d-voucher-header", children: [resolvedIconProps && (jsx(DIcon, Object.assign({}, resolvedIconProps))), jsxs("div", { className: "text-center", children: [jsx("h3", { className: "mb-2", children: title }), jsx("p", { className: "m-0", children: message })] })] }), amount && (jsxs("div", { className: "d-voucher-amount", children: [jsx("div", { className: classNames('text-center fw-bold fs-3', amountDetails ? 'mb-1' : 'm-0'), children: amount }), amountDetails] })), jsx("hr", { className: "my-4" }), children, jsx("hr", { className: "my-4" }), jsxs("div", { className: "d-voucher-footer", children: [jsx(DButton, { onClick: handleShare, iconStart: "Share2", text: shareText, variant: "outline", size: "sm" }), jsx(DButton, { onClick: handleDownload, iconStart: "Download", text: downloadText, variant: "outline", size: "sm" })] })] }) }));
2592
2664
  }
2593
2665
 
2594
2666
  function useCountdown(seconds) {