mirror of
https://github.com/usememos/memos.git
synced 2026-12-03 01:09:17 +01:00
98d8322f14
The sidebar was recently tightened onto one grammar: 28px rows on a shared rail, two chrome type tokens (13px and 11px), quiet kit controls, outline focus, and accent fill reserved for the one thing that is on. The memo card and editor still mixed 32px and 24px controls, 12px and 14px chrome type, bordered "slab" sections, ring focus, and hand-rolled control looks. Memo card - The header is a fixed 24px row; time and creator are 13px, the creator collapses to one line with a 20px avatar. - Attachments are part of the memo, not a labelled section: media renders as the bare gallery, and audio, files, relations and the location are one list of 28px rows whose glyphs sit on the memo's text edge and whose details sit on one trailing rail. A file row reveals its download arrow on hover; an audio row plays from its slot and opens a small player from its name. - Relations carry their direction as trailing detail instead of a header and tabs. Reactions are pills, since they are tokens on the memo rather than controls; your own reaction and the add control take the accent while on. - The comment strip is a titled row list with a View all action. Memo editor - Every toolbar control is 28px: quiet formatting segments with aria-pressed, an outline insert square matching the sidebar's compose control, a quiet visibility chip built like the scope pill, a quiet Cancel and a small Save. - Attachment, relation and location rows share the metadata row grammar; their controls overlay the trailing edge on hover so the detail rail never moves. The tag autocomplete matches the small dropdown. The row grammar lives in MetadataSection.tsx with its own helpers (icon slot, detail rail, remove control, list container) and stays deliberately separate from the sidebar's. Every Lucide glyph in these views draws at stroke 1.8, and the last ring-based focus sites move to the outline constant.
75 lines
2.6 KiB
TypeScript
75 lines
2.6 KiB
TypeScript
import { ChevronDownIcon, ChevronUpIcon } from "lucide-react";
|
|
import { type ReactNode, useEffect, useRef, useState } from "react";
|
|
import { Button } from "@/components/ui/button";
|
|
import { cn } from "@/lib/utils";
|
|
import { useTranslate } from "@/utils/i18n";
|
|
|
|
// A collapsed section shows this much content; anything taller folds behind a fade.
|
|
export const CLAMP_PREVIEW_HEIGHT_PX = 360;
|
|
// Only fold when content is taller than this, so cards barely over the preview aren't
|
|
// clamped for the sake of a few hidden pixels.
|
|
export const CLAMP_TRIGGER_HEIGHT_PX = 420;
|
|
|
|
interface ClampedSectionProps {
|
|
/** When false, children render untouched with no measurement. */
|
|
enabled: boolean;
|
|
children: ReactNode;
|
|
}
|
|
|
|
/**
|
|
* The one truncation mechanism for compact cards: measure the content, and when it is
|
|
* tall enough, collapse it to a fixed-height preview with a fade and a Show more/less
|
|
* toggle. The inner div is never clamped, so observing it keeps the measurement live
|
|
* while images and embeds load.
|
|
*/
|
|
const ClampedSection = ({ enabled, children }: ClampedSectionProps) => {
|
|
const t = useTranslate();
|
|
const measureRef = useRef<HTMLDivElement>(null);
|
|
const [clamped, setClamped] = useState(false);
|
|
const [expanded, setExpanded] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const el = measureRef.current;
|
|
if (!enabled || !el) {
|
|
setClamped(false);
|
|
return;
|
|
}
|
|
const check = () => setClamped(el.offsetHeight > CLAMP_TRIGGER_HEIGHT_PX);
|
|
check();
|
|
if (typeof ResizeObserver === "undefined") return;
|
|
const observer = new ResizeObserver(check);
|
|
observer.observe(el);
|
|
return () => observer.disconnect();
|
|
}, [enabled]);
|
|
|
|
const collapsed = clamped && !expanded;
|
|
|
|
return (
|
|
<>
|
|
<div
|
|
className={cn("relative w-full", collapsed && "overflow-hidden")}
|
|
style={collapsed ? { maxHeight: CLAMP_PREVIEW_HEIGHT_PX } : undefined}
|
|
>
|
|
<div ref={measureRef} className="w-full flex flex-col justify-start items-start gap-2">
|
|
{children}
|
|
</div>
|
|
{collapsed && (
|
|
<div className="pointer-events-none absolute inset-x-0 bottom-0 h-12 bg-linear-to-t from-card from-0% via-card/60 via-40% to-transparent to-100%" />
|
|
)}
|
|
</div>
|
|
{clamped && (
|
|
<Button variant="quiet" size="sm" onClick={() => setExpanded((prev) => !prev)}>
|
|
{t(collapsed ? "memo.show-more" : "memo.show-less")}
|
|
{collapsed ? (
|
|
<ChevronDownIcon className="size-3.5" strokeWidth={1.8} />
|
|
) : (
|
|
<ChevronUpIcon className="size-3.5" strokeWidth={1.8} />
|
|
)}
|
|
</Button>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default ClampedSection;
|