@pushwoosh/dumb-components 4.10.2 → 4.12.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.
@@ -12,7 +12,8 @@ export function ChatPreview(props) {
12
12
  content,
13
13
  status,
14
14
  issues,
15
- senderName
15
+ senderName,
16
+ name
16
17
  } = props;
17
18
  const look = CHAT_CHANNELS[channel];
18
19
  const view = viewOf(channel, status);
@@ -25,7 +26,8 @@ export function ChatPreview(props) {
25
26
  content: delivered,
26
27
  dropped: dropped,
27
28
  look: look,
28
- rcs: channel === 'rcs' ? content.rcs : undefined
29
+ rcs: channel === 'rcs' ? content.rcs : undefined,
30
+ name: name
29
31
  });
30
32
  return _jsxs(Screen, {
31
33
  "$skin": look.skin,
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Carousel, FlexBox } from './styles';
3
- import { cardsOf, fallbackTextOf } from '../../helpers';
3
+ import { altTextOf, cardsOf } from '../../helpers';
4
4
  import { Lang } from '../../polyglot';
5
5
  import { ChatCardView } from '../ChatCardView';
6
6
  import { ChatText } from '../ChatText';
@@ -14,18 +14,20 @@ export function NativeMessage(props) {
14
14
  content,
15
15
  look,
16
16
  dropped,
17
- rcs
17
+ rcs,
18
+ name
18
19
  } = props;
19
20
  const cards = cardsOf(content);
20
21
  if (content.type === 'custom_flex') {
22
+ const altText = altTextOf(content, name);
21
23
  return _jsxs(FlexBox, {
22
24
  children: [_jsx("strong", {
23
25
  children: _jsx(Lang, {
24
26
  message: "DUMB.CHAT_PREVIEW.FLEX"
25
27
  })
26
- }), fallbackTextOf(content) && _jsx(ChatText, {
28
+ }), altText && _jsx(ChatText, {
27
29
  markup: look.markup,
28
- text: fallbackTextOf(content)
30
+ text: altText
29
31
  })]
30
32
  });
31
33
  }
@@ -4,4 +4,6 @@ import type { ChatPartProps } from '../types';
4
4
  export type NativeMessageProps = ChatPartProps & {
5
5
  /** RCS card layout, passed only on RCS. */
6
6
  rcs?: ChatRcsLayout;
7
+ /** Preset name, the Flex alt text when the message carries no text. */
8
+ name?: string;
7
9
  };
@@ -8,6 +8,8 @@ export type ChatView = 'native'
8
8
  export declare function viewOf(channel: ChatChannel, status: ChatCompatibility | undefined): ChatView;
9
9
  /** Text the channel receives when it cannot render the content type. */
10
10
  export declare function fallbackTextOf(content: ChatContent): string;
11
+ /** LINE's Flex alt text, as the backend builds it: the message or first card text, else the fallback, else the preset name. */
12
+ export declare function altTextOf(content: ChatContent, name?: string): string;
11
13
  /** Buttons drawn below the bubble text: quick replies, call-to-action links and phone numbers. */
12
14
  export declare function bubbleButtonsOf(content: ChatContent): ChatButton[];
13
15
  /** Cards of a card or carousel message; a plain card is a one-slide carousel. */
@@ -13,6 +13,11 @@ export function viewOf(channel, status) {
13
13
  export function fallbackTextOf(content) {
14
14
  return content.fallback || content.body || '';
15
15
  }
16
+ /** LINE's Flex alt text, as the backend builds it: the message or first card text, else the fallback, else the preset name. */
17
+ export function altTextOf(content, name = '') {
18
+ const card = content.cards?.[0];
19
+ return content.body || card?.title || card?.body || content.fallback || name;
20
+ }
16
21
  /** Buttons drawn below the bubble text: quick replies, call-to-action links and phone numbers. */
17
22
  export function bubbleButtonsOf(content) {
18
23
  return content.type === 'quick_reply' || content.type === 'call_to_action' ? content.buttons ?? [] : [];
@@ -131,4 +131,6 @@ export interface ChatPreviewProps {
131
131
  issues?: ChatIssue[];
132
132
  /** Sender shown in the chat header. */
133
133
  senderName?: string;
134
+ /** Preset name: LINE's Flex alt text when the message carries no text. */
135
+ name?: string;
134
136
  }
@@ -171,7 +171,9 @@ function SelectCombobox({
171
171
  hasError,
172
172
  width,
173
173
  minWidth,
174
- fullWidth
174
+ fullWidth,
175
+ searchable = true,
176
+ selectedTone = 'soft'
175
177
  }) {
176
178
  const inputRef = useRef(null);
177
179
  const baseId = useId();
@@ -200,7 +202,7 @@ function SelectCombobox({
200
202
  const hasValue = value !== null && value !== undefined;
201
203
  const valueLabel = hasValue ? getLabel(value) : '';
202
204
  const selectedKey = hasValue ? getKey(value) : null;
203
- const inputValue = isOpen ? query : valueLabel;
205
+ const inputValue = isOpen && searchable ? query : valueLabel;
204
206
  const userMovedRef = useRef(false);
205
207
  const selectedIndex = sourceItems.findIndex(it => getKey(it) === selectedKey);
206
208
  const activateSelected = useCallback(() => {
@@ -222,6 +224,7 @@ function SelectCombobox({
222
224
  setActiveIndex(next);
223
225
  }, [setActiveIndex]);
224
226
  const search = event => {
227
+ if (!searchable) return;
225
228
  setQuery(event.target.value);
226
229
  if (event.target.value) moveActive(0);else activateSelected();
227
230
  };
@@ -269,9 +272,10 @@ function SelectCombobox({
269
272
  label: renderItem ? renderItem(item, state) : getLabel(item),
270
273
  active: state.active,
271
274
  selected,
275
+ selectedTone,
272
276
  onSelect: () => commit(item)
273
277
  };
274
- }), [filteredItems, activeIndex, selectedKey, getLabel, getKey, renderItem, commit, baseId]);
278
+ }), [filteredItems, activeIndex, selectedKey, getLabel, getKey, renderItem, commit, baseId, selectedTone]);
275
279
  const activeDescendant = activeIndex >= 0 && activeIndex < filteredItems.length ? optionId(getKey(filteredItems[activeIndex])) : undefined;
276
280
  return _jsx(FieldShell, {
277
281
  isOpen: isOpen,
@@ -303,6 +307,7 @@ function SelectCombobox({
303
307
  autosize: autosize,
304
308
  value: inputValue,
305
309
  onChange: search,
310
+ readOnly: !searchable,
306
311
  onKeyDown: onInputKeyDown,
307
312
  onFocus: open,
308
313
  onClick: open,
@@ -85,6 +85,10 @@ export type SelectComboboxProps<T> = ComboboxSource<T> & GetKeyProp<T> & CommonP
85
85
  onChange: (value: T | null) => void;
86
86
  /** Map an item to its display label (required). */
87
87
  getLabel: (item: T) => string;
88
+ /** Typing filters the items (default `true`); `false` keeps the selected label in the field while the list is open. */
89
+ searchable?: boolean;
90
+ /** Highlight of the selected row: `soft` (default) or `solid` (bright fill, white text). */
91
+ selectedTone?: 'soft' | 'solid';
88
92
  };
89
93
  /** Props of {@link Combobox} — free-text by default, strict single-select with `select`. */
90
94
  export type ComboboxProps<T> = FreeComboboxProps | SelectComboboxProps<T>;
@@ -25,6 +25,7 @@ export const RichMessageEditor = ({
25
25
  title,
26
26
  initialValue,
27
27
  minHeight,
28
+ compact,
28
29
  placeholder,
29
30
  error,
30
31
  isErrored,
@@ -129,6 +130,7 @@ export const RichMessageEditor = ({
129
130
  }),
130
131
  children: [_jsx(SlateEditable, {
131
132
  minHeight: minHeight,
133
+ compact: compact,
132
134
  placeholder: placeholder,
133
135
  isErrored: isErrored || !!error,
134
136
  onFocus: () => {
@@ -24,6 +24,8 @@ export type RichMessageEditorProps = {
24
24
  onChange: (value: string) => void;
25
25
  /** Minimum editor height (CSS value). */
26
26
  minHeight?: string;
27
+ /** Size a one-line editor like a text input, 36px high (default `false`). */
28
+ compact?: boolean;
27
29
  /** Hint shown while the editor is empty. */
28
30
  placeholder?: string;
29
31
  /** Error message; switches the field to the error state. */
@@ -12,6 +12,7 @@ type SlateEditor = {
12
12
  export declare const SlateEditor: FC<SlateEditor>;
13
13
  type SlateEditableProps = {
14
14
  minHeight?: string;
15
+ compact?: boolean;
15
16
  placeholder?: string;
16
17
  isErrored?: boolean;
17
18
  onFocus?: () => void;
@@ -26,6 +26,7 @@ export const SlateEditor = ({
26
26
  };
27
27
  export const SlateEditable = ({
28
28
  minHeight,
29
+ compact,
29
30
  placeholder,
30
31
  isErrored,
31
32
  onFocus,
@@ -35,10 +36,11 @@ export const SlateEditable = ({
35
36
  return renderElement(props, onDelete);
36
37
  });
37
38
  return _jsx(EditableStyled, {
38
- style: minHeight ? {
39
- minHeight
39
+ style: minHeight || compact ? {
40
+ minHeight: minHeight ?? '36px'
40
41
  } : undefined,
41
42
  "$isErrored": isErrored,
43
+ "$compact": compact,
42
44
  placeholder: placeholder,
43
45
  renderElement: renderElementPersistent,
44
46
  onFocus: onFocus
@@ -17,6 +17,7 @@ export declare const EditableStyled: import("styled-components/dist/types").ISty
17
17
  style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
18
18
  }, {
19
19
  $isErrored?: boolean;
20
+ $compact?: boolean;
20
21
  }>> & string & Omit<import("react").ForwardRefExoticComponent<{
21
22
  decorate?: ((entry: import("slate").NodeEntry) => import("slate").DecoratedRange[]) | undefined;
22
23
  onDOMBeforeInput?: ((event: InputEvent) => void) | undefined;
@@ -1,9 +1,11 @@
1
1
  import { Editable } from 'slate-react';
2
- import styled from 'styled-components';
2
+ import styled, { css } from 'styled-components';
3
3
  import { Color, FontSize, FontWeight, ShapeRadius } from '@pushwoosh/kit-constants';
4
4
  export const EditableStyled = styled(Editable).withConfig({
5
5
  displayName: "EditableStyled",
6
6
  componentId: "sc-16lukqt-0"
7
- })(["font-weight:", ";font-size:", ";line-height:140%;padding:8px;color:", ";background:", ";caret-color:", ";border:1px solid ", ";border-radius:", ";overflow-x:auto;& [data-slate-placeholder='true']{color:", ";opacity:1 !important;}&:focus{border-color:", ";outline:none;}& > p{position:relative;margin:4px 0;&:first-child{margin-top:0;}&:last-child{margin-bottom:0;}}"], FontWeight.REGULAR, FontSize.REGULAR, Color.MAIN, Color.CLEAR, Color.BRIGHT, ({
7
+ })(["font-weight:", ";font-size:", ";line-height:140%;padding:8px;color:", ";background:", ";caret-color:", ";border:1px solid ", ";border-radius:", ";overflow-x:auto;", " & [data-slate-placeholder='true']{color:", ";opacity:1 !important;}&:focus{border-color:", ";outline:none;}& > p{position:relative;margin:4px 0;&:first-child{margin-top:0;}&:last-child{margin-bottom:0;}}"], FontWeight.REGULAR, FontSize.REGULAR, Color.MAIN, Color.CLEAR, Color.BRIGHT, ({
8
8
  $isErrored
9
- }) => $isErrored ? Color.DANGER : Color.FORM, ShapeRadius.CONTROL, Color.PHANTOM, Color.BRIGHT);
9
+ }) => $isErrored ? Color.DANGER : Color.FORM, ShapeRadius.CONTROL, ({
10
+ $compact
11
+ }) => $compact && css(["box-sizing:border-box;padding-top:7px;padding-bottom:7px;"]), Color.PHANTOM, Color.BRIGHT);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "4.10.2",
3
+ "version": "4.12.0",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -109,6 +109,7 @@ export function SuggestionsDropdown({
109
109
  "aria-selected": !!item.selected,
110
110
  "$active": item.active,
111
111
  "$selected": item.selected,
112
+ "$solid": item.selectedTone === 'solid',
112
113
  onMouseDown: e => {
113
114
  e.preventDefault();
114
115
  item.onSelect?.();
@@ -35,6 +35,7 @@ export declare const DropdownItem: import("styled-components/dist/types").IStyle
35
35
  }, {
36
36
  $active?: boolean;
37
37
  $selected?: boolean;
38
+ $solid?: boolean;
38
39
  }>> & string;
39
40
  export declare const DropdownEmpty: import("styled-components/dist/types").IStyledComponentBase<"web", Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
40
41
  style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
@@ -63,7 +63,7 @@ export const Dropdown = styled.div.withConfig({
63
63
  export const DropdownItem = styled.div.withConfig({
64
64
  displayName: "DropdownItem",
65
65
  componentId: "sc-1pvwhhw-7"
66
- })(["display:flex;align-items:center;gap:6px;padding:6px 12px;overflow-wrap:anywhere;", ";& > *{min-width:0;}background:", ";cursor:pointer;&:hover{background:", ";}"], textBase, ({
66
+ })(["display:flex;align-items:center;gap:6px;padding:6px 12px;overflow-wrap:anywhere;", ";& > *{min-width:0;}background:", ";cursor:pointer;&:hover{background:", ";}", ""], textBase, ({
67
67
  $active,
68
68
  $selected
69
69
  }) => {
@@ -72,7 +72,11 @@ export const DropdownItem = styled.div.withConfig({
72
72
  return 'transparent';
73
73
  }, ({
74
74
  $selected
75
- }) => $selected ? Color.BRIGHT_LIGHT_HOVER : Color.ROW_HOVER);
75
+ }) => $selected ? Color.BRIGHT_LIGHT_HOVER : Color.ROW_HOVER, ({
76
+ $selected,
77
+ $solid,
78
+ $active
79
+ }) => $selected && $solid && css(["background:", ";color:", ";&:hover{background:", ";}"], $active ? Color.BRIGHT_HOVER : Color.BRIGHT, Color.CLEAR, Color.BRIGHT_HOVER));
76
80
  export const DropdownEmpty = styled.div.withConfig({
77
81
  displayName: "DropdownEmpty",
78
82
  componentId: "sc-1pvwhhw-8"
@@ -66,6 +66,8 @@ export type DropdownItemDescriptor = {
66
66
  active?: boolean;
67
67
  /** Row is the selected value. */
68
68
  selected?: boolean;
69
+ /** Highlight of the selected row: `soft` (default) or `solid` (bright fill, white text). */
70
+ selectedTone?: 'soft' | 'solid';
69
71
  /** Called when the row is chosen. */
70
72
  onSelect?: () => void;
71
73
  };