TypeScript
style: match the design's event title truncation
Vipul Kumar5f571161b26a
diff --git a/next.config.ts b/next.config.tsindex a0cf0c7..928a377 100644--- a/next.config.ts+++ b/next.config.ts@@ -1,7 +1,8 @@import type { NextConfig } from "next";const nextConfig: NextConfig = {- /* config options here */+ // The floating dev badge sits on top of the sidebar account block.+ devIndicators: false,cacheComponents: true,partialPrefetching: true,turbopack: {diff --git a/src/components/calendar/time-grid.tsx b/src/components/calendar/time-grid.tsxindex c647ec8..9468649 100644--- a/src/components/calendar/time-grid.tsx+++ b/src/components/calendar/time-grid.tsx@@ -10,6 +10,7 @@ import { useCalendarStore } from "@/stores/calendar-store";import { openOverlay } from "@/stores/overlay-store";import { AllDayRow } from "./all-day-row";import { eventStyle } from "./event-colors";+import { TwoLineTitle } from "./two-line-title";import {clamp,HOUR_HEIGHT,@@ -387,9 +388,11 @@ function EventBlock({</p>) : (<>- <p className={cn("t-14 salt w-full shrink-0 overflow-hidden break-words", height >= 60 ? "line-clamp-2" : "line-clamp-1")}>- {event.title}- </p>+ {height >= 60 ? (+ <TwoLineTitle text={event.title} className="t-14 salt w-full shrink-0 overflow-hidden" />+ ) : (+ <p className="t-14 salt w-full shrink-0 truncate">{event.title}</p>+ )}<p className="t-12 salt w-full shrink-0 truncate">{time}</p>{event.note && <p className="t-12 salt w-full shrink-0 truncate">{event.note}</p>}</>diff --git a/src/components/calendar/two-line-title.tsx b/src/components/calendar/two-line-title.tsxnew file mode 100644index 0000000..8ef7b31--- /dev/null+++ b/src/components/calendar/two-line-title.tsx@@ -0,0 +1,66 @@+"use client";++import { useLayoutEffect, useRef, useState } from "react";++let canvas: HTMLCanvasElement | null = null;++/** Greedy word wrap using the element's real font, like Figma's text layout. */+function wrap(text: string, el: HTMLElement): string[] {+ canvas ??= document.createElement("canvas");+ const ctx = canvas.getContext("2d")!;+ const cs = getComputedStyle(el);+ ctx.font = `${cs.fontWeight} ${cs.fontSize} ${cs.fontFamily}`;+ ctx.letterSpacing = cs.letterSpacing;+ ctx.fontKerning = "normal";+ const max = el.clientWidth;+ const lines: string[] = [];+ let line = "";+ for (const word of text.split(/\s+/)) {+ const next = line ? `${line} ${word}` : word;+ if (line && ctx.measureText(next).width > max) {+ lines.push(line);+ line = word;+ } else {+ line = next;+ }+ }+ if (line) lines.push(line);+ return lines;+}++/**+ * Wraps by words but, when the text needs more than two lines, ends the second+ * line with a character-level ellipsis — matching how the design truncates+ * ("Submit / medical certi…") rather than CSS line-clamp's whole-word cut.+ */+export function TwoLineTitle({ text, className }: { text: string; className?: string }) {+ const ref = useRef<HTMLParagraphElement>(null);+ const [lines, setLines] = useState<[string, string] | null>(null);++ useLayoutEffect(() => {+ const el = ref.current;+ if (!el) return;+ const measure = () => {+ const all = wrap(text, el);+ setLines(all.length > 2 ? [all[0], all.slice(1).join(" ")] : null);+ };+ measure();+ const ro = new ResizeObserver(measure);+ ro.observe(el);+ void document.fonts?.ready.then(measure);+ return () => ro.disconnect();+ }, [text]);++ return (+ <p ref={ref} className={className} title={lines ? text : undefined}>+ {lines ? (+ <>+ <span className="block">{lines[0]}</span>+ <span className="block truncate">{lines[1]}</span>+ </>+ ) : (+ <span className="line-clamp-2 break-words">{text}</span>+ )}+ </p>+ );+}