@capillarytech/creatives-library 9.0.13-alpha.1 → 9.0.13

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.
Files changed (22) hide show
  1. package/package.json +1 -1
  2. package/v2Components/CommonTestAndPreview/UnifiedPreview/ViberPreviewContent.js +15 -108
  3. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -141
  4. package/v2Components/CommonTestAndPreview/index.js +26 -244
  5. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/ViberPreviewContent.test.js +0 -364
  6. package/v2Components/ErrorInfoNote/index.js +1 -1
  7. package/v2Components/ErrorInfoNote/style.scss +3 -0
  8. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +216 -96
  9. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +37 -17
  10. package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +77 -37
  11. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +530 -250
  12. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +3 -3
  13. package/v2Containers/Templates/_templates.scss +1 -84
  14. package/v2Containers/Templates/index.js +10 -90
  15. package/v2Containers/Viber/constants.js +0 -21
  16. package/v2Containers/Viber/index.js +49 -719
  17. package/v2Containers/Viber/index.scss +0 -175
  18. package/v2Containers/Viber/messages.js +0 -121
  19. package/v2Containers/Viber/tests/index.test.js +0 -80
  20. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2645 -11346
  21. package/v2Components/CommonTestAndPreview/UnifiedPreview/ViberCarouselPreviewCards.js +0 -132
  22. package/v2Components/CommonTestAndPreview/UnifiedPreview/_viberCarouselPreviewCards.scss +0 -132
@@ -1,132 +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
-
7
- const getTrimmedText = (value = '') => (value ?? '').trim();
8
- const hasTrimmedText = (value = '') => Boolean(getTrimmedText(value));
9
-
10
- const getCarouselButtonsWithTitles = (card) => (
11
- (card?.buttons ?? []).filter((button) => hasTrimmedText(button?.title)).slice(0, 2)
12
- );
13
-
14
- const getCarouselButtonSlotCount = (cards = []) => {
15
- const buttonCounts = cards.map((card) => getCarouselButtonsWithTitles(card).length);
16
- return Math.min(2, Math.max(0, ...buttonCounts, 0));
17
- };
18
-
19
- const ViberCarouselPreviewCards = ({ cards = [] }) => {
20
- const previewCards = Array.isArray(cards) && cards.length ? cards : [{}];
21
- const carouselButtonSlotCount = useMemo(
22
- () => getCarouselButtonSlotCount(previewCards),
23
- [previewCards],
24
- );
25
- const carouselTitleRefs = useRef([]);
26
- const [carouselTitleLineCount, setCarouselTitleLineCount] = useState(1);
27
-
28
- carouselTitleRefs.current = previewCards.map(() => null);
29
-
30
- useLayoutEffect(() => {
31
- let maxLines = 1;
32
- carouselTitleRefs.current.forEach((node) => {
33
- if (!node) {
34
- return;
35
- }
36
- const { lineHeight } = window.getComputedStyle(node);
37
- const parsedLineHeight = parseFloat(lineHeight) || 18;
38
- const lines = Math.min(2, Math.max(1, Math.round(node.scrollHeight / parsedLineHeight)));
39
- if (lines > maxLines) {
40
- maxLines = lines;
41
- }
42
- });
43
- setCarouselTitleLineCount((prev) => (prev === maxLines ? prev : maxLines));
44
- }, [previewCards]);
45
-
46
- return (
47
- <CapRow type="flex" noWrap className="viber-carousel-preview-scroll">
48
- {previewCards.map((card, index) => {
49
- const cardButtons = getCarouselButtonsWithTitles(card);
50
- const titleLineClass = `viber-carousel-preview-text-wrap--${carouselTitleLineCount}-line`;
51
-
52
- return (
53
- <CapRow type="flex-column" className="viber-carousel-preview-card" key={`viber-carousel-preview-card-${index}`}>
54
- {hasTrimmedText(card?.mediaUrl) ? (
55
- <CapImage
56
- src={card?.mediaUrl}
57
- className="viber-carousel-preview-image"
58
- alt="Viber carousel card"
59
- />
60
- ) : (
61
- <CapRow className="viber-carousel-preview-image-placeholder" />
62
- )}
63
- <CapRow className="viber-carousel-preview-card-body">
64
- <CapRow className={`viber-carousel-preview-text-wrap ${titleLineClass}`}>
65
- {hasTrimmedText(card?.text) ? (
66
- <CapRow
67
- className="viber-carousel-preview-text-inner"
68
- ref={(node) => {
69
- carouselTitleRefs.current[index] = node;
70
- }}
71
- >
72
- <CapLabel type="label15" className="viber-carousel-preview-text">
73
- {card?.text}
74
- </CapLabel>
75
- </CapRow>
76
- ) : (
77
- <CapLabel type="label15" className="viber-carousel-preview-text-placeholder" />
78
- )}
79
- </CapRow>
80
- {carouselButtonSlotCount > 0 && (
81
- <CapRow className="viber-carousel-preview-buttons">
82
- {Array.from({ length: carouselButtonSlotCount }).map((_, btnIndex) => {
83
- const cardButton = cardButtons[btnIndex];
84
- const trimmedCardButtonTitle = cardButton
85
- ? getTrimmedText(cardButton?.title)
86
- : '';
87
-
88
- if (!trimmedCardButtonTitle) {
89
- return (
90
- <CapRow
91
- className="viber-carousel-preview-button viber-carousel-preview-button-placeholder"
92
- key={`viber-carousel-preview-btn-placeholder-${index}-${btnIndex}`}
93
- aria-hidden="true"
94
- />
95
- );
96
- }
97
-
98
- return (
99
- <CapLabel
100
- className={`viber-carousel-preview-button ${btnIndex === 1 ? 'viber-carousel-preview-button-secondary' : ''}`}
101
- key={`viber-carousel-preview-btn-${index}-${btnIndex}-${trimmedCardButtonTitle}`}
102
- >
103
- {trimmedCardButtonTitle}
104
- </CapLabel>
105
- );
106
- })}
107
- </CapRow>
108
- )}
109
- </CapRow>
110
- </CapRow>
111
- );
112
- })}
113
- </CapRow>
114
- );
115
- };
116
-
117
- ViberCarouselPreviewCards.propTypes = {
118
- cards: PropTypes.arrayOf(PropTypes.shape({
119
- text: PropTypes.string,
120
- mediaUrl: PropTypes.string,
121
- buttons: PropTypes.arrayOf(PropTypes.shape({
122
- title: PropTypes.string,
123
- action: PropTypes.string,
124
- })),
125
- })),
126
- };
127
-
128
- ViberCarouselPreviewCards.defaultProps = {
129
- cards: [],
130
- };
131
-
132
- export default ViberCarouselPreviewCards;
@@ -1,132 +0,0 @@
1
- // Shared Viber carousel card row (Test & Preview device preview)
2
- .viber-carousel-preview-scroll {
3
- display: flex;
4
- flex-direction: row;
5
- flex-wrap: nowrap;
6
- align-items: stretch;
7
- width: 100%;
8
- max-width: 100%;
9
- min-width: 0;
10
- overflow-x: auto;
11
- overflow-y: hidden;
12
- padding-right: $CAP_SPACE_12;
13
- scrollbar-width: none;
14
- -webkit-overflow-scrolling: touch;
15
-
16
- &::-webkit-scrollbar {
17
- display: none;
18
- }
19
-
20
- .viber-carousel-preview-card {
21
- flex: 0 0 68%;
22
- min-width: 80%;
23
- margin-right: $CAP_SPACE_08;
24
- background: $CAP_G09;
25
- border: 1px solid $CAP_G07;
26
- border-radius: $CAP_SPACE_12;
27
- overflow: hidden;
28
- display: flex;
29
- flex-direction: column;
30
- align-self: stretch;
31
-
32
- &:last-child {
33
- margin-right: 0;
34
- }
35
-
36
- .viber-carousel-preview-card-body {
37
- flex: 1;
38
- padding: $CAP_SPACE_08;
39
- display: flex;
40
- flex-direction: column;
41
- min-height: 0;
42
- }
43
-
44
- .viber-carousel-preview-text-wrap {
45
- flex-shrink: 0;
46
- width: 100%;
47
-
48
- &--1-line {
49
- min-height: 1.3em;
50
- }
51
-
52
- &--2-line {
53
- min-height: 2.6em;
54
- }
55
- }
56
-
57
- .viber-carousel-preview-text-inner {
58
- width: 100%;
59
- }
60
-
61
- .viber-carousel-preview-buttons {
62
- display: flex;
63
- flex-direction: column;
64
- gap: $CAP_SPACE_06;
65
- margin-top: auto;
66
- width: 100%;
67
- flex-shrink: 0;
68
- }
69
-
70
- .viber-carousel-preview-image {
71
- width: 100%;
72
- height: 10rem;
73
- object-fit: cover;
74
- border-radius: 0;
75
- }
76
-
77
- .viber-carousel-preview-image-placeholder {
78
- width: 100%;
79
- height: 10rem;
80
- border-radius: 0;
81
- background: $CAP_G07;
82
- }
83
-
84
- .viber-carousel-preview-text {
85
- color: $CAP_G01;
86
- line-height: 1.3;
87
- white-space: normal;
88
- word-break: break-word;
89
- display: block;
90
- width: 100%;
91
- margin: 0;
92
- }
93
-
94
- .viber-carousel-preview-text-placeholder {
95
- width: 100%;
96
- height: 0.875rem;
97
- border-radius: $CAP_SPACE_04;
98
- background: $CAP_G07;
99
- min-height: 0.875rem;
100
- display: block;
101
- }
102
-
103
- .viber-carousel-preview-button {
104
- color: $CAP_WHITE;
105
- background: $CAP_PURPLE01;
106
- border-radius: $CAP_SPACE_12;
107
- text-align: center;
108
- width: 100%;
109
- display: flex;
110
- align-items: center;
111
- justify-content: center;
112
- min-height: 1.5rem;
113
- padding: $CAP_SPACE_06 $CAP_SPACE_08;
114
- white-space: normal;
115
- box-sizing: border-box;
116
- }
117
-
118
- .viber-carousel-preview-button-placeholder {
119
- visibility: hidden;
120
- pointer-events: none;
121
- padding: 0;
122
- background: transparent;
123
- border: none;
124
- }
125
-
126
- .viber-carousel-preview-button-secondary {
127
- color: $CAP_PURPLE01;
128
- background: transparent;
129
- border: none;
130
- }
131
- }
132
- }