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 1818.env.development.local
1919.env.test.local
2020.env.production.local
21+ .idea
2122
2223npm-debug.log *
2324yarn-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';
99import FieldArray from '../field-array' ;
1010import Link from '../link' ;
1111import PlainText from '../plain-text' ;
12+ import ComboBox from '../combo-box' ;
1213
1314const NullComponent = ( ) => < span > Not implemented</ span > ;
1415
@@ -28,7 +29,8 @@ const mapper = {
2829 [ componentTypes . FIELD_ARRAY ] : FieldArray ,
2930 [ componentTypes . DUAL_LIST_SELECT ] : NullComponent ,
3031 [ componentTypes . SLIDER ] : NullComponent ,
31- 'link' : Link
32+ 'link' : Link ,
33+ 'combo-box' : ComboBox
3234} ;
3335
3436export default mapper ;
Original file line number Diff line number Diff line change 11export * from './checkbox' ;
2+ export * from './combo-box' ;
23export * from './component-mapper' ;
34export * from './field-array' ;
45export * from './link' ;
You can’t perform that action at this time.
0 commit comments