Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | 'use client' import { useEffect, useState } from 'react' import { css, cx } from '../../../styled-system/css' import type { AssistanceMachineState } from './hooks/useProgressiveAssistance' interface ProgressiveAssistanceUIProps { machineState: AssistanceMachineState showWrongAnswerSuggestion: boolean isDark: boolean onHelpRequested: () => void onSkip: () => void onDismissWrongAnswerSuggestion: () => void } export function ProgressiveAssistanceUI({ machineState, showWrongAnswerSuggestion, isDark, onHelpRequested, onSkip, onDismissWrongAnswerSuggestion, }: ProgressiveAssistanceUIProps) { const { state } = machineState // Track fade-in for encouragement text const [encourageVisible, setEncourageVisible] = useState(false) useEffect(() => { if (state === 'encouraging' || state === 'offeringHelp') { // Small delay before fading in const id = setTimeout(() => setEncourageVisible(true), 50) return () => clearTimeout(id) } setEncourageVisible(false) }, [state]) // Don't render anything during help mode or auto-paused (those have their own UI) if (state === 'inHelp' || state === 'autoPaused') { return null } return ( <div data-component="progressive-assistance" data-state={state} className={css({ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '0.5rem', minHeight: '2.5rem', })} > {/* Encouragement text */} {(state === 'encouraging' || state === 'offeringHelp') && ( <div data-element="encouragement" className={css({ fontSize: '0.875rem', fontWeight: '500', color: isDark ? 'blue.300' : 'blue.600', opacity: encourageVisible ? 1 : 0, transition: 'opacity 0.5s ease', textAlign: 'center', })} > Give it a try! </div> )} {/* Help button */} {state === 'offeringHelp' && ( <button type="button" data-action="request-help" onClick={onHelpRequested} className={css({ padding: '0.5rem 1.25rem', fontSize: '0.875rem', fontWeight: '600', borderRadius: '20px', border: 'none', cursor: 'pointer', backgroundColor: isDark ? 'blue.700' : 'blue.100', color: isDark ? 'blue.100' : 'blue.700', transition: 'all 0.2s ease', _hover: { backgroundColor: isDark ? 'blue.600' : 'blue.200', transform: 'scale(1.02)', }, })} > I need help </button> )} {/* Wrong answer suggestion */} {showWrongAnswerSuggestion && ( <div data-element="wrong-answer-suggestion" className={css({ display: 'flex', alignItems: 'center', gap: '0.75rem', padding: '0.5rem 1rem', borderRadius: '12px', backgroundColor: isDark ? 'orange.900/60' : 'orange.50', border: '1px solid', borderColor: isDark ? 'orange.700' : 'orange.200', })} > <span className={css({ fontSize: '0.8125rem', color: isDark ? 'orange.200' : 'orange.800', })} > This is tricky! Try using help to work through it step by step </span> <button type="button" data-action="wrong-answer-help" onClick={onHelpRequested} className={css({ padding: '0.25rem 0.75rem', fontSize: '0.75rem', fontWeight: '600', borderRadius: '12px', border: 'none', cursor: 'pointer', backgroundColor: isDark ? 'blue.700' : 'blue.500', color: 'white', whiteSpace: 'nowrap', _hover: { backgroundColor: isDark ? 'blue.600' : 'blue.600', }, })} > Help </button> <button type="button" data-action="dismiss-suggestion" onClick={onDismissWrongAnswerSuggestion} className={css({ padding: '0.125rem 0.375rem', fontSize: '0.75rem', color: isDark ? 'gray.400' : 'gray.500', backgroundColor: 'transparent', border: 'none', cursor: 'pointer', _hover: { color: isDark ? 'gray.200' : 'gray.700', }, })} aria-label="Dismiss suggestion" > × </button> </div> )} {/* Skip button — always visible but understated so kids find help first */} <button type="button" data-action="skip" onClick={onSkip} className={css({ padding: '0.25rem 0.75rem', fontSize: '0.75rem', fontWeight: '400', borderRadius: '8px', border: 'none', cursor: 'pointer', backgroundColor: 'transparent', color: isDark ? 'gray.400' : 'gray.500', textDecoration: 'underline', textUnderlineOffset: '2px', _hover: { color: isDark ? 'gray.300' : 'gray.700', }, })} > skip </button> </div> ) } |