@pushwoosh/dumb-components 4.7.1 → 4.8.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.
@@ -49,7 +49,12 @@ export const DropdownMenu = ({
49
49
  zIndex: menuZIndex
50
50
  });
51
51
  const {
52
- refs,
52
+ refs: {
53
+ reference,
54
+ floating,
55
+ setReference,
56
+ setFloating
57
+ },
53
58
  floatingStyles
54
59
  } = useFloating({
55
60
  open: isOpen,
@@ -70,7 +75,7 @@ export const DropdownMenu = ({
70
75
  useEffect(() => {
71
76
  if (isOpen) {
72
77
  const handleClickListener = e => {
73
- if (!refs.floating.current?.contains(e.target) && !refs.reference.current?.contains(e.target)) {
78
+ if (!floating.current?.contains(e.target) && !reference.current?.contains(e.target)) {
74
79
  handleClose();
75
80
  }
76
81
  };
@@ -82,17 +87,17 @@ export const DropdownMenu = ({
82
87
  document.removeEventListener('click', handleClickListener);
83
88
  };
84
89
  }
85
- }, [isOpen, refs.floating, refs.reference, handleClose]);
90
+ }, [isOpen, floating, reference, handleClose]);
86
91
  useEffect(() => {
87
- if (isOpen && isScrollable && refs.floating.current) {
88
- const activeElement = refs.floating.current.querySelector('[data-active="true"]');
92
+ if (isOpen && isScrollable && floating.current) {
93
+ const activeElement = floating.current.querySelector('[data-active="true"]');
89
94
  if (activeElement) {
90
95
  activeElement.scrollIntoView({
91
96
  block: 'nearest'
92
97
  });
93
98
  }
94
99
  }
95
- }, [isOpen, isScrollable, refs.floating]);
100
+ }, [isOpen, isScrollable, floating]);
96
101
  return _jsxs(DropdownContext.Provider, {
97
102
  value: setIsOpen,
98
103
  children: [renderHandler({
@@ -103,12 +108,12 @@ export const DropdownMenu = ({
103
108
  setIsOpen(true);
104
109
  }
105
110
  },
106
- ref: refs.setReference,
111
+ ref: setReference,
107
112
  isOpen
108
113
  }), isOpen && createPortal(_jsx(DropdownZIndexContext.Provider, {
109
114
  value: resolvedZIndex,
110
115
  children: _jsx(Place, {
111
- ref: refs.setFloating,
116
+ ref: setFloating,
112
117
  style: floatingStyles,
113
118
  "$color": color,
114
119
  "$width": width ?? undefined,
@@ -39,7 +39,10 @@ export const DropdownMenuSubmenu = ({
39
39
  const openedByClick = useRef(false);
40
40
  const [availableHeight, setAvailableHeight] = useState();
41
41
  const {
42
- refs,
42
+ refs: {
43
+ setReference,
44
+ setFloating
45
+ },
43
46
  floatingStyles
44
47
  } = useFloating({
45
48
  strategy: 'fixed',
@@ -98,7 +101,7 @@ export const DropdownMenuSubmenu = ({
98
101
  children: _jsxs(DropdownZIndexContext.Provider, {
99
102
  value: submenuZIndex,
100
103
  children: [_jsx(DropdownMenuItemStyled, {
101
- ref: refs.setReference,
104
+ ref: setReference,
102
105
  type: "button",
103
106
  "$active": isOpen,
104
107
  "$danger": isDanger,
@@ -122,7 +125,7 @@ export const DropdownMenuSubmenu = ({
122
125
  }), isOpen && createPortal(_jsx(SubmenuRegistryContext.Provider, {
123
126
  value: submenus,
124
127
  children: _jsx(Place, {
125
- ref: refs.setFloating,
128
+ ref: setFloating,
126
129
  style: {
127
130
  ...floatingStyles,
128
131
  maxHeight,
@@ -7,4 +7,4 @@ import { type CappingBase, type FrequencyCappingEditProps } from './types';
7
7
  * @example
8
8
  * <FrequencyCappingEdit capping={capping} globalCapping={global} applicationCode={code} onChange={setCapping} editGlobalClicked={openGlobal} />
9
9
  */
10
- export declare function FrequencyCappingEdit<T extends CappingBase>({ capping, globalCapping, onChange, applicationCode, editGlobalClicked, isInJourney, isDisabled, timezoneOptions, }: FrequencyCappingEditProps<T>): ReactElement;
10
+ export declare function FrequencyCappingEdit<T extends CappingBase>({ capping, globalCapping, onChange, applicationCode, editGlobalClicked, isInJourney, isDisabled, fullWidth, timezoneOptions, }: FrequencyCappingEditProps<T>): ReactElement;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback } from 'react';
3
3
  import { Color } from '@pushwoosh/kit-constants';
4
- import { Vertical } from '@pushwoosh/kit-helpers';
4
+ import { Horizontal, Vertical } from '@pushwoosh/kit-helpers';
5
5
  import { OpenIcon } from '@pushwoosh/kit-icons';
6
6
  import { CountingModeControl } from './components/CountingMode/CountingModeControl';
7
7
  import { Description } from './components/Description';
@@ -30,6 +30,7 @@ export function FrequencyCappingEdit({
30
30
  editGlobalClicked,
31
31
  isInJourney = false,
32
32
  isDisabled = false,
33
+ fullWidth = false,
33
34
  timezoneOptions
34
35
  }) {
35
36
  const lang = useLang();
@@ -43,6 +44,20 @@ export function FrequencyCappingEdit({
43
44
  const cappingOption = getCappingOption(enabled, ignoreGlobalCapping);
44
45
  const isGlobalCappingDisabled = globalCapping.count === 0 && globalCapping.days === 0;
45
46
  const globalCappingLinkText = getGlobalCappingLinkText(lang, isGlobalCappingDisabled);
47
+ const isUnlimited = cappingOption === CappingTypes.GLOBAL && isGlobalCappingDisabled;
48
+ const globalCappingLink = cappingOption === CappingTypes.GLOBAL && _jsx(Link, {
49
+ target: "_blank",
50
+ href: `/applications/${applicationCode}/message-delivery?tab=capping`,
51
+ title: globalCappingLinkText,
52
+ onClick: editGlobalClicked,
53
+ children: _jsxs(LinkWrapper, {
54
+ children: [globalCappingLinkText, _jsx(OpenIcon, {
55
+ size: "small",
56
+ view: "lined",
57
+ as: "span"
58
+ })]
59
+ })
60
+ });
46
61
  const onChangeFrequencyCapping = useCallback(value => {
47
62
  if (value === CappingTypes.IGNORE) {
48
63
  onChange({
@@ -76,6 +91,7 @@ export function FrequencyCappingEdit({
76
91
  });
77
92
  }, [capping, onChange]);
78
93
  return _jsx(Container, {
94
+ "$fullWidth": fullWidth,
79
95
  "$padding": 16,
80
96
  "$bgColor": Color.SOFT_LIGHT,
81
97
  "$borderRadius": 8,
@@ -92,24 +108,21 @@ export function FrequencyCappingEdit({
92
108
  value: cappingOptions.find(option => option.value === cappingOption),
93
109
  onChange: newValue => onChangeFrequencyCapping(newValue.value)
94
110
  })
95
- }), _jsx(Description, {
96
- cappingOption: cappingOption,
97
- messages: globalCapping.count,
98
- days: globalCapping.days,
99
- isInJourney: isInJourney,
100
- children: cappingOption === CappingTypes.GLOBAL && _jsx(Link, {
101
- target: "_blank",
102
- href: `/applications/${applicationCode}/message-delivery?tab=capping`,
103
- title: globalCappingLinkText,
104
- onClick: editGlobalClicked,
105
- children: _jsxs(LinkWrapper, {
106
- children: [globalCappingLinkText, _jsx(OpenIcon, {
107
- size: "small",
108
- view: "lined",
109
- as: "span"
110
- })]
111
- })
112
- })
111
+ }), _jsxs(Vertical, {
112
+ "$gap": 4,
113
+ children: [_jsx(Description, {
114
+ cappingOption: cappingOption,
115
+ messages: globalCapping.count,
116
+ days: globalCapping.days,
117
+ chipTooltip: isUnlimited ? lang({
118
+ message: 'DUMB.FREQUENCY_CAPPING.RO.TOOLTIP_UNLIMITED'
119
+ }) : undefined,
120
+ isInJourney: isInJourney,
121
+ children: !isUnlimited && globalCappingLink
122
+ }), isUnlimited && _jsx(Horizontal, {
123
+ "$justifyContent": "start",
124
+ children: globalCappingLink
125
+ })]
113
126
  }), cappingOption === CappingTypes.CUSTOM && !isDisabled && _jsx(EditCappingSettings, {
114
127
  messages: messages,
115
128
  days: days,
@@ -5,6 +5,7 @@ type Props = {
5
5
  messages: number;
6
6
  days: number;
7
7
  children?: ReactNode;
8
+ chipTooltip?: string;
8
9
  isInJourney: boolean;
9
10
  variant?: 'message' | 'in-app';
10
11
  };
@@ -9,6 +9,7 @@ export function Description(props) {
9
9
  messages,
10
10
  days,
11
11
  children,
12
+ chipTooltip,
12
13
  isInJourney,
13
14
  variant = 'message'
14
15
  } = props;
@@ -27,6 +28,7 @@ export function Description(props) {
27
28
  return _jsxs(Paragraph, {
28
29
  children: [prefix, chip && _jsx(ChipFrequencyCapping, {
29
30
  text: chip,
31
+ tooltip: chipTooltip,
30
32
  "$inText": true
31
33
  }), suffix, ' ', children]
32
34
  });
@@ -1,4 +1,4 @@
1
- export declare const Container: import("styled-components/dist/types").IStyledComponentBase<"web", Omit<import("styled-components").FastOmit<Omit<Omit<import("styled-components").FastOmit<import("styled-components/dist/types").Merged<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
1
+ export declare const Container: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Merged<Omit<import("styled-components").FastOmit<Omit<Omit<import("styled-components").FastOmit<import("styled-components/dist/types").Merged<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
2
2
  style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
3
3
  }, import("@pushwoosh/kit-helpers/styled-helpers").CommonBoxProps & {
4
4
  $alignContent?: import("@pushwoosh/kit-helpers/styled-helpers").AlignContentValue;
@@ -43,7 +43,9 @@ export declare const Container: import("styled-components/dist/types").IStyledCo
43
43
  }) | (import("react").CSSProperties & {
44
44
  [key: `--${string}`]: string | number | undefined;
45
45
  }) | undefined;
46
- }> & string;
46
+ }, {
47
+ $fullWidth?: boolean;
48
+ }>> & string;
47
49
  export declare const IconWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", Omit<import("styled-components").FastOmit<Omit<Omit<import("styled-components").FastOmit<import("styled-components/dist/types").Merged<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
48
50
  style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
49
51
  }, import("@pushwoosh/kit-helpers/styled-helpers").CommonBoxProps & {
@@ -4,7 +4,9 @@ import { Horizontal, Vertical } from '@pushwoosh/kit-helpers';
4
4
  export const Container = styled(Vertical).withConfig({
5
5
  displayName: "Container",
6
6
  componentId: "sc-1z3915-0"
7
- })(["max-width:560px;"]);
7
+ })(["max-width:", ";"], ({
8
+ $fullWidth
9
+ }) => $fullWidth ? 'none' : '560px');
8
10
  export const IconWrapper = styled(Horizontal).withConfig({
9
11
  displayName: "IconWrapper",
10
12
  componentId: "sc-1z3915-1"
@@ -83,6 +83,8 @@ export type FrequencyCappingEditProps<T extends CappingBase> = {
83
83
  isInJourney?: boolean;
84
84
  /** Disable editing. */
85
85
  isDisabled?: boolean;
86
+ /** Stretch to the parent width instead of the default 560px cap. */
87
+ fullWidth?: boolean;
86
88
  /**
87
89
  * IANA timezones offered for the calendar-day mode. Supplying them enables the
88
90
  * counting-mode selector; omit them to keep the rolling-only UI.
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { arrow, autoPlacement, offset, useFloating } from '@floating-ui/react-dom';
3
3
  import { isEqual } from 'es-toolkit';
4
- import { useEffect, useRef, useState } from 'react';
4
+ import { useEffect, useState } from 'react';
5
5
  import { Transforms } from 'slate';
6
6
  import { Collapse, elementAddListener, Horizontal, usePersistentFunction } from '@pushwoosh/kit-helpers';
7
7
  import { FieldBox } from '../FieldBox';
@@ -36,9 +36,13 @@ export const RichMessageEditor = ({
36
36
  }) => {
37
37
  const [showDrop, setShowDrop] = useState();
38
38
  const [isFocused, setIsFocused] = useState(false);
39
- const arrowRef = useRef(null);
39
+ const [arrowElement, setArrowElement] = useState(null);
40
40
  const {
41
- refs,
41
+ refs: {
42
+ reference,
43
+ setReference,
44
+ setFloating
45
+ },
42
46
  floatingStyles,
43
47
  update,
44
48
  middlewareData,
@@ -48,7 +52,7 @@ export const RichMessageEditor = ({
48
52
  middleware: [offset(8), autoPlacement({
49
53
  allowedPlacements: ['right', 'right-start', 'right-end', 'left', 'left-start', 'left-end']
50
54
  }), arrow({
51
- element: arrowRef
55
+ element: arrowElement
52
56
  })]
53
57
  });
54
58
  const onSelectionChange = selection => {
@@ -91,11 +95,11 @@ export const RichMessageEditor = ({
91
95
  return;
92
96
  }
93
97
  return elementAddListener(document, ['mousedown', 'touchstart', 'focusin'], event => {
94
- if (refs.reference.current instanceof HTMLElement && !refs.reference.current.contains(event.target)) {
98
+ if (reference.current instanceof HTMLElement && !reference.current.contains(event.target)) {
95
99
  clickAwayHandler();
96
100
  }
97
101
  });
98
- }, [clickAwayHandler, isFocused, refs.reference]);
102
+ }, [clickAwayHandler, isFocused, reference]);
99
103
  return _jsx(SlateEditor, {
100
104
  initialValue: initialValue,
101
105
  onChange: onChange,
@@ -104,7 +108,7 @@ export const RichMessageEditor = ({
104
108
  editor
105
109
  }) => _jsxs(FieldBox, {
106
110
  title: title,
107
- boxRef: refs.setReference,
111
+ boxRef: setReference,
108
112
  error: error,
109
113
  actions: _jsx(Collapse, {
110
114
  expanded: isFocused,
@@ -141,7 +145,7 @@ export const RichMessageEditor = ({
141
145
  }
142
146
  }), showDrop && _jsxs(DropArea, {
143
147
  style: floatingStyles,
144
- ref: refs.setFloating,
148
+ ref: setFloating,
145
149
  children: [showDrop.type === 'personalization' && _jsx(DropContent, {
146
150
  children: renderDynamicContent?.({
147
151
  dc: showDrop.path ? getDcByPath(editor.children, showDrop.path)?.dc : undefined,
@@ -163,7 +167,7 @@ export const RichMessageEditor = ({
163
167
  onEmojiSelect: s => editor.insertText(s)
164
168
  }), _jsx(Arrow, {
165
169
  "$direction": placementToDirection(placement),
166
- ref: arrowRef,
170
+ ref: setArrowElement,
167
171
  style: {
168
172
  left: middlewareData.arrow?.x,
169
173
  top: middlewareData.arrow?.y
@@ -44,7 +44,8 @@ export function Tooltip({
44
44
  isOpen
45
45
  });
46
46
  const {
47
- setReference
47
+ setReference,
48
+ setFloating
48
49
  } = refs;
49
50
  const originalRef = isValidElement(children) ? children.ref : undefined;
50
51
  const setChildRef = useCallback(node => {
@@ -86,7 +87,7 @@ export function Tooltip({
86
87
  }) : children ?? null;
87
88
  return _jsxs(_Fragment, {
88
89
  children: [anchor, isOpen && referenceEl && createPortal(_jsxs(TooltipBox, {
89
- ref: refs.setFloating,
90
+ ref: setFloating,
90
91
  style: {
91
92
  ...floatingStyles,
92
93
  zIndex
@@ -21,7 +21,7 @@ export declare function useTooltipPosition({ position, offset: offsetProp, arrow
21
21
  };
22
22
  floatingStyles: CSSProperties;
23
23
  placement: import("@floating-ui/react-dom").Placement;
24
- arrowRef: import("react").RefObject<HTMLDivElement | null>;
24
+ arrowRef: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement | null>>;
25
25
  arrowStyles: CSSProperties;
26
26
  };
27
27
  export {};
@@ -1,5 +1,5 @@
1
1
  import { arrow, autoUpdate, flip, offset, shift, useFloating } from '@floating-ui/react-dom';
2
- import { useRef } from 'react';
2
+ import { useState } from 'react';
3
3
  import { resolveArrowPadding } from './helpers';
4
4
  import { TooltipPositionToFloatingPlacementMap, TooltipPositionToOffsetMap } from './maps';
5
5
  const ArrowStaticSideMap = {
@@ -20,7 +20,7 @@ export function useTooltipPosition({
20
20
  arrowOffset,
21
21
  isOpen
22
22
  }) {
23
- const arrowRef = useRef(null);
23
+ const [arrowElement, setArrowElement] = useState(null);
24
24
  const [skidding, distance] = offsetProp ?? TooltipPositionToOffsetMap[position];
25
25
  const arrowPadding = resolveArrowPadding(arrowOffset);
26
26
  const {
@@ -38,7 +38,7 @@ export function useTooltipPosition({
38
38
  }), flip(), shift({
39
39
  padding: 8
40
40
  }), arrow({
41
- element: arrowRef,
41
+ element: arrowElement,
42
42
  padding: arrowPadding
43
43
  })],
44
44
  whileElementsMounted: autoUpdate
@@ -57,7 +57,7 @@ export function useTooltipPosition({
57
57
  refs,
58
58
  floatingStyles,
59
59
  placement,
60
- arrowRef,
60
+ arrowRef: setArrowElement,
61
61
  arrowStyles
62
62
  };
63
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "4.7.1",
3
+ "version": "4.8.0",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",