export function diaryStudyEntry(form: FormTs) {
// Daily Diary Study Entry - Research participant daily log
// Demonstrates: Datepicker, Timepicker, EmojiRating, Slider, CheckboxList, ThumbRating, dynamic labels
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'Daily Diary Entry',
computedValue: () => 'Take a moment to reflect on your day. This should only take 2 minutes.',
customStyles: {
backgroundColor: '#7c3aed',
color: 'white',
padding: '24px',
borderRadius: '12px',
textAlign: 'center'
}
});
});
// ============================================
// SECTION 1: Entry Timestamp
// ============================================
const timestampSection = form.addSubform('timestampSection', {
title: 'Entry Details',
customStyles: { padding: '16px', borderRadius: '8px', border: '1px solid #ddd6fe' }
});
timestampSection.addRow(row => {
row.addDatepicker('entryDate', {
label: 'Date of this entry',
maxDate: () => new Date().toISOString(),
isRequired: true
}, '1fr');
row.addTimepicker('entryTime', {
label: 'What time is it now?',
isRequired: true
}, '1fr');
});
timestampSection.addRow(row => {
row.addDropdown('entryContext', {
label: 'Where are you right now?',
options: [
{ id: 'home', name: 'At home' },
{ id: 'work', name: 'At work/office' },
{ id: 'commute', name: 'Commuting' },
{ id: 'public', name: 'Public place' },
{ id: 'outdoor', name: 'Outdoors' },
{ id: 'other', name: 'Other location' }
],
placeholder: 'Select location'
}, '1fr');
row.addDropdown('entryType', {
label: 'Type of entry',
options: [
{ id: 'morning', name: 'Morning check-in' },
{ id: 'midday', name: 'Midday check-in' },
{ id: 'evening', name: 'Evening reflection' },
{ id: 'triggered', name: 'Triggered by an event' }
],
placeholder: 'Select type'
}, '1fr');
});
// ============================================
// SECTION 2: Current State
// ============================================
const stateSection = form.addSubform('stateSection', {
title: 'How Are You Feeling?',
customStyles: () => {
const mood = stateSection.emojiRating('currentMood')?.value();
if (mood === 'excited' || mood === 'happy') {
return { backgroundColor: '#f5f3ff', padding: '16px', borderRadius: '8px', borderLeft: '4px solid #7c3aed' };
}
if (mood === 'sad' || mood === 'down') {
return { backgroundColor: '#fef3c7', padding: '16px', borderRadius: '8px', borderLeft: '4px solid #f59e0b' };
}
return { padding: '16px', borderRadius: '8px', border: '1px dashed #c4b5fd' };
}
});
stateSection.addRow(row => {
row.addEmojiRating('currentMood', {
label: 'Current mood',
preset: 'mood',
size: 'lg',
showLabels: true,
alignment: 'center'
});
});
stateSection.addRow(row => {
row.addSlider('energyLevel', {
label: 'Energy level',
min: 0,
max: 10,
step: 1,
showValue: true,
defaultValue: 5
}, '1fr');
row.addSlider('stressLevel', {
label: 'Stress level',
min: 0,
max: 10,
step: 1,
showValue: true,
defaultValue: 5
}, '1fr');
});
stateSection.addRow(row => {
row.addSlider('focusLevel', {
label: 'Focus/Concentration',
min: 0,
max: 10,
step: 1,
showValue: true,
defaultValue: 5
}, '1fr');
row.addSlider('motivationLevel', {
label: 'Motivation',
min: 0,
max: 10,
step: 1,
showValue: true,
defaultValue: 5
}, '1fr');
});
// ============================================
// SECTION 3: Activities
// ============================================
const activitiesSection = form.addSubform('activitiesSection', {
title: 'Recent Activities',
isVisible: () => stateSection.emojiRating('currentMood')?.value() !== null
});
activitiesSection.addRow(row => {
row.addCheckboxList('recentActivities', {
label: 'What have you been doing recently? (select all that apply)',
options: [
{ id: 'work', name: 'Working/Productive tasks' },
{ id: 'meeting', name: 'Meetings/Calls' },
{ id: 'exercise', name: 'Exercise/Physical activity' },
{ id: 'social', name: 'Social interaction' },
{ id: 'eating', name: 'Eating/Drinking' },
{ id: 'relaxing', name: 'Relaxing/Resting' },
{ id: 'commuting', name: 'Traveling/Commuting' },
{ id: 'entertainment', name: 'Entertainment (TV, games, etc.)' },
{ id: 'chores', name: 'Household chores' },
{ id: 'other', name: 'Other activity' }
],
orientation: 'vertical'
});
});
activitiesSection.addRow(row => {
row.addDropdown('primaryActivity', {
label: 'What was your main activity in the last hour?',
options: [
{ id: 'deep-work', name: 'Deep focused work' },
{ id: 'routine-work', name: 'Routine tasks' },
{ id: 'meetings', name: 'Meetings/Collaboration' },
{ id: 'learning', name: 'Learning/Reading' },
{ id: 'creative', name: 'Creative work' },
{ id: 'admin', name: 'Administrative tasks' },
{ id: 'break', name: 'Taking a break' },
{ id: 'personal', name: 'Personal activities' }
],
placeholder: 'Select primary activity'
});
});
// ============================================
// SECTION 4: Product/Experience Interaction (Research Focus)
// ============================================
const interactionSection = form.addSubform('interactionSection', {
title: 'Product/Experience Interaction',
isVisible: () => stateSection.emojiRating('currentMood')?.value() !== null,
customStyles: { backgroundColor: '#f5f3ff', padding: '16px', borderRadius: '8px' }
});
interactionSection.addRow(row => {
row.addRadioButton('usedProduct', {
label: 'Did you use the product/service being studied today?',
options: [
{ id: 'yes', name: 'Yes' },
{ id: 'no', name: 'No' },
{ id: 'na', name: 'Not applicable today' }
],
orientation: 'horizontal'
});
});
// Conditional: if used product
const productDetails = interactionSection.addSubform('productDetails', {
isVisible: () => interactionSection.radioButton('usedProduct')?.value() === 'yes',
customStyles: { backgroundColor: 'white', padding: '16px', borderRadius: '8px', marginTop: '12px' }
});
productDetails.addRow(row => {
row.addStarRating('productExperience', {
label: 'Rate your experience today',
maxStars: 5,
size: 'lg',
alignment: 'center',
filledColor: '#7c3aed'
});
});
productDetails.addRow(row => {
row.addEmojiRating('productFeeling', {
label: 'How did using it make you feel?',
preset: 'satisfaction',
size: 'md',
showLabels: true,
alignment: 'center'
});
});
productDetails.addRow(row => {
row.addTextarea('productNotes', {
label: 'Describe what happened (context, task, outcome)',
placeholder: 'What were you trying to do? What happened? How did it go?',
rows: 2,
autoExpand: true
});
});
// ============================================
// SECTION 5: Notable Events
// ============================================
const eventsSection = form.addSubform('eventsSection', {
title: 'Notable Events',
isVisible: () => stateSection.emojiRating('currentMood')?.value() !== null
});
eventsSection.addRow(row => {
row.addRadioButton('notableEvent', {
label: 'Did anything notable happen since your last entry?',
options: [
{ id: 'yes', name: 'Yes, something notable' },
{ id: 'no', name: 'No, nothing unusual' }
],
orientation: 'horizontal'
});
});
// Conditional: Notable event details
const eventDetails = eventsSection.addSubform('eventDetails', {
isVisible: () => eventsSection.radioButton('notableEvent')?.value() === 'yes',
customStyles: { backgroundColor: '#fef3c7', padding: '16px', borderRadius: '8px', marginTop: '12px' }
});
eventDetails.addRow(row => {
row.addDropdown('eventType', {
label: 'Type of event',
options: [
{ id: 'positive', name: 'Positive experience' },
{ id: 'negative', name: 'Negative experience' },
{ id: 'surprising', name: 'Surprising/Unexpected' },
{ id: 'frustrating', name: 'Frustrating moment' },
{ id: 'successful', name: 'Achievement/Success' },
{ id: 'social', name: 'Social interaction' },
{ id: 'discovery', name: 'Discovery/Learning' },
{ id: 'other', name: 'Other' }
],
placeholder: 'Select event type'
}, '1fr');
row.addThumbRating('eventImpact', {
label: 'Was the impact positive or negative?',
showLabels: true,
upLabel: 'Positive',
downLabel: 'Negative',
alignment: 'center'
}, '1fr');
});
eventDetails.addRow(row => {
row.addTextarea('eventDescription', {
label: 'Describe what happened',
placeholder: 'What happened? How did it affect you?',
rows: 3,
autoExpand: true,
isRequired: () => eventsSection.radioButton('notableEvent')?.value() === 'yes'
});
});
// ============================================
// SECTION 6: Quick Reflection
// ============================================
const reflectionSection = form.addSubform('reflectionSection', {
title: 'Quick Reflection',
isVisible: () => stateSection.emojiRating('currentMood')?.value() !== null
});
reflectionSection.addRow(row => {
row.addTextarea('highlights', {
label: () => {
const mood = stateSection.emojiRating('currentMood')?.value();
if (mood === 'excited' || mood === 'happy') {
return 'What made today good so far?';
} else if (mood === 'sad' || mood === 'down') {
return 'What has been challenging today?';
}
return 'Anything worth noting about today?';
},
placeholder: 'A few words about your day...',
rows: 2,
autoExpand: true
});
});
reflectionSection.addRow(row => {
row.addSlider('overallDay', {
label: 'Rate your day so far (1-10)',
min: 1,
max: 10,
step: 1,
showValue: true,
defaultValue: 5
});
});
// ============================================
// SECTION 7: Summary
// ============================================
const summarySection = form.addSubform('summarySection', {
title: 'Entry Summary',
isVisible: () => stateSection.emojiRating('currentMood')?.value() !== null
});
summarySection.addRow(row => {
row.addTextPanel('summary', {
computedValue: () => {
const mood = stateSection.emojiRating('currentMood')?.value();
const energy = stateSection.slider('energyLevel')?.value();
const stress = stateSection.slider('stressLevel')?.value();
const focus = stateSection.slider('focusLevel')?.value();
const motivation = stateSection.slider('motivationLevel')?.value();
const overallDay = reflectionSection.slider('overallDay')?.value();
const usedProduct = interactionSection.radioButton('usedProduct')?.value();
const productRating = productDetails.starRating('productExperience')?.value();
const activities = activitiesSection.checkboxList('recentActivities')?.value() || [];
if (!mood) return '';
const moodLabels: Record<string, string> = {
'sad': '😢 Sad',
'down': '😔 Down',
'neutral': '😐 Neutral',
'happy': '😊 Happy',
'excited': '🤩 Excited'
};
let summary = `📓 DIARY ENTRY\n`;
summary += `${'═'.repeat(22)}\n\n`;
summary += `Mood: ${moodLabels[mood] || mood}\n\n`;
summary += `Energy: ${'█'.repeat(energy || 0)}${'░'.repeat(10 - (energy || 0))} ${energy}/10\n`;
summary += `Stress: ${'█'.repeat(stress || 0)}${'░'.repeat(10 - (stress || 0))} ${stress}/10\n`;
summary += `Focus: ${'█'.repeat(focus || 0)}${'░'.repeat(10 - (focus || 0))} ${focus}/10\n`;
summary += `Motivation: ${'█'.repeat(motivation || 0)}${'░'.repeat(10 - (motivation || 0))} ${motivation}/10\n`;
if (activities.length > 0) {
summary += `\nActivities: ${activities.length} logged`;
}
if (usedProduct === 'yes' && productRating) {
summary += `\n\n📱 Product: ${'★'.repeat(productRating)}${'☆'.repeat(5 - productRating)}`;
}
if (overallDay) {
summary += `\n\n📊 Day Rating: ${overallDay}/10`;
}
return summary;
},
customStyles: () => {
const mood = stateSection.emojiRating('currentMood')?.value();
const baseStyles = {
padding: '16px',
borderRadius: '8px',
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '12px'
};
if (mood === 'excited' || mood === 'happy') {
return { ...baseStyles, backgroundColor: '#f5f3ff', borderLeft: '4px solid #7c3aed' };
} else if (mood === 'sad' || mood === 'down') {
return { ...baseStyles, backgroundColor: '#fef3c7', borderLeft: '4px solid #f59e0b' };
}
return { ...baseStyles, backgroundColor: '#f8fafc', borderLeft: '4px solid #7c3aed' };
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: 'Save Entry',
isVisible: () => stateSection.emojiRating('currentMood')?.value() !== null
});
form.configureCompletionScreen({
type: 'text',
title: 'Entry Saved!',
message: 'Thank you for logging your experience. Your consistent participation makes this research valuable. See you at your next entry!'
});
}