import React from 'react'; import { Icon } from '@/components/icon/Icon'; import { useI18n } from '@/lib/i18n'; import { cn } from '@/lib/utils'; /** * One entry in any project knowledge list. * * Notes and memories drifted into two different-looking rows in the same panel: * one a bare block of text opened by clicking the text, the other a bordered * card opened by a chevron. They hold different content but they are the same * kind of thing to read, so they share this shell and this interaction. * * A collapsed card opens on a click anywhere on it — the whole card is the * target, not a chevron the user has to aim at. An expanded card closes only * through its collapse action, because its body is editable and a stray click * in the text must not throw the editor away. */ export const KnowledgeCard: React.FC<{ expanded: boolean; onToggleExpanded: () => void; /** Shown above the body: a badge, a title, whatever the section needs. */ header?: React.ReactNode; /** The preview or the editor, depending on `expanded`. */ children: React.ReactNode; /** Stacked to the right, so the text keeps the full row width. */ actions?: React.ReactNode; footer?: React.ReactNode; expandLabel: string; }> = ({ expanded, onToggleExpanded, header, children, actions, footer, expandLabel }) => { const { t } = useI18n(); return (
  • { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); onToggleExpanded(); } }} role={expanded ? undefined : 'button'} tabIndex={expanded ? undefined : 0} aria-label={expanded ? undefined : expandLabel} >
    {header} {children}
    {/* Stopped here rather than on each control: every action is a click on the card too, and without this each one would also toggle it. */}
    event.stopPropagation()} onKeyDown={(event) => event.stopPropagation()} > {expanded ? ( ) : null} {actions}
    {footer ?
    {footer}
    : null}
  • ); };