1
1
import React from 'react'
2
- import { Button , InputGroup , InputGroupAddon , Input } from 'reactstrap '
2
+ import { Select } from '@oacore/design '
3
3
4
- const SearchField = ( {
5
- size = '' ,
6
- id = 'search-form-field' ,
7
- label = 'Search in CORE' ,
8
- ...fieldProps
9
- } ) => (
10
- < >
11
- < label className = "sr-only" htmlFor = { id } >
12
- { label }
13
- </ label >
14
- < InputGroup size = { size } >
15
- < Input type = "search" id = { id } { ...fieldProps } />
16
- < InputGroupAddon addonType = "append" >
17
- < Button color = "primary" > Search</ Button >
18
- </ InputGroupAddon >
19
- </ InputGroup >
20
- </ >
21
- )
4
+ import styles from './styles.module.css'
5
+
6
+ const options = [
7
+ { id : 1 , icon : '#magnify' , value : 'Option A' } ,
8
+ { id : 2 , icon : '#magnify' , value : 'Option B' } ,
9
+ { id : 3 , icon : '#magnify' , value : 'Option C' } ,
10
+ { id : 4 , icon : '#magnify' , value : 'Option D' } ,
11
+ { id : 5 , icon : '#magnify' , value : 'Option E' } ,
12
+ ]
13
+
14
+ const SelectExample = ( { ...passProps } ) => {
15
+ const [ suggestions , setSuggestions ] = React . useState ( options )
16
+ const [ value , setValue ] = React . useState ( '' )
17
+
18
+ const handleOnChange = data => {
19
+ // eslint-disable-next-line no-console
20
+ console . log ( data )
21
+ // trigger search here
22
+ }
23
+
24
+ const handleOnInput = data => {
25
+ // if id doesn't exists it means user type own text
26
+ // and didn't use suggestion
27
+ if ( ! data . id ) {
28
+ setSuggestions (
29
+ options . slice ( 0 , Math . max ( 0 , options . length - data . value . length ) )
30
+ )
31
+ }
32
+
33
+ setValue ( data . value )
34
+ }
35
+
36
+ return (
37
+ < Select
38
+ id = "search-select"
39
+ value = { value }
40
+ onChange = { handleOnChange }
41
+ onInput = { handleOnInput }
42
+ prependIcon = "#magnify"
43
+ className = { styles [ 'search-box' ] }
44
+ { ...passProps }
45
+ >
46
+ { suggestions . map ( el => (
47
+ < Select . Option key = { el . id } id = { el . id } value = { el . value } icon = { el . icon } >
48
+ { el . value }
49
+ </ Select . Option >
50
+ ) ) }
51
+ </ Select >
52
+ )
53
+ }
22
54
23
55
const SearchForm = ( {
24
56
action,
@@ -28,7 +60,7 @@ const SearchForm = ({
28
60
...fieldProps
29
61
} ) => (
30
62
< form id = { id } action = { action } method = { method } onSubmit = { onSubmit } >
31
- < SearchField id = { `${ id } -field` } size = "lg" { ...fieldProps } />
63
+ < SelectExample id = { `${ id } -field` } { ...fieldProps } />
32
64
</ form >
33
65
)
34
66
0 commit comments