@product7/product7-js 0.1.8 → 0.1.9
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/dist/product7-js.js +89 -11
- package/dist/product7-js.js.map +1 -1
- package/dist/product7-js.min.js +1 -1
- package/dist/product7-js.min.js.map +1 -1
- package/package.json +1 -1
- package/src/styles/survey.js +26 -0
- package/src/widgets/SurveyWidget.js +61 -9
- package/src/widgets/messenger/views/ConversationsView.js +2 -2
package/package.json
CHANGED
package/src/styles/survey.js
CHANGED
|
@@ -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-2);
|
|
374
|
+
justify-content: center;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
.feedback-survey-star-btn {
|
|
378
|
+
background: none;
|
|
379
|
+
border: none;
|
|
380
|
+
cursor: pointer;
|
|
381
|
+
font-size: 2rem;
|
|
382
|
+
color: var(--color-neutral-300);
|
|
383
|
+
padding: 0 2px;
|
|
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 === '
|
|
431
|
-
ratingType = 'ces';
|
|
432
|
-
} else if (topSurveyType === 'nps') {
|
|
430
|
+
if (topSurveyType === 'nps') {
|
|
433
431
|
ratingType = 'nps';
|
|
434
|
-
} else if (
|
|
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 =
|
|
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
|
-
|
|
793
|
-
.
|
|
794
|
-
|
|
795
|
-
|
|
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
|
|
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
|
|