-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
farrah/76186/currency selector component (#6512)
* currency dropdown component * refactor * fixed bugs
- Loading branch information
1 parent
fc8c9fd
commit 5e32328
Showing
4 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/p2p/src/components/buy-sell/currency-selector.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
import { Field, Formik } from 'formik'; | ||
import { Autocomplete, Icon } from '@deriv/components'; | ||
import { localize } from 'Components/i18next'; | ||
import './currency-selector.scss'; | ||
|
||
const CurrencySelector = ({ className, default_value, list, onSelect }) => { | ||
const filtered_currency_list = list.filter(item => item.has_adverts); | ||
|
||
return ( | ||
<Formik enableReinitialize initialValues={{ currency: '' }}> | ||
{({ setFieldValue }) => ( | ||
<Field name='currency'> | ||
{({ field }) => ( | ||
<Autocomplete | ||
{...field} | ||
autoComplete='off' | ||
className={classNames('currency-selector', className)} | ||
data-lpignore='true' | ||
historyValue={default_value} | ||
is_list_visible | ||
leading_icon={<Icon className='currency-selector__search-icon' icon='IcSearch' />} | ||
list_items={filtered_currency_list} | ||
not_found_text={ | ||
list.filter( | ||
item => item.text.toLowerCase() === field.value.toLowerCase() && !item.has_adverts | ||
).length === 1 | ||
? localize('No ads for this currency.') | ||
: localize('No results for "{{value}}".', { | ||
value: field.value, | ||
interpolation: { escapeValue: false }, | ||
}) | ||
} | ||
onItemSelection={({ value }) => { | ||
if (value) onSelect?.(value); | ||
}} | ||
placeholder={localize('Search currency')} | ||
trailing_icon={ | ||
field.value ? ( | ||
<Icon | ||
color='secondary' | ||
icon='IcCloseCircle' | ||
onClick={() => { | ||
setFieldValue('currency', ''); | ||
}} | ||
/> | ||
) : ( | ||
<></> | ||
) | ||
} | ||
type='text' | ||
/> | ||
)} | ||
</Field> | ||
)} | ||
</Formik> | ||
); | ||
}; | ||
|
||
CurrencySelector.propTypes = { | ||
className: PropTypes.string, | ||
default_value: PropTypes.string, | ||
list: PropTypes.array, | ||
onSelect: PropTypes.func, | ||
}; | ||
|
||
export default CurrencySelector; |
24 changes: 24 additions & 0 deletions
24
packages/p2p/src/components/buy-sell/currency-selector.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.currency-selector { | ||
&__search-icon { | ||
margin-right: 1rem; | ||
} | ||
|
||
.dc-dropdown-list { | ||
margin-top: 0; | ||
border-top-left-radius: 0; | ||
border-top-right-radius: 0; | ||
} | ||
|
||
.dc-input { | ||
border: 0; | ||
border-bottom: 1px solid var(--border-normal); | ||
border-bottom-right-radius: 0; | ||
border-bottom-left-radius: 0; | ||
box-shadow: 0 8px 16px 0 var(--shadow-menu); | ||
background: var(--general-main-2); | ||
|
||
&__field { | ||
padding-left: 3.4rem; | ||
} | ||
} | ||
} |