Browse Source

Update style of Input, Select, and SelectAccount components

master
meriadec 7 years ago
parent
commit
1362db5430
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 41
      src/components/SelectAccount/index.js
  2. 7
      src/components/base/Input/index.js
  3. 33
      src/components/base/Select/Triangles.js
  4. 48
      src/components/base/Select/index.js

41
src/components/SelectAccount/index.js

@ -1,10 +1,10 @@
// @flow
import React from 'react'
import { compose } from 'redux'
import { connect } from 'react-redux'
import { translate } from 'react-i18next'
import noop from 'lodash/noop'
import { getIconByCoinType } from '@ledgerhq/currencies/react'
import type { T, Accounts, Account } from 'types/common'
@ -19,18 +19,27 @@ const mapStateToProps = state => ({
accounts: getVisibleAccounts(state),
})
const renderItem = a => (
<Box horizontal alignItems="center">
<Box grow>
<Text ff="Open Sans|SemiBold" color="dark" fontSize={4}>
{a.name}
</Text>
const renderItem = a => {
const Icon = getIconByCoinType(a.coinType)
const { color } = a.currency
return (
<Box horizontal alignItems="center" flow={2}>
{Icon && (
<Box style={{ width: 16, height: 16, color }}>
<Icon size={16} />
</Box>
)}
<Box grow>
<Text ff="Open Sans|SemiBold" color="dark" fontSize={4}>
{a.name}
</Text>
</Box>
<Box>
<FormattedVal color="grey" val={a.balance} unit={a.unit} showCode />
</Box>
</Box>
<Box>
<FormattedVal color="grey" val={a.balance} unit={a.unit} />
</Box>
</Box>
)
)
}
type Props = {
accounts: Accounts,
@ -39,7 +48,7 @@ type Props = {
t: T,
}
export const SelectAccount = ({ accounts, onChange, value, t }: Props) => (
const RawSelectAccount = ({ accounts, onChange, value, t }: Props) => (
<Select
value={value && accounts.find(a => value && a.id === value.id)}
renderSelected={renderItem}
@ -52,9 +61,11 @@ export const SelectAccount = ({ accounts, onChange, value, t }: Props) => (
/>
)
SelectAccount.defaultProps = {
RawSelectAccount.defaultProps = {
onChange: noop,
value: undefined,
}
export default compose(connect(mapStateToProps), translate())(SelectAccount)
export const SelectAccount = translate()(RawSelectAccount)
export default connect(mapStateToProps)(SelectAccount)

7
src/components/base/Input/index.js

@ -2,16 +2,19 @@
import React, { PureComponent } from 'react'
import styled from 'styled-components'
import { space } from 'styled-system'
import { space, fontSize } from 'styled-system'
import fontFamily from 'styles/styled/fontFamily'
const Base = styled.input.attrs({
p: 4,
px: 3,
ff: 'Open Sans|SemiBold',
fontSize: 4,
})`
${space};
${fontFamily};
${fontSize};
height: 40px;
border: 1px solid ${p => p.theme.colors.fog};
border-radius: 3px;
display: flex;

33
src/components/base/Select/Triangles.js

@ -1,33 +0,0 @@
// @flow
import React from 'react'
import styled from 'styled-components'
import Box from 'components/base/Box'
const UpTriangle = styled.div`
width: 0;
height: 0;
border-left: ${p => p.size}px solid transparent;
border-right: ${p => p.size}px solid transparent;
border-bottom: ${p => p.size}px solid ${p => p.theme.colors[p.color]};
`
const DownTriangle = styled.div`
width: 0;
height: 0;
border-left: ${p => p.size}px solid transparent;
border-right: ${p => p.size}px solid transparent;
border-top: ${p => p.size}px solid ${p => p.theme.colors[p.color]};
`
const Triangles = ({ size, color }: { size?: number, color?: string }) => (
<Box flow={1}>
<UpTriangle size={size} color={color} />
<DownTriangle size={size} color={color} />
</Box>
)
Triangles.defaultProps = { size: 5, color: 'fog' }
export default Triangles

48
src/components/base/Select/index.js

@ -14,8 +14,7 @@ import Search from 'components/base/Search'
import Text from 'components/base/Text'
import IconCheck from 'icons/Check'
import Triangles from './Triangles'
import IconAngleDown from 'icons/AngleDown'
type Props = {
fuseOptions?: Object,
@ -37,10 +36,11 @@ const Container = styled(Box).attrs({ relative: true, color: 'graphite' })``
const TriggerBtn = styled(Box).attrs({
ff: 'Open Sans|SemiBold',
p: 4,
fontSize: 4,
pl: 3,
pr: 5,
})`
min-height: 64px;
height: 40px;
${space};
border: 1px solid ${p => p.theme.colors.fog};
border-radius: 3px;
@ -62,12 +62,6 @@ const Item = styled(Box).attrs({
background: ${p => (p.highlighted ? p.theme.colors.lightGrey : p.theme.colors.white)};
`
const ItemWrapper = styled(Box)`
& + & {
border-top: 1px solid ${p => p.theme.colors.fog};
}
`
const Dropdown = styled(Box).attrs({
mt: 1,
})`
@ -81,7 +75,7 @@ const Dropdown = styled(Box).attrs({
z-index: 1;
`
const FloatingTriangles = styled(Box).attrs({
const FloatingDown = styled(Box).attrs({
alignItems: 'center',
justifyContent: 'center',
mr: 2,
@ -90,6 +84,7 @@ const FloatingTriangles = styled(Box).attrs({
top: 0;
right: 0;
bottom: 0;
color: ${p => p.theme.colors.grey};
// to "simulate" border to make arrows appears at the exact same place as
// the no-input version
@ -97,15 +92,12 @@ const FloatingTriangles = styled(Box).attrs({
`
const IconSelected = styled(Box).attrs({
bg: 'wallet',
color: 'white',
color: 'wallet',
alignItems: 'center',
justifyContent: 'center',
})`
border-radius: 50%;
height: 15px;
font-size: 5px;
width: 15px;
height: 12px;
width: 12px;
opacity: ${p => (p.selected ? 1 : 0)};
`
@ -156,7 +148,7 @@ class Select extends PureComponent<Props> {
}}
>
{items.map((item, i) => (
<ItemWrapper
<Box
key={keyProp ? item[keyProp] : item.key}
innerRef={n => (this._children[i] = n)}
{...getItemProps({ item })}
@ -171,17 +163,17 @@ class Select extends PureComponent<Props> {
</Box>
<Box>
<IconSelected selected={selectedItem === item}>
<IconCheck height={7} width={7} />
<IconCheck height={12} width={12} />
</IconSelected>
</Box>
</Item>
</ItemWrapper>
</Box>
))}
</GrowScroll>
) : (
<ItemWrapper>
<Box>
<Item>{'No results'}</Item>
</ItemWrapper>
</Box>
)}
</Dropdown>
)
@ -231,9 +223,9 @@ class Select extends PureComponent<Props> {
{searchable ? (
<Box relative>
<Input keepEvent {...getInputProps({ placeholder })} onClick={openMenu} />
<FloatingTriangles>
<Triangles />
</FloatingTriangles>
<FloatingDown>
<IconAngleDown width={10} height={10} />
</FloatingDown>
</Box>
) : (
<TriggerBtn
@ -250,9 +242,9 @@ class Select extends PureComponent<Props> {
<Text color="fog">{placeholder}</Text>
)}
</Box>
<FloatingTriangles>
<Triangles />
</FloatingTriangles>
<FloatingDown>
<IconAngleDown width={10} height={10} />
</FloatingDown>
</TriggerBtn>
)}
{isOpen &&

Loading…
Cancel
Save