11import React from 'react'
22
3- import { CheckIcon } from '@phosphor-icons/react'
3+ import { CheckIcon , UserIcon } from '@phosphor-icons/react'
44
55import {
66 Button ,
@@ -13,6 +13,10 @@ import {
1313 ComboboxProvider ,
1414 ComboboxTrigger ,
1515 ComboboxTriggerMultiValue ,
16+ InputGroup ,
17+ InputGroupAddon ,
18+ InputGroupControl ,
19+ InputGroupText ,
1620 Typography ,
1721} from '@genseki/react/v2'
1822
@@ -205,6 +209,70 @@ function ControlledComboboxSingle() {
205209 )
206210}
207211
212+ function ControlledInputGroupComboboxSingle ( ) {
213+ const [ value , setValue ] = React . useState < string [ ] > ( [ ] )
214+ const [ open , setOpen ] = React . useState ( false )
215+
216+ return (
217+ < div className = "space-y-4" >
218+ < div className = "flex" >
219+ < InputGroup >
220+ < ComboboxProvider
221+ items = { languages }
222+ open = { open }
223+ onOpenChange = { setOpen }
224+ value = { value ?? undefined }
225+ onValueChange = { setValue }
226+ >
227+ < InputGroupAddon align = "inline-start" >
228+ < InputGroupText >
229+ < UserIcon />
230+ </ InputGroupText >
231+ </ InputGroupAddon >
232+ < InputGroupControl >
233+ < ComboboxTrigger >
234+ < div className = "py-4 px-6" >
235+ < Typography > { value || 'Please select item' } </ Typography >
236+ </ div >
237+ </ ComboboxTrigger >
238+ </ InputGroupControl >
239+ < ComboboxContent >
240+ < ComboboxCommandInput />
241+ < ComboboxCommandEmpty > No language found.</ ComboboxCommandEmpty >
242+ < ComboboxCommandList >
243+ < ComboboxCommandGroup >
244+ { ( { items } ) => {
245+ return items . map ( ( language ) => (
246+ < ComboboxCommandItem
247+ key = { language . value }
248+ value = { language . value }
249+ label = { language . label }
250+ />
251+ ) )
252+ } }
253+ </ ComboboxCommandGroup >
254+ </ ComboboxCommandList >
255+ </ ComboboxContent >
256+ </ ComboboxProvider >
257+ </ InputGroup >
258+ </ div >
259+ < div className = "flex gap-2 items-center" >
260+ < Typography type = "caption" className = "text-muted-foreground" >
261+ Selected: { value . join ( ', ' ) || 'None' }
262+ </ Typography >
263+ < div className = "inline-flex gap-x-4" >
264+ < Button size = "sm" variant = "outline" onClick = { ( ) => setValue ( [ '' ] ) } >
265+ Clear
266+ </ Button >
267+ < Button size = "sm" variant = "outline" onClick = { ( ) => setValue ( [ 'typescript' ] ) } >
268+ TypeScript
269+ </ Button >
270+ </ div >
271+ </ div >
272+ </ div >
273+ )
274+ }
275+
208276// Custom Trigger Combobox Example
209277function CustomTriggerComboboxMultiple ( ) {
210278 return (
@@ -326,6 +394,18 @@ export function ComboboxSection() {
326394 </ div >
327395 </ PlaygroundCard >
328396
397+ < PlaygroundCard
398+ title = "Input group controlled Combobox (Single selection)"
399+ categoryTitle = "Component"
400+ >
401+ < Typography type = "body" className = "text-muted-foreground mb-4" >
402+ A controlled combobox with input group.
403+ </ Typography >
404+ < div className = "p-4 bg-background w-full rounded-lg" >
405+ < ControlledInputGroupComboboxSingle />
406+ </ div >
407+ </ PlaygroundCard >
408+
329409 < PlaygroundCard title = "Custom Trigger (Multiple selection)" categoryTitle = "Component" >
330410 < Typography type = "body" className = "text-muted-foreground mb-4" >
331411 A combobox with a custom trigger using a render prop.
0 commit comments