@capillarytech/creatives-library 9.0.45 → 9.0.47

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.
@@ -1491,6 +1491,14 @@ describe('WhatsApp edit Done button whitespace validation', () => {
1491
1491
  expect(getDoneButton().props().disabled).toBe(true);
1492
1492
  });
1493
1493
 
1494
+ it('propagates templateId from edit content into TestAndPreviewSlidebox formData', () => {
1495
+ mountEditFlow(mockData.editData1);
1496
+ const slidebox = renderedComponent.find('TestAndPreviewSlidebox').first();
1497
+ expect(slidebox.exists()).toBe(true);
1498
+ expect(slidebox.prop('formData').templateId).toBe('HT9bb4d61eea1699d2dbcaecd1cb558345');
1499
+ expect(slidebox.prop('content').templateId).toBe('HT9bb4d61eea1699d2dbcaecd1cb558345');
1500
+ });
1501
+
1494
1502
  it('keeps Done disabled for whitespace-only carousel variable', () => {
1495
1503
  const editData = {
1496
1504
  templateDetails: {
@@ -1,127 +0,0 @@
1
- import React, { useLayoutEffect, useMemo, useRef, useState } from 'react';
2
- import PropTypes from 'prop-types';
3
- import CapRow from '@capillarytech/cap-ui-library/CapRow';
4
- import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
5
- import CapImage from '@capillarytech/cap-ui-library/CapImage';
6
- import {
7
- getTrimmedText,
8
- hasTrimmedText,
9
- getCarouselButtonsWithTitles,
10
- getCarouselButtonSlotCount,
11
- } from '../utils';
12
- import { DEFAULT_CAROUSEL_TITLE_LINE_HEIGHT_PX } from '../constants';
13
-
14
- const ViberCarouselPreviewCards = ({ cards = [] }) => {
15
- const previewCards = Array.isArray(cards) && cards.length ? cards : [{}];
16
- const carouselButtonSlotCount = useMemo(
17
- () => getCarouselButtonSlotCount(previewCards),
18
- [previewCards],
19
- );
20
- const carouselTitleRefs = useRef([]);
21
- const [carouselTitleLineCount, setCarouselTitleLineCount] = useState(1);
22
-
23
- carouselTitleRefs.current = previewCards.map(() => null);
24
-
25
- useLayoutEffect(() => {
26
- let maxLines = 1;
27
- carouselTitleRefs.current?.forEach((node) => {
28
- if (!node) {
29
- return;
30
- }
31
- const { lineHeight } = window.getComputedStyle(node);
32
- const parsedLineHeight = parseFloat(lineHeight) || DEFAULT_CAROUSEL_TITLE_LINE_HEIGHT_PX;
33
- const lines = Math.min(2, Math.max(1, Math.round(node?.scrollHeight / parsedLineHeight)));
34
- if (lines > maxLines) {
35
- maxLines = lines;
36
- }
37
- });
38
- setCarouselTitleLineCount((prev) => (prev === maxLines ? prev : maxLines));
39
- }, [previewCards]);
40
-
41
- return (
42
- <CapRow type="flex" noWrap className="scroll">
43
- {previewCards?.map((card, index) => {
44
- const cardButtons = getCarouselButtonsWithTitles(card);
45
- const titleLineClass = `text-wrap--${carouselTitleLineCount}-line`;
46
-
47
- return (
48
- <CapRow type="flex-column" className="card" key={`viber-carousel-card-${index}`}>
49
- {hasTrimmedText(card?.mediaUrl) ? (
50
- <CapImage
51
- src={card?.mediaUrl}
52
- className="image"
53
- alt="Viber carousel card"
54
- />
55
- ) : (
56
- <CapRow className="image-placeholder" />
57
- )}
58
- <CapRow className="card-body">
59
- <CapRow className={`text-wrap ${titleLineClass}`}>
60
- {hasTrimmedText(card?.text) ? (
61
- <CapRow
62
- className="text-inner"
63
- ref={(node) => {
64
- carouselTitleRefs.current[index] = node;
65
- }}
66
- >
67
- <CapLabel type="label15" className="text">
68
- {card?.text}
69
- </CapLabel>
70
- </CapRow>
71
- ) : (
72
- <CapLabel type="label15" className="text-placeholder" />
73
- )}
74
- </CapRow>
75
- {carouselButtonSlotCount > 0 && (
76
- <CapRow className="buttons">
77
- {Array.from({ length: carouselButtonSlotCount }).map((_, btnIndex) => {
78
- const cardButton = cardButtons[btnIndex];
79
- const trimmedCardButtonTitle = cardButton
80
- ? getTrimmedText(cardButton?.title)
81
- : '';
82
-
83
- if (!trimmedCardButtonTitle) {
84
- return (
85
- <CapRow
86
- className="button button-placeholder"
87
- key={`viber-carousel-btn-placeholder-${index}-${btnIndex}`}
88
- aria-hidden="true"
89
- />
90
- );
91
- }
92
-
93
- return (
94
- <CapLabel
95
- className={`button ${btnIndex === 1 ? 'button-secondary' : ''}`}
96
- key={`viber-carousel-btn-${index}-${btnIndex}-${trimmedCardButtonTitle}`}
97
- >
98
- {trimmedCardButtonTitle}
99
- </CapLabel>
100
- );
101
- })}
102
- </CapRow>
103
- )}
104
- </CapRow>
105
- </CapRow>
106
- );
107
- })}
108
- </CapRow>
109
- );
110
- };
111
-
112
- ViberCarouselPreviewCards.propTypes = {
113
- cards: PropTypes.arrayOf(PropTypes.shape({
114
- text: PropTypes.string,
115
- mediaUrl: PropTypes.string,
116
- buttons: PropTypes.arrayOf(PropTypes.shape({
117
- title: PropTypes.string,
118
- action: PropTypes.string,
119
- })),
120
- })),
121
- };
122
-
123
- ViberCarouselPreviewCards.defaultProps = {
124
- cards: [],
125
- };
126
-
127
- export default ViberCarouselPreviewCards;
@@ -1,133 +0,0 @@
1
- // Shared Viber carousel card row (Test & Preview device preview)
2
- .viber-carousel-preview {
3
- .scroll {
4
- display: flex;
5
- flex-direction: row;
6
- flex-wrap: nowrap;
7
- align-items: stretch;
8
- width: 100%;
9
- max-width: 100%;
10
- min-width: 0;
11
- overflow-x: auto;
12
- overflow-y: hidden;
13
- padding-right: $CAP_SPACE_12;
14
- scrollbar-width: none;
15
- -webkit-overflow-scrolling: touch;
16
-
17
- &::-webkit-scrollbar {
18
- display: none;
19
- }
20
-
21
- .card {
22
- flex: 0 0 68%;
23
- min-width: 80%;
24
- margin-right: $CAP_SPACE_08;
25
- background: $CAP_G09;
26
- border: 1px solid $CAP_G07;
27
- border-radius: $CAP_SPACE_12;
28
- overflow: hidden;
29
- display: flex;
30
- flex-direction: column;
31
- align-self: stretch;
32
-
33
- &:last-child {
34
- margin-right: 0;
35
- }
36
-
37
- .image {
38
- width: 100%;
39
- height: 10rem;
40
- object-fit: cover;
41
- border-radius: 0;
42
- }
43
-
44
- .image-placeholder {
45
- width: 100%;
46
- height: 10rem;
47
- border-radius: 0;
48
- background: $CAP_G07;
49
- }
50
-
51
- .card-body {
52
- flex: 1;
53
- padding: $CAP_SPACE_08;
54
- display: flex;
55
- flex-direction: column;
56
- min-height: 0;
57
-
58
- .text-wrap {
59
- flex-shrink: 0;
60
- width: 100%;
61
-
62
- &--1-line {
63
- min-height: 1.3em;
64
- }
65
-
66
- &--2-line {
67
- min-height: 2.6em;
68
- }
69
-
70
- .text-inner {
71
- width: 100%;
72
-
73
- .text {
74
- color: $CAP_G01;
75
- line-height: 1.3;
76
- white-space: normal;
77
- word-break: break-word;
78
- display: block;
79
- width: 100%;
80
- margin: 0;
81
- }
82
- }
83
-
84
- .text-placeholder {
85
- width: 100%;
86
- height: 0.875rem;
87
- border-radius: $CAP_SPACE_04;
88
- background: $CAP_G07;
89
- min-height: 0.875rem;
90
- display: block;
91
- }
92
- }
93
-
94
- .buttons {
95
- display: flex;
96
- flex-direction: column;
97
- gap: $CAP_SPACE_06;
98
- width: 100%;
99
- flex-shrink: 0;
100
-
101
- .button {
102
- color: $CAP_WHITE;
103
- background: $CAP_PURPLE01;
104
- border-radius: $CAP_SPACE_12;
105
- text-align: center;
106
- width: 100%;
107
- display: flex;
108
- align-items: center;
109
- justify-content: center;
110
- min-height: 1.5rem;
111
- padding: $CAP_SPACE_06 $CAP_SPACE_08;
112
- white-space: normal;
113
- box-sizing: border-box;
114
- }
115
-
116
- .button-placeholder {
117
- visibility: hidden;
118
- pointer-events: none;
119
- padding: 0;
120
- background: transparent;
121
- border: none;
122
- }
123
-
124
- .button-secondary {
125
- color: $CAP_PURPLE01;
126
- background: transparent;
127
- border: none;
128
- }
129
- }
130
- }
131
- }
132
- }
133
- }