Loëck Vézien
7 years ago
committed by
meriadec
12 changed files with 217 additions and 53 deletions
@ -0,0 +1,60 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
import React from 'react' |
||||
|
import { translate } from 'react-i18next' |
||||
|
import { getIconByCoinType } from '@ledgerhq/currencies/react' |
||||
|
import { listCurrencies } from '@ledgerhq/currencies' |
||||
|
|
||||
|
import noop from 'lodash/noop' |
||||
|
|
||||
|
import type { Currency } from '@ledgerhq/currencies' |
||||
|
import type { T } from 'types/common' |
||||
|
|
||||
|
import Select from 'components/base/Select' |
||||
|
import Box from 'components/base/Box' |
||||
|
|
||||
|
const renderItem = a => { |
||||
|
const { color, name, coinType } = a |
||||
|
const Icon = getIconByCoinType(coinType) |
||||
|
return ( |
||||
|
<Box grow horizontal alignItems="center" flow={2}> |
||||
|
{Icon && ( |
||||
|
<Box style={{ width: 16, height: 16, color }}> |
||||
|
<Icon size={16} /> |
||||
|
</Box> |
||||
|
)} |
||||
|
<Box grow ff="Open Sans|SemiBold" color="dark" fontSize={4}> |
||||
|
{name} |
||||
|
</Box> |
||||
|
</Box> |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
const currencies = listCurrencies() |
||||
|
|
||||
|
type Props = { |
||||
|
onChange: Function, |
||||
|
value?: Currency, |
||||
|
t: T, |
||||
|
} |
||||
|
|
||||
|
const SelectCurrency = ({ onChange, value, t, ...props }: Props) => ( |
||||
|
<Select |
||||
|
{...props} |
||||
|
value={value} |
||||
|
renderSelected={renderItem} |
||||
|
renderItem={renderItem} |
||||
|
keyProp="coinType" |
||||
|
items={currencies.sort((a, b) => (a.name < b.name ? -1 : 1))} |
||||
|
placeholder={t('common:selectCurrency')} |
||||
|
fontSize={4} |
||||
|
onChange={onChange} |
||||
|
/> |
||||
|
) |
||||
|
|
||||
|
SelectCurrency.defaultProps = { |
||||
|
onChange: noop, |
||||
|
value: undefined, |
||||
|
} |
||||
|
|
||||
|
export default translate()(SelectCurrency) |
@ -0,0 +1,31 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
import React, { Component } from 'react' |
||||
|
import { storiesOf } from '@storybook/react' |
||||
|
import { action } from '@storybook/addon-actions' |
||||
|
|
||||
|
import SelectCurrency from 'components/SelectCurrency' |
||||
|
|
||||
|
const stories = storiesOf('Components', module) |
||||
|
|
||||
|
class Wrapper extends Component<any, any> { |
||||
|
state = { |
||||
|
value: '', |
||||
|
} |
||||
|
|
||||
|
handleChange = item => { |
||||
|
this.setState({ value: item }) |
||||
|
action('onChange')(item) |
||||
|
} |
||||
|
|
||||
|
render() { |
||||
|
const { render } = this.props |
||||
|
const { value } = this.state |
||||
|
|
||||
|
return render({ onChange: this.handleChange, value }) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
stories.add('SelectCurrency', () => ( |
||||
|
<Wrapper render={({ onChange, value }) => <SelectCurrency onChange={onChange} value={value} />} /> |
||||
|
)) |
Loading…
Reference in new issue