export function socialMediaPoll(form: FormTs) {
// Quick Social Media Poll
// Demonstrates: EmojiRating, RadioButton, Slider, SuggestionChips, ThumbRating, compact layout
// State for tracking engagement level
const engagementLevel = form.state<'quick' | 'engaged' | null>(null);
// ============================================
// HEADER - Compact for social media
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'Quick Poll',
computedValue: () => 'Tap your reaction below!',
customStyles: {
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
color: 'white',
padding: '16px 20px',
borderRadius: '12px',
textAlign: 'center',
fontSize: '14px'
}
});
});
// ============================================
// SECTION 1: Quick Reaction (Core poll question)
// ============================================
const reactionSection = form.addSubform('reactionSection', {
title: 'What do you think?',
customStyles: { padding: '12px', borderRadius: '8px' }
});
reactionSection.addRow(row => {
row.addEmojiRating('quickReaction', {
label: 'React to this content:',
preset: 'mood',
size: 'lg',
showLabels: true,
alignment: 'center',
onValueChange: () => {
engagementLevel.set('quick');
}
});
});
// ============================================
// SECTION 2: Topic Preference
// ============================================
const topicSection = form.addSubform('topicSection', {
title: 'Content Preference',
isVisible: () => reactionSection.emojiRating('quickReaction')?.value() !== null && reactionSection.emojiRating('quickReaction')?.value() !== undefined,
customStyles: () => {
const reaction = reactionSection.emojiRating('quickReaction')?.value();
if (reaction === 'excited' || reaction === 'happy') {
return { backgroundColor: '#ecfdf5', padding: '16px', borderRadius: '10px' };
}
return { backgroundColor: '#f8fafc', padding: '16px', borderRadius: '10px' };
}
});
topicSection.addRow(row => {
row.addRadioButton('contentType', {
label: () => {
const reaction = reactionSection.emojiRating('quickReaction')?.value();
if (reaction === 'excited' || reaction === 'happy') {
return 'What type of content would you love more of?';
}
return 'What content would you prefer instead?';
},
options: [
{ id: 'tutorials', name: 'Tutorials & How-tos' },
{ id: 'tips', name: 'Quick Tips' },
{ id: 'behind-scenes', name: 'Behind the Scenes' },
{ id: 'trends', name: 'Trending Topics' },
{ id: 'entertainment', name: 'Entertainment & Fun' }
],
orientation: 'vertical'
});
});
// ============================================
// SECTION 3: Engagement Level
// ============================================
const engagementSection = form.addSubform('engagementSection', {
title: 'Your Engagement',
isVisible: () => topicSection.radioButton('contentType')?.value() !== null && topicSection.radioButton('contentType')?.value() !== undefined,
customStyles: { backgroundColor: '#faf5ff', padding: '16px', borderRadius: '10px' }
});
engagementSection.addRow(row => {
row.addSlider('engagementScore', {
label: 'How often do you engage with our content?',
min: 0,
max: 10,
step: 1,
showValue: true,
unit: '',
defaultValue: 5,
onValueChange: (val) => {
if (val !== null && val !== undefined && val >= 7) {
engagementLevel.set('engaged');
}
}
});
});
engagementSection.addRow(row => {
row.addStarRating('contentQuality', {
label: 'Rate overall content quality',
maxStars: 5,
size: 'md',
alignment: 'center',
showCounter: true
});
});
// ============================================
// SECTION 4: Interest Tags (for engaged users)
// ============================================
const tagsSection = form.addSubform('tagsSection', {
title: 'What interests you?',
isVisible: () => engagementLevel() === 'engaged',
customStyles: { backgroundColor: '#fef3c7', padding: '16px', borderRadius: '10px' }
});
tagsSection.addRow(row => {
row.addSuggestionChips('interestTags', {
label: 'Select topics you want to see more (pick up to 3):',
suggestions: [
{ id: 'tech', name: 'Technology' },
{ id: 'lifestyle', name: 'Lifestyle' },
{ id: 'business', name: 'Business' },
{ id: 'creative', name: 'Creative' },
{ id: 'news', name: 'News' },
{ id: 'reviews', name: 'Reviews' },
{ id: 'interviews', name: 'Interviews' },
{ id: 'community', name: 'Community' }
],
max: 3,
alignment: 'center'
});
});
// ============================================
// SECTION 5: Follow & Subscribe
// ============================================
const followSection = form.addSubform('followSection', {
title: 'Stay Connected',
isVisible: () => engagementSection.starRating('contentQuality')?.value() !== null && engagementSection.starRating('contentQuality')?.value() !== undefined,
customStyles: { backgroundColor: '#f0f9ff', padding: '16px', borderRadius: '10px' }
});
followSection.addRow(row => {
row.addThumbRating('wouldFollow', {
label: 'Would you follow us for more content?',
showLabels: true,
upLabel: 'Yes, follow!',
downLabel: 'Maybe later',
size: 'lg',
alignment: 'center'
});
});
followSection.addRow(row => {
row.addTextbox('socialHandle', {
label: 'Drop your social handle (optional):',
placeholder: '@yourusername',
isVisible: () => followSection.thumbRating('wouldFollow')?.value() === 'up',
maxLength: 50
});
});
// ============================================
// SECTION 6: Quick Summary
// ============================================
const summarySection = form.addSubform('summarySection', {
title: 'Your Poll Response',
isVisible: () => followSection.thumbRating('wouldFollow')?.value() !== null && followSection.thumbRating('wouldFollow')?.value() !== undefined
});
summarySection.addRow(row => {
row.addTextPanel('summaryContent', {
computedValue: () => {
const reaction = reactionSection.emojiRating('quickReaction')?.value();
const contentType = topicSection.radioButton('contentType')?.value();
const quality = engagementSection.starRating('contentQuality')?.value();
const wouldFollow = followSection.thumbRating('wouldFollow')?.value();
if (!reaction) return '';
const reactionEmojis: Record<string, string> = {
'sad': '😢',
'down': '😔',
'neutral': '😐',
'happy': '😊',
'excited': '🤩'
};
const contentLabels: Record<string, string> = {
'tutorials': 'Tutorials & How-tos',
'tips': 'Quick Tips',
'behind-scenes': 'Behind the Scenes',
'trends': 'Trending Topics',
'entertainment': 'Entertainment & Fun'
};
let summary = `${reactionEmojis[reaction] || '📊'} Your Response\n`;
summary += `${'─'.repeat(20)}\n\n`;
summary += `Reaction: ${reactionEmojis[reaction] || reaction}\n`;
if (contentType) summary += `Preference: ${contentLabels[contentType] || contentType}\n`;
if (quality) summary += `Quality Rating: ${'⭐'.repeat(quality)}\n`;
summary += `Follow: ${wouldFollow === 'up' ? 'Yes! 🎉' : 'Maybe later'}`;
return summary;
},
customStyles: () => {
const wouldFollow = followSection.thumbRating('wouldFollow')?.value();
return {
padding: '16px',
borderRadius: '10px',
whiteSpace: 'pre-wrap',
fontFamily: 'system-ui, -apple-system, sans-serif',
fontSize: '14px',
backgroundColor: wouldFollow === 'up' ? '#d1fae5' : '#f1f5f9',
borderLeft: wouldFollow === 'up' ? '4px solid #10b981' : '4px solid #94a3b8',
textAlign: 'center'
};
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: () => {
const wouldFollow = followSection.thumbRating('wouldFollow')?.value();
return wouldFollow === 'up' ? 'Submit & Follow!' : 'Submit Poll';
},
isVisible: () => followSection.thumbRating('wouldFollow')?.value() !== null && followSection.thumbRating('wouldFollow')?.value() !== undefined
});
form.configureCompletionScreen({
type: 'text',
title: 'Thanks for voting!',
message: 'Your opinion shapes our content. Stay tuned for more awesome posts!'
});
}