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'
12+ import { SelectOptions } from '@hackjunction/shared'
1413
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- }
14+ /* [x] Removed menu component
15+ [x] removed NoOptions component */
3016
3117const inputComponent = ( { inputRef, ...props } ) => (
3218 < div ref = { inputRef } { ...props } />
@@ -52,16 +38,19 @@ const Control = props => {
5238 return (
5339 < TextField
5440 fullWidth
55- InputProps = { {
56- inputComponent,
57- inputProps : {
58- className : 'flex p-0 h-auto' ,
59- ref : innerRef ,
60- children,
61- ...innerProps ,
41+ variant = "standard"
42+ { ...TextFieldProps }
43+ slotProps = { {
44+ input : {
45+ inputComponent,
46+ inputProps : {
47+ sx : { display : 'flex' , p : 0 , height : 'auto' } ,
48+ ref : innerRef ,
49+ children,
50+ ...innerProps ,
51+ } ,
6252 } ,
6353 } }
64- { ...TextFieldProps }
6554 />
6655 )
6756}
@@ -116,56 +105,57 @@ Option.propTypes = {
116105 isSelected : PropTypes . bool . isRequired ,
117106}
118107
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- // )
108+ const Placeholder = props => (
109+ < Typography
110+ color = "textSecondary"
111+ sx = { { position : 'absolute' , left : 2 , bottom : 6 , fontSize : 16 } }
112+ { ...props . innerProps }
113+ >
114+ { props . children }
115+ </ Typography >
116+ )
128117
129- // Placeholder.propTypes = {
130- // children: PropTypes.node,
131- // innerProps: PropTypes.object,
132- // selectProps: PropTypes.object.isRequired,
133- // }
118+ Placeholder . propTypes = {
119+ children : PropTypes . node ,
120+ innerProps : PropTypes . object ,
121+ selectProps : PropTypes . object . isRequired ,
122+ }
134123
135124const SingleValue = props => (
136- // <Typography
137- // className={props.selectProps.classes.singleValue}
138- // {...props.innerProps}
139- // >
140- < div > { props . children } </ div >
125+ < Typography { ...props . innerProps } > { props . children } </ Typography >
141126)
142- // {/* </Typography> */}
143127
144128SingleValue . propTypes = {
145129 children : PropTypes . node ,
146130 innerProps : PropTypes . any ,
147131 selectProps : PropTypes . object . isRequired ,
148132}
149133
150- // const ValueContainer = props => (
151- // <div className={props.selectProps.classes.valueContainer}>
152- // {props.children}
153- // </div>
154- // )
134+ const ValueContainer = props => (
135+ < Box
136+ sx = { {
137+ display : 'flex' ,
138+ flexWrap : 'wrap' ,
139+ flex : 1 ,
140+ alignItems : 'center' ,
141+ overflow : 'hidden' ,
142+ } }
143+ >
144+ { props . children }
145+ </ Box >
146+ )
155147
156- // ValueContainer.propTypes = {
157- // children: PropTypes.node,
158- // selectProps: PropTypes.object.isRequired,
159- // }
148+ ValueContainer . propTypes = {
149+ children : PropTypes . node ,
150+ selectProps : PropTypes . object . isRequired ,
151+ }
160152
161153const MultiValue = props => (
162154 < Chip
163155 avatar = { props . data . icon ? < Avatar src = { props . data . icon } /> : null }
164156 tabIndex = { - 1 }
165157 label = { props . children }
166- className = { clsx ( props . selectProps . classes ?. chip , {
167- [ props . selectProps . classes ?. chipFocused ] : props . isFocused ,
168- } ) }
158+ sx = { { margin : '0.25rem 0.125rem' } }
169159 onDelete = { props . removeProps . onClick }
170160 deleteIcon = { < CancelIcon { ...props . removeProps } /> }
171161 />
@@ -182,31 +172,14 @@ MultiValue.propTypes = {
182172 selectProps : PropTypes . object . isRequired ,
183173}
184174
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-
175+ //https://react-select.com/components
201176const components = {
202177 Control,
203- Menu,
204178 MultiValue,
205- NoOptionsMessage,
206179 Option,
207- // Placeholder,
180+ Placeholder,
208181 SingleValue,
209- // ValueContainer,
182+ ValueContainer,
210183}
211184
212185const IntegrationReactSelect = ( {
@@ -220,23 +193,12 @@ const IntegrationReactSelect = ({
220193 onBlur,
221194 onChange,
222195 options = [ ] ,
223- // placeholder,
196+ placeholder,
224197 value,
225198 allowCreate = false ,
226199} ) => {
227- // const theme = useTheme()
228200 const inputId = 'select-' + name
229201
230- // const selectStyles = {
231- // input: base => ({
232- // ...base,
233- // color: theme.palette.text.primary,
234- // '& input': {
235- // font: 'inherit',
236- // },
237- // }),
238- // }
239-
240202 const _options = useMemo ( ( ) => {
241203 if ( Array . isArray ( options ) ) {
242204 return options
@@ -335,7 +297,6 @@ const IntegrationReactSelect = ({
335297 const SelectProps = {
336298 isDisabled : disabled ,
337299 autoFocus,
338- // styles: selectStyles,
339300 inputId,
340301 TextFieldProps : {
341302 label,
@@ -344,7 +305,7 @@ const IntegrationReactSelect = ({
344305 shrink : true ,
345306 } ,
346307 } ,
347- // placeholder,
308+ placeholder,
348309 options : _options ,
349310 components,
350311 value : transformedInput ,
@@ -356,13 +317,13 @@ const IntegrationReactSelect = ({
356317 }
357318
358319 return (
359- < div className = "flex-grow" >
320+ < Box sx = { { flexGrow : 1 } } >
360321 { allowCreate ? (
361322 < CreatableSelect { ...SelectProps } />
362323 ) : (
363324 < Select { ...SelectProps } />
364325 ) }
365- </ div >
326+ </ Box >
366327 )
367328}
368329
@@ -378,7 +339,7 @@ IntegrationReactSelect.propTypes = {
378339 onChange : PropTypes . func . isRequired ,
379340 options : PropTypes . oneOfType ( [ PropTypes . array , PropTypes . string ] )
380341 . isRequired ,
381- // placeholder: PropTypes.string,
342+ placeholder : PropTypes . string ,
382343 value : PropTypes . any ,
383344 allowCreate : PropTypes . bool ,
384345}
0 commit comments