diff --git a/src/components/observation/FindingsTreePicker.tsx b/src/components/observation/FindingsTreePicker.tsx index b66c951f..afe483be 100644 --- a/src/components/observation/FindingsTreePicker.tsx +++ b/src/components/observation/FindingsTreePicker.tsx @@ -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([]) + 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(() => { if (path.length === 0) return tree.categories @@ -136,7 +156,7 @@ export default function FindingsTreePicker({ )} -
    + {currentNodes.length === 0 ? (
  • {t('findings.no_options')} @@ -227,7 +255,7 @@ export default function FindingsTreePicker({
+ ) }