Skip to content

Commit 438465d

Browse files
authored
feat: add customizable soft-tint project monograms (#11845)
1 parent d07ffbe commit 438465d

11 files changed

Lines changed: 303 additions & 91 deletions

File tree

‎apps/server/src/orchestration/Layers/ProjectionPipeline.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4353,6 +4353,45 @@ engineLayer("OrchestrationProjectionPipeline via engine dispatch", (it) => {
43534353
}),
43544354
);
43554355

4356+
it.effect("persists and clears a project monogram", () =>
4357+
Effect.gen(function* () {
4358+
const engine = yield* OrchestrationEngineService;
4359+
const sql = yield* SqlClient.SqlClient;
4360+
const projectId = ProjectId.make("project-monogram");
4361+
yield* engine.dispatch({
4362+
type: "project.create",
4363+
commandId: CommandId.make("cmd-monogram-create"),
4364+
projectId,
4365+
title: "Monogram",
4366+
workspaceRoot: "/tmp/project-monogram",
4367+
defaultModelSelection: null,
4368+
createdAt: "2026-01-01T00:00:00.000Z",
4369+
});
4370+
yield* engine.dispatch({
4371+
type: "project.meta.update",
4372+
commandId: CommandId.make("cmd-monogram-save"),
4373+
projectId,
4374+
projectIcon: { kind: "lucide", name: "folder-code", color: "violet", monogram: "T3" },
4375+
});
4376+
const saved = yield* sql<{
4377+
readonly icon: string | null;
4378+
}>`SELECT project_icon_json AS icon FROM projection_projects WHERE project_id = ${projectId}`;
4379+
assert.deepEqual(saved, [
4380+
{ icon: '{"kind":"lucide","name":"folder-code","color":"violet","monogram":"T3"}' },
4381+
]);
4382+
yield* engine.dispatch({
4383+
type: "project.meta.update",
4384+
commandId: CommandId.make("cmd-monogram-clear"),
4385+
projectId,
4386+
projectIcon: null,
4387+
});
4388+
const cleared = yield* sql<{
4389+
readonly icon: string | null;
4390+
}>`SELECT project_icon_json AS icon FROM projection_projects WHERE project_id = ${projectId}`;
4391+
assert.deepEqual(cleared, [{ icon: null }]);
4392+
}),
4393+
);
4394+
43564395
it.effect("re-creating a deleted thread id starts from an empty projection", () =>
43574396
Effect.gen(function* () {
43584397
const engine = yield* OrchestrationEngineService;

‎apps/web/src/components/ProjectFavicon.tsx‎

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useAtomValue } from "@effect/atom-react";
1111
import { projectFaviconUrlAtom } from "../state/assets";
1212
import { deriveProjectIdentity } from "../projectIdentity";
1313
import { projectIconColorClassName } from "../projectIconColors";
14+
import { ProjectMonogram } from "./ProjectMonogram";
1415
import { cn } from "~/lib/utils";
1516

1617
const DynamicIcon = lazy(() =>
@@ -42,6 +43,15 @@ export function ProjectFavicon(input: {
4243
faviconPath: project.faviconPath,
4344
}),
4445
);
46+
if (project.projectIcon?.kind === "lucide" && project.projectIcon.monogram) {
47+
return (
48+
<ProjectMonogram
49+
text={project.projectIcon.monogram}
50+
color={project.projectIcon.color}
51+
className={input.className}
52+
/>
53+
);
54+
}
4555
if (project.projectIcon?.kind === "emoji") {
4656
return (
4757
<ProjectFaviconFallback
@@ -112,49 +122,8 @@ function ProjectFaviconFallback({
112122
}) {
113123
if (projectName && projectName.trim().length > 0) {
114124
const identity = deriveProjectIdentity(projectName);
115-
// Wrapped like the emoji and Lucide branches so the monogram sits where an
116-
// <img> favicon would. Menu items, buttons and the like pull every bare svg
117-
// in with [&_svg]:-mx-0.5 to trim the padding stroke icons carry, and this
118-
// tile has no such padding.
119125
return (
120-
<span
121-
aria-hidden="true"
122-
className={cn("inline-flex size-4 shrink-0 items-center justify-center", className)}
123-
>
124-
<svg
125-
viewBox="0 0 16 16"
126-
className="size-full overflow-hidden rounded-[25%] font-mono select-none"
127-
style={{
128-
backgroundColor: identity.background,
129-
backgroundImage: `linear-gradient(145deg, ${identity.highlight}, ${identity.background} 72%)`,
130-
}}
131-
>
132-
<text
133-
x="8"
134-
y="10.8"
135-
textAnchor="middle"
136-
fill="white"
137-
className="font-mono"
138-
fontSize="8.25"
139-
fontWeight="700"
140-
textLength="12"
141-
lengthAdjust="spacingAndGlyphs"
142-
textRendering="geometricPrecision"
143-
>
144-
{identity.monogram}
145-
</text>
146-
<rect
147-
x="0.25"
148-
y="0.25"
149-
width="15.5"
150-
height="15.5"
151-
rx="3.75"
152-
fill="none"
153-
strokeWidth="0.5"
154-
className="stroke-black/10 dark:stroke-white/10"
155-
/>
156-
</svg>
157-
</span>
126+
<ProjectMonogram text={identity.monogram} color={identity.color} className={className} />
158127
);
159128
}
160129

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { ProjectIconColor } from "@t3tools/contracts";
2+
import { projectIconColorClassName } from "../projectIconColors";
3+
import { cn } from "~/lib/utils";
4+
5+
const monogramSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
6+
7+
export function ProjectMonogram({
8+
text,
9+
color,
10+
className,
11+
}: {
12+
readonly text: string;
13+
readonly color: ProjectIconColor;
14+
readonly className?: string | undefined;
15+
}) {
16+
// Wrapped like the emoji and Lucide branches so the monogram sits where an
17+
// <img> favicon would. Menu items, buttons and the like pull every bare svg
18+
// in with [&_svg]:-mx-0.5 to trim the padding stroke icons carry, and this
19+
// tile has no such padding.
20+
return (
21+
<span
22+
aria-hidden="true"
23+
className={cn("inline-flex size-4 shrink-0 items-center justify-center", className)}
24+
>
25+
<svg
26+
viewBox="0 0 16 16"
27+
className={cn(
28+
"size-full overflow-hidden rounded-[25%] font-mono select-none",
29+
projectIconColorClassName(color),
30+
)}
31+
style={{
32+
backgroundColor: "color-mix(in srgb, currentColor 14%, transparent)",
33+
}}
34+
>
35+
<text
36+
x="8"
37+
y="10.8"
38+
textAnchor="middle"
39+
fill="currentColor"
40+
className="font-mono"
41+
fontSize="8.25"
42+
fontWeight="700"
43+
textLength={Array.from(monogramSegmenter.segment(text)).length === 1 ? 6 : 12}
44+
lengthAdjust="spacingAndGlyphs"
45+
textRendering="geometricPrecision"
46+
>
47+
{text}
48+
</text>
49+
</svg>
50+
</span>
51+
);
52+
}

‎apps/web/src/components/settings/ProjectIconPickerDialog.test.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ import { ProjectIconPickerDialog } from "./ProjectIconPickerDialog";
4141
describe("ProjectIconPickerDialog", () => {
4242
it("shows icons first and selects them for an automatic project", () => {
4343
const markup = renderToStaticMarkup(
44-
<ProjectIconPickerDialog current={null} open onOpenChange={() => {}} onSelect={() => {}} />,
44+
<ProjectIconPickerDialog
45+
current={null}
46+
projectName="Test"
47+
open
48+
onOpenChange={() => {}}
49+
onSelect={() => {}}
50+
/>,
4551
);
4652

4753
expect(markup).toContain('data-current="lucide"');

‎apps/web/src/components/settings/ProjectIconPickerDialog.tsx‎

Lines changed: 87 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import type { ProjectIconColor, ProjectIconOverride } from "@t3tools/contracts";
1+
import * as Schema from "effect/Schema";
2+
import { deriveProjectIdentity } from "../../projectIdentity";
3+
import { ProjectMonogram } from "../ProjectMonogram";
4+
import {
5+
ProjectMonogramText,
6+
type ProjectIconColor,
7+
type ProjectIconOverride,
8+
} from "@t3tools/contracts";
29
import { DynamicIcon, type IconName } from "lucide-react/dynamic";
310
import { useEffect, useMemo, useRef, useState } from "react";
411
import {
@@ -24,7 +31,7 @@ import { ScrollArea } from "../ui/scroll-area";
2431
import { Toggle, ToggleGroup } from "../ui/toggle-group";
2532

2633
const DEFAULT_ICON: IconName = "folder-code";
27-
const DEFAULT_COLOR: ProjectIconColor = "blue";
34+
const isMonogramText = Schema.is(ProjectMonogramText);
2835

2936
function iconLabel(name: string): string {
3037
return name
@@ -35,23 +42,29 @@ function iconLabel(name: string): string {
3542

3643
export function ProjectIconPickerDialog({
3744
current,
45+
projectName,
3846
open,
3947
onOpenChange,
4048
onSelect,
4149
}: {
4250
readonly current: ProjectIconOverride | null;
51+
readonly projectName: string;
4352
readonly open: boolean;
4453
readonly onOpenChange: (open: boolean) => void;
4554
readonly onSelect: (icon: ProjectIconOverride) => void;
4655
}) {
47-
const [mode, setMode] = useState<"lucide" | "emoji">(
48-
current?.kind === "emoji" ? "emoji" : "lucide",
56+
const automatic = deriveProjectIdentity(projectName);
57+
const [mode, setMode] = useState<ProjectIconOverride["kind"] | "monogram">(
58+
current?.kind === "lucide" && current.monogram ? "monogram" : (current?.kind ?? "lucide"),
4959
);
5060
const [iconName, setIconName] = useState<IconName>(
5161
current?.kind === "lucide" ? (current.name as IconName) : DEFAULT_ICON,
5262
);
5363
const [color, setColor] = useState<ProjectIconColor>(
54-
current?.kind === "lucide" ? current.color : DEFAULT_COLOR,
64+
current && current.kind !== "emoji" ? current.color : automatic.color,
65+
);
66+
const [letters, setLetters] = useState(
67+
current?.kind === "lucide" && current.monogram ? current.monogram : automatic.monogram,
5568
);
5669
const [emoji, setEmoji] = useState(current?.kind === "emoji" ? current.emoji : "💻");
5770
const [query, setQuery] = useState("");
@@ -60,21 +73,33 @@ export function ProjectIconPickerDialog({
6073

6174
useEffect(() => {
6275
if (open && !previousOpenRef.current) {
63-
setMode(current?.kind === "emoji" ? "emoji" : "lucide");
76+
setMode(
77+
current?.kind === "lucide" && current.monogram ? "monogram" : (current?.kind ?? "lucide"),
78+
);
6479
setIconName(current?.kind === "lucide" ? (current.name as IconName) : DEFAULT_ICON);
65-
setColor(current?.kind === "lucide" ? current.color : DEFAULT_COLOR);
80+
setColor(current && current.kind !== "emoji" ? current.color : automatic.color);
81+
setLetters(
82+
current?.kind === "lucide" && current.monogram ? current.monogram : automatic.monogram,
83+
);
6684
setEmoji(current?.kind === "emoji" ? current.emoji : "💻");
6785
setQuery("");
6886
setCustomEmoji("");
6987
}
7088
previousOpenRef.current = open;
71-
}, [current, open]);
89+
}, [current, open, automatic.color, automatic.monogram]);
7290

7391
const icons = useMemo(() => filterProjectIconNames(query), [query]);
7492
const selectedColorClassName = projectIconColorClassName(color);
93+
const monogram = letters.normalize("NFKC").trim().toUpperCase();
94+
const validMonogram = isMonogramText(monogram);
7595
const save = () => {
96+
if (mode === "monogram" && !validMonogram) return;
7697
onSelect(
77-
mode === "lucide" ? { kind: "lucide", name: iconName, color } : { kind: "emoji", emoji },
98+
mode === "monogram"
99+
? { kind: "lucide", name: DEFAULT_ICON, monogram, color }
100+
: mode === "lucide"
101+
? { kind: "lucide", name: iconName, color }
102+
: { kind: "emoji", emoji },
78103
);
79104
onOpenChange(false);
80105
};
@@ -84,7 +109,7 @@ export function ProjectIconPickerDialog({
84109
<DialogPopup className="w-full sm:w-[32rem]">
85110
<DialogHeader>
86111
<DialogTitle>Choose project icon</DialogTitle>
87-
<DialogDescription>Pick any Lucide icon and color, or use an emoji.</DialogDescription>
112+
<DialogDescription>Choose an icon, emoji, or monogram.</DialogDescription>
88113
</DialogHeader>
89114
<DialogPanel className="flex min-h-0 flex-col gap-4">
90115
<ToggleGroup
@@ -93,35 +118,39 @@ export function ProjectIconPickerDialog({
93118
value={[mode]}
94119
onValueChange={(next) => {
95120
const value = next[0];
96-
if (value === "lucide" || value === "emoji") setMode(value);
121+
if (value === "lucide" || value === "emoji" || value === "monogram") setMode(value);
97122
}}
98123
>
99124
<Toggle value="lucide">Icons</Toggle>
100125
<Toggle value="emoji">Emoji</Toggle>
126+
<Toggle value="monogram">Monogram</Toggle>
101127
</ToggleGroup>
102128

129+
{mode !== "emoji" ? (
130+
<div>
131+
<div className="mb-2 text-xs font-medium text-muted-foreground">Color</div>
132+
<div className="flex flex-wrap gap-1.5" role="group" aria-label="Icon color">
133+
{PROJECT_ICON_COLORS.map((option) => (
134+
<button
135+
key={option.value}
136+
type="button"
137+
aria-label={option.label}
138+
aria-pressed={color === option.value}
139+
className={cn(
140+
"flex size-6 items-center justify-center rounded-full border border-transparent outline-none focus-visible:ring-2 focus-visible:ring-ring",
141+
color === option.value && "border-foreground/64",
142+
)}
143+
onClick={() => setColor(option.value)}
144+
>
145+
<span className={cn("size-4 rounded-full", option.swatchClassName)} />
146+
</button>
147+
))}
148+
</div>
149+
</div>
150+
) : null}
151+
103152
{mode === "lucide" ? (
104153
<>
105-
<div>
106-
<div className="mb-2 text-xs font-medium text-muted-foreground">Color</div>
107-
<div className="flex flex-wrap gap-1.5" role="group" aria-label="Icon color">
108-
{PROJECT_ICON_COLORS.map((option) => (
109-
<button
110-
key={option.value}
111-
type="button"
112-
aria-label={option.label}
113-
aria-pressed={color === option.value}
114-
className={cn(
115-
"flex size-6 items-center justify-center rounded-full border border-transparent outline-none focus-visible:ring-2 focus-visible:ring-ring",
116-
color === option.value && "border-foreground/64",
117-
)}
118-
onClick={() => setColor(option.value)}
119-
>
120-
<span className={cn("size-4 rounded-full", option.swatchClassName)} />
121-
</button>
122-
))}
123-
</div>
124-
</div>
125154
<Input
126155
type="search"
127156
value={query}
@@ -153,6 +182,30 @@ export function ProjectIconPickerDialog({
153182
<p className="py-8 text-center text-sm text-muted-foreground">No icons found.</p>
154183
) : null}
155184
</>
185+
) : mode === "monogram" ? (
186+
<div className="flex items-center gap-4 py-2">
187+
<ProjectMonogram
188+
text={validMonogram ? monogram : automatic.monogram}
189+
color={color}
190+
className="size-12"
191+
/>
192+
<div className="flex-1 space-y-2">
193+
<label htmlFor="project-monogram" className="text-sm font-medium">
194+
Letters
195+
</label>
196+
<Input
197+
id="project-monogram"
198+
value={letters}
199+
onChange={(event) => setLetters(event.currentTarget.value)}
200+
aria-describedby="project-monogram-hint"
201+
aria-invalid={!validMonogram}
202+
autoComplete="off"
203+
/>
204+
<p id="project-monogram-hint" className="text-xs text-muted-foreground">
205+
One or two letters or numbers.
206+
</p>
207+
</div>
208+
</div>
156209
) : (
157210
<>
158211
<ScrollArea scrollFade className="max-h-64">
@@ -197,7 +250,9 @@ export function ProjectIconPickerDialog({
197250
<Button variant="outline" onClick={() => onOpenChange(false)}>
198251
Cancel
199252
</Button>
200-
<Button onClick={save}>Save icon</Button>
253+
<Button onClick={save} disabled={mode === "monogram" && !validMonogram}>
254+
Save icon
255+
</Button>
201256
</DialogFooter>
202257
</DialogPopup>
203258
</Dialog>

0 commit comments

Comments
 (0)