chore(workspace): move the app to apps/app under a pnpm workspace (step 2)

144 files moved with git mv (pure renames). Root package.json delegates
dev/typecheck/test:run/lint/build to the packages; Node 24 LTS and
pnpm 10.13.1 pinned (.nvmrc, .node-version, engines, packageManager,
root devDependency, engine-strict). Dockerfile builds @faunosteo/app on
node:24-alpine and copies apps/app/dist; nginx and runtime config
unchanged. CI workflow for Gitea Actions. packages/ reserved (README only).
Docs synced: WORKSPACE.md, CLAUDE.md, README, DEPLOY, CHANGELOG, plan.
271/271 tests, typecheck, lint, build green from the root.
This commit is contained in:
bchanot committed 2026-10-08 21:51:13 +02:00
1 parent c8d48ab4cc
commit 8673475293
164 files changed
+348 -128

No files matched your search

@@ -0,0 +1,34 @@
import { Link } from 'react-router-dom'
import Brand from './Brand'
import LanguageSwitcher from './LanguageSwitcher'
import { useConfig } from '@/app/providers/ConfigProvider'
import { useT } from '@/i18n/useT'
interface AppHeaderProps {
children?: React.ReactNode
}
export default function AppHeader({ children }: AppHeaderProps) {
const cfg = useConfig()
const t = useT()
return (
<header className="px-3 sm:px-6 py-2 sm:py-3 border-b border-[var(--color-border)] flex items-center justify-between bg-[var(--color-surface)]">
<div className="flex items-center gap-3">
<Link
to="/"
aria-label={t('common.home')}
className="rounded-md px-1 py-0.5 hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
>
<Brand size="lg" />
</Link>
<span className="text-sm text-[var(--color-ink-muted)] hidden sm:inline">
{cfg.tagline}
</span>
</div>
<div className="flex items-center gap-2 sm:gap-4">
{children}
<LanguageSwitcher />
</div>
</header>
)
}
+14
View File
@@ -0,0 +1,14 @@
import { useConfig } from '@/app/providers/ConfigProvider'
const HEIGHT = { sm: 'h-7', md: 'h-9', lg: 'h-11' } as const
export default function Brand({ size = 'md' }: { size?: 'sm' | 'md' | 'lg' }) {
const { brandName } = useConfig()
return (
<img
src="/logo-horizontal.svg"
alt={brandName}
className={`${HEIGHT[size]} w-auto`}
/>
)
}
+57
View File
@@ -0,0 +1,57 @@
import { Link } from 'react-router-dom'
import { useConfig } from '@/app/providers/ConfigProvider'
import { useT } from '@/i18n/useT'
export default function Footer() {
const cfg = useConfig()
const t = useT()
const year = new Date().getFullYear()
return (
<footer className="mt-8 sm:mt-12 border-t border-neutral-200 bg-neutral-50 py-4 sm:py-6 text-center text-xs sm:text-sm text-neutral-600">
<p className="mb-3">
© {year} {cfg.footerName}. {t('footer.all_rights_reserved')}{' '}
<span className="text-neutral-300">·</span>{' '}
<Link
to="/editors"
className="text-[var(--color-accent)] hover:text-[var(--color-accent-strong)] transition-colors"
>
{t('footer.editors')}
</Link>
</p>
<div className="flex flex-wrap items-center justify-center gap-2 sm:gap-4">
<span className="flex items-center gap-2">
<span>{t('footer.powered_by')}</span>
<a
href="https://zenquality.fr"
target="_blank"
rel="noopener noreferrer"
aria-label="ZenQuality"
className="inline-flex items-center"
>
<img
src="https://zenquality.fr/assets/logo-horizontal-1024.png"
alt="ZenQuality"
className="h-6 w-auto"
loading="lazy"
/>
</a>
</span>
<span className="flex items-center gap-1.5">
<span>{t('footer.in_partnership')}</span>
<a
href="https://www.instagram.com/paws.iin.harmony"
target="_blank"
rel="noopener noreferrer"
className="text-[var(--color-accent)] hover:text-[var(--color-accent-strong)] transition-colors font-medium"
>
<img
src="/Paws_in_harmony.svg"
alt="Paws in Harmony"
className="h-6 w-auto inline-block align-middle"
/>
</a>
</span>
</div>
</footer>
)
}
@@ -0,0 +1,42 @@
import { useLocaleStore } from '@/state/localeStore'
import { useT } from '@/i18n/useT'
import type { Locale } from '@/i18n/types'
const ITEMS: { value: Locale; labelKey: string; ariaKey: string }[] = [
{ value: 'fr', labelKey: 'lang.fr', ariaKey: 'lang.switch_to_fr' },
{ value: 'en', labelKey: 'lang.en', ariaKey: 'lang.switch_to_en' },
]
export default function LanguageSwitcher() {
const locale = useLocaleStore((s) => s.locale)
const setLocale = useLocaleStore((s) => s.setLocale)
const t = useT()
return (
<div
role="group"
aria-label={t('lang.group_label')}
className="inline-flex rounded-full border border-[var(--color-border)] overflow-hidden text-xs font-medium"
>
{ITEMS.map((item) => {
const active = locale === item.value
return (
<button
key={item.value}
type="button"
aria-label={t(item.ariaKey)}
aria-pressed={active}
onClick={() => setLocale(item.value)}
className={[
'px-2.5 py-1 transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]',
active
? 'bg-[var(--color-accent)] text-white'
: 'text-[var(--color-ink)] hover:bg-[var(--color-surface-strong)]',
].join(' ')}
>
{t(item.labelKey)}
</button>
)
})}
</div>
)
}
@@ -0,0 +1,125 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { loadSvg } from '@/anatomy/svgLoader'
import {
getBoneIdFromEvent,
getAnnotatedElement,
} from '@/anatomy/svgConvention'
import type { BoneState } from '@/anatomy/types'
import { useLocaleStore } from '@/state/localeStore'
import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
export interface AnatomyCanvasProps {
src: string
boneStates: Map<string, BoneState>
onZoneClick: (boneId: string) => void
className?: string
}
export default function AnatomyCanvas({
src,
boneStates,
onZoneClick,
className = '',
}: AnatomyCanvasProps) {
const wrapperRef = useRef<HTMLDivElement | null>(null)
const svgRef = useRef<HTMLDivElement | null>(null)
const tooltipRef = useRef<HTMLDivElement | null>(null)
const [loadedSrc, setLoadedSrc] = useState<string | null>(null)
const locale = useLocaleStore((s) => s.locale)
useEffect(() => {
let cancelled = false
const c = svgRef.current
if (!c) return
c.replaceChildren()
setLoadedSrc(null)
loadSvg(src).then((root) => {
if (cancelled || !c) return
c.appendChild(root)
setLoadedSrc(src)
})
return () => { cancelled = true }
}, [src])
useEffect(() => {
const c = svgRef.current
if (!c) return
const onClick = (e: Event) => {
const id = getBoneIdFromEvent(e)
if (id) onZoneClick(id)
}
c.addEventListener('click', onClick)
return () => c.removeEventListener('click', onClick)
}, [onZoneClick])
useEffect(() => {
const c = svgRef.current
if (!c || loadedSrc !== src) return
const all = c.querySelectorAll<Element>('[data-anno-id]')
all.forEach((el) => {
const id = el.getAttribute('data-anno-id') as string
const state = boneStates.get(id)
if (state && state !== 'default') el.setAttribute('data-state', state)
else el.removeAttribute('data-state')
})
}, [boneStates, loadedSrc, src])
const showTooltip = useCallback(
(el: Element, x: number, y: number) => {
const tip = tooltipRef.current
if (!tip) return
const fr = el.getAttribute('data-anno-name-fr') ?? ''
const en = el.getAttribute('data-anno-name-en') ?? ''
const label = pickLocaleLabel(fr, en, locale)
if (!label) { tip.style.opacity = '0'; return }
tip.textContent = label
tip.style.opacity = '1'
tip.style.left = `${x + 12}px`
tip.style.top = `${y - 8}px`
},
[locale],
)
const hideTooltip = useCallback(() => {
const tip = tooltipRef.current
if (tip) tip.style.opacity = '0'
}, [])
useEffect(() => {
const c = svgRef.current
if (!c || loadedSrc !== src) return
const onMove = (e: MouseEvent) => {
const el = getAnnotatedElement(e)
if (el && !el.hasAttribute('data-anno-opens-detail')) {
const w = wrapperRef.current
if (!w) return
const rect = w.getBoundingClientRect()
showTooltip(el, e.clientX - rect.left, e.clientY - rect.top)
} else {
hideTooltip()
}
}
const onLeave = () => hideTooltip()
c.addEventListener('mousemove', onMove)
c.addEventListener('mouseleave', onLeave)
return () => {
c.removeEventListener('mousemove', onMove)
c.removeEventListener('mouseleave', onLeave)
}
}, [loadedSrc, src, showTooltip, hideTooltip])
return (
<div
data-testid="anatomy-canvas"
ref={wrapperRef}
className={`svg-canvas relative w-full h-full ${className}`}
>
<div ref={svgRef} className="w-full h-full [&>svg]:max-w-full [&>svg]:max-h-full [&>svg]:mx-auto" />
<div
ref={tooltipRef}
className="zone-tooltip"
style={{ opacity: 0 }}
/>
</div>
)
}
@@ -0,0 +1,40 @@
import Dialog from '@/components/ui/Dialog'
import AnatomyCanvas from './AnatomyCanvas'
import type { BoneState } from '@/anatomy/types'
import { useT } from '@/i18n/useT'
export interface DetailModalProps {
open: boolean
onClose: () => void
detailSrc: string
detailId: string
title: string
boneStates: Map<string, BoneState>
onZoneClick: (boneId: string, detailId: string) => void
}
export default function DetailModal({
open,
onClose,
detailSrc,
detailId,
title,
boneStates,
onZoneClick,
}: DetailModalProps) {
const t = useT()
return (
<Dialog open={open} onClose={onClose} title={title} size="xl">
<div className="aspect-[4/3] w-full">
<AnatomyCanvas
src={detailSrc}
boneStates={boneStates}
onZoneClick={(id) => onZoneClick(id, detailId)}
/>
</div>
<p className="mt-4 text-sm text-[var(--color-ink-muted)]">
{t('detail.click_to_add')}
</p>
</Dialog>
)
}
@@ -0,0 +1,292 @@
import { useMemo, useState } from 'react'
import { motion } from 'motion/react'
import type {
FindingNode,
ZoneFindings,
} from '@/domain/schema/findings'
import type { Finding, LateralSide } from '@/domain/schema/observation'
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 * 32 }),
center: { opacity: 1, x: 0 },
}
export interface FindingsTreePickerProps {
zoneId: string
tree: ZoneFindings
side?: LateralSide
selected: Finding[]
onChange: (next: Finding[]) => void
}
function isLeaf(node: FindingNode): boolean {
return !node.children || node.children.length === 0
}
function samePath(a: string[], b: string[]): boolean {
if (a.length !== b.length) return false
for (let i = 0; i < a.length; i += 1) {
if (a[i] !== b[i]) return false
}
return true
}
function pathStartsWith(full: string[], prefix: string[]): boolean {
if (full.length < prefix.length) return false
for (let i = 0; i < prefix.length; i += 1) {
if (full[i] !== prefix[i]) return false
}
return true
}
function findNode(
categories: FindingNode[],
path: string[],
): FindingNode | undefined {
let nodes: FindingNode[] = categories
let node: FindingNode | undefined
for (const segment of path) {
node = nodes.find((n) => n.id === segment)
if (!node) return undefined
nodes = node.children ?? []
}
return node
}
export default function FindingsTreePicker({
zoneId,
tree,
side,
selected,
onChange,
}: FindingsTreePickerProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const nameOf = (node: { name_fr: string; name_en: string }) =>
locale === 'en' ? node.name_en : node.name_fr
const descOf = (node: { description_fr?: string; description_en?: string }) =>
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
const node = findNode(tree.categories, path)
return node?.children ?? []
}, [tree, path])
const focusedNode = useMemo(
() => (path.length === 0 ? undefined : findNode(tree.categories, path)),
[tree, path],
)
const breadcrumb = useMemo<{ label: string; depth: number }[]>(() => {
const pick = (z: { name_fr: string; name_en: string }) =>
locale === 'en' ? z.name_en : z.name_fr
const crumbs: { label: string; depth: number }[] = [
{ label: pick(tree), depth: 0 },
]
let nodes: FindingNode[] = tree.categories
path.forEach((seg, i) => {
const n = nodes.find((x) => x.id === seg)
if (n) {
crumbs.push({ label: pick(n), depth: i + 1 })
nodes = n.children ?? []
}
})
return crumbs
}, [tree, path, locale])
function matchesSide(f: Finding): boolean {
return f.zoneId === zoneId && f.side === side
}
function isLeafSelected(leafPath: string[]): boolean {
return selected.some(
(f) => matchesSide(f) && samePath(f.path, leafPath),
)
}
function countSelectedUnder(nodePath: string[]): number {
let n = 0
for (const f of selected) {
if (!matchesSide(f)) continue
if (!pathStartsWith(f.path, nodePath)) continue
n += 1
}
return n
}
function toggleLeaf(leafPath: string[], leaf: FindingNode) {
if (isLeafSelected(leafPath)) {
onChange(
selected.filter(
(f) => !(matchesSide(f) && samePath(f.path, leafPath)),
),
)
return
}
const next: Finding = {
zoneId,
path: leafPath,
labelFrSnapshot: leaf.name_fr,
labelEnSnapshot: leaf.name_en,
}
if (leaf.requires_vet_referral) next.requiresVetReferral = true
if (side) next.side = side
onChange([...selected, next])
}
return (
<div className="space-y-2">
<div className="flex flex-wrap items-center gap-1 text-xs text-[var(--color-ink-muted)]">
{breadcrumb.map((c, i) => {
const isLast = i === breadcrumb.length - 1
return (
<span key={`${c.label}-${i}`} className="flex items-center gap-1">
<button
type="button"
onClick={() => goToDepth(c.depth)}
disabled={isLast}
className={
isLast
? 'text-[var(--color-ink)] font-medium'
: 'underline text-[var(--color-accent-strong)]'
}
>
{c.label}
</button>
{!isLast && <span aria-hidden="true">›</span>}
</span>
)
})}
</div>
{focusedNode && descOf(focusedNode) && (
<p className="text-xs italic text-[var(--color-ink-muted)]">
{descOf(focusedNode)}
</p>
)}
{path.length > 0 && (
<Button
size="sm"
variant="ghost"
onClick={goBack}
aria-label={t('findings.back_to_parent')}
>
{t('findings.back')}
</Button>
)}
<motion.ul
key={path.join('/') || '__root__'}
custom={direction}
variants={levelVariants}
initial="enter"
animate="center"
transition={{ duration: 0.22, ease: 'easeOut' }}
style={{ willChange: 'transform, opacity' }}
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')}
</li>
) : (
currentNodes.map((node) => {
const nodePath = [...path, node.id]
if (isLeaf(node)) {
const checked = isLeafSelected(nodePath)
const nodeLabel = nameOf(node)
const nodeDesc = descOf(node)
return (
<li key={node.id}>
<label className="flex items-start gap-2 cursor-pointer">
<input
type="checkbox"
checked={checked}
onChange={() => toggleLeaf(nodePath, node)}
className="mt-1 accent-[var(--color-accent)]"
aria-label={nodeLabel}
/>
<div className="flex-1">
<div className="flex items-center gap-2">
<span className="text-sm font-medium text-[var(--color-ink)]">
{nodeLabel}
</span>
{node.requires_vet_referral && (
<span
title={t('findings.vet_referral')}
aria-label={t('findings.vet_referral')}
className="text-[var(--color-danger)]"
>
⚠
</span>
)}
</div>
{nodeDesc && (
<div className="text-xs text-[var(--color-ink-muted)]">
{nodeDesc}
</div>
)}
</div>
</label>
</li>
)
}
const selectedCount = countSelectedUnder(nodePath)
const nodeLabel = nameOf(node)
const selectedAria = `${selectedCount} ${
selectedCount > 1
? t('findings.selected_plural')
: t('findings.selected_singular')
}`
return (
<li key={node.id}>
<button
type="button"
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}`}
>
<span className="flex items-center gap-2">
<span>{nodeLabel}</span>
{selectedCount > 0 && (
<span
aria-label={selectedAria}
className="inline-flex items-center justify-center min-w-[20px] h-[20px] px-1.5 rounded-full text-[11px] font-semibold bg-[var(--color-accent)] text-white"
>
{selectedCount}
</span>
)}
</span>
<span aria-hidden="true" className="text-[var(--color-ink-muted)]">
›
</span>
</button>
</li>
)
})
)}
</motion.ul>
</div>
)
}
@@ -0,0 +1,70 @@
import { useState } from 'react'
import Input from '@/components/ui/Input'
import Button from '@/components/ui/Button'
import Badge from '@/components/ui/Badge'
import { useT } from '@/i18n/useT'
export interface FreeTextFindingInputProps {
items: string[]
onChange: (next: string[]) => void
}
export default function FreeTextFindingInput({
items,
onChange,
}: FreeTextFindingInputProps) {
const [v, setV] = useState('')
const t = useT()
function add() {
const trimmed = v.trim()
if (!trimmed) return
onChange([...items, trimmed])
setV('')
}
function remove(i: number) {
onChange(items.filter((_, k) => k !== i))
}
return (
<div className="space-y-2">
<div className="flex gap-2">
<Input
value={v}
onChange={(e) => setV(e.target.value)}
placeholder={t('observation.free_placeholder')}
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault()
add()
}
}}
aria-label={t('observation.free_aria')}
/>
<Button onClick={add} variant="secondary">
{t('common.add')}
</Button>
</div>
{items.length > 0 && (
<ul className="flex flex-wrap gap-2">
{items.map((it, i) => (
<li key={`${it}-${i}`}>
<Badge tone="accent" className="gap-1">
{it}
<button
type="button"
aria-label={`${t('observation.remove_zone')} ${it}`}
onClick={() => remove(i)}
className="ml-1 text-[var(--color-accent-strong)] hover:text-[var(--color-danger)]"
>
✕
</button>
</Badge>
</li>
))}
</ul>
)}
</div>
)
}
@@ -0,0 +1,62 @@
import Dialog from '@/components/ui/Dialog'
import Button from '@/components/ui/Button'
import type { LateralSide } from '@/domain/schema/observation'
import { useT } from '@/i18n/useT'
export interface LateralityPickerProps {
open: boolean
onClose: () => void
onSelect: (sides: LateralSide[]) => void
title: string
existingSides: LateralSide[]
}
export default function LateralityPicker({
open,
onClose,
onSelect,
title,
existingSides,
}: LateralityPickerProps) {
const t = useT()
const hasLeft = existingSides.includes('left')
const hasRight = existingSides.includes('right')
return (
<Dialog open={open} onClose={onClose} title={title} size="sm">
<div className="space-y-4">
<p className="text-sm text-[var(--color-ink-muted)]">
{t('lateral.which_side')}
</p>
<div className="flex gap-3 justify-center">
<Button
variant={hasLeft ? 'ghost' : 'primary'}
disabled={hasLeft}
onClick={() => onSelect(['left'])}
>
{t('lateral.left')}
</Button>
<Button
variant={hasRight ? 'ghost' : 'primary'}
disabled={hasRight}
onClick={() => onSelect(['right'])}
>
{t('lateral.right')}
</Button>
<Button
variant={hasLeft && hasRight ? 'ghost' : 'primary'}
disabled={hasLeft && hasRight}
onClick={() => {
const sides: LateralSide[] = []
if (!hasLeft) sides.push('left')
if (!hasRight) sides.push('right')
onSelect(sides)
}}
>
{t('lateral.both')}
</Button>
</div>
</div>
</Dialog>
)
}
@@ -0,0 +1,418 @@
import { useMemo, useState } from 'react'
import type {
Observation,
ObservationZone,
Vertebra,
LateralSide,
} from '@/domain/schema/observation'
import type {
SpeciesFindings,
ZoneFindings,
} from '@/domain/schema/findings'
import type { Bone } from '@/anatomy/types'
import { matchZoneFindings } from '@/lib/zoneMatch'
import { AnimatePresence, motion } from 'motion/react'
import Card from '@/components/ui/Card'
import Badge from '@/components/ui/Badge'
import Button from '@/components/ui/Button'
import Label from '@/components/ui/Label'
import Textarea from '@/components/ui/Textarea'
import FindingsTreePicker from './FindingsTreePicker'
import FreeTextFindingInput from './FreeTextFindingInput'
import SeveritySelector from './SeveritySelector'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import { boneLabel } from '@/anatomy/labels'
import type { Locale } from '@/i18n/types'
export interface ObservationCardProps {
observation: Observation
index: number
expanded: boolean
onToggle: () => void
onDelete: () => void
onMoveUp: () => void
onMoveDown: () => void
canMoveUp: boolean
canMoveDown: boolean
// Editor body props (used only when expanded)
bones: Map<string, Bone>
findings: SpeciesFindings | null
onChange: (next: Observation) => void
onOpenVertebraPicker: (zoneIndex: number) => void
onRemoveZone: (zoneIndex: number) => void
}
function describeZone(
z: ObservationZone,
bones: Map<string, Bone>,
locale: Locale,
t: (key: string) => string,
): string {
const label = boneLabel(bones.get(z.boneId), locale, z.boneId)
if (z.vertebrae?.length) {
const vs = z.vertebrae
.map((v: Vertebra) => `${v.region}${v.index}`)
.join(', ')
return `${label} (${vs})`
}
if (z.side) {
const sideLabel = t(
z.side === 'left' ? 'lateral.left_short' : 'lateral.right_short',
)
return `${label} (${sideLabel})`
}
return label
}
export default function ObservationCard({
observation,
index,
expanded,
onToggle,
onDelete,
onMoveUp,
onMoveDown,
canMoveUp,
canMoveDown,
bones,
findings,
onChange,
onOpenVertebraPicker,
onRemoveZone,
}: ObservationCardProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const nameOf = (z: { name_fr: string; name_en: string }) =>
locale === 'en' ? z.name_en : z.name_fr
// Per-zone picker accordion — only one tree picker open at a time,
// matching the observation-card accordion semantics. Closed by default
// so the card stays compact when first expanded.
const [expandedZoneId, setExpandedZoneId] = useState<string | null>(null)
const zoneCount = observation.zones.length
const findingCount =
observation.findings.length + observation.freeTextFindings.length
const zoneCountLabel =
zoneCount > 1
? t('observation.zone_label_plural')
: t('observation.zone_label_singular')
const findingCountLabel =
findingCount > 1
? t('observation.finding_label_plural')
: t('observation.finding_label_singular')
function onHeaderKey(event: React.KeyboardEvent<HTMLDivElement>) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault()
onToggle()
}
}
function stop(fn: () => void) {
return (event: React.MouseEvent) => {
event.stopPropagation()
fn()
}
}
const zonesArray = useMemo(
() => (findings ? Object.values(findings.zones) : []),
[findings],
)
const zonesWithTree = useMemo(() => {
if (zonesArray.length === 0)
return [] as { tree: ZoneFindings; side?: LateralSide }[]
const seen = new Set<string>()
const out: { tree: ZoneFindings; side?: LateralSide }[] = []
for (const z of observation.zones) {
const bone = bones.get(z.boneId)
if (!bone) continue
const tree = matchZoneFindings(
{ fr: bone.fr, en: bone.en },
zonesArray,
)
if (!tree) continue
const key = z.side ? `${tree.id}:${z.side}` : tree.id
if (seen.has(key)) continue
seen.add(key)
out.push({ tree, side: z.side })
}
return out
}, [observation.zones, bones, zonesArray])
return (
<Card
className={[
'transition',
expanded
? 'ring-2 ring-[var(--color-accent)]'
: 'hover:bg-[var(--color-surface-strong)]',
].join(' ')}
>
<div
role="button"
tabIndex={0}
aria-expanded={expanded}
aria-label={`${expanded ? t('observation.collapse_aria') : t('observation.expand_aria')} ${index + 1}`}
onClick={onToggle}
onKeyDown={onHeaderKey}
className="flex items-start justify-between gap-3 p-4 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/40 rounded-2xl"
>
<div className="flex-1 min-h-[60px] text-left">
<div className="flex items-center gap-2 mb-2">
<Badge tone="neutral">{t('observation.badge_n')}{index + 1}</Badge>
{observation.severity && (
<Badge
tone={
observation.severity === 'sévère'
? 'danger'
: observation.severity === 'modérée'
? 'warn'
: 'neutral'
}
>
{t(`severity.${observation.severity}`)}
</Badge>
)}
</div>
<div className="text-sm text-[var(--color-ink-muted)]">
{zoneCount} {zoneCountLabel} · {findingCount} {findingCountLabel}
</div>
{!expanded && observation.comment && (
<p className="mt-2 text-sm line-clamp-2 text-[var(--color-ink)]">
{observation.comment}
</p>
)}
</div>
<div
className="flex items-start gap-1"
onClick={(event) => event.stopPropagation()}
>
<Button
size="sm"
variant="ghost"
disabled={!canMoveUp}
onClick={stop(onMoveUp)}
aria-label={t('common.move_up')}
>
↑
</Button>
<Button
size="sm"
variant="ghost"
disabled={!canMoveDown}
onClick={stop(onMoveDown)}
aria-label={t('common.move_down')}
>
↓
</Button>
<Button
size="sm"
variant="ghost"
onClick={stop(onDelete)}
aria-label={t('common.delete')}
>
🗑
</Button>
<Button
size="sm"
variant="ghost"
onClick={stop(onToggle)}
aria-label={expanded ? t('common.collapse') : t('common.expand')}
>
{expanded ? '▲' : '▼'}
</Button>
</div>
</div>
<AnimatePresence initial={false}>
{expanded && (
<motion.div
key="body"
initial={{ height: 0, opacity: 0 }}
animate={{ height: 'auto', opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{ duration: 0.18, ease: 'easeOut' }}
className="overflow-hidden"
>
<div className="px-4 pb-4 pt-2 border-t border-[var(--color-border)] space-y-6">
<section>
<Label>{t('observation.zones_label')}</Label>
{observation.zones.length === 0 ? (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('observation.zones_empty')}
</p>
) : (
<ul className="flex flex-wrap gap-2">
{observation.zones.map((z, i) => {
const b = bones.get(z.boneId)
const supportsVertebrae =
b?.special === 'vertebral-precision'
return (
<li key={`${z.boneId}-${i}`}>
<Badge tone="accent" className="gap-2">
{describeZone(z, bones, locale, t)}
{supportsVertebrae && (
<button
type="button"
onClick={() => onOpenVertebraPicker(i)}
className="underline text-xs text-[var(--color-accent-strong)]"
title={t('observation.vertebrae_button_title')}
>
{t('observation.vertebrae_button')}
</button>
)}
<button
type="button"
aria-label={`${t('observation.remove_zone')} ${boneLabel(b, locale, z.boneId)}`}
onClick={() => onRemoveZone(i)}
className="ml-1 text-[var(--color-accent-strong)]"
>
✕
</button>
</Badge>
</li>
)
})}
</ul>
)}
</section>
<section>
<Label>{t('observation.findings_catalog_label')}</Label>
{zonesWithTree.length === 0 ? (
<p className="text-sm text-[var(--color-ink-muted)]">
{observation.zones.length === 0
? t('observation.findings_pick_zone_first')
: t('observation.findings_no_catalog')}
</p>
) : (
<ul className="space-y-2">
{zonesWithTree.map(({ tree, side }) => {
const pickerKey = side
? `${tree.id}:${side}`
: tree.id
const expanded = expandedZoneId === pickerKey
const selectedCount = observation.findings.filter(
(f) =>
f.zoneId === tree.id && f.side === side,
).length
const selectedAria = `${selectedCount} ${
selectedCount > 1
? t('findings.selected_plural')
: t('findings.selected_singular')
}`
return (
<li
key={pickerKey}
className={[
'rounded-xl border bg-[var(--color-surface)] transition',
expanded
? 'border-[var(--color-accent)] ring-1 ring-[var(--color-accent)]'
: 'border-[var(--color-border)]',
].join(' ')}
>
<button
type="button"
onClick={() =>
setExpandedZoneId(expanded ? null : pickerKey)
}
aria-expanded={expanded}
aria-controls={`findings-zone-${pickerKey}`}
className="w-full flex items-center justify-between gap-2 px-3 py-2 text-left rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/40"
>
<span className="flex items-center gap-2">
<span className="text-sm font-medium text-[var(--color-ink)]">
{nameOf(tree)}
{side && ` (${t(side === 'left' ? 'lateral.left' : 'lateral.right')})`}
</span>
{selectedCount > 0 && (
<span
aria-label={selectedAria}
className="inline-flex items-center justify-center min-w-[20px] h-[20px] px-1.5 rounded-full text-[11px] font-semibold bg-[var(--color-accent)] text-white"
>
{selectedCount}
</span>
)}
</span>
<span
aria-hidden="true"
className="text-[var(--color-ink-muted)]"
>
{expanded ? '▲' : '▼'}
</span>
</button>
<AnimatePresence initial={false}>
{expanded && (
<motion.div
key="picker-body"
id={`findings-zone-${pickerKey}`}
initial={{ height: 0, opacity: 0 }}
animate={{ height: 'auto', opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{ duration: 0.18, ease: 'easeOut' }}
className="overflow-hidden"
>
<div className="px-3 pb-3 pt-1 border-t border-[var(--color-border)]">
<FindingsTreePicker
zoneId={tree.id}
tree={tree}
side={side}
selected={observation.findings}
onChange={(next) =>
onChange({ ...observation, findings: next })
}
/>
</div>
</motion.div>
)}
</AnimatePresence>
</li>
)
})}
</ul>
)}
</section>
<section>
<Label>{t('observation.findings_free_label')}</Label>
<FreeTextFindingInput
items={observation.freeTextFindings}
onChange={(items) =>
onChange({ ...observation, freeTextFindings: items })
}
/>
</section>
<section>
<Label>{t('observation.severity_label')}</Label>
<SeveritySelector
value={observation.severity}
onChange={(s) => onChange({ ...observation, severity: s })}
/>
</section>
<section>
<Label htmlFor={`obs-comment-${observation.id}`}>
{t('observation.comment_label')}
</Label>
<Textarea
id={`obs-comment-${observation.id}`}
value={observation.comment}
onChange={(e) =>
onChange({ ...observation, comment: e.target.value })
}
placeholder={t('observation.comment_placeholder')}
/>
</section>
</div>
</motion.div>
)}
</AnimatePresence>
</Card>
)
}
@@ -0,0 +1,81 @@
import type { Observation } from '@/domain/schema/observation'
import type { SpeciesFindings } from '@/domain/schema/findings'
import type { Bone } from '@/anatomy/types'
import ObservationCard from './ObservationCard'
import Button from '@/components/ui/Button'
import { useT } from '@/i18n/useT'
export interface ObservationListProps {
observations: Observation[]
activeIndex: number
onToggle: (i: number) => void
onAdd: () => void
onDelete: (i: number) => void
onMoveUp: (i: number) => void
onMoveDown: (i: number) => void
// Editor body props forwarded to each card
bones: Map<string, Bone>
findings: SpeciesFindings | null
onChange: (i: number, next: Observation) => void
onOpenVertebraPicker: (i: number, zoneIndex: number) => void
onRemoveZone: (i: number, zoneIndex: number) => void
}
export default function ObservationList({
observations,
activeIndex,
onToggle,
onAdd,
onDelete,
onMoveUp,
onMoveDown,
bones,
findings,
onChange,
onOpenVertebraPicker,
onRemoveZone,
}: ObservationListProps) {
const t = useT()
return (
<div className="space-y-3">
<div className="flex items-center justify-between">
<h2 className="font-serif text-lg sm:text-xl text-[var(--color-ink)]">
{t('observation.section_title')}
</h2>
<Button size="sm" onClick={onAdd}>
{t('observation.add')}
</Button>
</div>
{observations.length === 0 ? (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('observation.empty')}
</p>
) : (
<ul className="space-y-2">
{observations.map((obs, i) => (
<li key={obs.id}>
<ObservationCard
observation={obs}
index={i}
expanded={i === activeIndex}
onToggle={() => onToggle(i)}
onDelete={() => onDelete(i)}
onMoveUp={() => onMoveUp(i)}
onMoveDown={() => onMoveDown(i)}
canMoveUp={i > 0}
canMoveDown={i < observations.length - 1}
bones={bones}
findings={findings}
onChange={(next) => onChange(i, next)}
onOpenVertebraPicker={(zoneIndex) =>
onOpenVertebraPicker(i, zoneIndex)
}
onRemoveZone={(zoneIndex) => onRemoveZone(i, zoneIndex)}
/>
</li>
))}
</ul>
)}
</div>
)
}
@@ -0,0 +1,38 @@
import type { Severity } from '@/domain/schema/observation'
import { useT } from '@/i18n/useT'
export interface SeveritySelectorProps {
value: Severity | undefined
onChange: (s: Severity | undefined) => void
}
const SEVERITIES: Severity[] = ['légère', 'modérée', 'sévère']
const COLORS: Record<Severity, string> = {
'légère': 'border-[var(--severity-mild)] text-[var(--severity-mild)]',
'modérée': 'border-[var(--severity-moderate)] text-[var(--severity-moderate)]',
'sévère': 'border-[var(--severity-severe)] text-[var(--severity-severe)]',
}
export default function SeveritySelector({ value, onChange }: SeveritySelectorProps) {
const t = useT()
return (
<div role="radiogroup" aria-label={t('severity.aria')} className="flex gap-2">
{SEVERITIES.map((s) => (
<button
key={s}
role="radio"
aria-checked={value === s}
onClick={() => onChange(value === s ? undefined : s)}
className={[
'rounded-full border px-3 py-1.5 text-sm font-medium capitalize',
value === s
? `bg-white ${COLORS[s]}`
: 'border-[var(--color-border)] text-[var(--color-ink-muted)]',
].join(' ')}
>
{t(`severity.${s}`)}
</button>
))}
</div>
)
}
@@ -0,0 +1,115 @@
import { useState } from 'react'
import Dialog from '@/components/ui/Dialog'
import Button from '@/components/ui/Button'
import Chip from '@/components/ui/Chip'
import type { Vertebra, VertebralRegion } from '@/domain/schema/observation'
import type { VertebralFormula } from '@/domain/species/types'
import { useT } from '@/i18n/useT'
const REGIONS: VertebralRegion[] = ['C', 'T', 'L', 'S', 'Cd']
const REGION_KEY: Record<VertebralRegion, string> = {
C: 'vertebra.region.C',
T: 'vertebra.region.T',
L: 'vertebra.region.L',
S: 'vertebra.region.S',
Cd: 'vertebra.region.Cd',
}
export interface VertebraPickerProps {
open: boolean
onClose: () => void
onConfirm: (vertebrae: Vertebra[]) => void
initial: Vertebra[]
formula: VertebralFormula
title: string
/** Tab to open on. Takes priority so a click always lands on its own zone. */
initialRegion?: VertebralRegion
}
export default function VertebraPicker({
open,
onClose,
onConfirm,
initial,
formula,
title,
initialRegion,
}: VertebraPickerProps) {
const t = useT()
const [selected, setSelected] = useState<Vertebra[]>(initial)
const [activeRegion, setActiveRegion] = useState<VertebralRegion>(
() => initialRegion ?? initial[0]?.region ?? 'C',
)
const has = (r: VertebralRegion, i: number) =>
selected.some((v) => v.region === r && v.index === i)
const toggle = (r: VertebralRegion, i: number) => {
setSelected((cur) =>
has(r, i)
? cur.filter((v) => !(v.region === r && v.index === i))
: [...cur, { region: r, index: i }],
)
}
const all = (r: VertebralRegion, count: number) => {
setSelected((cur) => {
const rest = cur.filter((v) => v.region !== r)
return [...rest, ...Array.from({ length: count }, (_, k) => ({ region: r, index: k + 1 }))]
})
}
const none = (r: VertebralRegion) =>
setSelected((cur) => cur.filter((v) => v.region !== r))
const count = formula[activeRegion]
return (
<Dialog open={open} onClose={onClose} title={title} size="lg">
<div role="tablist" className="flex flex-wrap gap-2 mb-4">
{REGIONS.map((r) => (
<button
key={r}
role="tab"
aria-selected={activeRegion === r}
onClick={() => setActiveRegion(r)}
className={[
'rounded-full px-4 py-2.5 sm:py-1.5 text-sm font-medium border min-h-[2.75rem]',
activeRegion === r
? 'bg-[var(--color-accent)] text-white border-[var(--color-accent)]'
: 'bg-white text-[var(--color-ink)] border-[var(--color-border)]',
].join(' ')}
>
{t(REGION_KEY[r])}
</button>
))}
</div>
<div className="flex flex-wrap gap-2 mb-4 max-h-64 overflow-auto">
{Array.from({ length: count }, (_, k) => k + 1).map((i) => (
<Chip
key={i}
active={has(activeRegion, i)}
onClick={() => toggle(activeRegion, i)}
>
{activeRegion}{i}
</Chip>
))}
</div>
<div className="flex flex-wrap items-center gap-2 mb-6">
<Button variant="ghost" size="sm" onClick={() => all(activeRegion, count)}>
{t('vertebra.check_all')}
</Button>
<Button variant="ghost" size="sm" onClick={() => none(activeRegion)}>
{t('vertebra.uncheck_all')}
</Button>
</div>
<div className="flex justify-end gap-2">
<Button variant="ghost" onClick={onClose}>{t('common.cancel')}</Button>
<Button onClick={() => onConfirm(selected)}>{t('common.confirm')}</Button>
</div>
</Dialog>
)
}
@@ -0,0 +1,56 @@
import type { Animal, Owner } from '@/domain/schema/animal'
import Label from '@/components/ui/Label'
import Input from '@/components/ui/Input'
import Select from '@/components/ui/Select'
import { getAllSpecies, speciesLabel } from '@/domain/species/registry'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
export interface AnimalFormProps {
animal: Animal
owner: Owner
onChangeAnimal: (next: Animal) => void
onChangeOwner: (next: Owner) => void
}
export default function AnimalForm({ animal, owner, onChangeAnimal, onChangeOwner }: AnimalFormProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const species = getAllSpecies()
const setA = (patch: Partial<Animal>) => onChangeAnimal({ ...animal, ...patch })
return (
<fieldset className="space-y-3">
<legend className="font-serif text-xl mb-2 text-[var(--color-ink)]">
{t('form.animal.legend')}
</legend>
<div>
<Label htmlFor="an-species">{t('form.animal.species')}</Label>
<Select
id="an-species"
value={animal.speciesId}
onChange={(e) => setA({ speciesId: e.target.value })}
>
{species.map((s) => (
<option key={s.id} value={s.id}>{speciesLabel(s, locale)}</option>
))}
</Select>
</div>
<div>
<Label htmlFor="an-name">{t('form.animal.name')}</Label>
<Input id="an-name" required value={animal.name} onChange={(e) => setA({ name: e.target.value })} />
</div>
<div>
<Label htmlFor="an-breed">{t('form.animal.breed')}</Label>
<Input id="an-breed" value={animal.breed ?? ''} onChange={(e) => setA({ breed: e.target.value || undefined })} />
</div>
<div>
<Label htmlFor="an-age">{t('form.animal.age')}</Label>
<Input id="an-age" value={animal.age ?? ''} onChange={(e) => setA({ age: e.target.value || undefined })} />
</div>
<div>
<Label htmlFor="own-name">{t('form.owner.name')}</Label>
<Input id="own-name" required value={owner.name} onChange={(e) => onChangeOwner({ name: e.target.value })} />
</div>
</fieldset>
)
}
@@ -0,0 +1,41 @@
import type { Report } from '@/domain/schema/report'
import Label from '@/components/ui/Label'
import Textarea from '@/components/ui/Textarea'
import NextAppointmentPicker from './NextAppointmentPicker'
import { useT } from '@/i18n/useT'
export interface ConclusionPanelProps {
conclusion: string
recommendations: string
nextAppointment: Report['nextAppointment']
onChangeConclusion: (s: string) => void
onChangeRecommendations: (s: string) => void
onChangeNextAppointment: (n: Report['nextAppointment']) => void
}
export default function ConclusionPanel({
conclusion,
recommendations,
nextAppointment,
onChangeConclusion,
onChangeRecommendations,
onChangeNextAppointment,
}: ConclusionPanelProps) {
const t = useT()
return (
<section className="space-y-4">
<h2 className="font-serif text-lg sm:text-xl text-[var(--color-ink)]">
{t('conclusion.section_title')}
</h2>
<div>
<Label htmlFor="conclusion">{t('conclusion.conclusion')}</Label>
<Textarea id="conclusion" value={conclusion} onChange={(e) => onChangeConclusion(e.target.value)} />
</div>
<div>
<Label htmlFor="recommendations">{t('conclusion.recommendations')}</Label>
<Textarea id="recommendations" value={recommendations} onChange={(e) => onChangeRecommendations(e.target.value)} />
</div>
<NextAppointmentPicker value={nextAppointment} onChange={onChangeNextAppointment} />
</section>
)
}
@@ -0,0 +1,62 @@
import type { Report } from '@/domain/schema/report'
import Input from '@/components/ui/Input'
import Label from '@/components/ui/Label'
import { useT } from '@/i18n/useT'
export interface NextAppointmentPickerProps {
value: Report['nextAppointment']
onChange: (next: Report['nextAppointment']) => void
}
export default function NextAppointmentPicker({
value,
onChange,
}: NextAppointmentPickerProps) {
const t = useT()
const kind = value?.kind
return (
<div className="space-y-2">
<Label>{t('conclusion.next_appointment')}</Label>
<div className="flex gap-2 mb-2">
<label className="text-sm flex items-center gap-1">
<input
type="radio"
checked={kind === 'date'}
onChange={() => onChange({ kind: 'date', date: '' })}
/>
{t('conclusion.next_kind_date')}
</label>
<label className="text-sm flex items-center gap-1">
<input
type="radio"
checked={kind === 'period'}
onChange={() => onChange({ kind: 'period', text: '' })}
/>
{t('conclusion.next_kind_period')}
</label>
<label className="text-sm flex items-center gap-1">
<input
type="radio"
checked={value === undefined}
onChange={() => onChange(undefined)}
/>
{t('conclusion.next_kind_none')}
</label>
</div>
{value?.kind === 'date' && (
<Input
type="date"
value={value.date}
onChange={(e) => onChange({ kind: 'date', date: e.target.value })}
/>
)}
{value?.kind === 'period' && (
<Input
value={value.text}
placeholder={t('conclusion.next_period_placeholder')}
onChange={(e) => onChange({ kind: 'period', text: e.target.value })}
/>
)}
</div>
)
}
@@ -0,0 +1,37 @@
import type { Practitioner } from '@/domain/schema/practitioner'
import Label from '@/components/ui/Label'
import Input from '@/components/ui/Input'
import { useT } from '@/i18n/useT'
export interface PractitionerFormProps {
value: Practitioner
onChange: (next: Practitioner) => void
}
export default function PractitionerForm({ value, onChange }: PractitionerFormProps) {
const t = useT()
const set = (patch: Partial<Practitioner>) => onChange({ ...value, ...patch })
return (
<fieldset className="space-y-3">
<legend className="font-serif text-xl mb-2 text-[var(--color-ink)]">
{t('form.practitioner.legend')}
</legend>
<div>
<Label htmlFor="prac-name">{t('form.practitioner.name')}</Label>
<Input id="prac-name" required value={value.name} onChange={(e) => set({ name: e.target.value })} />
</div>
<div>
<Label htmlFor="prac-cabinet">{t('form.practitioner.cabinet')}</Label>
<Input id="prac-cabinet" value={value.cabinet ?? ''} onChange={(e) => set({ cabinet: e.target.value || undefined })} />
</div>
<div>
<Label htmlFor="prac-contact">{t('form.practitioner.contact')}</Label>
<Input id="prac-contact" value={value.contact ?? ''} onChange={(e) => set({ contact: e.target.value || undefined })} />
</div>
<div>
<Label htmlFor="prac-siret">{t('form.practitioner.siret')}</Label>
<Input id="prac-siret" value={value.siret ?? ''} onChange={(e) => set({ siret: e.target.value || undefined })} />
</div>
</fieldset>
)
}
@@ -0,0 +1,31 @@
import type { Report } from '@/domain/schema/report'
import AppHeader from '@/components/brand/AppHeader'
import Button from '@/components/ui/Button'
import { formatDate } from '@/lib/dates'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
export interface ReportHeaderProps {
report: Report
onEditInfos?: () => void
}
export default function ReportHeader({ report, onEditInfos }: ReportHeaderProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
return (
<AppHeader>
<div className="text-xs sm:text-sm text-right text-[var(--color-ink-muted)]">
<div className="text-[var(--color-ink)] font-medium truncate max-w-[10rem] sm:max-w-none">
{report.animal.name} · {report.owner.name}
</div>
<div className="hidden sm:block">{formatDate(report.date, locale)}</div>
</div>
{onEditInfos && (
<Button variant="secondary" size="sm" onClick={onEditInfos}>
{t('editor.edit_infos')}
</Button>
)}
</AppHeader>
)
}
+25
View File
@@ -0,0 +1,25 @@
import type { ReactNode } from 'react'
export default function Badge({
children,
tone = 'neutral',
className = '',
}: {
children: ReactNode
tone?: 'neutral' | 'accent' | 'warn' | 'danger'
className?: string
}) {
const map = {
neutral: 'bg-[var(--color-surface-strong)] text-[var(--color-ink)]',
accent: 'bg-[var(--color-accent)]/10 text-[var(--color-accent-strong)]',
warn: 'bg-amber-50 text-amber-700',
danger: 'bg-red-50 text-red-700',
} as const
return (
<span
className={`inline-flex items-center px-2 py-0.5 rounded-md text-xs font-medium ${map[tone]} ${className}`}
>
{children}
</span>
)
}
+46
View File
@@ -0,0 +1,46 @@
import type { ButtonHTMLAttributes, ReactNode } from 'react'
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary' | 'ghost' | 'danger'
size?: 'sm' | 'md' | 'lg'
children?: ReactNode
}
const VARIANTS: Record<NonNullable<ButtonProps['variant']>, string> = {
primary:
'bg-[var(--color-accent)] text-white hover:bg-[var(--color-accent-strong)] focus-visible:ring-[var(--color-accent)]',
secondary:
'bg-[var(--color-surface)] text-[var(--color-ink)] border border-[var(--color-border)] hover:bg-[var(--color-surface-strong)]',
ghost:
'bg-transparent text-[var(--color-ink)] hover:bg-[var(--color-surface)]',
danger:
'bg-[var(--color-danger)] text-white hover:bg-[var(--color-danger-strong)]',
}
const SIZES: Record<NonNullable<ButtonProps['size']>, string> = {
sm: 'h-9 px-3 text-sm rounded-md',
md: 'h-10 px-4 text-sm sm:text-base rounded-lg',
lg: 'h-12 px-5 sm:px-6 text-base rounded-lg',
}
export default function Button({
variant = 'primary',
size = 'md',
className = '',
children,
...rest
}: ButtonProps) {
return (
<button
className={[
'inline-flex items-center justify-center font-medium transition disabled:opacity-50 disabled:cursor-not-allowed focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2',
VARIANTS[variant],
SIZES[size],
className,
].join(' ')}
{...rest}
>
{children}
</button>
)
}
+20
View File
@@ -0,0 +1,20 @@
import type { ReactNode } from 'react'
export interface CardProps {
children: ReactNode
className?: string
as?: 'div' | 'section' | 'article'
}
export default function Card({ children, className = '', as: Tag = 'div' }: CardProps) {
return (
<Tag
className={[
'rounded-2xl border border-[var(--color-border)] bg-[var(--color-surface)] shadow-sm',
className,
].join(' ')}
>
{children}
</Tag>
)
}
+25
View File
@@ -0,0 +1,25 @@
import type { ButtonHTMLAttributes, ReactNode } from 'react'
export default function Chip({
active = false,
children,
className = '',
...rest
}: ButtonHTMLAttributes<HTMLButtonElement> & { active?: boolean; children: ReactNode }) {
return (
<button
type="button"
aria-pressed={active}
className={[
'inline-flex items-center justify-center min-w-[40px] h-10 px-3 rounded-full border text-sm font-medium transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/30',
active
? 'bg-[var(--color-accent)] text-white border-[var(--color-accent)]'
: 'bg-white text-[var(--color-ink)] border-[var(--color-border)] hover:bg-[var(--color-surface)]',
className,
].join(' ')}
{...rest}
>
{children}
</button>
)
}
+69
View File
@@ -0,0 +1,69 @@
import { useEffect, type ReactNode } from 'react'
import { AnimatePresence, motion } from 'motion/react'
import { useT } from '@/i18n/useT'
export interface DialogProps {
open: boolean
onClose: () => void
title: string
children: ReactNode
size?: 'sm' | 'md' | 'lg' | 'xl'
}
const SIZE: Record<NonNullable<DialogProps['size']>, string> = {
sm: 'max-w-sm',
md: 'max-w-md',
lg: 'max-w-2xl',
xl: 'max-w-4xl',
}
export default function Dialog({ open, onClose, title, children, size = 'md' }: DialogProps) {
const t = useT()
useEffect(() => {
if (!open) return
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose()
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [open, onClose])
return (
<AnimatePresence>
{open && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4">
<motion.div
data-testid="dialog-backdrop"
className="absolute inset-0 bg-black/40"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.15 }}
onClick={onClose}
/>
<motion.div
role="dialog"
aria-modal="true"
aria-label={title}
initial={{ opacity: 0, scale: 0.96 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.96 }}
transition={{ duration: 0.18 }}
className={`relative w-full ${SIZE[size]} max-h-[85vh] overflow-y-auto rounded-2xl bg-[var(--color-surface)] shadow-xl`}
>
<header className="flex items-center justify-between px-4 sm:px-6 py-3 sm:py-4 border-b border-[var(--color-border)]">
<h2 className="text-lg font-semibold text-[var(--color-ink)]">{title}</h2>
<button
type="button"
aria-label={t('common.close')}
onClick={onClose}
className="rounded-md p-1 text-[var(--color-ink-muted)] hover:bg-[var(--color-surface-strong)]"
>
✕
</button>
</header>
<div className="px-4 sm:px-6 py-3 sm:py-4">{children}</div>
</motion.div>
</div>
)}
</AnimatePresence>
)
}
+16
View File
@@ -0,0 +1,16 @@
import { forwardRef, type InputHTMLAttributes } from 'react'
const Input = forwardRef<HTMLInputElement, InputHTMLAttributes<HTMLInputElement>>(
({ className = '', ...rest }, ref) => (
<input
ref={ref}
className={[
'h-10 w-full rounded-lg border border-[var(--color-border)] bg-white px-3 text-base text-[var(--color-ink)] placeholder:text-[var(--color-ink-muted)] focus-visible:border-[var(--color-accent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/30',
className,
].join(' ')}
{...rest}
/>
),
)
Input.displayName = 'Input'
export default Input
+19
View File
@@ -0,0 +1,19 @@
import type { LabelHTMLAttributes, ReactNode } from 'react'
export default function Label({
children,
className = '',
...rest
}: LabelHTMLAttributes<HTMLLabelElement> & { children: ReactNode }) {
return (
<label
className={[
'block text-sm font-medium text-[var(--color-ink)] mb-1',
className,
].join(' ')}
{...rest}
>
{children}
</label>
)
}
+18
View File
@@ -0,0 +1,18 @@
import { forwardRef, type SelectHTMLAttributes } from 'react'
const Select = forwardRef<HTMLSelectElement, SelectHTMLAttributes<HTMLSelectElement>>(
({ className = '', children, ...rest }, ref) => (
<select
ref={ref}
className={[
'h-10 w-full rounded-lg border border-[var(--color-border)] bg-white px-3 text-base text-[var(--color-ink)] focus-visible:border-[var(--color-accent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/30',
className,
].join(' ')}
{...rest}
>
{children}
</select>
),
)
Select.displayName = 'Select'
export default Select
+16
View File
@@ -0,0 +1,16 @@
import { forwardRef, type TextareaHTMLAttributes } from 'react'
const Textarea = forwardRef<HTMLTextAreaElement, TextareaHTMLAttributes<HTMLTextAreaElement>>(
({ className = '', ...rest }, ref) => (
<textarea
ref={ref}
className={[
'w-full min-h-[96px] rounded-lg border border-[var(--color-border)] bg-white p-3 text-base text-[var(--color-ink)] placeholder:text-[var(--color-ink-muted)] focus-visible:border-[var(--color-accent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/30',
className,
].join(' ')}
{...rest}
/>
),
)
Textarea.displayName = 'Textarea'
export default Textarea