feat(editor): directional slide transition between findings-tree levels

Opening a finding category (e.g. "Dysfonction ostéopathique") and
backing out felt abrupt — list content swapped instantly with no
visual continuity. Now the list animates a short slide+fade between
levels:
- Drill down → new list enters from the right (+16px → 0).
- Back / breadcrumb up → new list enters from the left (-16px → 0).

Implementation:
- Wrap the list in `motion.ul` keyed by the path string so React
  remounts when the level changes; motion's `initial`/`animate`
  variants then play on every remount.
- A direction state (1 | -1) feeds the `enter` variant via `custom`
  so forward vs. back have opposite slide directions.
- All path mutations go through `goInto` / `goBack` / `goToDepth`
  helpers that set direction before calling `setPath`.
- 180ms ease-out — perceptible but does not block interaction.

AnimatePresence was deliberately omitted: it defers DOM swap, which
broke the existing synchronous `getByLabelText` assertions in
components.FindingsTreePicker.test.tsx. The key-based remount keeps
the new content reachable immediately while still providing a
direction-aware entrance.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude Opus 4.7 committed 2026-05-21 07:22:55 +02:00
1 parent ef0ef62f2d
commit adbab1bc87
1 file changed
+33 -5
@@ -1,4 +1,5 @@
import { useMemo, useState } from 'react'
import { motion } from 'motion/react'
import type {
FindingNode,
ZoneFindings,
@@ -8,6 +9,11 @@ import Button from '@/components/ui/Button'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
const levelVariants = {
enter: (dir: 1 | -1) => ({ opacity: 0, x: dir * 16 }),
center: { opacity: 1, x: 0 },
}
export interface FindingsTreePickerProps {
zoneId: string
tree: ZoneFindings
@@ -63,6 +69,20 @@ export default function FindingsTreePicker({
locale === 'en' ? node.description_en : node.description_fr
const [path, setPath] = useState<string[]>([])
const [direction, setDirection] = useState<1 | -1>(1)
function goInto(nodePath: string[]) {
setDirection(1)
setPath(nodePath)
}
function goBack() {
setDirection(-1)
setPath(path.slice(0, -1))
}
function goToDepth(depth: number) {
setDirection(depth >= path.length ? 1 : -1)
setPath(path.slice(0, depth))
}
const currentNodes = useMemo<FindingNode[]>(() => {
if (path.length === 0) return tree.categories
@@ -136,7 +156,7 @@ export default function FindingsTreePicker({
<span key={`${c.label}-${i}`} className="flex items-center gap-1">
<button
type="button"
onClick={() => setPath(path.slice(0, c.depth))}
onClick={() => goToDepth(c.depth)}
disabled={isLast}
className={
isLast
@@ -162,14 +182,22 @@ export default function FindingsTreePicker({
<Button
size="sm"
variant="ghost"
onClick={() => setPath(path.slice(0, -1))}
onClick={goBack}
aria-label={t('findings.back_to_parent')}
>
{t('findings.back')}
</Button>
)}
<ul className="space-y-1.5 max-h-64 overflow-auto pr-1">
<motion.ul
key={path.join('/') || '__root__'}
custom={direction}
variants={levelVariants}
initial="enter"
animate="center"
transition={{ duration: 0.18, ease: 'easeOut' }}
className="space-y-1.5 max-h-64 overflow-auto pr-1"
>
{currentNodes.length === 0 ? (
<li className="text-sm text-[var(--color-ink-muted)]">
{t('findings.no_options')}
@@ -227,7 +255,7 @@ export default function FindingsTreePicker({
<li key={node.id}>
<button
type="button"
onClick={() => setPath(nodePath)}
onClick={() => goInto(nodePath)}
className="flex items-center justify-between w-full text-left text-sm px-2 py-1.5 rounded hover:bg-[var(--color-surface-strong)] text-[var(--color-ink)]"
aria-label={`${t('findings.open')} ${nodeLabel}`}
>
@@ -250,7 +278,7 @@ export default function FindingsTreePicker({
)
})
)}
</ul>
</motion.ul>
</div>
)
}