Files
metabuilder/fakemui/react/components/email/surfaces/EmailCard.tsx
johndoe6345789 89f83a7476 Organize fakemui folder: email components complete, docs consolidated
- Email components (Phase 2 COMPLETE):
  * Fixed 18 broken imports: @metabuilder/fakemui/hooks → ../../../src/utils/useAccessible
  * Renamed email-wip/ → email/ (production-ready)
  * Enabled exports in react/components/index.ts
  * All 22 email components now production-ready (1244 lines)

- Cleanup:
  * Removed wip/ directory (duplicate of src/utils/accessibility)
  * Preserved 15 Python/PyQt6 implementation files (full implementations, not stubs)
  * Moved 7 markdown files to fakemui/docs/ (better organization)

- Documentation:
  * Updated CLAUDE.md: Phase 2 email complete, added deletion safety gotcha
  * Created plan: txt/FAKEMUI_REORGANIZATION_PLAN_2026-02-01.txt

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 20:18:49 +00:00

92 lines
2.5 KiB
TypeScript

// fakemui/react/components/email/surfaces/EmailCard.tsx
import React, { forwardRef } from 'react'
import { Card, CardProps, Box, Typography } from '..'
import { useAccessible } from '../../../src/utils/useAccessible'
import { MarkAsReadCheckbox, StarButton } from '../atoms'
export interface EmailCardProps extends CardProps {
from: string
subject: string
preview: string
receivedAt: number
isRead: boolean
isStarred?: boolean
onSelect?: () => void
onToggleRead?: (read: boolean) => void
onToggleStar?: (starred: boolean) => void
testId?: string
}
export const EmailCard = forwardRef<HTMLDivElement, EmailCardProps>(
(
{
from,
subject,
preview,
receivedAt,
isRead,
isStarred = false,
onSelect,
onToggleRead,
onToggleStar,
testId: customTestId,
...props
},
ref
) => {
const accessible = useAccessible({
feature: 'email',
component: 'card',
identifier: customTestId || subject.substring(0, 20)
})
const formatDate = (timestamp: number) => {
const date = new Date(timestamp)
const today = new Date()
if (date.toDateString() === today.toDateString()) {
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
}
return date.toLocaleDateString([], { month: 'short', day: 'numeric' })
}
return (
<Card
ref={ref}
className={`email-card ${isRead ? 'email-card--read' : 'email-card--unread'}`}
onClick={onSelect}
{...accessible}
{...props}
>
<Box className="email-card-header">
<MarkAsReadCheckbox
isRead={isRead}
onToggleRead={onToggleRead}
onClick={(e) => e.stopPropagation()}
/>
<Typography variant="subtitle2" className="email-from">
{from}
</Typography>
<div className="email-card-actions">
<StarButton
isStarred={isStarred}
onToggleStar={onToggleStar}
onClick={(e) => e.stopPropagation()}
/>
<Typography variant="caption" className="email-date">
{formatDate(receivedAt)}
</Typography>
</div>
</Box>
<Typography variant="h6" className="email-subject">
{subject}
</Typography>
<Typography variant="body2" className="email-preview" noWrap>
{preview}
</Typography>
</Card>
)
}
)
EmailCard.displayName = 'EmailCard'