@pushwoosh/smart-components-kit 1.0.36 → 1.0.38

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.
@@ -5,7 +5,9 @@ type State = Record<string, VariedDynamicContent>;
5
5
  type DynamicContentPickerProps = {
6
6
  applicationCode: string;
7
7
  text: string;
8
+ icon?: ReactNode;
8
9
  title?: string;
10
+ hintText?: string;
9
11
  initState?: State;
10
12
  error?: ReactNode;
11
13
  renderDynamicContent?: (props: RenderDynamicContentProps) => ReactNode;
@@ -1,7 +1,7 @@
1
1
  import { arrow, autoPlacement, offset, useFloating } from '@floating-ui/react-dom';
2
- import React, { useMemo, useReducer, useRef, useState } from 'react';
2
+ import React, { useEffect, useMemo, useReducer, useRef, useState } from 'react';
3
3
  import { Color } from '@pushwoosh/kit-constants';
4
- import { Horizontal } from '@pushwoosh/kit-helpers';
4
+ import { elementAddListener, Horizontal, usePersistentFunction } from '@pushwoosh/kit-helpers';
5
5
  import { WarningRoundIcon } from '@pushwoosh/kit-icons';
6
6
  import { Text } from '@pushwoosh/kit-typography';
7
7
  import { Arrow, FieldPlace, TextPlace } from './styled';
@@ -24,7 +24,9 @@ const reducer = (state, action) => {
24
24
  export const DynamicContentPicker = ({
25
25
  applicationCode,
26
26
  text,
27
+ icon,
27
28
  title,
29
+ hintText,
28
30
  initState,
29
31
  error,
30
32
  renderDynamicContent
@@ -50,24 +52,44 @@ export const DynamicContentPicker = ({
50
52
  const parsedLines = useMemo(() => {
51
53
  const lines = text.split('\n');
52
54
  return lines.map(line => {
53
- return line.split(/\{\{(\d+)}}/g).map((match, index) => {
54
- if (index % 2 === 0) {
55
+ return line.split(/(\{\{[^}]+\}\}|\{[^}]+\})/g).filter(match => match !== '').map(match => {
56
+ if (!match.includes('{')) {
55
57
  return match;
56
58
  }
59
+ const varname = match.replace(/^\{\{?/, '').replace(/\}?\}$/, '').split('|')[0].trim();
57
60
  return {
58
- varname: match
61
+ varname
59
62
  };
60
63
  });
61
64
  });
62
65
  }, [text]);
66
+ const onClose = () => {
67
+ setActiveVar(undefined);
68
+ };
69
+ const clickAwayHandler = usePersistentFunction(() => {
70
+ onClose();
71
+ });
72
+ useEffect(() => {
73
+ if (!activeVar) {
74
+ return;
75
+ }
76
+ return elementAddListener(document, ['mousedown', 'touchstart', 'focusin'], event => {
77
+ if (refs.floating.current instanceof HTMLElement && !refs.floating.current.contains(event.target)) {
78
+ clickAwayHandler();
79
+ }
80
+ });
81
+ }, [clickAwayHandler, activeVar, refs.reference, refs.floating]);
63
82
  return React.createElement(React.Fragment, null, React.createElement(FieldPlace, {
64
83
  ref: refs.setReference
65
84
  }, React.createElement(Horizontal, {
66
85
  "$padding": "8px 16px",
67
86
  "$justifyContent": "space-between"
68
- }, React.createElement(Text, {
87
+ }, React.createElement(Horizontal, {
88
+ "$alignItems": "center",
89
+ "$gap": 8
90
+ }, icon && icon, React.createElement(Text, {
69
91
  "$variant": "h4"
70
- }, title), error && React.createElement(Horizontal, {
92
+ }, title)), error && React.createElement(Horizontal, {
71
93
  "$alignItems": "center",
72
94
  "$gap": 8
73
95
  }, React.createElement(WarningRoundIcon, {
@@ -76,8 +98,11 @@ export const DynamicContentPicker = ({
76
98
  color: Color.WARNING
77
99
  }), React.createElement(Text, {
78
100
  "$variant": "footnote",
79
- color: Color.WARNING
80
- }, error))), React.createElement(Horizontal, {
101
+ "$color": Color.WARNING
102
+ }, error)), !error && hintText && React.createElement(Text, {
103
+ "$variant": "footnote",
104
+ "$color": Color.LOCKED
105
+ }, hintText)), React.createElement(Horizontal, {
81
106
  "$padding": "12px 16px"
82
107
  }, React.createElement(TextPlace, null, parsedLines.map((line, index) => React.createElement(Line, {
83
108
  key: index /* eslint-disable-line react/no-array-index-key */,
@@ -95,7 +120,7 @@ export const DynamicContentPicker = ({
95
120
  key: activeVar,
96
121
  value: newDC
97
122
  }),
98
- onClose: () => setActiveVar(undefined),
123
+ onClose,
99
124
  update
100
125
  }) : React.createElement(VariedDynamicContentPickerFormSmart, {
101
126
  key: activeVar,
@@ -1,2 +1,3 @@
1
1
  export { SimpleDynamicContentPickerFormSmart } from './SimpleDynamicContentPickerFormSmart';
2
+ export type { VariedDynamicContent } from './types';
2
3
  export * from './hooks';
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './EmailTemplatePreview';
2
2
  export * from './context';
3
+ export * from './DynamicContentPicker';
3
4
  export * from './DynamicContentPickerForm';
4
5
  export * from './PlatformsConfigurationDrawer';
5
6
  export * from './LanguagesSelector';
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './EmailTemplatePreview';
2
2
  export * from './context';
3
+ export * from './DynamicContentPicker';
3
4
  export * from './DynamicContentPickerForm';
4
5
  export * from './PlatformsConfigurationDrawer';
5
6
  export * from './LanguagesSelector';
package/package.json CHANGED
@@ -51,5 +51,5 @@
51
51
  "engines": {
52
52
  "node": ">= 18"
53
53
  },
54
- "version": "1.0.36"
54
+ "version": "1.0.38"
55
55
  }