File size: 953 Bytes
d15f07c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { Fragment, type CSSProperties } from 'react'
import { titleWords } from '../../utils/storyQuestion'

/**
 * A title whose words rise out of a mask, one after another, when its screen arrives (#915). The words stay plain inline text
 * for a screen reader. The motion itself is in stance.css: scrubbed by the scroll on a wide screen (`--title`), played on a
 * clock when the screen arrives on a phone (`data-state`), and absent under reduced motion.
 */
export default function KineticText({ text }: { text: string }) {
  const words = titleWords(text)
  const last = words.length - 1
  return (
    <>
      {words.map((w, i) => (
        <Fragment key={i}>
          <span className="stance-kw">
            <span className="stance-kw-i" style={{ '--wi': i, '--wf': last > 0 ? i / last : 0 } as CSSProperties}>
              {w}
            </span>
          </span>
          {i < last ? ' ' : ''}
        </Fragment>
      ))}
    </>
  )
}