export function sizeFitFeedback(form: FormTs) {
// Size & Fit Feedback Form - Collecting sizing data to reduce returns
// Demonstrates: RatingScale (custom), MatrixQuestion, RadioButton, Slider, conditional visibility
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'How Does It Fit?',
computedValue: () => 'Help other shoppers find their perfect size!',
customStyles: {
background: 'linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%)',
color: 'white',
padding: '24px',
borderRadius: '12px',
textAlign: 'center'
}
});
});
// ============================================
// SECTION 1: Product & Order Info
// ============================================
const orderSection = form.addSubform('order', {
title: 'Your Order'
});
orderSection.addRow(row => {
row.addDropdown('productCategory', {
label: 'What type of item is this?',
placeholder: 'Select category',
options: [
{ id: 'tops', name: 'Tops (shirts, blouses, sweaters)' },
{ id: 'bottoms', name: 'Bottoms (pants, jeans, skirts)' },
{ id: 'dresses', name: 'Dresses & Jumpsuits' },
{ id: 'outerwear', name: 'Outerwear (jackets, coats)' },
{ id: 'shoes', name: 'Shoes & Footwear' },
{ id: 'activewear', name: 'Activewear & Sportswear' }
],
isRequired: true
}, '1fr');
row.addDropdown('sizeOrdered', {
label: 'What size did you order?',
placeholder: 'Select size',
options: [
{ id: 'xxs', name: 'XXS' },
{ id: 'xs', name: 'XS' },
{ id: 's', name: 'S' },
{ id: 'm', name: 'M' },
{ id: 'l', name: 'L' },
{ id: 'xl', name: 'XL' },
{ id: 'xxl', name: 'XXL' },
{ id: '3xl', name: '3XL+' }
],
isRequired: true
}, '1fr');
});
orderSection.addRow(row => {
row.addDropdown('usualSize', {
label: 'What size do you usually wear in this category?',
placeholder: 'Your usual size',
options: [
{ id: 'xxs', name: 'XXS' },
{ id: 'xs', name: 'XS' },
{ id: 's', name: 'S' },
{ id: 'm', name: 'M' },
{ id: 'l', name: 'L' },
{ id: 'xl', name: 'XL' },
{ id: 'xxl', name: 'XXL' },
{ id: '3xl', name: '3XL+' }
]
}, '1fr');
row.addDropdown('bodyType', {
label: 'How would you describe your body type?',
placeholder: 'Select body type',
options: [
{ id: 'petite', name: 'Petite' },
{ id: 'average', name: 'Average' },
{ id: 'tall', name: 'Tall' },
{ id: 'athletic', name: 'Athletic' },
{ id: 'curvy', name: 'Curvy' },
{ id: 'plus', name: 'Plus size' }
]
}, '1fr');
});
// ============================================
// SECTION 2: Overall Fit Assessment
// ============================================
const overallFitSection = form.addSubform('overallFit', {
title: 'Overall Fit',
isVisible: () => !!orderSection.dropdown('sizeOrdered')?.value()
});
overallFitSection.addRow(row => {
row.addRatingScale('overallFitScale', {
label: 'How does this item fit overall?',
preset: 'custom',
min: 1,
max: 5,
lowLabel: 'Much too small',
highLabel: 'Much too large',
variant: 'segmented',
size: 'lg',
alignment: 'center',
isRequired: true
});
});
overallFitSection.addRow(row => {
row.addTextPanel('fitLabel', {
computedValue: () => {
const fit = overallFitSection.ratingScale('overallFitScale')?.value();
if (fit === 1) return '👕 Runs Very Small - Order 2 sizes up';
if (fit === 2) return '👕 Runs Small - Order 1 size up';
if (fit === 3) return '✅ True to Size';
if (fit === 4) return '👕 Runs Large - Order 1 size down';
if (fit === 5) return '👕 Runs Very Large - Order 2 sizes down';
return '';
},
customStyles: () => {
const fit = overallFitSection.ratingScale('overallFitScale')?.value();
if (!fit) return { display: 'none' };
const color = fit === 3 ? '#10b981' :
(fit === 2 || fit === 4) ? '#f59e0b' : '#ef4444';
return {
textAlign: 'center',
padding: '12px',
backgroundColor: fit === 3 ? '#d1fae5' :
(fit === 2 || fit === 4) ? '#fef3c7' : '#fee2e2',
borderRadius: '8px',
fontWeight: '600',
color: color
};
},
isVisible: () => overallFitSection.ratingScale('overallFitScale')?.value() !== null
});
});
overallFitSection.addRow(row => {
row.addRadioButton('wouldKeep', {
label: 'Will you keep this item?',
options: [
{ id: 'yes', name: 'Yes, keeping it' },
{ id: 'exchange', name: 'Exchanging for different size' },
{ id: 'return', name: 'Returning it' }
],
orientation: 'horizontal'
});
});
// ============================================
// SECTION 3: Detailed Fit by Area (for Clothing)
// ============================================
const detailedFitSection = form.addSubform('detailedFit', {
title: 'Fit Details',
isVisible: () => {
const category = orderSection.dropdown('productCategory')?.value();
return category !== 'shoes' && !!category;
}
});
// For Tops
detailedFitSection.addRow(row => {
row.addMatrixQuestion('topsFit', {
label: 'How does this top fit in each area?',
rows: [
{ id: 'shoulders', label: 'Shoulders' },
{ id: 'bust', label: 'Bust/Chest' },
{ id: 'waist', label: 'Waist' },
{ id: 'length', label: 'Length' },
{ id: 'sleeves', label: 'Sleeve Length' }
],
columns: [
{ id: 'too-small', label: 'Too Small' },
{ id: 'slightly-small', label: 'Slightly Small' },
{ id: 'perfect', label: 'Perfect' },
{ id: 'slightly-large', label: 'Slightly Large' },
{ id: 'too-large', label: 'Too Large' }
],
fullWidth: true,
isVisible: () => orderSection.dropdown('productCategory')?.value() === 'tops'
});
});
// For Bottoms
detailedFitSection.addRow(row => {
row.addMatrixQuestion('bottomsFit', {
label: 'How do these bottoms fit in each area?',
rows: [
{ id: 'waist', label: 'Waist' },
{ id: 'hips', label: 'Hips' },
{ id: 'thighs', label: 'Thighs' },
{ id: 'inseam', label: 'Inseam/Length' },
{ id: 'rise', label: 'Rise' }
],
columns: [
{ id: 'too-small', label: 'Too Tight' },
{ id: 'slightly-small', label: 'Slightly Tight' },
{ id: 'perfect', label: 'Perfect' },
{ id: 'slightly-large', label: 'Slightly Loose' },
{ id: 'too-large', label: 'Too Loose' }
],
fullWidth: true,
isVisible: () => orderSection.dropdown('productCategory')?.value() === 'bottoms'
});
});
// For Dresses
detailedFitSection.addRow(row => {
row.addMatrixQuestion('dressFit', {
label: 'How does this dress fit in each area?',
rows: [
{ id: 'bust', label: 'Bust' },
{ id: 'waist', label: 'Waist' },
{ id: 'hips', label: 'Hips' },
{ id: 'length', label: 'Length' }
],
columns: [
{ id: 'too-small', label: 'Too Tight' },
{ id: 'slightly-small', label: 'Slightly Tight' },
{ id: 'perfect', label: 'Perfect' },
{ id: 'slightly-large', label: 'Slightly Loose' },
{ id: 'too-large', label: 'Too Loose' }
],
fullWidth: true,
isVisible: () => orderSection.dropdown('productCategory')?.value() === 'dresses'
});
});
// For Outerwear
detailedFitSection.addRow(row => {
row.addMatrixQuestion('outerwearFit', {
label: 'How does this outerwear fit?',
rows: [
{ id: 'shoulders', label: 'Shoulders' },
{ id: 'chest', label: 'Chest' },
{ id: 'arms', label: 'Arms' },
{ id: 'length', label: 'Length' }
],
columns: [
{ id: 'too-small', label: 'Too Tight' },
{ id: 'slightly-small', label: 'Slightly Tight' },
{ id: 'perfect', label: 'Perfect' },
{ id: 'slightly-large', label: 'Slightly Loose' },
{ id: 'too-large', label: 'Too Loose' }
],
fullWidth: true,
isVisible: () => orderSection.dropdown('productCategory')?.value() === 'outerwear'
});
});
// For Activewear
detailedFitSection.addRow(row => {
row.addMatrixQuestion('activewearFit', {
label: 'How does this activewear fit?',
rows: [
{ id: 'stretch', label: 'Stretch/Flexibility' },
{ id: 'compression', label: 'Compression Level' },
{ id: 'coverage', label: 'Coverage' },
{ id: 'waistband', label: 'Waistband' }
],
columns: [
{ id: 'too-tight', label: 'Too Tight' },
{ id: 'good-compression', label: 'Good Compression' },
{ id: 'just-right', label: 'Just Right' },
{ id: 'relaxed', label: 'Relaxed Fit' },
{ id: 'too-loose', label: 'Too Loose' }
],
fullWidth: true,
isVisible: () => orderSection.dropdown('productCategory')?.value() === 'activewear'
});
});
// ============================================
// SECTION 4: Shoe Fit (for Footwear)
// ============================================
const shoeFitSection = form.addSubform('shoeFit', {
title: 'Shoe Fit Details',
isVisible: () => orderSection.dropdown('productCategory')?.value() === 'shoes'
});
shoeFitSection.addRow(row => {
row.addRatingScale('shoeWidth', {
label: 'How is the width?',
preset: 'custom',
min: 1,
max: 5,
lowLabel: 'Too narrow',
highLabel: 'Too wide',
variant: 'segmented',
alignment: 'center'
});
});
shoeFitSection.addRow(row => {
row.addRatingScale('toeRoom', {
label: 'How is the toe room?',
preset: 'custom',
min: 1,
max: 5,
lowLabel: 'Too cramped',
highLabel: 'Too much room',
variant: 'segmented',
alignment: 'center'
});
});
shoeFitSection.addRow(row => {
row.addRatingScale('archSupport', {
label: 'How is the arch support?',
preset: 'custom',
min: 1,
max: 5,
lowLabel: 'Not enough',
highLabel: 'Too much',
variant: 'segmented',
alignment: 'center'
});
});
// ============================================
// SECTION 5: Quality & Comfort
// ============================================
const qualitySection = form.addSubform('quality', {
title: 'Quality & Comfort',
isVisible: () => !!overallFitSection.ratingScale('overallFitScale')?.value()
});
qualitySection.addRow(row => {
row.addStarRating('fabricQuality', {
label: 'How would you rate the fabric/material quality?',
maxStars: 5,
size: 'lg',
alignment: 'center'
}, '1fr');
row.addStarRating('comfort', {
label: 'How comfortable is this item?',
maxStars: 5,
size: 'lg',
alignment: 'center'
}, '1fr');
});
qualitySection.addRow(row => {
row.addCheckboxList('qualityNotes', {
label: 'Any quality observations?',
options: [
{ id: 'soft', name: 'Soft and comfortable' },
{ id: 'stretchy', name: 'Good stretch' },
{ id: 'stiff', name: 'Stiff/needs breaking in' },
{ id: 'thin', name: 'Thinner than expected' },
{ id: 'thick', name: 'Thicker than expected' },
{ id: 'itchy', name: 'Scratchy/itchy' }
]
});
});
// ============================================
// SECTION 6: Recommendation
// ============================================
const recommendSection = form.addSubform('recommend', {
title: 'Your Recommendation',
isVisible: () => !!qualitySection.starRating('fabricQuality')?.value()
});
recommendSection.addRow(row => {
row.addRadioButton('sizeRecommendation', {
label: 'What would you recommend to other shoppers?',
options: [
{ id: 'size-down-2', name: 'Order 2 sizes down' },
{ id: 'size-down-1', name: 'Order 1 size down' },
{ id: 'true-to-size', name: 'Order your usual size' },
{ id: 'size-up-1', name: 'Order 1 size up' },
{ id: 'size-up-2', name: 'Order 2 sizes up' }
],
isRequired: true
});
});
recommendSection.addSpacer();
recommendSection.addRow(row => {
row.addTextarea('fitNotes', {
label: 'Any tips for future buyers about sizing or fit?',
placeholder: 'e.g., "I\'m 5\'6" and the medium was perfect length" or "Runs tight in the shoulders"',
rows: 3
});
});
// ============================================
// SECTION 7: Summary
// ============================================
const summarySection = form.addSubform('summary', {
title: 'Your Fit Feedback',
isVisible: () => !!recommendSection.radioButton('sizeRecommendation')?.value()
});
summarySection.addRow(row => {
row.addTextPanel('summaryContent', {
computedValue: () => {
const category = orderSection.dropdown('productCategory')?.value();
const sizeOrdered = orderSection.dropdown('sizeOrdered')?.value();
const overallFit = overallFitSection.ratingScale('overallFitScale')?.value();
const wouldKeep = overallFitSection.radioButton('wouldKeep')?.value();
const fabricQuality = qualitySection.starRating('fabricQuality')?.value();
const comfort = qualitySection.starRating('comfort')?.value();
const recommendation = recommendSection.radioButton('sizeRecommendation')?.value();
if (!overallFit) return '';
const fitLabels: Record<number, string> = {
1: 'Much too small',
2: 'Slightly small',
3: 'True to size',
4: 'Slightly large',
5: 'Much too large'
};
const recLabels: Record<string, string> = {
'size-down-2': 'Order 2 sizes down',
'size-down-1': 'Order 1 size down',
'true-to-size': 'Order usual size',
'size-up-1': 'Order 1 size up',
'size-up-2': 'Order 2 sizes up'
};
let summary = '👕 Fit Feedback Summary\n';
summary += '═'.repeat(25) + '\n\n';
if (category && sizeOrdered) {
summary += `Category: ${category.charAt(0).toUpperCase() + category.slice(1)}\n`;
summary += `Size Ordered: ${sizeOrdered.toUpperCase()}\n`;
}
summary += `Overall Fit: ${fitLabels[overallFit]}\n`;
if (wouldKeep) {
const keepLabels: Record<string, string> = {
'yes': 'Keeping',
'exchange': 'Exchanging',
'return': 'Returning'
};
summary += `Decision: ${keepLabels[wouldKeep]}\n`;
}
if (fabricQuality || comfort) {
summary += '\n';
if (fabricQuality) summary += `Quality: ${'⭐'.repeat(fabricQuality)}\n`;
if (comfort) summary += `Comfort: ${'⭐'.repeat(comfort)}\n`;
}
if (recommendation) {
summary += `\n📏 Recommendation: ${recLabels[recommendation]}`;
}
return summary;
},
customStyles: () => {
const overallFit = overallFitSection.ratingScale('overallFitScale')?.value();
const baseStyles = {
padding: '16px',
borderRadius: '8px',
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '14px'
};
if (overallFit === 3) {
return { ...baseStyles, backgroundColor: '#d1fae5', borderLeft: '4px solid #10b981' };
} else if (overallFit === 2 || overallFit === 4) {
return { ...baseStyles, backgroundColor: '#fef3c7', borderLeft: '4px solid #f59e0b' };
} else {
return { ...baseStyles, backgroundColor: '#fee2e2', borderLeft: '4px solid #ef4444' };
}
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: 'Submit Fit Feedback',
isVisible: () => !!recommendSection.radioButton('sizeRecommendation')?.value()
});
form.configureCompletionScreen({
type: 'text',
title: 'Thank You!',
message: 'Your fit feedback helps other shoppers find their perfect size. We appreciate you taking the time to share your experience!'
});
}