Files
react-website/src/demo/threats/ThreatDemosSlider.tsx
T
MehboobKandClaude Sonnet 5 51c05ccc3a
CI / build (push) Has been cancelled
Don't autoplay the embedded threat-demo voiceover on page load
ThreatDemosSlider always passed autoPlay to ThreatCinematic, so the
Mobile SDK page's embedded demo — including its speech-synthesis
narration — started 450ms after the page loaded rather than waiting
for a visitor to tap the phone. Autoplay is now standalone-only
(/threat-demos); the embedded instance stays idle until tapped.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-13 14:03:41 +05:00

97 lines
5.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { AnimatePresence, motion } from 'framer-motion'
import { THREAT_SCENARIOS } from './scenarios'
import { ThreatCinematic } from './ThreatDemo'
import '../demo.css'
const ACCENT = '#3BB586'
// Isolated so useNavigate() is only ever invoked when this is actually mounted
// under a <Router> — the embedded (no-router) instance never renders it.
function BackToSiteButton() {
const navigate = useNavigate()
return (
<button onClick={() => navigate('/')} style={{ display: 'inline-flex', alignItems: 'center', gap: 7, fontFamily: 'inherit', fontSize: 13, fontWeight: 500, color: 'rgba(255,255,255,.8)', background: 'rgba(255,255,255,.05)', border: '1px solid rgba(255,255,255,.12)', borderRadius: 100, padding: '7px 14px', cursor: 'pointer', flexShrink: 0 }}>← Back to site</button>
)
}
export default function ThreatDemosSlider({ embedded = false }: { embedded?: boolean } = {}) {
const [idx, setIdx] = useState(0)
const [dir, setDir] = useState(1)
const scenario = THREAT_SCENARIOS[idx]
const n = THREAT_SCENARIOS.length
const go = (next: number) => {
setDir(next > idx ? 1 : -1)
setIdx((next + n) % n)
}
return (
<div className="bd-demo-root" style={{ position: 'relative', height: embedded ? '100%' : '100vh', overflow: 'hidden', background: '#010e14', fontFamily: "'Ubuntu', -apple-system, system-ui, sans-serif", display: 'flex', flexDirection: 'column' }}>
{/* ── Top bar (reserved) — standalone /threat-demos only ── */}
{!embedded && (
<div style={{ flexShrink: 0, height: 60, display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '0 20px', borderBottom: '1px solid rgba(255,255,255,.06)', background: 'rgba(1,14,20,.7)', backdropFilter: 'blur(10px)', zIndex: 80 }}>
<BackToSiteButton />
<div style={{ textAlign: 'center', color: '#e8f4f3', minWidth: 0 }}>
<div style={{ fontSize: 14, fontWeight: 600, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{scenario.title}</div>
<div style={{ fontSize: 10.5, color: '#8aa5ab' }}>{idx + 1} / {n} · {scenario.product}</div>
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, background: 'rgba(0,0,0,.4)', border: '1px solid rgba(255,255,255,.1)', borderRadius: 100, padding: '5px 11px', flexShrink: 0 }}>
<motion.span animate={{ opacity: [1, 0, 1] }} transition={{ duration: 1.2, repeat: Infinity }} style={{ width: 7, height: 7, borderRadius: '50%', background: '#ef4444', display: 'inline-block' }} />
<span style={{ fontSize: 10, fontWeight: 700, color: '#fff', letterSpacing: '.5px' }}>REC</span>
</div>
</div>
)}
{/* ── Stage (flex, holds the sliding players) ── */}
<div style={{ position: 'relative', flex: 1, minHeight: 0, overflow: 'hidden' }}>
<AnimatePresence initial={false} custom={dir} mode="popLayout">
<motion.div
key={scenario.id}
custom={dir}
initial={{ x: dir > 0 ? '100%' : '-100%' }}
animate={{ x: 0 }}
exit={{ x: dir > 0 ? '-100%' : '100%' }}
transition={{ type: 'spring', stiffness: 260, damping: 30 }}
style={{ position: 'absolute', inset: 0 }}>
<ThreatCinematic scenario={scenario} autoPlay={!embedded} chrome={false} />
</motion.div>
</AnimatePresence>
{/* Prev / Next arrows (inside the stage, vertically centred) */}
<button onClick={() => go(idx - 1)} aria-label="Previous" style={navBtn('left')}>‹</button>
<button onClick={() => go(idx + 1)} aria-label="Next" style={navBtn('right')}>›</button>
</div>
{/* ── Bottom: scenario tabs (reserved) — moves above the stage on mobile via .bd-demo-tabs media query ── */}
<div className="bd-demo-tabs" style={{ flexShrink: 0, minHeight: 56, display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, flexWrap: 'wrap', padding: '10px 16px', borderTop: '1px solid rgba(255,255,255,.06)', background: 'rgba(1,14,20,.7)', backdropFilter: 'blur(10px)', zIndex: 80 }}>
{THREAT_SCENARIOS.map((s, i) => (
<button key={s.id} onClick={() => go(i)}
style={{
fontFamily: 'inherit', fontSize: 11, fontWeight: 500, cursor: 'pointer',
padding: '6px 12px', borderRadius: 100,
border: `1px solid ${i === idx ? ACCENT : 'rgba(255,255,255,.12)'}`,
background: i === idx ? 'rgba(59,181,134,0.18)' : 'rgba(255,255,255,.03)',
color: i === idx ? ACCENT : 'rgba(255,255,255,.6)', whiteSpace: 'nowrap',
}}>
{s.title}
</button>
))}
</div>
</div>
)
}
function navBtn(side: 'left' | 'right'): React.CSSProperties {
return {
position: 'absolute', top: '50%', transform: 'translateY(-50%)', [side]: 16,
zIndex: 70, width: 44, height: 44, borderRadius: '50%',
background: 'rgba(0,0,0,.45)', backdropFilter: 'blur(10px)',
border: '1px solid rgba(255,255,255,.14)', color: '#e8f4f3',
fontSize: 22, lineHeight: 1, cursor: 'pointer', fontFamily: 'inherit',
display: 'flex', alignItems: 'center', justifyContent: 'center',
} as React.CSSProperties
}