1+ import { ChevronDown } from "lucide-react" ;
2+
13import type { ChannelTemplate } from "@/shared/api/types" ;
24import { cn } from "@/shared/lib/cn" ;
35import { Button } from "@/shared/ui/button" ;
6+ import {
7+ DropdownMenu ,
8+ DropdownMenuContent ,
9+ DropdownMenuRadioGroup ,
10+ DropdownMenuRadioItem ,
11+ DropdownMenuTrigger ,
12+ } from "@/shared/ui/dropdown-menu" ;
413import { Input } from "@/shared/ui/input" ;
514import { Textarea } from "@/shared/ui/textarea" ;
615
@@ -14,6 +23,7 @@ import type { CreateChannelFormState } from "@/features/sidebar/lib/useCreateCha
1423
1524const CREATE_LABEL_OPTIONAL_CLASS =
1625 "ml-1 text-xs font-normal text-muted-foreground/50" ;
26+ const NO_TEMPLATE_VALUE = "__no-template__" ;
1727
1828export const CREATE_CHANNEL_FORM_ID = "create-channel-form" ;
1929
@@ -29,6 +39,9 @@ export function CreateChannelFormFields({
2939 form : CreateChannelFormState ;
3040} ) {
3141 const { channelKind, kindLabel, isCreating } = form ;
42+ const selectedTemplate = form . templates . find (
43+ ( template ) => template . id === form . selectedTemplateId ,
44+ ) ;
3245
3346 return (
3447 < div className = "space-y-5" >
@@ -104,29 +117,59 @@ export function CreateChannelFormFields({
104117 />
105118
106119 { form . templates . length > 0 ? (
107- < div className = "space-y-1.5" >
108- < label
109- className = "text-sm font-medium text-foreground"
110- htmlFor = "create-channel-template"
111- >
120+ < div
121+ className = { cn (
122+ "flex min-h-12 items-center justify-between gap-4 rounded-xl border border-input bg-background px-3 py-3" ,
123+ isCreating && "opacity-50" ,
124+ ) }
125+ >
126+ < span className = "text-sm font-medium text-foreground" >
112127 Template
113128 < span className = { CREATE_LABEL_OPTIONAL_CLASS } > Optional</ span >
114- </ label >
115- < select
116- className = "flex min-h-11 w-full rounded-xl border border-input bg-muted/40 px-3 py-2 text-sm text-muted-foreground/55 shadow-none transition-colors duration-150 ease-out hover:border-muted-foreground/40 focus:border-muted-foreground/50 focus:text-foreground focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50"
117- data-testid = "create-channel-template"
118- disabled = { isCreating }
119- id = "create-channel-template"
120- onChange = { ( event ) => form . handleTemplateChange ( event . target . value ) }
121- value = { form . selectedTemplateId ?? "" }
122- >
123- < option value = "" > No template</ option >
124- { form . templates . map ( ( template : ChannelTemplate ) => (
125- < option key = { template . id } value = { template . id } >
126- { template . name }
127- </ option >
128- ) ) }
129- </ select >
129+ </ span >
130+ < DropdownMenu modal = { false } >
131+ < DropdownMenuTrigger asChild >
132+ < Button
133+ aria-label = { `Template: ${ selectedTemplate ?. name ?? "No template" } ` }
134+ className = "-mr-2.5 ml-auto h-9 min-w-0 max-w-[60%] justify-end px-2.5 text-right text-sm font-medium text-foreground hover:bg-muted/50"
135+ data-testid = "create-channel-template"
136+ disabled = { isCreating }
137+ id = "create-channel-template"
138+ type = "button"
139+ variant = "ghost"
140+ >
141+ < span className = "truncate text-right" >
142+ { selectedTemplate ?. name ?? "No template" }
143+ </ span >
144+ < ChevronDown className = "size-4 shrink-0 text-muted-foreground/70" />
145+ </ Button >
146+ </ DropdownMenuTrigger >
147+ < DropdownMenuContent
148+ align = "end"
149+ onCloseAutoFocus = { ( event ) => event . preventDefault ( ) }
150+ style = { {
151+ minWidth : "var(--radix-dropdown-menu-trigger-width)" ,
152+ } }
153+ >
154+ < DropdownMenuRadioGroup
155+ onValueChange = { ( templateId ) =>
156+ form . handleTemplateChange (
157+ templateId === NO_TEMPLATE_VALUE ? "" : templateId ,
158+ )
159+ }
160+ value = { form . selectedTemplateId ?? NO_TEMPLATE_VALUE }
161+ >
162+ < DropdownMenuRadioItem value = { NO_TEMPLATE_VALUE } >
163+ No template
164+ </ DropdownMenuRadioItem >
165+ { form . templates . map ( ( template : ChannelTemplate ) => (
166+ < DropdownMenuRadioItem key = { template . id } value = { template . id } >
167+ { template . name }
168+ </ DropdownMenuRadioItem >
169+ ) ) }
170+ </ DropdownMenuRadioGroup >
171+ </ DropdownMenuContent >
172+ </ DropdownMenu >
130173 </ div >
131174 ) : null }
132175
0 commit comments