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" ;
29import { DynamicIcon , type IconName } from "lucide-react/dynamic" ;
310import { useEffect , useMemo , useRef , useState } from "react" ;
411import {
@@ -24,7 +31,7 @@ import { ScrollArea } from "../ui/scroll-area";
2431import { Toggle , ToggleGroup } from "../ui/toggle-group" ;
2532
2633const DEFAULT_ICON : IconName = "folder-code" ;
27- const DEFAULT_COLOR : ProjectIconColor = "blue" ;
34+ const isMonogramText = Schema . is ( ProjectMonogramText ) ;
2835
2936function iconLabel ( name : string ) : string {
3037 return name
@@ -35,23 +42,29 @@ function iconLabel(name: string): string {
3542
3643export 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