From 98f5b6be6b949bedebd6ed5aacfed63ec7314dbd Mon Sep 17 00:00:00 2001 From: meriadec Date: Thu, 31 May 2018 09:00:00 +0200 Subject: [PATCH 1/4] Select -> LegacySelect --- src/components/FeesField/BitcoinKind.js | 2 +- src/components/SelectAccount/index.js | 2 +- src/components/SelectCurrency/index.js | 2 +- src/components/SelectExchange.js | 2 +- src/components/SettingsPage/sections/Display.js | 2 +- src/components/base/InputCurrency/index.js | 2 +- src/components/base/{Select => LegacySelect}/index.js | 4 ++-- .../base/{Select => LegacySelect}/stories.js | 10 +++++----- src/components/modals/AccountSettingRenderBody.js | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) rename src/components/base/{Select => LegacySelect}/index.js (99%) rename src/components/base/{Select => LegacySelect}/stories.js (94%) diff --git a/src/components/FeesField/BitcoinKind.js b/src/components/FeesField/BitcoinKind.js index 2739adf9..64fe3074 100644 --- a/src/components/FeesField/BitcoinKind.js +++ b/src/components/FeesField/BitcoinKind.js @@ -5,7 +5,7 @@ import type { Account } from '@ledgerhq/live-common/lib/types' import styled from 'styled-components' import InputCurrency from 'components/base/InputCurrency' -import Select from 'components/base/Select' +import Select from 'components/base/LegacySelect' import type { Fees } from 'api/Fees' import WithFeesAPI from '../WithFeesAPI' import GenericContainer from './GenericContainer' diff --git a/src/components/SelectAccount/index.js b/src/components/SelectAccount/index.js index 5ab4067a..ca9a610d 100644 --- a/src/components/SelectAccount/index.js +++ b/src/components/SelectAccount/index.js @@ -12,7 +12,7 @@ import type { T } from 'types/common' import { getVisibleAccounts } from 'reducers/accounts' -import Select from 'components/base/Select' +import Select from 'components/base/LegacySelect' import FormattedVal from 'components/base/FormattedVal' import Box from 'components/base/Box' import Text from 'components/base/Text' diff --git a/src/components/SelectCurrency/index.js b/src/components/SelectCurrency/index.js index 35e55c83..16441d2d 100644 --- a/src/components/SelectCurrency/index.js +++ b/src/components/SelectCurrency/index.js @@ -11,7 +11,7 @@ import type { T } from 'types/common' import { availableCurrencies } from 'reducers/settings' import CryptoCurrencyIcon from 'components/CryptoCurrencyIcon' -import Select from 'components/base/Select' +import Select from 'components/base/LegacySelect' import Box from 'components/base/Box' const renderItem = (currency: CryptoCurrency) => { diff --git a/src/components/SelectExchange.js b/src/components/SelectExchange.js index 9fe264eb..8ae03f4c 100644 --- a/src/components/SelectExchange.js +++ b/src/components/SelectExchange.js @@ -2,7 +2,7 @@ import React, { Component } from 'react' import type { Currency } from '@ledgerhq/live-common/lib/types' import type { Exchange } from '@ledgerhq/live-common/lib/countervalues/types' -import Select from 'components/base/Select' +import Select from 'components/base/LegacySelect' import Box from 'components/base/Box' import Text from 'components/base/Text' import CounterValues from 'helpers/countervalues' diff --git a/src/components/SettingsPage/sections/Display.js b/src/components/SettingsPage/sections/Display.js index 343dc942..61ab266b 100644 --- a/src/components/SettingsPage/sections/Display.js +++ b/src/components/SettingsPage/sections/Display.js @@ -7,7 +7,7 @@ import { listFiatCurrencies } from '@ledgerhq/live-common/lib/helpers/currencies import type { SettingsState as Settings } from 'reducers/settings' import type { T } from 'types/common' -import Select from 'components/base/Select' +import Select from 'components/base/LegacySelect' import RadioGroup from 'components/base/RadioGroup' import IconDisplay from 'icons/Display' import languageKeys from 'config/languages' diff --git a/src/components/base/InputCurrency/index.js b/src/components/base/InputCurrency/index.js index 65c65886..f1a36f77 100644 --- a/src/components/base/InputCurrency/index.js +++ b/src/components/base/InputCurrency/index.js @@ -10,7 +10,7 @@ import isNaN from 'lodash/isNaN' import Box from 'components/base/Box' import Input from 'components/base/Input' -import Select from 'components/base/Select' +import Select from 'components/base/LegacySelect' import type { Unit } from '@ledgerhq/live-common/lib/types' diff --git a/src/components/base/Select/index.js b/src/components/base/LegacySelect/index.js similarity index 99% rename from src/components/base/Select/index.js rename to src/components/base/LegacySelect/index.js index f5604443..b726b999 100644 --- a/src/components/base/Select/index.js +++ b/src/components/base/LegacySelect/index.js @@ -144,7 +144,7 @@ const renderSelectedItem = ({ selectedItem, renderSelected, placeholder }: any) {placeholder} ) -class Select extends PureComponent { +class LegacySelect extends PureComponent { static defaultProps = { bg: undefined, disabled: false, @@ -340,4 +340,4 @@ class Select extends PureComponent { } } -export default Select +export default LegacySelect diff --git a/src/components/base/Select/stories.js b/src/components/base/LegacySelect/stories.js similarity index 94% rename from src/components/base/Select/stories.js rename to src/components/base/LegacySelect/stories.js index 75b0c414..a5b2d475 100644 --- a/src/components/base/Select/stories.js +++ b/src/components/base/LegacySelect/stories.js @@ -5,10 +5,10 @@ import { storiesOf } from '@storybook/react' import { boolean } from '@storybook/addon-knobs' import Box from 'components/base/Box' -import Select from 'components/base/Select' +import LegacySelect from 'components/base/LegacySelect' import Text from 'components/base/Text' -const stories = storiesOf('Components/base/Select', module) +const stories = storiesOf('Components/base/LegacySelect', module) const itemsChessPlayers = [ { key: 'aleksandr-grichtchouk', name: 'Aleksandr Grichtchouk' }, @@ -57,7 +57,7 @@ class Wrapper extends PureComponent { stories.add('basic', () => ( {onChange => ( - ( - item.name} + onChange={onChange} + /> + )} + +)) + +const itemsColors = [ + { value: 'absolute zero', label: 'Absolute Zero', color: '#0048BA' }, + { value: 'acid green', label: 'Acid Green', color: '#B0BF1A' }, + { value: 'aero', label: 'Aero', color: '#7CB9E8' }, + { value: 'aero blue', label: 'Aero Blue', color: '#C9FFE5' }, + { value: 'african violet', label: 'African Violet', color: '#B284BE' }, + { value: 'air force blue (usaf)', label: 'Air Force Blue (USAF)', color: '#00308F' }, + { value: 'air superiority blue', label: 'Air Superiority Blue', color: '#72A0C1' }, +] + +stories.add('custom render', () => ( + + {onChange => ( + value && a.id === value.id)} - renderSelected={renderItem} - renderItem={renderItem} - keyProp="id" - items={accounts.sort((a, b) => (a.name < b.name ? -1 : 1))} - placeholder={t('common:selectAccount')} - fontSize={4} - onChange={onChange} - /> -) - -RawSelectAccount.defaultProps = { - onChange: noop, - value: undefined, +const RawSelectAccount = ({ accounts, onChange, value, t, ...props }: Props) => { + const options = accounts + .sort((a, b) => (a.name < b.name ? -1 : 1)) + .map(a => ({ ...a, value: a.id, label: a.name })) + const selectedOption = value ? options.find(o => o.value === value.id) : null + return ( + -) +const SelectCurrency = ({ onChange, value, t, placeholder, currencies, ...props }: Props) => { + const options = currencies ? currencies.map(c => ({ ...c, value: c.id, label: c.name })) : [] + return ( + (item ? item.name : '')} renderSelected={item => item && item.name} - items={fiats} - value={cachedCounterValue} + options={fiats} + value={cvOption} /> item && item.name} value={currentRegion} - items={regionsFiltered} + options={regionsFiltered} />