@kindly/react-chat 2.47.1 → 2.48.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kindly/react-chat",
3
- "version": "2.47.1",
3
+ "version": "2.48.1",
4
4
  "description": "Kindly Chat react component",
5
5
  "repository": "https://github.com/kindly-ai/kindly-chat/tree/main/packages/react-chat",
6
6
  "main": "dist/index.js",
@@ -144,5 +144,5 @@
144
144
  }
145
145
  }
146
146
  },
147
- "gitHead": "610dad2e9405f4193f1293d17dac2e6da16665b3"
147
+ "gitHead": "06a145945114368fb6ec162da2f1f16c7c98c098"
148
148
  }
@@ -0,0 +1,203 @@
1
+ import React from 'react';
2
+
3
+ import { IMAGE_WIDTH } from '../../../src/constants';
4
+ import KindlyChatButton from '../../../src/features/KindlyChatButton/KindlyChatButton';
5
+ import settingsJSON from '../../assets/settingsJson';
6
+ import withContainer from '../../decorators/withContainer';
7
+ import withMockProvider from '../../decorators/withProvider';
8
+
9
+ const defaultBotSettings = {
10
+ welcomePage: settingsJSON.welcome_page,
11
+ feedbackForm: settingsJSON.feedback_form,
12
+ maintenanceAlert: settingsJSON.maintenance_alert,
13
+ ...settingsJSON.settings,
14
+ ...settingsJSON,
15
+ };
16
+
17
+ const todayTime = new Date();
18
+ todayTime.setHours(13);
19
+ todayTime.setMinutes(37);
20
+ const created = todayTime.toISOString();
21
+
22
+ export default {
23
+ title: 'Screen/Chat/ImageCarousel',
24
+ component: KindlyChatButton,
25
+ decorators: [withContainer, withMockProvider],
26
+ argTypes: {
27
+ initialStateModifierFromArgs: {
28
+ table: {
29
+ disable: true,
30
+ },
31
+ },
32
+ },
33
+ };
34
+
35
+ const defaultParameters = {
36
+ botSettings: defaultBotSettings,
37
+ initialStateModifier: {
38
+ chatbubble: {
39
+ active: true,
40
+ chatHasStarted: true,
41
+ currentLanguage: 'en',
42
+ },
43
+ },
44
+ };
45
+
46
+ function Template(args, context) {
47
+ return <KindlyChatButton {...args} {...context} />;
48
+ }
49
+
50
+ export const ImageGallery = Template.bind({});
51
+ const textSizes = [
52
+ undefined,
53
+ 'Lorem ipsum dolor sit amet.',
54
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
55
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n\n Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
56
+ ];
57
+ const buttons = [
58
+ {
59
+ id: '1',
60
+ label: 'Add to cart',
61
+ value: 'https://example.com',
62
+ button_type: 'link',
63
+ },
64
+ {
65
+ id: '2',
66
+ label: 'Send as a gift',
67
+ value: '123',
68
+ button_type: 'dialogue_trigger',
69
+ },
70
+ {
71
+ id: '3',
72
+ label: 'Add to wishlist',
73
+ value: '234',
74
+ button_type: 'dialogue_trigger',
75
+ },
76
+ ];
77
+ ImageGallery.args = {
78
+ imageCarouselSize: 1000,
79
+ titleSize: 0,
80
+ descriptionSize: 0,
81
+ imageQuantity: 3,
82
+ buttonQuantity: 0,
83
+ hasLink: false,
84
+ newTab: false,
85
+ initialStateModifierFromArgs: ({
86
+ imageCarouselSize,
87
+ imageQuantity,
88
+ titleSize,
89
+ descriptionSize,
90
+ buttonQuantity,
91
+ hasLink,
92
+ newTab,
93
+ }) => ({
94
+ ...defaultParameters.initialStateModifier,
95
+ messages: {
96
+ chatMessages: [
97
+ {
98
+ id: '1',
99
+ chat_source: 'web',
100
+ chat_language_code: 'en',
101
+ from_bot: true,
102
+ sender: 'BOT',
103
+ message: 'Here is an image gallery',
104
+ message_format: 'txt',
105
+ image_carousel: [
106
+ {
107
+ id: '1',
108
+ imageUrl: 'https://i.imgur.com/Iz1nJrw.jpg',
109
+ title: textSizes[titleSize],
110
+ description: textSizes[descriptionSize],
111
+ linkUrl: hasLink ? 'https://example.com' : undefined,
112
+ altText: textSizes[titleSize] || 'Alt text',
113
+ newTab,
114
+ buttons: buttons.slice(0, buttonQuantity),
115
+ },
116
+ {
117
+ id: '2',
118
+ imageUrl: 'https://i.imgur.com/H49sTpN.jpg',
119
+ title: textSizes[titleSize],
120
+ description: textSizes[descriptionSize],
121
+ linkUrl: hasLink ? 'https://example.com' : undefined,
122
+ altText: textSizes[titleSize] || 'Alt text',
123
+ newTab,
124
+ buttons: buttons.slice(0, buttonQuantity - 1 > 0 ? buttonQuantity - 1 : 0),
125
+ },
126
+ {
127
+ id: '3',
128
+ imageUrl: 'https://i.imgur.com/Htlr2rv.jpg',
129
+ title: textSizes[titleSize],
130
+ description: textSizes[descriptionSize],
131
+ linkUrl: hasLink ? 'https://example.com' : undefined,
132
+ altText: textSizes[titleSize] || 'Alt text',
133
+ newTab,
134
+ buttons: buttons.slice(0, buttonQuantity - 2 > 0 ? buttonQuantity - 2 : 0),
135
+ },
136
+ ].slice(0, imageQuantity),
137
+ image_carousel_size: imageCarouselSize,
138
+ title: 'Image Gallery',
139
+ created,
140
+ },
141
+ ],
142
+ },
143
+ }),
144
+ };
145
+ ImageGallery.argTypes = {
146
+ imageCarouselSize: {
147
+ options: Object.keys(IMAGE_WIDTH).map((size) => parseInt(size, 10)),
148
+ control: { type: 'radio' },
149
+ },
150
+ imageQuantity: {
151
+ control: { type: 'range', min: 1, max: 3, step: 1 },
152
+ },
153
+ titleSize: {
154
+ control: { type: 'range', min: 0, max: textSizes.length - 1, step: 1 },
155
+ },
156
+ descriptionSize: {
157
+ control: { type: 'range', min: 0, max: textSizes.length - 1, step: 1 },
158
+ },
159
+ buttonQuantity: {
160
+ control: { type: 'range', min: 0, max: buttons.length, step: 1 },
161
+ },
162
+ hasLink: {
163
+ control: 'boolean',
164
+ },
165
+ newTab: {
166
+ control: 'boolean',
167
+ },
168
+ };
169
+ ImageGallery.parameters = {
170
+ botSettings: defaultBotSettings,
171
+ };
172
+
173
+ export const ImageGalleryWithDescription = Template.bind({});
174
+ ImageGalleryWithDescription.args = {
175
+ ...ImageGallery.args,
176
+ titleSize: 2,
177
+ descriptionSize: 3,
178
+ hasLink: true,
179
+ };
180
+ ImageGalleryWithDescription.argTypes = ImageGallery.argTypes;
181
+ ImageGalleryWithDescription.parameters = ImageGallery.parameters;
182
+
183
+ export const ImageGalleryWithButtons = Template.bind({});
184
+ ImageGalleryWithButtons.args = {
185
+ ...ImageGallery.args,
186
+ titleSize: 0,
187
+ descriptionSize: 0,
188
+ hasLink: true,
189
+ buttonQuantity: 3,
190
+ };
191
+ ImageGalleryWithButtons.argTypes = ImageGallery.argTypes;
192
+ ImageGalleryWithButtons.parameters = ImageGallery.parameters;
193
+
194
+ export const ImageGalleryWithButtonsAndDescription = Template.bind({});
195
+ ImageGalleryWithButtonsAndDescription.args = {
196
+ ...ImageGallery.args,
197
+ titleSize: 1,
198
+ descriptionSize: 1,
199
+ hasLink: false,
200
+ buttonQuantity: 2,
201
+ };
202
+ ImageGalleryWithButtonsAndDescription.argTypes = ImageGallery.argTypes;
203
+ ImageGalleryWithButtonsAndDescription.parameters = ImageGallery.parameters;
@@ -3,7 +3,7 @@ import { fireEvent, userEvent, waitFor, within } from '@storybook/testing-librar
3
3
  import MockDate from 'mockdate';
4
4
  import React from 'react';
5
5
 
6
- import { HANDLERS, IMAGE_WIDTH } from 'app/constants';
6
+ import { HANDLERS } from 'app/constants';
7
7
 
8
8
  import { chromaticViewports } from '../../../.storybook/preview';
9
9
  import KindlyChatButton from '../../../src/features/KindlyChatButton/KindlyChatButton';
@@ -564,157 +564,6 @@ Fallback.parameters = {
564
564
  },
565
565
  };
566
566
 
567
- const videoSources = [
568
- ['YouTube', 'https://www.youtube.com/watch?v=vvg5AfQEmUc'],
569
- ['Vimeo', 'https://vimeo.com/153882097'],
570
- ['Self hosted', 'https://www.crockpot.se/wp-content/uploads/2019/02/Comp-1-1.mp4'],
571
- ];
572
- export const VideoEmbed = Template.bind({});
573
- VideoEmbed.args = {
574
- videoSource: videoSources[0][0],
575
- videoSourceList: videoSources,
576
- initialStateModifierFromArgs: ({ videoSource, videoSourceList }) => ({
577
- ...defaultParameters.initialStateModifier,
578
- messages: {
579
- chatMessages: [
580
- {
581
- id: '1',
582
- chat_language_code: 'en',
583
- from_bot: true,
584
- sender: 'BOT',
585
- message: 'Here is Video embed',
586
- message_format: 'txt',
587
- video_source: videoSourceList.find((videoSourceMap) => videoSourceMap[0] === videoSource)[1],
588
- title: 'embed',
589
- created,
590
- },
591
- ],
592
- },
593
- }),
594
- };
595
- VideoEmbed.argTypes = {
596
- videoSource: {
597
- options: videoSources.map((videoSource) => videoSource[0]),
598
- control: { type: 'select' },
599
- },
600
- videoSourceList: {
601
- table: {
602
- disable: true,
603
- },
604
- },
605
- };
606
- VideoEmbed.parameters = {
607
- botSettings: defaultBotSettings,
608
- };
609
-
610
- export const ImageGallery = Template.bind({});
611
- const textSizes = [
612
- undefined,
613
- 'Lorem ipsum dolor sit amet.',
614
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
615
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n\n Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
616
- ];
617
- ImageGallery.args = {
618
- imageCarouselSize: 1000,
619
- titleSize: 0,
620
- descriptionSize: 0,
621
- imageQuantity: 3,
622
- hasLink: false,
623
- newTab: false,
624
- thonImageAboveText: false,
625
- initialStateModifierFromArgs: ({
626
- imageCarouselSize,
627
- imageQuantity,
628
- titleSize,
629
- descriptionSize,
630
- hasLink,
631
- newTab,
632
- thonImageAboveText,
633
- }) => ({
634
- ...defaultParameters.initialStateModifier,
635
- messages: {
636
- chatMessages: [
637
- {
638
- id: '1',
639
- chat_source: 'web',
640
- chat_language_code: 'en',
641
- from_bot: true,
642
- sender: 'BOT',
643
- message: 'Here is an image gallery',
644
- message_format: 'txt',
645
- thon_image_above_text: thonImageAboveText,
646
- image_carousel: [
647
- {
648
- id: '1',
649
- imageUrl: 'https://i.imgur.com/Iz1nJrw.jpg',
650
- title: textSizes[titleSize],
651
- description: textSizes[descriptionSize],
652
- linkUrl: hasLink ? 'https://example.com' : undefined,
653
- altText: textSizes[titleSize] || 'Alt text',
654
- newTab,
655
- },
656
- {
657
- id: '2',
658
- imageUrl: 'https://i.imgur.com/H49sTpN.jpg',
659
- title: textSizes[titleSize],
660
- description: textSizes[descriptionSize],
661
- linkUrl: hasLink ? 'https://example.com' : undefined,
662
- altText: textSizes[titleSize] || 'Alt text',
663
- newTab,
664
- },
665
- {
666
- id: '3',
667
- imageUrl: 'https://i.imgur.com/Htlr2rv.jpg',
668
- title: textSizes[titleSize],
669
- description: textSizes[descriptionSize],
670
- linkUrl: hasLink ? 'https://example.com' : undefined,
671
- altText: textSizes[titleSize] || 'Alt text',
672
- newTab,
673
- },
674
- ].slice(0, imageQuantity),
675
- image_carousel_size: imageCarouselSize,
676
- title: 'Image Gallery',
677
- created,
678
- },
679
- ],
680
- },
681
- }),
682
- };
683
- ImageGallery.argTypes = {
684
- imageCarouselSize: {
685
- options: Object.keys(IMAGE_WIDTH).map((size) => parseInt(size, 10)),
686
- control: { type: 'radio' },
687
- },
688
- imageQuantity: {
689
- control: { type: 'range', min: 1, max: 3, step: 1 },
690
- },
691
- titleSize: {
692
- control: { type: 'range', min: 0, max: textSizes.length - 1, step: 1 },
693
- },
694
- descriptionSize: {
695
- control: { type: 'range', min: 0, max: textSizes.length - 1, step: 1 },
696
- },
697
- hasLink: {
698
- control: 'boolean',
699
- },
700
- newTab: {
701
- control: 'boolean',
702
- },
703
- };
704
- ImageGallery.parameters = {
705
- botSettings: defaultBotSettings,
706
- };
707
-
708
- export const ImageGalleryWithDescription = Template.bind({});
709
- ImageGalleryWithDescription.args = {
710
- ...ImageGallery.args,
711
- titleSize: 2,
712
- descriptionSize: 3,
713
- hasLink: true,
714
- };
715
- ImageGalleryWithDescription.argTypes = ImageGallery.argTypes;
716
- ImageGalleryWithDescription.parameters = ImageGallery.parameters;
717
-
718
567
  export const Slider = Template.bind({});
719
568
  Slider.parameters = {
720
569
  ...defaultParameters,
@@ -764,75 +613,47 @@ Slider.parameters = {
764
613
  },
765
614
  };
766
615
 
767
- export const Buttons = Template.bind({});
768
- Buttons.parameters = {
769
- ...defaultParameters,
770
- initialStateModifier: {
616
+ const videoSources = [
617
+ ['YouTube', 'https://www.youtube.com/watch?v=vvg5AfQEmUc'],
618
+ ['Vimeo', 'https://vimeo.com/153882097'],
619
+ ['Self hosted', 'https://www.crockpot.se/wp-content/uploads/2019/02/Comp-1-1.mp4'],
620
+ ];
621
+ export const VideoEmbed = Template.bind({});
622
+ VideoEmbed.args = {
623
+ videoSource: videoSources[0][0],
624
+ videoSourceList: videoSources,
625
+ initialStateModifierFromArgs: ({ videoSource, videoSourceList }) => ({
771
626
  ...defaultParameters.initialStateModifier,
772
627
  messages: {
773
628
  chatMessages: [
774
629
  {
775
- chat_source: 'web',
630
+ id: '1',
776
631
  chat_language_code: 'en',
777
632
  from_bot: true,
778
633
  sender: 'BOT',
779
- message: 'Button list!',
634
+ message: 'Here is Video embed',
780
635
  message_format: 'txt',
781
- buttons: [
782
- {
783
- id: '1',
784
- button_type: 'EXTERNAL_LINK',
785
- language_code: 'en',
786
- label: 'Open a link',
787
- value: 'https://example.com',
788
- index: 0,
789
- },
790
- {
791
- id: '2',
792
- button_type: 'QUICK_REPLY',
793
- language_code: 'en',
794
- label: 'Quick reply',
795
- value: 'This is a quick reply',
796
- index: 1,
797
- },
798
- {
799
- id: '3',
800
- button_type: 'EMAIL',
801
- language_code: 'en',
802
- label: 'Email',
803
- value: 'support@example.com',
804
- index: 2,
805
- },
806
- {
807
- id: '4',
808
- button_type: 'PHONE',
809
- language_code: 'en',
810
- label: 'Phone',
811
- value: '+46 070-174 06 05',
812
- index: 3,
813
- },
814
- {
815
- id: '5',
816
- button_type: 'UPLOAD_ATTACHMENT',
817
- language_code: 'en',
818
- label: 'Upload attachment',
819
- index: 4,
820
- },
821
- {
822
- id: '6',
823
- button_type: 'DIALOGUE_TRIGGER',
824
- language_code: 'en',
825
- label: 'Trigger another dialogue',
826
- value: 'dialogue_id',
827
- index: 5,
828
- },
829
- ],
636
+ video_source: videoSourceList.find((videoSourceMap) => videoSourceMap[0] === videoSource)[1],
637
+ title: 'embed',
830
638
  created,
831
- id: '1',
832
639
  },
833
640
  ],
834
641
  },
642
+ }),
643
+ };
644
+ VideoEmbed.argTypes = {
645
+ videoSource: {
646
+ options: videoSources.map((videoSource) => videoSource[0]),
647
+ control: { type: 'select' },
835
648
  },
649
+ videoSourceList: {
650
+ table: {
651
+ disable: true,
652
+ },
653
+ },
654
+ };
655
+ VideoEmbed.parameters = {
656
+ botSettings: defaultBotSettings,
836
657
  };
837
658
 
838
659
  export const LeaveContactDetails = Template.bind({});