File tree Expand file tree Collapse file tree 5 files changed +75
-1
lines changed
packages/evergreen-component-mapper/src Expand file tree Collapse file tree 5 files changed +75
-1
lines changed Original file line number Diff line number Diff line change 18
18
.env.development.local
19
19
.env.test.local
20
20
.env.production.local
21
+ .idea
21
22
22
23
npm-debug.log *
23
24
yarn-debug.log *
Original file line number Diff line number Diff line change
1
+ import React , { useMemo } from 'react' ;
2
+
3
+ import { Combobox as EvergreenCombobox , FormField } from 'evergreen-ui' ;
4
+
5
+ import useFieldApi from '@data-driven-forms/react-form-renderer/use-field-api' ;
6
+ import {
7
+ AnyObject ,
8
+ UseFieldApiProps ,
9
+ } from '@data-driven-forms/react-form-renderer' ;
10
+
11
+ export interface ComboBoxItem extends AnyObject {
12
+ value ?: any ;
13
+ label : string ;
14
+ }
15
+
16
+ export interface ComboBoxProps extends UseFieldApiProps < string > {
17
+ name : string ;
18
+ isRequired ?: boolean ;
19
+ options : ComboBoxItem [ ] ;
20
+ }
21
+
22
+ const ComboBox : React . FC < ComboBoxProps > = ( props ) => {
23
+ const {
24
+ id,
25
+ input,
26
+ meta,
27
+ isDisabled,
28
+ options,
29
+ isRequired,
30
+ label,
31
+ description,
32
+ inputProps,
33
+ ...rest
34
+ } = useFieldApi ( props ) ;
35
+
36
+ const selectedItem = useMemo ( ( ) => {
37
+ return options . find ( ( item : ComboBoxItem ) => item . value === input . value ) ;
38
+ } , [ input . value , options ] ) ;
39
+
40
+ return (
41
+ < FormField
42
+ labelFor = { id }
43
+ label = { label }
44
+ description = { description }
45
+ isRequired = { isRequired }
46
+ validationMessage = { meta . error }
47
+ marginBottom = { 24 }
48
+ >
49
+ < EvergreenCombobox
50
+ id = { id }
51
+ width = "100%"
52
+ selectedItem = { selectedItem }
53
+ onChange = { ( item ?: ComboBoxItem ) => input . onChange ( item ?. value ) }
54
+ disabled = { isDisabled }
55
+ items = { options }
56
+ itemToString = { ( item ?: ComboBoxItem ) => ( item ? item . label : '' ) }
57
+ inputProps = { {
58
+ required : isRequired ,
59
+ isInvalid : Boolean ( meta . error ) ,
60
+ ...inputProps ,
61
+ } }
62
+ { ...rest }
63
+ />
64
+ </ FormField >
65
+ ) ;
66
+ } ;
67
+
68
+ export default ComboBox ;
Original file line number Diff line number Diff line change
1
+ export { default } from './combo-box' ;
2
+ export * from './combo-box' ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import Tabs from '../tabs';
9
9
import FieldArray from '../field-array' ;
10
10
import Link from '../link' ;
11
11
import PlainText from '../plain-text' ;
12
+ import ComboBox from '../combo-box' ;
12
13
13
14
const NullComponent = ( ) => < span > Not implemented</ span > ;
14
15
@@ -28,7 +29,8 @@ const mapper = {
28
29
[ componentTypes . FIELD_ARRAY ] : FieldArray ,
29
30
[ componentTypes . DUAL_LIST_SELECT ] : NullComponent ,
30
31
[ componentTypes . SLIDER ] : NullComponent ,
31
- 'link' : Link
32
+ 'link' : Link ,
33
+ 'combo-box' : ComboBox
32
34
} ;
33
35
34
36
export default mapper ;
Original file line number Diff line number Diff line change 1
1
export * from './checkbox' ;
2
+ export * from './combo-box' ;
2
3
export * from './component-mapper' ;
3
4
export * from './field-array' ;
4
5
export * from './link' ;
You can’t perform that action at this time.
0 commit comments