Task 9: Rebuild MedicationsView (Skills view)

Rebuild medications/skills view from ref-medications.md spec with
Clinical Luxury design direction. Three category tabs with count
badges, semantic table with sortable columns, expandable prescribing
history with vertical timeline, and Framer Motion height animation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 00:56:35 +00:00
parent ad1ce81948
commit 06f0d658b0
+278 -265
View File
@@ -1,8 +1,10 @@
import { useState, useMemo } from 'react' import { useState, useMemo } from 'react'
import { ChevronDown, ChevronUp, ArrowUpDown, ArrowUp, ArrowDown } from 'lucide-react' import { motion, AnimatePresence } from 'framer-motion'
import { ChevronDown, ChevronUp, ChevronsUpDown } from 'lucide-react'
import { medications } from '@/data/medications' import { medications } from '@/data/medications'
import type { Medication } from '@/types/pmr' import type { Medication } from '@/types/pmr'
import { useBreakpoint } from '@/hooks/useBreakpoint' import { useBreakpoint } from '@/hooks/useBreakpoint'
import { useAccessibility } from '@/contexts/AccessibilityContext'
type SortField = 'name' | 'dose' | 'frequency' | 'startYear' | 'status' type SortField = 'name' | 'dose' | 'frequency' | 'startYear' | 'status'
type SortDirection = 'asc' | 'desc' | null type SortDirection = 'asc' | 'desc' | null
@@ -12,21 +14,30 @@ interface SortState {
direction: SortDirection direction: SortDirection
} }
const categoryTabs = [ type CategoryId = 'Active' | 'Clinical' | 'PRN'
{ id: 'Active', label: 'Active Medications', shortLabel: 'Active', description: 'Technical skills (daily use)' },
{ id: 'Clinical', label: 'Clinical Medications', shortLabel: 'Clinical', description: 'Healthcare domain skills' }, const categoryTabs: { id: CategoryId; label: string; shortLabel: string }[] = [
{ id: 'PRN', label: 'PRN (As Required)', shortLabel: 'PRN', description: 'Strategic & leadership skills' }, { id: 'Active', label: 'Active Medications', shortLabel: 'Active' },
] as const { id: 'Clinical', label: 'Clinical Medications', shortLabel: 'Clinical' },
{ id: 'PRN', label: 'PRN (As Required)', shortLabel: 'PRN' },
]
const categoryCounts: Record<CategoryId, number> = {
Active: medications.filter(m => m.category === 'Active').length,
Clinical: medications.filter(m => m.category === 'Clinical').length,
PRN: medications.filter(m => m.category === 'PRN').length,
}
const prefersReducedMotion = typeof window !== 'undefined'
? window.matchMedia('(prefers-reduced-motion: reduce)').matches
: false
export function MedicationsView() { export function MedicationsView() {
const [activeTab, setActiveTab] = useState<'Active' | 'Clinical' | 'PRN'>('Active') const [activeTab, setActiveTab] = useState<CategoryId>('Active')
const [expandedRow, setExpandedRow] = useState<string | null>(null) const [expandedRow, setExpandedRow] = useState<string | null>(null)
const [sort, setSort] = useState<SortState>({ field: 'name', direction: null }) const [sort, setSort] = useState<SortState>({ field: 'name', direction: null })
const { isMobile } = useBreakpoint() const { isMobile } = useBreakpoint()
const { setExpandedItem } = useAccessibility()
const prefersReducedMotion = typeof window !== 'undefined'
? window.matchMedia('(prefers-reduced-motion: reduce)').matches
: false
const filteredMedications = useMemo(() => { const filteredMedications = useMemo(() => {
return medications.filter(med => med.category === activeTab) return medications.filter(med => med.category === activeTab)
@@ -45,8 +56,8 @@ export function MedicationsView() {
comparison = a.dose - b.dose comparison = a.dose - b.dose
break break
case 'frequency': { case 'frequency': {
const freqOrder = { 'Daily': 0, 'Weekly': 1, 'Monthly': 2, 'As needed': 3 } const freqOrder: Record<string, number> = { 'Daily': 0, 'Weekly': 1, 'Monthly': 2, 'As needed': 3 }
comparison = freqOrder[a.frequency] - freqOrder[b.frequency] comparison = (freqOrder[a.frequency] ?? 4) - (freqOrder[b.frequency] ?? 4)
break break
} }
case 'startYear': case 'startYear':
@@ -74,33 +85,37 @@ export function MedicationsView() {
} }
} }
const toggleRow = (id: string) => { const toggleRow = (id: string, name: string) => {
setExpandedRow(expandedRow === id ? null : id) const nextExpanded = expandedRow === id ? null : id
setExpandedRow(nextExpanded)
setExpandedItem(nextExpanded ? name : null)
} }
const getSortIcon = (field: SortField) => { const SortIndicator = ({ field }: { field: SortField }) => {
if (sort.field !== field || !sort.direction) { if (sort.field !== field || !sort.direction) {
return <ArrowUpDown size={12} className="text-gray-400" /> return <ChevronsUpDown className="w-3.5 h-3.5 text-gray-400" />
} }
return sort.direction === 'asc' return sort.direction === 'asc'
? <ArrowUp size={12} className="text-pmr-nhsblue" /> ? <ChevronUp className="w-3.5 h-3.5 text-[#005EB8]" />
: <ArrowDown size={12} className="text-pmr-nhsblue" /> : <ChevronDown className="w-3.5 h-3.5 text-[#005EB8]" />
} }
return ( return (
<div className="space-y-6"> <div className="space-y-6">
<div className="bg-white border border-gray-200 rounded"> <div className="bg-white border border-[#E5E7EB] rounded shadow-pmr overflow-hidden">
<div className="px-4 py-3 border-b border-gray-200 bg-gray-50"> {/* Header */}
<h1 className="font-inter font-semibold text-lg text-gray-900"> <div className="px-5 py-3 border-b border-[#E5E7EB] bg-[#F9FAFB]">
<h1 className="font-ui font-semibold text-[15px] text-gray-900">
Current Medications Current Medications
</h1> </h1>
<p className="font-inter text-sm text-gray-500 mt-1"> <p className="font-ui text-[13px] text-gray-500 mt-0.5">
Skills mapped as active medications proficiency shown as dosage Skills mapped as active medications proficiency shown as dosage
</p> </p>
</div> </div>
<div className="border-b border-gray-200"> {/* Category Tabs */}
<nav className="flex" role="tablist"> <div className="border-b border-[#E5E7EB]">
<nav className="flex" role="tablist" aria-label="Medication categories">
{categoryTabs.map((tab) => ( {categoryTabs.map((tab) => (
<button <button
key={tab.id} key={tab.id}
@@ -110,120 +125,97 @@ export function MedicationsView() {
onClick={() => { onClick={() => {
setActiveTab(tab.id) setActiveTab(tab.id)
setExpandedRow(null) setExpandedRow(null)
setExpandedItem(null)
}} }}
className={` className={`
flex-1 px-4 py-3 text-left transition-colors duration-100 flex-1 px-4 py-2.5 transition-colors duration-100 text-left
border-b-2
${activeTab === tab.id ${activeTab === tab.id
? 'bg-white border-b-2 border-pmr-nhsblue' ? 'bg-white border-[#005EB8]'
: 'bg-gray-50 hover:bg-gray-100 border-b-2 border-transparent'} : 'bg-[#F9FAFB] border-transparent text-gray-600 hover:bg-white'}
`} `}
> >
<span className={`font-inter font-medium text-sm ${activeTab === tab.id ? 'text-gray-900' : 'text-gray-600'}`}> <span className="flex items-center gap-2">
{isMobile ? tab.shortLabel : tab.label} <span className={`font-ui font-medium text-[14px] ${activeTab === tab.id ? 'text-[#005EB8]' : 'text-gray-600'}`}>
</span> {isMobile ? tab.shortLabel : tab.label}
{!isMobile && (
<span className="block font-inter text-xs text-gray-500 mt-0.5">
{tab.description}
</span> </span>
)} <span
className={`
inline-flex items-center justify-center min-w-[20px] h-5 px-1.5 rounded-full text-[11px] font-ui font-medium
${activeTab === tab.id
? 'bg-[#005EB8]/10 text-[#005EB8]'
: 'bg-gray-200 text-gray-500'}
`}
>
{categoryCounts[tab.id]}
</span>
</span>
</button> </button>
))} ))}
</nav> </nav>
</div> </div>
{isMobile ? ( {/* Tab Panel */}
<MobileMedicationList <div
medications={sortedMedications} id={`panel-${activeTab}`}
expandedRow={expandedRow} role="tabpanel"
onToggle={toggleRow} aria-labelledby={activeTab}
prefersReducedMotion={prefersReducedMotion} >
/> {isMobile ? (
) : ( <MobileMedicationList
<div className="overflow-x-auto"> medications={sortedMedications}
<table className="w-full" role="grid"> expandedRow={expandedRow}
<thead> onToggle={toggleRow}
<tr className="border-b border-gray-200 bg-gray-50"> />
<th scope="col" className="w-8"></th> ) : (
<th scope="col" className="text-left"> <div className="overflow-x-auto">
<button <table className="w-full" role="grid">
type="button" <thead>
onClick={() => handleSort('name')} <tr className="border-b border-[#E5E7EB] bg-[#F9FAFB]">
className="w-full px-4 py-3 flex items-center gap-2 hover:bg-gray-100 transition-colors" {(['name', 'dose', 'frequency', 'startYear', 'status'] as SortField[]).map((field) => {
> const labels: Record<SortField, string> = {
<span className="font-inter font-semibold text-xs uppercase tracking-wide text-gray-400"> name: 'Drug Name',
Drug Name dose: 'Dose',
</span> frequency: 'Frequency',
{getSortIcon('name')} startYear: 'Start',
</button> status: 'Status',
</th> }
<th scope="col" className="text-left"> return (
<button <th key={field} scope="col" className="text-left border-r border-[#E5E7EB] last:border-r-0">
type="button" <button
onClick={() => handleSort('dose')} type="button"
className="w-full px-4 py-3 flex items-center gap-2 hover:bg-gray-100 transition-colors" onClick={() => handleSort(field)}
> className="w-full px-4 h-[40px] flex items-center gap-2 hover:bg-[#EFF6FF] transition-colors duration-100"
<span className="font-inter font-semibold text-xs uppercase tracking-wide text-gray-400"> >
Dose <span className="font-ui font-semibold text-[13px] uppercase tracking-[0.03em] text-gray-400">
</span> {labels[field]}
{getSortIcon('dose')} </span>
</button> <SortIndicator field={field} />
</th> </button>
<th scope="col" className="text-left"> </th>
<button )
type="button" })}
onClick={() => handleSort('frequency')} </tr>
className="w-full px-4 py-3 flex items-center gap-2 hover:bg-gray-100 transition-colors" </thead>
> <tbody>
<span className="font-inter font-semibold text-xs uppercase tracking-wide text-gray-400"> {sortedMedications.map((med, index) => (
Frequency <MedicationRow
</span> key={med.id}
{getSortIcon('frequency')} medication={med}
</button> isExpanded={expandedRow === med.id}
</th> isEven={index % 2 === 1}
<th scope="col" className="text-left"> onToggle={() => toggleRow(med.id, med.name)}
<button />
type="button" ))}
onClick={() => handleSort('startYear')} </tbody>
className="w-full px-4 py-3 flex items-center gap-2 hover:bg-gray-100 transition-colors" </table>
> </div>
<span className="font-inter font-semibold text-xs uppercase tracking-wide text-gray-400"> )}
Start </div>
</span>
{getSortIcon('startYear')}
</button>
</th>
<th scope="col" className="text-left">
<button
type="button"
onClick={() => handleSort('status')}
className="w-full px-4 py-3 flex items-center gap-2 hover:bg-gray-100 transition-colors"
>
<span className="font-inter font-semibold text-xs uppercase tracking-wide text-gray-400">
Status
</span>
{getSortIcon('status')}
</button>
</th>
</tr>
</thead>
<tbody>
{sortedMedications.map((med, index) => (
<MedicationRow
key={med.id}
medication={med}
isExpanded={expandedRow === med.id}
isAlternating={index % 2 === 1}
onToggle={() => toggleRow(med.id)}
prefersReducedMotion={prefersReducedMotion}
/>
))}
</tbody>
</table>
</div>
)}
<div className="px-4 py-3 border-t border-gray-200 bg-gray-50"> {/* Footer */}
<p className="font-inter text-xs text-gray-500"> <div className="px-5 py-3 border-t border-[#E5E7EB] bg-[#F9FAFB]">
<p className="font-ui text-[12px] text-gray-500">
{sortedMedications.length} medications in this category. {isMobile ? 'Tap' : 'Click'} a row to view prescribing history. {sortedMedications.length} medications in this category. {isMobile ? 'Tap' : 'Click'} a row to view prescribing history.
</p> </p>
</div> </div>
@@ -232,188 +224,209 @@ export function MedicationsView() {
) )
} }
/* ─── Mobile Card Layout ───────────────────────────────────────────── */
interface MobileMedicationListProps { interface MobileMedicationListProps {
medications: Medication[] medications: Medication[]
expandedRow: string | null expandedRow: string | null
onToggle: (id: string) => void onToggle: (id: string, name: string) => void
prefersReducedMotion: boolean
} }
function MobileMedicationList({ medications, expandedRow, onToggle, prefersReducedMotion }: MobileMedicationListProps) { function MobileMedicationList({ medications, expandedRow, onToggle }: MobileMedicationListProps) {
const statusColors = {
'Active': 'bg-green-500',
'Historical': 'bg-gray-400',
}
return ( return (
<div className="divide-y divide-gray-200"> <div className="divide-y divide-[#E5E7EB]">
{medications.map((med) => ( {medications.map((med) => {
<div key={med.id} className="bg-white"> const isExpanded = expandedRow === med.id
<button return (
type="button" <div key={med.id} className="bg-white">
onClick={() => onToggle(med.id)} <button
className="w-full p-4 text-left" type="button"
aria-expanded={expandedRow === med.id} onClick={() => onToggle(med.id, med.name)}
> className="w-full p-4 text-left hover:bg-[#EFF6FF] transition-colors duration-100 focus-visible:ring-2 focus-visible:ring-[#005EB8]/40 focus-visible:ring-inset"
<div className="flex items-start justify-between gap-3"> aria-expanded={isExpanded}
<div className="flex-1 min-w-0"> aria-label={`${med.name}, ${med.dose}% proficiency, ${med.frequency}, since ${med.startYear}`}
<h3 className="font-inter font-medium text-sm text-gray-900"> >
{med.name} <div className="flex items-start justify-between gap-3">
</h3> <div className="flex-1 min-w-0">
<div className="flex items-center gap-3 mt-1.5 text-xs text-gray-500"> <h3 className="font-ui font-medium text-[14px] text-gray-900">
<span className="font-geist">{med.dose}%</span> {med.name}
<span></span> </h3>
<span>{med.frequency}</span> <div className="flex items-center gap-3 mt-1.5 font-ui text-[12px] text-gray-500">
<span></span> <span className="font-geist">{med.dose}%</span>
<span className="font-geist">Since {med.startYear}</span> <span className="text-gray-300">·</span>
<span>{med.frequency}</span>
<span className="text-gray-300">·</span>
<span className="font-geist">Since {med.startYear}</span>
</div>
</div>
<div className="flex items-center gap-2 flex-shrink-0">
<StatusDot status={med.status} />
<motion.div
animate={{ rotate: isExpanded ? 180 : 0 }}
transition={{ duration: prefersReducedMotion ? 0 : 0.2 }}
>
<ChevronDown size={16} className="text-gray-400" />
</motion.div>
</div> </div>
</div> </div>
<div className="flex items-center gap-2 flex-shrink-0"> </button>
<span className={`w-2 h-2 rounded-full ${statusColors[med.status]}`} /> <AnimatePresence initial={false}>
<span className="text-xs text-gray-600">{med.status}</span> {isExpanded && (
{expandedRow === med.id ? ( <motion.div
<ChevronUp size={16} className="text-gray-400" /> initial={{ height: 0 }}
) : ( animate={{ height: 'auto' }}
<ChevronDown size={16} className="text-gray-400" /> exit={{ height: 0 }}
)} transition={{ duration: prefersReducedMotion ? 0 : 0.2, ease: [0.4, 0, 0.2, 1] }}
</div> className="overflow-hidden"
</div> >
</button> <div className="px-4 pb-4">
{expandedRow === med.id && ( <PrescribingHistory history={med.prescribingHistory} />
<div className={`px-4 pb-4 ${prefersReducedMotion ? '' : 'animate-fadeIn'}`}> </div>
<div className="bg-gray-50 rounded p-3"> </motion.div>
<p className="font-inter font-medium text-xs uppercase tracking-wide text-gray-400 mb-2"> )}
Prescribing History </AnimatePresence>
</p> </div>
<div className="space-y-1.5"> )
{med.prescribingHistory.map((entry, index) => ( })}
<div key={index} className="flex gap-3">
<span className="font-geist font-medium text-xs text-gray-500 w-10 flex-shrink-0">
{entry.year}
</span>
<span className="font-geist text-xs text-gray-600">
{entry.description}
</span>
</div>
))}
</div>
</div>
</div>
)}
</div>
))}
</div> </div>
) )
} }
/* ─── Desktop Table Row ────────────────────────────────────────────── */
interface MedicationRowProps { interface MedicationRowProps {
medication: Medication medication: Medication
isExpanded: boolean isExpanded: boolean
isAlternating: boolean isEven: boolean
onToggle: () => void onToggle: () => void
prefersReducedMotion: boolean
} }
function MedicationRow({ medication, isExpanded, isAlternating, onToggle, prefersReducedMotion }: MedicationRowProps) { function MedicationRow({ medication, isExpanded, isEven, onToggle }: MedicationRowProps) {
const statusColors = {
'Active': 'bg-green-500',
'Historical': 'bg-gray-400',
}
return ( return (
<> <>
<tr <tr
className={` className={`
border-b border-gray-200 cursor-pointer transition-colors duration-100 h-[40px] border-b border-[#E5E7EB] cursor-pointer transition-colors duration-100
${isAlternating ? 'bg-gray-50' : 'bg-white'} ${isEven ? 'bg-[#F9FAFB]' : 'bg-white'}
hover:bg-blue-50 hover:bg-[#EFF6FF]
`} `}
onClick={onToggle} onClick={onToggle}
role="row" role="row"
aria-expanded={isExpanded} aria-expanded={isExpanded}
tabIndex={0}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault()
onToggle()
}
}}
> >
<td className="w-8 px-2 py-0"> <td className="px-4 py-2 border-r border-[#E5E7EB]">
<button <div className="flex items-center gap-2">
type="button" <motion.div
className="p-1 hover:bg-gray-200 rounded transition-colors" animate={{ rotate: isExpanded ? 180 : 0 }}
aria-label={isExpanded ? 'Collapse' : 'Expand'} transition={{ duration: prefersReducedMotion ? 0 : 0.2 }}
> className="flex-shrink-0"
{isExpanded ? ( >
<ChevronUp size={16} className="text-gray-500" /> <ChevronDown size={14} className="text-gray-400" />
) : ( </motion.div>
<ChevronDown size={16} className="text-gray-500" /> <span className="font-ui font-medium text-[14px] text-gray-900">
)} {medication.name}
</button> </span>
</div>
</td> </td>
<td className="px-4 py-2.5"> <td className="px-4 py-2 border-r border-[#E5E7EB]">
<span className="font-inter font-medium text-sm text-gray-900"> <span className="font-geist text-[13px] text-gray-700">
{medication.name}
</span>
</td>
<td className="px-4 py-2.5">
<span className="font-geist text-sm text-gray-700">
{medication.dose}% {medication.dose}%
</span> </span>
</td> </td>
<td className="px-4 py-2.5"> <td className="px-4 py-2 border-r border-[#E5E7EB]">
<span className="font-inter text-sm text-gray-700"> <span className="font-ui text-[13px] text-gray-700">
{medication.frequency} {medication.frequency}
</span> </span>
</td> </td>
<td className="px-4 py-2.5"> <td className="px-4 py-2 border-r border-[#E5E7EB]">
<span className="font-geist text-sm text-gray-700"> <span className="font-geist text-[13px] text-gray-700">
{medication.startYear} {medication.startYear}
</span> </span>
</td> </td>
<td className="px-4 py-2.5"> <td className="px-4 py-2">
<span className="flex items-center gap-2"> <StatusDot status={medication.status} />
<span className={`w-2 h-2 rounded-full ${statusColors[medication.status]}`} />
<span className="font-inter text-sm text-gray-600">{medication.status}</span>
</span>
</td> </td>
</tr> </tr>
{isExpanded && ( <AnimatePresence initial={false}>
<PrescribingHistory {isExpanded && (
history={medication.prescribingHistory} <motion.tr
prefersReducedMotion={prefersReducedMotion} initial={{ height: 0 }}
/> animate={{ height: 'auto' }}
)} exit={{ height: 0 }}
transition={{ duration: prefersReducedMotion ? 0 : 0.2, ease: [0.4, 0, 0.2, 1] }}
className="overflow-hidden"
>
<td colSpan={5} className="p-0">
<motion.div
initial={{ height: 0 }}
animate={{ height: 'auto' }}
exit={{ height: 0 }}
transition={{ duration: prefersReducedMotion ? 0 : 0.2, ease: [0.4, 0, 0.2, 1] }}
className="overflow-hidden"
>
<div className="px-6 py-4 bg-[#F9FAFB] border-b border-[#E5E7EB]">
<PrescribingHistory history={medication.prescribingHistory} />
</div>
</motion.div>
</td>
</motion.tr>
)}
</AnimatePresence>
</> </>
) )
} }
interface PrescribingHistoryProps { /* ─── Status Dot ───────────────────────────────────────────────────── */
history: { year: number; description: string }[]
prefersReducedMotion: boolean
}
function PrescribingHistory({ history, prefersReducedMotion }: PrescribingHistoryProps) { function StatusDot({ status }: { status: 'Active' | 'Historical' }) {
const color = status === 'Active' ? 'bg-[#22C55E]' : 'bg-gray-400'
return ( return (
<tr className="bg-gray-50 border-b border-gray-200"> <div className="flex items-center gap-2">
<td colSpan={6} className="px-4 py-4"> <span className={`w-1.5 h-1.5 rounded-full ${color}`} aria-hidden="true" />
<div <span className="font-ui text-[13px] text-gray-700">{status}</span>
className={` </div>
pl-8 )
${prefersReducedMotion ? '' : 'animate-fadeIn'} }
`}
> /* ─── Prescribing History (shared) ─────────────────────────────────── */
<p className="font-inter font-medium text-xs uppercase tracking-wide text-gray-400 mb-3">
Prescribing History interface PrescribingHistoryProps {
</p> history: { year: number; description: string }[]
<div className="space-y-2"> }
{history.map((entry, index) => (
<div key={index} className="flex gap-4"> function PrescribingHistory({ history }: PrescribingHistoryProps) {
<span className="font-geist font-medium text-sm text-gray-500 w-12 flex-shrink-0"> return (
{entry.year} <div className="pl-6">
</span> <p className="font-ui font-semibold text-[12px] uppercase tracking-[0.05em] text-gray-400 mb-3">
<span className="font-geist text-sm text-gray-600"> Prescribing History
{entry.description} </p>
</span> <div className="relative">
</div> {/* Vertical timeline line */}
))} <div className="absolute left-[18px] top-1 bottom-1 w-px bg-[#E5E7EB]" aria-hidden="true" />
</div> <div className="space-y-2">
</div> {history.map((entry, index) => (
</td> <div key={index} className="flex gap-4 relative">
</tr> {/* Timeline dot */}
<div className="relative z-10 flex-shrink-0 mt-1.5">
<span className="block w-2 h-2 rounded-full bg-[#005EB8] ring-2 ring-white" aria-hidden="true" />
</div>
<span className="font-geist font-semibold text-[12px] text-gray-600 w-10 flex-shrink-0 pt-[1px]">
{entry.year}
</span>
<span className="font-geist text-[12px] text-gray-500 pt-[1px]">
{entry.description}
</span>
</div>
))}
</div>
</div>
</div>
) )
} }