1
+ import { useState } from "react" ;
1
2
import type { JSX } from "react" ;
2
3
3
4
import { useComboboxFilter , useId } from "@lib-hooks" ;
@@ -7,10 +8,35 @@ import type { TComboboxProps } from "@lib-components";
7
8
import { OptionLayoutTemplate } from "../../templates" ;
8
9
import useClasses from "./styles" ;
9
10
11
+ const options = [
12
+ { children : "Alligator" , value : "Alligator" } ,
13
+ { children : "Bee" , value : "Bee" } ,
14
+ { children : "Bird" , value : "Bird" } ,
15
+ { children : "Cheetah" , disabled : true , value : "Cheetah" } ,
16
+ { children : "Dog" , value : "Dog" } ,
17
+ { children : "Dolphin" , value : "Dolphin" } ,
18
+ { children : "Ferret" , value : "Ferret" } ,
19
+ { children : "Firefly" , value : "Firefly" } ,
20
+ { children : "Fish" , value : "Fish" } ,
21
+ { children : "Goat" , value : "Goat" } ,
22
+ { children : "Horse" , value : "Horse" } ,
23
+ { children : "Lion" , value : "Lion" } ,
24
+ ] ;
25
+
10
26
type TProps = { } ;
11
27
12
28
export default function OptionTrace ( { } : TProps ) : JSX . Element {
13
29
const classes = useClasses ( ) ;
30
+ const comboId = useId ( ) ;
31
+ const [ query , setQuery ] = useState < string > ( "" ) ;
32
+
33
+ const children = useComboboxFilter ( query , options , {
34
+ noOptionsMessage : "No animals match your search." ,
35
+ } ) ;
36
+ const onOptionSelect : TComboboxProps [ "onOptionSelect" ] = ( e , data ) => {
37
+ setQuery ( data . optionText ?? "" ) ;
38
+ } ;
39
+
14
40
return (
15
41
< OptionLayoutTemplate
16
42
header = "Trace a Word"
@@ -19,6 +45,19 @@ export default function OptionTrace({}: TProps): JSX.Element {
19
45
isLoading = { false }
20
46
disableClick = { false }
21
47
buttonLabel = "Construct trace tree"
22
- > </ OptionLayoutTemplate >
48
+ >
49
+ < Flex direction = "column" gap = "SNudge" >
50
+ < label id = { comboId } > Search</ label >
51
+ < Combobox
52
+ onOptionSelect = { onOptionSelect }
53
+ aria-labelledby = { comboId }
54
+ placeholder = "Select a known word from the dictionary"
55
+ onChange = { ( ev ) => setQuery ( ev . target . value ) }
56
+ value = { query }
57
+ >
58
+ { children }
59
+ </ Combobox >
60
+ </ Flex >
61
+ </ OptionLayoutTemplate >
23
62
) ;
24
63
}
0 commit comments