@product7/product7-js 0.1.8 → 0.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@product7/product7-js",
3
- "version": "0.1.8",
3
+ "version": "0.2.0",
4
4
  "description": "JavaScript SDK for integrating Product7 feedback widgets into any website",
5
5
  "main": "dist/product7-js.js",
6
6
  "module": "src/index.js",
@@ -616,8 +616,8 @@ export const messengerViewsStyles = `
616
616
 
617
617
  .messenger-help-collection-icon {
618
618
  flex-shrink: 0;
619
- width: 2.75rem;
620
- height: 2.75rem;
619
+ width: 2.25rem;
620
+ height: 2.25rem;
621
621
  display: flex;
622
622
  align-items: center;
623
623
  justify-content: center;
@@ -625,14 +625,14 @@ export const messengerViewsStyles = `
625
625
  }
626
626
 
627
627
  .messenger-help-collection-icon svg {
628
- width: 2rem;
629
- height: 2rem;
628
+ width: 1.5rem;
629
+ height: 1.5rem;
630
630
  display: block;
631
631
  flex-shrink: 0;
632
632
  }
633
633
 
634
634
  .messenger-help-collection-icon iconify-icon {
635
- font-size: 2rem;
635
+ font-size: 1.5rem;
636
636
  width: 1em;
637
637
  height: 1em;
638
638
  display: block;
@@ -368,6 +368,32 @@ export const surveyStyles = `
368
368
  RATING SCALE (generic)
369
369
  ======================================== */
370
370
 
371
+ .feedback-survey-stars {
372
+ display: flex;
373
+ gap: var(--spacing-4);
374
+ justify-content: center;
375
+ }
376
+
377
+ .feedback-survey-star-btn {
378
+ background: none;
379
+ border: none;
380
+ cursor: pointer;
381
+ font-size: 2.75rem;
382
+ color: var(--color-neutral-300);
383
+ padding: 0;
384
+ line-height: 1;
385
+ transition: color var(--transition-fast), transform var(--transition-fast);
386
+ }
387
+
388
+ .feedback-survey-star-btn.filled,
389
+ .feedback-survey-star-btn.hovered {
390
+ color: #f59e0b;
391
+ }
392
+
393
+ .feedback-survey-star-btn:active {
394
+ transform: scale(0.9);
395
+ }
396
+
371
397
  .feedback-survey-rating-scale {
372
398
  display: flex;
373
399
  gap: 0;
@@ -427,14 +427,16 @@ export class SurveyWidget extends BaseWidget {
427
427
  const topSurveyType = this.surveyOptions.surveyType;
428
428
  const configType = config.survey_type;
429
429
  let ratingType;
430
- if (topSurveyType === 'ces') {
431
- ratingType = 'ces';
432
- } else if (topSurveyType === 'nps') {
430
+ if (topSurveyType === 'nps') {
433
431
  ratingType = 'nps';
434
- } else if (topSurveyType === 'csat' && !configType) {
432
+ } else if (configType) {
433
+ ratingType = configType;
434
+ } else if (topSurveyType === 'ces') {
435
+ ratingType = 'ces';
436
+ } else if (topSurveyType === 'csat') {
435
437
  ratingType = 'emoji';
436
438
  } else {
437
- ratingType = configType || topSurveyType || 'csat';
439
+ ratingType = topSurveyType || 'csat';
438
440
  }
439
441
  const pageAnswer = this.surveyState.pageAnswers[pageId] || {};
440
442
  const currentRating = pageAnswer.rating;
@@ -526,6 +528,22 @@ export class SurveyWidget extends BaseWidget {
526
528
  `;
527
529
  }
528
530
 
531
+ if (ratingType === 'star') {
532
+ const starScale = Number.isFinite(scale) && scale >= 2 ? scale : 5;
533
+ return `
534
+ <div class="feedback-survey-stars" data-page-id="${pageId}">
535
+ ${[...Array(starScale).keys()]
536
+ .map((i) => {
537
+ const score = i + 1;
538
+ const filled = currentRating >= score ? ' filled' : '';
539
+ return `<button class="feedback-survey-page-rating-btn feedback-survey-star-btn${filled}" data-page-id="${pageId}" data-score="${score}">★</button>`;
540
+ })
541
+ .join('')}
542
+ </div>
543
+ ${labels}
544
+ `;
545
+ }
546
+
529
547
  return `
530
548
  <div class="feedback-survey-rating-scale" data-page-id="${pageId}">
531
549
  ${[...Array(scale).keys()]
@@ -781,6 +799,8 @@ export class SurveyWidget extends BaseWidget {
781
799
  const pageId = page.id || `page_${this.surveyState.currentPageIndex}`;
782
800
 
783
801
  if (page.type === 'rating') {
802
+ const isStarRating = !!this.surveyElement.querySelector('.feedback-survey-star-btn');
803
+
784
804
  this.surveyElement
785
805
  .querySelectorAll('.feedback-survey-page-rating-btn')
786
806
  .forEach((btn) => {
@@ -789,12 +809,44 @@ export class SurveyWidget extends BaseWidget {
789
809
  if (Number.isNaN(score)) return;
790
810
  this._setPageAnswer(pageId, { rating: score });
791
811
 
792
- this.surveyElement
793
- .querySelectorAll('.feedback-survey-page-rating-btn')
794
- .forEach((item) => item.classList.remove('selected'));
795
- btn.classList.add('selected');
812
+ if (isStarRating) {
813
+ this.surveyElement
814
+ .querySelectorAll('.feedback-survey-star-btn')
815
+ .forEach((star) => {
816
+ const starScore = parseInt(star.dataset.score);
817
+ star.classList.toggle('filled', starScore <= score);
818
+ });
819
+ } else {
820
+ this.surveyElement
821
+ .querySelectorAll('.feedback-survey-page-rating-btn')
822
+ .forEach((item) => item.classList.remove('selected'));
823
+ btn.classList.add('selected');
824
+ }
796
825
  });
826
+
827
+ if (isStarRating) {
828
+ btn.addEventListener('mouseenter', () => {
829
+ const hoverScore = parseInt(btn.dataset.score);
830
+ this.surveyElement
831
+ .querySelectorAll('.feedback-survey-star-btn')
832
+ .forEach((star) => {
833
+ const starScore = parseInt(star.dataset.score);
834
+ star.classList.toggle('hovered', starScore <= hoverScore);
835
+ });
836
+ });
837
+ }
797
838
  });
839
+
840
+ if (isStarRating) {
841
+ const container = this.surveyElement.querySelector('.feedback-survey-stars');
842
+ if (container) {
843
+ container.addEventListener('mouseleave', () => {
844
+ this.surveyElement
845
+ .querySelectorAll('.feedback-survey-star-btn')
846
+ .forEach((star) => star.classList.remove('hovered'));
847
+ });
848
+ }
849
+ }
798
850
  }
799
851
 
800
852
  if (page.type === 'multiple_choice') {
@@ -67,8 +67,8 @@ export class ConversationsView {
67
67
  this.element.innerHTML = `
68
68
  <div class="messenger-conversations-header">
69
69
  <h2>Messages</h2>
70
- <button class="sdk-close-btn" aria-label="Close">
71
- <iconify-icon icon="ph:x-duotone" width="18" height="18"></iconify-icon>
70
+ <button class="sdk-close-btn messenger-mobile-close-btn" aria-label="Close">
71
+ <iconify-icon icon="ph:x" width="18" height="18"></iconify-icon>
72
72
  </button>
73
73
  </div>
74
74