11import React , { useMemo , useCallback } from 'react'
22import PropTypes from 'prop-types'
3- import clsx from 'clsx'
43import Select from 'react-select'
54import CreatableSelect from 'react-select/creatable'
6- import { SelectOptions } from '@hackjunction/shared'
75import Typography from '@mui/material/Typography'
86import TextField from '@mui/material/TextField'
9- import Paper from '@mui/material/Paper'
107import Chip from '@mui/material/Chip'
118import Avatar from '@mui/material/Avatar'
129import MenuItem from '@mui/material/MenuItem'
10+ import Box from '@mui/material/Box'
1311import CancelIcon from '@mui/icons-material/Cancel'
14-
15- const NoOptionsMessage = props => (
16- // <Typography
17- // color="textSecondary"
18- // className={props.selectProps.classes.noOptionsMessage}
19- // {...props.innerProps}
20- // >
21- < div > { props . children } </ div >
22- )
23- // {/* </Typography> */}
24-
25- NoOptionsMessage . propTypes = {
26- children : PropTypes . node ,
27- innerProps : PropTypes . object . isRequired ,
28- selectProps : PropTypes . object . isRequired ,
29- }
12+ import { SelectOptions } from '@hackjunction/shared'
3013
3114const inputComponent = ( { inputRef, ...props } ) => (
3215 < div ref = { inputRef } { ...props } />
@@ -52,16 +35,19 @@ const Control = props => {
5235 return (
5336 < TextField
5437 fullWidth
55- InputProps = { {
56- inputComponent,
57- inputProps : {
58- className : 'flex p-0 h-auto' ,
59- ref : innerRef ,
60- children,
61- ...innerProps ,
38+ variant = "standard"
39+ { ...TextFieldProps }
40+ slotProps = { {
41+ input : {
42+ inputComponent,
43+ inputProps : {
44+ sx : { display : 'flex' , p : 0 , height : 'auto' } ,
45+ ref : innerRef ,
46+ children,
47+ ...innerProps ,
48+ } ,
6249 } ,
6350 } }
64- { ...TextFieldProps }
6551 />
6652 )
6753}
@@ -116,56 +102,57 @@ Option.propTypes = {
116102 isSelected : PropTypes . bool . isRequired ,
117103}
118104
119- // const Placeholder = props => (
120- // <Typography
121- // color="textSecondary"
122- // className={props.selectProps.classes.placeholder }
123- // {...props.innerProps}
124- // >
125- // {props.children}
126- // </Typography>
127- // )
105+ const Placeholder = props => (
106+ < Typography
107+ color = "textSecondary"
108+ sx = { { position : 'absolute' , left : 2 , bottom : 6 , fontSize : 16 } }
109+ { ...props . innerProps }
110+ >
111+ { props . children }
112+ </ Typography >
113+ )
128114
129- // Placeholder.propTypes = {
130- // children: PropTypes.node,
131- // innerProps: PropTypes.object,
132- // selectProps: PropTypes.object.isRequired,
133- // }
115+ Placeholder . propTypes = {
116+ children : PropTypes . node ,
117+ innerProps : PropTypes . object ,
118+ selectProps : PropTypes . object . isRequired ,
119+ }
134120
135121const SingleValue = props => (
136- // <Typography
137- // className={props.selectProps.classes.singleValue}
138- // {...props.innerProps}
139- // >
140- < div > { props . children } </ div >
122+ < Typography { ...props . innerProps } > { props . children } </ Typography >
141123)
142- // {/* </Typography> */}
143124
144125SingleValue . propTypes = {
145126 children : PropTypes . node ,
146127 innerProps : PropTypes . any ,
147128 selectProps : PropTypes . object . isRequired ,
148129}
149130
150- // const ValueContainer = props => (
151- // <div className={props.selectProps.classes.valueContainer}>
152- // {props.children}
153- // </div>
154- // )
131+ const ValueContainer = props => (
132+ < Box
133+ sx = { {
134+ display : 'flex' ,
135+ flexWrap : 'wrap' ,
136+ flex : 1 ,
137+ alignItems : 'center' ,
138+ overflow : 'hidden' ,
139+ } }
140+ >
141+ { props . children }
142+ </ Box >
143+ )
155144
156- // ValueContainer.propTypes = {
157- // children: PropTypes.node,
158- // selectProps: PropTypes.object.isRequired,
159- // }
145+ ValueContainer . propTypes = {
146+ children : PropTypes . node ,
147+ selectProps : PropTypes . object . isRequired ,
148+ }
160149
161150const MultiValue = props => (
162151 < Chip
163152 avatar = { props . data . icon ? < Avatar src = { props . data . icon } /> : null }
164153 tabIndex = { - 1 }
165154 label = { props . children }
166- className = { clsx ( props . selectProps . classes ?. chip , {
167- [ props . selectProps . classes ?. chipFocused ] : props . isFocused ,
168- } ) }
155+ sx = { { margin : '0.25rem 0.125rem' } }
169156 onDelete = { props . removeProps . onClick }
170157 deleteIcon = { < CancelIcon { ...props . removeProps } /> }
171158 />
@@ -182,31 +169,14 @@ MultiValue.propTypes = {
182169 selectProps : PropTypes . object . isRequired ,
183170}
184171
185- const Menu = props => (
186- // <Paper
187- // square
188- // className={props.selectProps.classes.paper}
189- // {...props.innerProps}
190- // >
191- < div > { props . children } </ div >
192- )
193-
194- // {/* </Paper> */}
195- Menu . propTypes = {
196- children : PropTypes . element . isRequired ,
197- innerProps : PropTypes . object . isRequired ,
198- selectProps : PropTypes . object . isRequired ,
199- }
200-
172+ //https://react-select.com/components
201173const components = {
202174 Control,
203- Menu,
204175 MultiValue,
205- NoOptionsMessage,
206176 Option,
207- // Placeholder,
177+ Placeholder,
208178 SingleValue,
209- // ValueContainer,
179+ ValueContainer,
210180}
211181
212182const IntegrationReactSelect = ( {
@@ -220,23 +190,12 @@ const IntegrationReactSelect = ({
220190 onBlur,
221191 onChange,
222192 options = [ ] ,
223- // placeholder,
193+ placeholder,
224194 value,
225195 allowCreate = false ,
226196} ) => {
227- // const theme = useTheme()
228197 const inputId = 'select-' + name
229198
230- // const selectStyles = {
231- // input: base => ({
232- // ...base,
233- // color: theme.palette.text.primary,
234- // '& input': {
235- // font: 'inherit',
236- // },
237- // }),
238- // }
239-
240199 const _options = useMemo ( ( ) => {
241200 if ( Array . isArray ( options ) ) {
242201 return options
@@ -335,7 +294,6 @@ const IntegrationReactSelect = ({
335294 const SelectProps = {
336295 isDisabled : disabled ,
337296 autoFocus,
338- // styles: selectStyles,
339297 inputId,
340298 TextFieldProps : {
341299 label,
@@ -344,7 +302,7 @@ const IntegrationReactSelect = ({
344302 shrink : true ,
345303 } ,
346304 } ,
347- // placeholder,
305+ placeholder,
348306 options : _options ,
349307 components,
350308 value : transformedInput ,
@@ -356,13 +314,13 @@ const IntegrationReactSelect = ({
356314 }
357315
358316 return (
359- < div className = "flex-grow" >
317+ < Box sx = { { flexGrow : 1 } } >
360318 { allowCreate ? (
361319 < CreatableSelect { ...SelectProps } />
362320 ) : (
363321 < Select { ...SelectProps } />
364322 ) }
365- </ div >
323+ </ Box >
366324 )
367325}
368326
@@ -378,7 +336,7 @@ IntegrationReactSelect.propTypes = {
378336 onChange : PropTypes . func . isRequired ,
379337 options : PropTypes . oneOfType ( [ PropTypes . array , PropTypes . string ] )
380338 . isRequired ,
381- // placeholder: PropTypes.string,
339+ placeholder : PropTypes . string ,
382340 value : PropTypes . any ,
383341 allowCreate : PropTypes . bool ,
384342}
0 commit comments