|
| 1 | +import type { CSSProperties } from 'react'; |
| 2 | + |
| 3 | +/** |
| 4 | + * October decoration: a few leaves drifting down the left edge of the |
| 5 | + * viewport. Pure CSS (no client JS), aria-hidden and pointer-events: none so |
| 6 | + * it never intercepts clicks or reaches assistive tech. Negative delays start |
| 7 | + * each leaf mid-fall so the strip is populated on first paint. Under |
| 8 | + * `prefers-reduced-motion` the leaves rest in place instead of falling. |
| 9 | + */ |
| 10 | +type LeafShape = 'maple' | 'oval'; |
| 11 | + |
| 12 | +interface Leaf { |
| 13 | + shape: LeafShape; |
| 14 | + /** Horizontal position inside the strip, as a percentage. */ |
| 15 | + left: number; |
| 16 | + /** Rendered size in px. */ |
| 17 | + size: number; |
| 18 | + /** Fall duration in seconds. */ |
| 19 | + duration: number; |
| 20 | + /** Negative start offset in seconds. */ |
| 21 | + delay: number; |
| 22 | + /** Peak horizontal sway in px. */ |
| 23 | + sway: number; |
| 24 | + /** Resting top position (%) used when motion is reduced. */ |
| 25 | + rest: number; |
| 26 | + color: string; |
| 27 | + /** Rendered on wide viewports only, keeping phones uncluttered. */ |
| 28 | + desktopOnly?: boolean; |
| 29 | +} |
| 30 | + |
| 31 | +const LEAVES: readonly Leaf[] = [ |
| 32 | + { |
| 33 | + shape: 'maple', |
| 34 | + left: 18, |
| 35 | + size: 32, |
| 36 | + duration: 14, |
| 37 | + delay: -2, |
| 38 | + sway: 18, |
| 39 | + rest: 14, |
| 40 | + color: '#c2410c', |
| 41 | + }, |
| 42 | + { |
| 43 | + shape: 'oval', |
| 44 | + left: 62, |
| 45 | + size: 23, |
| 46 | + duration: 17, |
| 47 | + delay: -9, |
| 48 | + sway: 14, |
| 49 | + rest: 33, |
| 50 | + color: '#d97706', |
| 51 | + }, |
| 52 | + { |
| 53 | + shape: 'maple', |
| 54 | + left: 40, |
| 55 | + size: 38, |
| 56 | + duration: 19, |
| 57 | + delay: -14, |
| 58 | + sway: 22, |
| 59 | + rest: 55, |
| 60 | + color: '#b91c1c', |
| 61 | + }, |
| 62 | + { |
| 63 | + shape: 'oval', |
| 64 | + left: 10, |
| 65 | + size: 26, |
| 66 | + duration: 15, |
| 67 | + delay: -6, |
| 68 | + sway: 16, |
| 69 | + rest: 76, |
| 70 | + color: '#ca8a04', |
| 71 | + }, |
| 72 | + { |
| 73 | + shape: 'maple', |
| 74 | + left: 74, |
| 75 | + size: 26, |
| 76 | + duration: 16, |
| 77 | + delay: -11, |
| 78 | + sway: 12, |
| 79 | + rest: 88, |
| 80 | + color: '#ea580c', |
| 81 | + desktopOnly: true, |
| 82 | + }, |
| 83 | + { |
| 84 | + shape: 'oval', |
| 85 | + left: 34, |
| 86 | + size: 20, |
| 87 | + duration: 21, |
| 88 | + delay: -17, |
| 89 | + sway: 20, |
| 90 | + rest: 44, |
| 91 | + color: '#9a3412', |
| 92 | + desktopOnly: true, |
| 93 | + }, |
| 94 | + { |
| 95 | + shape: 'maple', |
| 96 | + left: 55, |
| 97 | + size: 29, |
| 98 | + duration: 18, |
| 99 | + delay: -4, |
| 100 | + sway: 16, |
| 101 | + rest: 66, |
| 102 | + color: '#d97706', |
| 103 | + desktopOnly: true, |
| 104 | + }, |
| 105 | + { |
| 106 | + shape: 'maple', |
| 107 | + left: 22, |
| 108 | + size: 28, |
| 109 | + duration: 20, |
| 110 | + delay: -12, |
| 111 | + sway: 18, |
| 112 | + rest: 6, |
| 113 | + color: '#c2410c', |
| 114 | + desktopOnly: true, |
| 115 | + }, |
| 116 | + { |
| 117 | + shape: 'oval', |
| 118 | + left: 82, |
| 119 | + size: 22, |
| 120 | + duration: 13, |
| 121 | + delay: -8, |
| 122 | + sway: 10, |
| 123 | + rest: 22, |
| 124 | + color: '#b45309', |
| 125 | + desktopOnly: true, |
| 126 | + }, |
| 127 | +]; |
| 128 | + |
| 129 | +const MAPLE_PATH = |
| 130 | + 'M12 1l1.5 4.5 2.5-1-.5 4.5 4-2.5-.5 3 4 .5-3 3 1 1.5-5 1 .5 2.5-4-1.5V23h-1v-6.5l-4 1.5.5-2.5-5-1 1-1.5-3-3 4-.5-.5-3 4 2.5L8 4.5l2.5 1z'; |
| 131 | +const OVAL_PATH = |
| 132 | + 'M12 2C7 6 4.5 10 5 14.5c.5 4 3.5 6.5 7 7.5 3.5-1 6.5-3.5 7-7.5C19.5 10 17 6 12 2z'; |
| 133 | + |
| 134 | +function LeafGlyph({ shape, color }: { shape: LeafShape; color: string }) { |
| 135 | + return ( |
| 136 | + <svg viewBox="0 0 24 24" width="100%" height="100%" focusable="false"> |
| 137 | + <path d={shape === 'maple' ? MAPLE_PATH : OVAL_PATH} fill={color} /> |
| 138 | + {shape === 'oval' && ( |
| 139 | + <path d="M12 4.5V23" stroke="rgba(0,0,0,0.25)" strokeWidth="0.9" fill="none" /> |
| 140 | + )} |
| 141 | + </svg> |
| 142 | + ); |
| 143 | +} |
| 144 | + |
| 145 | +export function AutumnLeaves() { |
| 146 | + return ( |
| 147 | + <div aria-hidden="true" data-testid="autumn-leaves" className="autumn-leaves"> |
| 148 | + {LEAVES.map((leaf, i) => ( |
| 149 | + <span |
| 150 | + key={i} |
| 151 | + data-testid="autumn-leaf" |
| 152 | + className={leaf.desktopOnly ? 'autumn-leaf hidden sm:block' : 'autumn-leaf'} |
| 153 | + style={ |
| 154 | + { |
| 155 | + '--leaf-left': `${leaf.left}%`, |
| 156 | + '--leaf-size': `${leaf.size}px`, |
| 157 | + '--leaf-duration': `${leaf.duration}s`, |
| 158 | + '--leaf-delay': `${leaf.delay}s`, |
| 159 | + '--leaf-sway': `${leaf.sway}px`, |
| 160 | + '--leaf-rest': `${leaf.rest}%`, |
| 161 | + } as CSSProperties |
| 162 | + } |
| 163 | + > |
| 164 | + <span className="autumn-leaf-sway"> |
| 165 | + <LeafGlyph shape={leaf.shape} color={leaf.color} /> |
| 166 | + </span> |
| 167 | + </span> |
| 168 | + ))} |
| 169 | + </div> |
| 170 | + ); |
| 171 | +} |
0 commit comments