Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Add a star rating component for the survey

Scott Petrovica0b27ec6363b
diff --git a/src/dialog.css b/src/dialog.css
index 367b275..ce8c309 100644
--- a/src/dialog.css
+++ b/src/dialog.css
@@ -277,6 +277,43 @@ color: var(--text-primary);
justify-content: center;
}
+/* ── Star Rating Component ── */
+
+.star-rating {
+ display: flex;
+ gap: 0.5rem;
+ justify-content: center;
+ margin: 1rem 0;
+}
+
+.star-button {
+ background: none;
+ border: none;
+ cursor: pointer;
+ padding: 0;
+ transition: all 0.2s ease;
+ box-shadow: none;
+ opacity: 0.2;
+ margin: 0 0.3rem;
+}
+
+.star-icon {
+font-size: 2rem;
+ color: #fff566;
+ -webkit-text-stroke: 1px #978530;
+}
+
+.star-button:hover {
+ opacity: 1;
+ transform: scale(1.2);
+}
+
+.star-button.active,
+.star-button:active {
+ color: var(--button-primary-bg);
+ opacity: 1;
+}
+
@media (max-width: 768px) {
.download-success-dialog-body {
grid-template-columns: 1fr;
@@ -289,5 +326,9 @@ color: var(--text-primary);
.download-success-dialog-content {
max-width: 90%;
}
+
+ .star-button {
+ font-size: 1.5rem;
+ }
}
diff --git a/src/lib/EventListeners.ts b/src/lib/EventListeners.ts
index 660ca89..e87c05b 100644
--- a/src/lib/EventListeners.ts
+++ b/src/lib/EventListeners.ts
@@ -4,7 +4,7 @@ import { ProcessStep } from './enums/ProcessStep'
import { TransformSpace } from './enums/TransformSpace'
import { Utility } from './Utilities'
import { ModelCleanupUtility } from './processes/load-model/ModelCleanupUtility'
-import { DownloadSuccessDialog } from './DownloadSuccessDialog'
+import { DownloadSuccessDialog } from './components/download-success/DownloadSuccessDialog'
import { type Bone } from 'three'
export class EventListeners {
diff --git a/src/lib/DownloadSuccessDialog.ts b/src/lib/components/download-success/DownloadSuccessDialog.ts
similarity index 78%
rename from src/lib/DownloadSuccessDialog.ts
rename to src/lib/components/download-success/DownloadSuccessDialog.ts
index 44b58be..b82aebd 100644
--- a/src/lib/DownloadSuccessDialog.ts
+++ b/src/lib/components/download-success/DownloadSuccessDialog.ts
@@ -1,5 +1,8 @@
+import { StarRating } from './StarRating'
+
export class DownloadSuccessDialog {
private dialog_element: HTMLDivElement | null = null
+ private star_rating: StarRating | null = null
private readonly content_html = `
@@ -10,8 +13,8 @@ export class DownloadSuccessDialog {
<h3>How was your experience</h3>
<p>Quick question: Are you enjoying Mesh2Motion? We'd love to hear your feedback!
It only takes 2 minutes to answer our brief survey.</p>
-
- <button>Take Survey</button>
+ <div class="star-rating-container"></div>
+ <button class="download-success-survey-btn">Take Survey</button>
</div>
<div class="download-success-section">
@@ -41,10 +44,19 @@ export class DownloadSuccessDialog {
this.dialog_element = document.createElement('div')
this.dialog_element.className = 'download-success-dialog-overlay'
- // HTML template for the content
this.dialog_element.innerHTML = this.content_html
document.body.appendChild(this.dialog_element)
+ // Initialize star rating
+ const rating_container = this.dialog_element.querySelector('.star-rating-container')
+ if (rating_container) {
+ this.star_rating = new StarRating((rating) => {
+ console.log('User rated:', rating)
+ })
+ rating_container.innerHTML = this.star_rating.getHTML()
+ this.star_rating.attachEventListeners(rating_container as HTMLElement)
+ }
+
// Close button handler
const close_button = this.dialog_element.querySelector('.download-success-dialog-close')
close_button?.addEventListener('click', () => { this.remove() })
diff --git a/src/lib/components/download-success/StarRating.ts b/src/lib/components/download-success/StarRating.ts
new file mode 100644
index 0000000..243515d
--- /dev/null
+++ b/src/lib/components/download-success/StarRating.ts
@@ -0,0 +1,65 @@
+export class StarRating {
+ private rating: number = 3
+ private onRatingChange?: (rating: number) => void
+
+ constructor (onRatingChange?: (rating: number) => void) {
+ this.onRatingChange = onRatingChange
+ }
+
+ public getHTML (): string {
+ return `
+ <div class="star-rating">
+ ${[1, 2, 3, 4, 5].map(star => `
+ <button class="star-button" data-star="${star}" aria-label="Rate ${star} stars">
+ <span class="star-icon">★</span>
+ </button>
+ `).join('')}
+ </div>
+ `
+ }
+
+ public attachEventListeners (container: HTMLElement): void {
+ const buttons = container.querySelectorAll('.star-button')
+
+ buttons.forEach(button => {
+ button.addEventListener('click', (e) => {
+ e.preventDefault()
+ const star = parseInt((button as HTMLElement).getAttribute('data-star') || '0')
+ this.setRating(star, container)
+ this.onRatingChange?.(star)
+ })
+
+ button.addEventListener('mouseenter', () => {
+ const star = parseInt((button as HTMLElement).getAttribute('data-star') || '0')
+ this.highlightStars(star, container)
+ })
+ })
+
+ container.addEventListener('mouseleave', () => {
+ this.highlightStars(this.rating, container)
+ })
+
+ this.highlightStars(this.rating, container)
+ }
+
+ private setRating (rating: number, container: HTMLElement): void {
+ this.rating = rating
+ this.highlightStars(rating, container)
+ }
+
+ private highlightStars (rating: number, container: HTMLElement): void {
+ const buttons = container.querySelectorAll('.star-button')
+ buttons.forEach(button => {
+ const star = parseInt((button as HTMLElement).getAttribute('data-star') || '0')
+ if (star <= rating) {
+ button.classList.add('active')
+ } else {
+ button.classList.remove('active')
+ }
+ })
+ }
+
+ public getRating (): number {
+ return this.rating
+ }
+}