1
1
import React , { Component , createRef , Fragment } from 'react' ;
2
2
import isEqual from 'lodash/isEqual' ;
3
3
import './react-select.scss' ;
4
+ import PropTypes from 'prop-types' ;
4
5
5
- import NewSelect from '@data-driven-forms/common/src/select' ;
6
+ import DataDrivenSelect from '@data-driven-forms/common/src/select' ;
6
7
import { DropdownButton } from 'patternfly-react' ;
7
8
import fnToString from '@data-driven-forms/common/src/utils/fn-to-string' ;
8
9
import clsx from 'clsx' ;
9
10
import Option from './option' ;
10
11
import DropdownIndicator from './dropdown-indicator' ;
11
12
import ClearIndicator from './clear-indicator' ;
12
13
import './react-select.scss' ;
14
+ import { optionsPropType } from '@data-driven-forms/common/src/prop-types-templates' ;
13
15
14
16
const getDropdownText = ( value , placeholder , options ) => {
15
17
if ( Array . isArray ( value ) ) {
@@ -55,6 +57,10 @@ class SearchInput extends Component {
55
57
56
58
}
57
59
60
+ SearchInput . propTypes = {
61
+ value : PropTypes . any ,
62
+ } ;
63
+
58
64
const SelectTitle = ( { title, classNamePrefix, isClearable, value, onClear, isFetching, isDisabled } ) => (
59
65
< Fragment >
60
66
< span key = "searchable-select-value-label" className = { `${ classNamePrefix } -value` } > { title } </ span >
@@ -77,6 +83,16 @@ const SelectTitle = ({ title, classNamePrefix, isClearable, value, onClear, isFe
77
83
</ Fragment >
78
84
) ;
79
85
86
+ SelectTitle . propTypes = {
87
+ title : PropTypes . string . isRequired ,
88
+ classNamePrefix : PropTypes . string ,
89
+ isClearable : PropTypes . bool ,
90
+ value : PropTypes . any ,
91
+ onClear : PropTypes . func ,
92
+ isFetching : PropTypes . bool ,
93
+ isDisabled : PropTypes . bool ,
94
+ } ;
95
+
80
96
class Select extends Component { constructor ( props ) {
81
97
super ( props ) ;
82
98
this . state = {
@@ -171,7 +187,7 @@ class Select extends Component { constructor(props){
171
187
disabled = { props . isDisabled }
172
188
noCaret
173
189
open = { isOpen }
174
- id = { props . id || props . input . name }
190
+ id = { props . id || input . name }
175
191
title = { < SelectTitle
176
192
isDisabled = { props . isDisabled }
177
193
isFetching = { isFetching }
@@ -185,7 +201,7 @@ class Select extends Component { constructor(props){
185
201
'is-empty' : isPlaceholder ,
186
202
} ) } >
187
203
{ isOpen &&
188
- < NewSelect
204
+ < DataDrivenSelect
189
205
isFetching = { isFetching }
190
206
input = { searchableInput }
191
207
{ ...props }
@@ -216,7 +232,7 @@ class Select extends Component { constructor(props){
216
232
}
217
233
218
234
return (
219
- < NewSelect
235
+ < DataDrivenSelect
220
236
{ ...this . props }
221
237
isFetching = { isFetching }
222
238
options = { options }
@@ -237,4 +253,15 @@ Select.defaultProps = {
237
253
placeholder : 'Search...' ,
238
254
} ;
239
255
256
+ Select . propTypes = {
257
+ input : PropTypes . shape ( {
258
+ name : PropTypes . string . isRequired ,
259
+ onChange : PropTypes . func . isRequired ,
260
+ value : PropTypes . any ,
261
+ } ) . isRequired ,
262
+ classNamePrefix : PropTypes . string ,
263
+ loadOptions : PropTypes . func ,
264
+ options : optionsPropType ,
265
+ } ;
266
+
240
267
export default Select ;
0 commit comments