11import React , { FC , Fragment , ReactNode } from 'react' ;
22import Select , { components } from 'react-select' ;
33import { IndicatorProps } from 'react-select/lib/components/indicators' ;
4+ import { OptionProps } from 'react-select/lib/components/Option' ;
45import { Styles } from 'react-select/lib/styles' ;
5- import { intersectionWith , filter , includes } from 'lodash' ;
66import { types } from '@polymathnetwork/new-shared' ;
77import {
88 FormikProxy ,
@@ -21,20 +21,22 @@ import { SvgPax } from '~/images/icons/pax';
2121import { withTheme , ThemeInterface , styled } from '~/styles' ;
2222import { Box } from '~/components/Box' ;
2323import { Icon } from '~/components/Icon' ;
24+ import { TooltipPrimary } from '~/components/TooltipPrimary' ;
2425import { InputProps } from '~/components/inputs/types' ;
2526import { Label } from './Label' ;
2627import * as sc from './styles' ;
2728
2829interface OptionType {
2930 value : types . Tokens ;
3031 label : ReactNode ;
32+ isDisabled ?: boolean ;
3133}
3234
3335type Value = types . Tokens | types . Tokens [ ] ;
3436
3537interface ExternalProps extends EnhancedComponentProps < Value > {
3638 theme : ThemeInterface ;
37- options : types . Tokens [ ] ;
39+ options : OptionType [ ] ;
3840 placeholder ?: string ;
3941}
4042
@@ -88,11 +90,12 @@ export const CURRENCY_OPTIONS: OptionType[] = [
8890interface SelectProps
8991 extends Pick < InputProps , 'onChange' | 'error' | 'name' | 'autoComplete' > {
9092 theme : ThemeInterface ;
91- options : types . Tokens [ ] ;
93+ options : OptionType [ ] ;
9294 value : types . Tokens | types . Tokens [ ] ;
9395 // Override because ReactSelect does not provide the event
9496 onBlur : ( ) => void ;
9597 placeholder ?: string ;
98+ disabledOptionText ?: string ;
9699}
97100
98101const getStyles = ( theme : ThemeInterface ) : Styles => ( {
@@ -186,6 +189,19 @@ const ClearIndicator: FC<CustomIndicatorProps> = props => {
186189 ) ;
187190} ;
188191
192+ const Option : FC < OptionProps < OptionType > > = ( { children, ...props } ) => {
193+ return (
194+ < components . Option { ...props } >
195+ { children }
196+ { props . isDisabled && props . selectProps . disabledOptionText && (
197+ < TooltipPrimary boundariesElement = "viewport" >
198+ { props . selectProps . disabledOptionText }
199+ </ TooltipPrimary >
200+ ) }
201+ </ components . Option >
202+ ) ;
203+ } ;
204+
189205interface SelectValueProps {
190206 label : ReactNode ;
191207 value : types . Tokens ;
@@ -253,13 +269,12 @@ class CurrencySelectPrimitiveBase extends React.Component<SelectProps> {
253269 public render ( ) {
254270 const { value, options, onChange, onBlur, theme, ...rest } = this . props ;
255271
256- const filteredOptions = intersectionWith (
257- CURRENCY_OPTIONS ,
258- options ,
259- ( currency , symbol ) => {
260- return currency . value === symbol ;
261- }
262- ) ;
272+ const mergedOptions = options . map ( option => {
273+ return {
274+ ...CURRENCY_OPTIONS . find ( currency => option . value === currency . value ) ,
275+ ...option ,
276+ } ;
277+ } ) ;
263278
264279 const valueIsArray = Array . isArray ( value ) ;
265280 let arrayValue : types . Tokens [ ] ;
@@ -270,8 +285,8 @@ class CurrencySelectPrimitiveBase extends React.Component<SelectProps> {
270285 arrayValue = value ;
271286 }
272287
273- const selectedValues = filter ( filteredOptions , ( { value : currencyType } ) =>
274- includes ( arrayValue , currencyType )
288+ const selectedValues = mergedOptions . filter ( ( { value : currencyType } ) =>
289+ arrayValue . includes ( currencyType )
275290 ) ;
276291
277292 return (
@@ -287,16 +302,17 @@ class CurrencySelectPrimitiveBase extends React.Component<SelectProps> {
287302 DropdownIndicator,
288303 ClearIndicator,
289304 IndicatorSeparator : null ,
305+ Option,
290306 } }
291- options = { filteredOptions }
307+ options = { mergedOptions }
292308 value = { selectedValues }
293309 onChange = { this . handleChange }
294310 onMenuClose = { onBlur }
295311 { ...rest }
296312 />
297313 </ SelectWrapper >
298314 { arrayValue . map ( val => {
299- const option = filteredOptions . find (
315+ const option = mergedOptions . find (
300316 ( { value : currencyType } ) => currencyType === val
301317 ) ;
302318 return option ? (
0 commit comments