@digital-ai/dot-components 3.16.0 → 3.17.0

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/index.esm.js CHANGED
@@ -9923,6 +9923,7 @@ const DotSnackbar = ({
9923
9923
  anchorOrigin = DEFAULT_ANCHOR_ORIGIN,
9924
9924
  anchorOriginTop = 108,
9925
9925
  ariaLabel,
9926
+ autoCloseOnAction = false,
9926
9927
  autoHideDuration,
9927
9928
  children,
9928
9929
  className,
@@ -9943,6 +9944,17 @@ const DotSnackbar = ({
9943
9944
  onClose();
9944
9945
  }
9945
9946
  };
9947
+ const handlePrimaryActionClick = () => {
9948
+ primaryAction === null || primaryAction === void 0 ? void 0 : primaryAction.onClick();
9949
+ if (autoCloseOnAction) {
9950
+ onClose();
9951
+ }
9952
+ };
9953
+ const handleSecondaryActionClick = () => {
9954
+ if (autoCloseOnAction) {
9955
+ onClose();
9956
+ }
9957
+ };
9946
9958
  return jsx(StyledSnackbar, {
9947
9959
  anchorOrigin: anchorOrigin,
9948
9960
  "$anchorOriginTop": anchorOriginTop,
@@ -9978,14 +9990,15 @@ const DotSnackbar = ({
9978
9990
  children: [primaryAction && jsx(DotButton, {
9979
9991
  className: "primary-action-btn",
9980
9992
  "data-testid": "primary-action-btn",
9981
- onClick: primaryAction.onClick,
9993
+ onClick: handlePrimaryActionClick,
9982
9994
  size: "small",
9983
9995
  type: "outlined",
9984
9996
  children: primaryAction.label
9985
9997
  }), secondaryAction && jsx(DotLink, {
9998
+ color: "inherit",
9986
9999
  "data-testid": "secondary-action-link",
9987
10000
  href: secondaryAction.href,
9988
- color: "inherit",
10001
+ onClick: handleSecondaryActionClick,
9989
10002
  children: secondaryAction.label
9990
10003
  })]
9991
10004
  })]
@@ -10017,6 +10030,7 @@ const DotSnackbarContext = createContext({
10017
10030
  removeMessage: _id => null
10018
10031
  });
10019
10032
  const DotSnackbarContainer = ({
10033
+ autoCloseOnAction,
10020
10034
  hideOnClickAway
10021
10035
  }) => {
10022
10036
  const {
@@ -10035,6 +10049,7 @@ const DotSnackbarContainer = ({
10035
10049
  "data-testid": rootClassName$F,
10036
10050
  children: alerts.slice().reverse().map(alert => {
10037
10051
  return jsx(DotSnackbar, {
10052
+ autoCloseOnAction: autoCloseOnAction,
10038
10053
  autoHideDuration: alert.autoHideDuration,
10039
10054
  hideOnClickAway: hideOnClickAway,
10040
10055
  onClose: handleClose(alert.id),
@@ -10049,6 +10064,7 @@ const DotSnackbarContainer = ({
10049
10064
  });
10050
10065
  };
10051
10066
  const DotSnackbarProvider = ({
10067
+ autoCloseOnAction = false,
10052
10068
  children,
10053
10069
  hideOnClickAway = true
10054
10070
  }) => {
@@ -10087,6 +10103,7 @@ const DotSnackbarProvider = ({
10087
10103
  return jsxs(DotSnackbarContext.Provider, {
10088
10104
  value: memoizedValues,
10089
10105
  children: [jsx(DotSnackbarContainer, {
10106
+ autoCloseOnAction: autoCloseOnAction,
10090
10107
  hideOnClickAway: hideOnClickAway
10091
10108
  }), children]
10092
10109
  });
@@ -13448,34 +13465,25 @@ const getWarningAdornment = () => {
13448
13465
  };
13449
13466
  const applyBindings = (bindings, inlineEditText) => {
13450
13467
  if (!bindings || !bindings.length || !inlineEditText) return;
13451
- let text = inlineEditText;
13452
- let boundNode = [];
13453
- bindings.forEach((binding, index) => {
13454
- const {
13455
- binding: stringBinding,
13456
- className = null,
13457
- value
13458
- } = binding;
13459
- let bindingStringIndex = text.indexOf(stringBinding);
13460
- let key = 0;
13461
- while (bindingStringIndex >= 0) {
13462
- // Since key is needed only for bindings with className,
13463
- // increment key value only if className value is defined
13464
- className && key++;
13465
- const nextStartingIndex = bindingStringIndex + stringBinding.length;
13466
- const previousText = text.substring(0, bindingStringIndex);
13467
- text = text.substring(nextStartingIndex, text.length);
13468
- bindingStringIndex = text.indexOf(stringBinding);
13469
- // Add nodes to array
13470
- boundNode = [boundNode, previousText, className ? jsx("span", {
13471
- className: className,
13472
- children: value
13473
- }, `${index}-${key}`) : value];
13474
- }
13468
+ let result = [inlineEditText];
13469
+ const getBoundSpan = (value, className, key) => className ? jsx("span", {
13470
+ className: className,
13471
+ children: value
13472
+ }, key) : value;
13473
+ bindings.forEach(({
13474
+ binding,
13475
+ className,
13476
+ value
13477
+ }, index) => {
13478
+ result = result.flatMap((part, i) => {
13479
+ if (typeof part === 'string') {
13480
+ // Split the text by the binding and interleave with the replacement value
13481
+ return part.split(binding).flatMap((textPart, j, arr) => [textPart, j < arr.length - 1 ? getBoundSpan(value, className, `${index}-${i}-${j}`) : null]);
13482
+ }
13483
+ return part;
13484
+ });
13475
13485
  });
13476
- // Add remainder of the text to the node
13477
- boundNode = [boundNode, text];
13478
- return boundNode;
13486
+ return result;
13479
13487
  };
13480
13488
  const checkIfEmptyValue = inputValue => inputValue.trim() === '';
13481
13489
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digital-ai/dot-components",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "private": false,
5
5
  "license": "SEE LICENSE IN <LICENSE.md>",
6
6
  "contributors": [
@@ -15,6 +15,8 @@ export interface SnackbarProps extends CommonProps {
15
15
  anchorOrigin?: SnackbarOrigin;
16
16
  /** When specified, will set `top` property (in pixels) only for the vertical top origins */
17
17
  anchorOriginTop?: number;
18
+ /** Automatically triggers onClose handler when primary or secondary action has been clicked */
19
+ autoCloseOnAction?: boolean;
18
20
  /** The number of milliseconds to wait before automatically closing the snackbar. If null is passed, then the snackbar never automatically closes. If the prop is not passed at all, then snackbars close after 10 seconds (except error snackbar which never closes automatically). */
19
21
  autoHideDuration?: number | null;
20
22
  /** The message the user sees once the alert displays. */
@@ -34,4 +36,4 @@ export interface SnackbarProps extends CommonProps {
34
36
  /** Width of the encapsulated Alert component. */
35
37
  width?: string;
36
38
  }
37
- export declare const DotSnackbar: ({ anchorOrigin, anchorOriginTop, ariaLabel, autoHideDuration, children, className, "data-testid": dataTestId, hideOnClickAway, onClose, open, primaryAction, secondaryAction, severity, width, }: SnackbarProps) => import("react/jsx-runtime").JSX.Element;
39
+ export declare const DotSnackbar: ({ anchorOrigin, anchorOriginTop, ariaLabel, autoCloseOnAction, autoHideDuration, children, className, "data-testid": dataTestId, hideOnClickAway, onClose, open, primaryAction, secondaryAction, severity, width, }: SnackbarProps) => import("react/jsx-runtime").JSX.Element;
@@ -11,11 +11,13 @@ declare const initialState: {
11
11
  secondaryAction: SnackbarSecondaryAction;
12
12
  }[];
13
13
  export interface SnackbarProviderProps {
14
+ autoCloseOnAction?: boolean;
14
15
  /** The components or string that load inside the snackbar provider. */
15
16
  children: ReactNode;
16
17
  hideOnClickAway?: boolean;
17
18
  }
18
19
  interface SnackbarContainerProps {
20
+ autoCloseOnAction?: boolean;
19
21
  hideOnClickAway?: boolean;
20
22
  }
21
23
  interface DotSnackbarProps {
@@ -24,8 +26,8 @@ interface DotSnackbarProps {
24
26
  removeMessage: (id: string) => void;
25
27
  }
26
28
  export declare const DotSnackbarContext: import("react").Context<DotSnackbarProps>;
27
- export declare const DotSnackbarContainer: ({ hideOnClickAway, }: SnackbarContainerProps) => import("react/jsx-runtime").JSX.Element;
28
- export declare const DotSnackbarProvider: ({ children, hideOnClickAway, }: SnackbarProviderProps) => import("react/jsx-runtime").JSX.Element;
29
+ export declare const DotSnackbarContainer: ({ autoCloseOnAction, hideOnClickAway, }: SnackbarContainerProps) => import("react/jsx-runtime").JSX.Element;
30
+ export declare const DotSnackbarProvider: ({ autoCloseOnAction, children, hideOnClickAway, }: SnackbarProviderProps) => import("react/jsx-runtime").JSX.Element;
29
31
  export declare const useDotSnackbarContext: () => DotSnackbarProps;
30
32
  export declare const useEnqueueErrorMessage: (error: GenericApiError | Error) => void;
31
33
  export {};