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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 64x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 62x 64x 64x 64x 64x 10x 52x 52x 64x 64x 52x 52x 21x 31x 10x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 64x 64x 64x 62x 62x 62x 62x 62x 62x 62x 52x 10x 62x 62x 62x 52x 10x 62x 62x 62x 62x 62x 52x 52x 10x 10x 62x 52x 52x 10x 10x 62x 62x 62x 62x 62x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 52x 52x 10x 10x 64x 64x 64x 64x 64x 64x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 64x 64x 64x 64x 64x 64x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 64x 19x 19x 19x 19x 19x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x | 'use client'
import * as Popover from '@radix-ui/react-popover'
import * as TooltipPrimitive from '@radix-ui/react-tooltip'
import { useState } from 'react'
import { useTheme } from '@/contexts/ThemeContext'
import { css } from '../../../../styled-system/css'
const DISABLED_PERCENT_3 = 25
const DISABLED_PERCENT_4 = 15
/** Shared styles for the +/× toggle badge in the top-left corner */
const toggleBadgeClass = css({
position: 'absolute',
top: '4px',
left: '4px',
width: '22px',
height: '22px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: '0.875rem',
fontWeight: 'bold',
borderRadius: '50%',
lineHeight: 1,
transition: 'transform 0.25s ease, background-color 0.2s ease, color 0.2s ease',
'@media (max-width: 480px), (max-height: 700px)': {
top: '3px',
left: '3px',
width: '18px',
height: '18px',
fontSize: '0.75rem',
},
})
/** Tooltip portal content styles */
const tooltipPortalClass = css({
zIndex: 15000,
outline: 'none',
})
/** Popover card for a locked segment's "why" note */
const lockedPopoverClass = css({
zIndex: 15000,
outline: 'none',
maxWidth: '280px',
padding: '0.75rem 0.875rem',
borderRadius: '12px',
fontSize: '0.8125rem',
lineHeight: 1.4,
boxShadow: '0 8px 24px rgba(0, 0, 0, 0.18)',
})
/**
* A segment the student can't turn on yet. It stays live (no `disabled`): tapping it
* opens a short note on why, instead of cycling the weight.
*/
export interface ProportionBarLock {
/** Popover body: the reason and, optionally, where to go to work on it */
content: React.ReactNode
/** Accessible label for the locked control (defaults to "<label> locked") */
ariaLabel?: string
}
export interface ProportionBarSegment {
key: string
emoji: string
label: string
weight: number
/** Optional badge in top-right (e.g., problem count) */
badgeContent?: React.ReactNode
/** Optional rich tooltip content shown on hover (desktop) */
tooltipContent?: React.ReactNode
/** When set, the segment renders locked (🔒, muted) and tapping opens the note */
locked?: ProportionBarLock
/** Color for enabled state: [lightBg, lightBgBoosted, darkBg, darkBgBoosted] */
colors: {
lightBg: string
lightBgBoosted: string
darkBg: string
darkBgBoosted: string
lightAccent: string
darkAccent: string
}
}
interface ProportionBarProps {
/** Section label above the bar */
label: string
/** Optional extra content rendered inline after the label (e.g., info button) */
labelExtra?: React.ReactNode
/** data-setting attribute for the outer div */
dataSetting: string
/** Segment definitions */
segments: ProportionBarSegment[]
/** Called when a segment is tapped (cycle weight) */
onCycleWeight: (key: string) => void
/** Called when a segment's × is tapped (disable) */
onDisable: (key: string) => void
/** Number of currently enabled segments */
enabledCount: number
}
export function ProportionBar({
label,
labelExtra,
dataSetting,
segments,
onCycleWeight,
onDisable,
enabledCount,
}: ProportionBarProps) {
const { resolvedTheme } = useTheme()
const isDark = resolvedTheme === 'dark'
const disabledPercent = segments.length <= 3 ? DISABLED_PERCENT_3 : DISABLED_PERCENT_4
const disabledCount = segments.filter((s) => s.weight === 0 || s.locked).length
const reservedPercent = disabledCount * disabledPercent
const activeTotal = segments.reduce((sum, s) => sum + (s.locked ? 0 : s.weight), 0)
const remainingPercent = 100 - reservedPercent
// Only show ×2 when active segments have mixed weights
const activeWeights = segments.filter((s) => s.weight > 0 && !s.locked).map((s) => s.weight)
const hasMixedWeights = activeWeights.length >= 2 && new Set(activeWeights).size > 1
return (
<div data-setting={dataSetting}>
<div
data-element="bar-label"
className={css({
display: 'flex',
alignItems: 'center',
gap: '0.375rem',
fontSize: '0.6875rem',
fontWeight: '600',
color: isDark ? 'gray.500' : 'gray.400',
textTransform: 'uppercase',
letterSpacing: '0.05em',
marginBottom: '0.5rem',
'@media (max-width: 480px), (max-height: 700px)': {
marginBottom: '0.25rem',
fontSize: '0.625rem',
},
})}
>
{label}
{labelExtra}
</div>
<div
data-element="proportion-bar"
className={css({
display: 'flex',
gap: '2px',
borderRadius: '12px',
overflow: 'hidden',
height: '56px',
'@media (max-width: 480px), (max-height: 700px)': {
height: '44px',
borderRadius: '10px',
},
})}
style={{
backgroundColor: isDark ? 'rgba(255,255,255,0.05)' : 'rgba(0,0,0,0.04)',
}}
>
{segments.map((segment) => {
if (segment.locked) {
return (
<LockedSegment
key={segment.key}
segment={segment}
lock={segment.locked}
widthPercent={disabledPercent}
isDark={isDark}
/>
)
}
const isEnabled = segment.weight > 0
const isLastActive = isEnabled && enabledCount === 1
const widthPercent =
segment.weight === 0
? disabledPercent
: activeTotal > 0
? (remainingPercent * segment.weight) / activeTotal
: 0
const bgColor = isEnabled
? isDark
? segment.weight >= 2
? segment.colors.darkBgBoosted
: segment.colors.darkBg
: segment.weight >= 2
? segment.colors.lightBgBoosted
: segment.colors.lightBg
: 'transparent'
const buttonClassName = css({
position: 'relative',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
gap: '2px',
border: 'none',
cursor: 'pointer',
transition: 'width 0.2s ease, background-color 0.15s ease, opacity 0.15s ease',
padding: '0 0.25rem',
'@media (max-width: 480px), (max-height: 700px)': {
padding: '0 0.125rem',
},
})
const buttonStyle = {
width: `${widthPercent}%`,
backgroundColor: bgColor,
opacity: isEnabled ? 1 : 0.5,
}
const buttonChildren = (
<>
{/* Optional badge — top-right */}
{isEnabled && segment.badgeContent && (
<span
data-element="problem-badge"
className={css({
position: 'absolute',
top: '2px',
right: '4px',
minWidth: '20px',
height: '20px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: '0.6875rem',
fontWeight: 'bold',
color: 'white',
backgroundColor: 'green.500',
borderRadius: '10px',
padding: '0 4px',
'@media (max-width: 480px), (max-height: 700px)': {
top: '1px',
right: '2px',
minWidth: '16px',
height: '16px',
fontSize: '0.5625rem',
borderRadius: '8px',
padding: '0 3px',
},
})}
>
{segment.badgeContent}
</span>
)}
{/* Toggle badge — top-left: "+" (0°) to add, rotates 45° to become "×" to remove */}
{!isLastActive && (
<span
data-element={isEnabled ? 'remove-hint' : 'add-hint'}
data-action={isEnabled ? 'disable-mode' : undefined}
role={isEnabled ? 'button' : undefined}
tabIndex={isEnabled ? 0 : undefined}
onClick={
isEnabled
? (e: React.MouseEvent) => {
e.stopPropagation()
onDisable(segment.key)
}
: undefined
}
onKeyDown={
isEnabled
? (e: React.KeyboardEvent) => {
if (e.key === 'Enter' || e.key === ' ') {
e.stopPropagation()
e.preventDefault()
onDisable(segment.key)
}
}
: undefined
}
className={toggleBadgeClass}
style={{
transform: isEnabled ? 'rotate(45deg)' : 'rotate(0deg)',
color: isEnabled
? isDark
? '#f87171'
: '#dc2626'
: isDark
? '#e2e8f0'
: '#334155',
backgroundColor: isEnabled
? isDark
? 'rgba(248, 113, 113, 0.15)'
: 'rgba(220, 38, 38, 0.1)'
: isDark
? 'rgba(34, 197, 94, 0.3)'
: 'rgba(22, 163, 74, 0.15)',
cursor: isEnabled ? 'pointer' : undefined,
}}
>
+
</span>
)}
{/* Emoji */}
<span
className={css({
fontSize: '1.25rem',
lineHeight: 1,
flexShrink: 0,
'@media (max-width: 480px), (max-height: 700px)': {
fontSize: '1rem',
},
})}
>
{segment.emoji}
</span>
{/* Label row: label + optional ×N badge */}
<span
className={css({
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '2px',
maxWidth: '100%',
overflow: 'hidden',
})}
>
<span
data-element="segment-label"
className={css({
fontSize: '0.625rem',
fontWeight: '600',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
lineHeight: 1.2,
'@media (max-width: 480px), (max-height: 700px)': {
fontSize: '0.5625rem',
},
})}
style={{
color: isEnabled
? isDark
? '#e2e8f0'
: '#334155'
: isDark
? '#94a3b8'
: '#94a3b8',
}}
>
{segment.label}
</span>
{/* ×N badge — only when weights are mixed and this segment is boosted */}
{segment.weight >= 2 && hasMixedWeights && (
<span
data-element="weight-label"
className={css({
fontSize: '0.5625rem',
fontWeight: 'bold',
lineHeight: 1,
flexShrink: 0,
'@media (max-width: 480px), (max-height: 700px)': {
fontSize: '0.5rem',
},
})}
style={{
color: isDark ? segment.colors.darkAccent : segment.colors.lightAccent,
}}
>
×{segment.weight}
</span>
)}
</span>
</>
)
if (segment.tooltipContent) {
return (
<TooltipPrimitive.Provider key={segment.key}>
<TooltipPrimitive.Root delayDuration={400}>
<TooltipPrimitive.Trigger asChild>
<button
type="button"
data-option={`segment-${segment.key}`}
data-enabled={isEnabled}
data-weight={segment.weight}
onClick={() => onCycleWeight(segment.key)}
className={buttonClassName}
style={buttonStyle}
>
{buttonChildren}
</button>
</TooltipPrimitive.Trigger>
<TooltipPrimitive.Portal>
<TooltipPrimitive.Content
side="bottom"
sideOffset={8}
className={tooltipPortalClass}
>
{segment.tooltipContent}
</TooltipPrimitive.Content>
</TooltipPrimitive.Portal>
</TooltipPrimitive.Root>
</TooltipPrimitive.Provider>
)
}
return (
<button
key={segment.key}
type="button"
data-option={`segment-${segment.key}`}
data-enabled={isEnabled}
data-weight={segment.weight}
onClick={() => onCycleWeight(segment.key)}
className={buttonClassName}
style={buttonStyle}
>
{buttonChildren}
</button>
)
})}
</div>
</div>
)
}
function LockedSegment({
segment,
lock,
widthPercent,
isDark,
}: {
segment: ProportionBarSegment
lock: ProportionBarLock
widthPercent: number
isDark: boolean
}) {
const [open, setOpen] = useState(false)
return (
<Popover.Root open={open} onOpenChange={setOpen}>
<Popover.Trigger asChild>
<button
type="button"
data-option={`segment-${segment.key}`}
data-element="mode-segment-locked"
data-part={segment.key}
data-enabled={false}
data-weight={0}
data-locked="true"
aria-label={lock.ariaLabel ?? `${segment.label} locked`}
aria-expanded={open}
className={css({
position: 'relative',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
gap: '2px',
border: 'none',
cursor: 'pointer',
transition: 'width 0.2s ease, background-color 0.15s ease, opacity 0.15s ease',
padding: '0 0.25rem',
'@media (max-width: 480px), (max-height: 700px)': {
padding: '0 0.125rem',
},
})}
style={{
width: `${widthPercent}%`,
backgroundColor: 'transparent',
opacity: 0.7,
}}
>
<span
data-element="lock-glyph"
aria-hidden
className={css({
fontSize: '1.25rem',
lineHeight: 1,
flexShrink: 0,
'@media (max-width: 480px), (max-height: 700px)': {
fontSize: '1rem',
},
})}
>
🔒
</span>
<span
data-element="segment-label"
className={css({
fontSize: '0.625rem',
fontWeight: '600',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
lineHeight: 1.2,
'@media (max-width: 480px), (max-height: 700px)': {
fontSize: '0.5625rem',
},
})}
style={{ color: '#94a3b8' }}
>
{segment.label}
</span>
</button>
</Popover.Trigger>
<Popover.Portal>
<Popover.Content
side="bottom"
sideOffset={8}
align="center"
collisionPadding={12}
data-element="mode-segment-locked-note"
data-part={segment.key}
className={lockedPopoverClass}
style={{
backgroundColor: isDark ? '#1e293b' : 'white',
color: isDark ? '#e2e8f0' : '#334155',
border: `1px solid ${isDark ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.08)'}`,
}}
>
{lock.content}
</Popover.Content>
</Popover.Portal>
</Popover.Root>
)
}
|