PostContent
Location: src/components/post-parts/PostContent.jsx
Overview
PostContent renders the text body of a post card. It handles content truncation for long posts and provides a "Quote this" popup on desktop when the user selects text (minimum 10 characters). This enables the "Build On" feature where users can reference specific passages from a post.
Truncation is based on non-whitespace character count rather than total length, ensuring fair treatment of posts with varied formatting.
Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
content | string | Yes | -- | The post's text content |
onQuote | function | No | -- | Callback receiving selected text when user clicks "Quote this" |
Constants
| Constant | Value | Description |
|---|---|---|
MAX_NON_SPACE_CHARS | 500 | Maximum non-whitespace characters before truncation |
MIN_SELECTION_LENGTH | 10 | Minimum selected characters to show the quote popup |
Key Behaviors
- Smart Truncation: Counts only non-space characters (excluding spaces, newlines, tabs). When the limit is exceeded, content is cut at the 500th non-space character with a "..." indicator and a chevron arrow.
- Text Selection Quote (Desktop Only): When the user selects 10+ characters within the content area, a floating "Quote this" popup appears at the selection position. Clicking it calls
onQuotewith the selected text. - Mobile Disabled: The quote popup is disabled on mobile via the
useIsMobilehook, deferring to native text selection behavior. - Popup Positioning: The popup is positioned using
fixedpositioning based on the selection's bounding rect, centered horizontally. - Cleanup: The popup is dismissed when clicking outside it or making a new selection shorter than the minimum.
Usage
import PostContent from '@/components/post-parts/PostContent';
<PostContent
content={post.content}
onQuote={(selectedText) => handleQuote(selectedText)}
/>
Related
- Post -- Parent component that renders PostContent
- PostDetail -- Full post view (renders content directly, not via this component)
Last updated: 2026-02-07