Gaëtan Renaudeau
7 years ago
committed by
GitHub
33 changed files with 334 additions and 208 deletions
@ -0,0 +1,98 @@ |
|||
// @flow
|
|||
|
|||
import React from 'react' |
|||
import styled from 'styled-components' |
|||
import { translate } from 'react-i18next' |
|||
import type { Account } from '@ledgerhq/live-common/lib/types' |
|||
|
|||
import Box from 'components/base/Box' |
|||
import FakeLink from 'components/base/FakeLink' |
|||
import Spinner from 'components/base/Spinner' |
|||
import type { T } from 'types/common' |
|||
|
|||
import AccountRow from './AccountRow' |
|||
|
|||
const AccountsList = ({ |
|||
accounts, |
|||
checkedIds, |
|||
onToggleAccount, |
|||
onUpdateAccount, |
|||
onSelectAll, |
|||
onUnselectAll, |
|||
isLoading, |
|||
title, |
|||
emptyText, |
|||
t, |
|||
}: { |
|||
accounts: Account[], |
|||
checkedIds: string[], |
|||
onToggleAccount: Account => void, |
|||
onUpdateAccount: Account => void, |
|||
onSelectAll: () => void, |
|||
onUnselectAll: () => void, |
|||
isLoading?: boolean, |
|||
title?: string, |
|||
emptyText?: string, |
|||
t: T, |
|||
}) => { |
|||
const withToggleAll = !!onSelectAll && !!onUnselectAll && accounts.length > 1 |
|||
const isAllSelected = accounts.every(acc => !!checkedIds.find(id => acc.id === id)) |
|||
return ( |
|||
<Box flow={3}> |
|||
{(title || withToggleAll) && ( |
|||
<Box horizontal align="center"> |
|||
{title && ( |
|||
<Box ff="Open Sans|Bold" color="dark" fontSize={2} textTransform="uppercase"> |
|||
{title} |
|||
</Box> |
|||
)} |
|||
{withToggleAll && ( |
|||
<FakeLink |
|||
ml="auto" |
|||
onClick={isAllSelected ? onUnselectAll : onSelectAll} |
|||
fontSize={3} |
|||
style={{ lineHeight: '10px' }} |
|||
> |
|||
{isAllSelected ? t('app:addAccounts.unselectAll') : t('app:addAccounts.selectAll')} |
|||
</FakeLink> |
|||
)} |
|||
</Box> |
|||
)} |
|||
{accounts.length || isLoading ? ( |
|||
<Box flow={2}> |
|||
{accounts.map(account => ( |
|||
<AccountRow |
|||
key={account.id} |
|||
account={account} |
|||
isChecked={checkedIds.find(id => id === account.id) !== undefined} |
|||
onClick={onToggleAccount} |
|||
onAccountUpdate={onUpdateAccount} |
|||
/> |
|||
))} |
|||
{isLoading && ( |
|||
<LoadingRow> |
|||
<Spinner color="grey" size={16} /> |
|||
</LoadingRow> |
|||
)} |
|||
</Box> |
|||
) : emptyText && !isLoading ? ( |
|||
<Box ff="Open Sans|Regular" fontSize={3}> |
|||
{emptyText} |
|||
</Box> |
|||
) : null} |
|||
</Box> |
|||
) |
|||
} |
|||
|
|||
const LoadingRow = styled(Box).attrs({ |
|||
horizontal: true, |
|||
borderRadius: 1, |
|||
px: 3, |
|||
align: 'center', |
|||
justify: 'center', |
|||
})` |
|||
height: 48px; |
|||
border: 1px dashed ${p => p.theme.colors.grey}; |
|||
` |
|||
|
|||
export default translate()(AccountsList) |
@ -0,0 +1,30 @@ |
|||
// @flow
|
|||
|
|||
import React from 'react' |
|||
import { genAccount } from '@ledgerhq/live-common/lib/mock/account' |
|||
import { storiesOf } from '@storybook/react' |
|||
import { action } from '@storybook/addon-actions' |
|||
import { boolean, text } from '@storybook/addon-knobs' |
|||
|
|||
import AccountsList from 'components/base/AccountsList' |
|||
|
|||
const stories = storiesOf('Components/base', module) |
|||
|
|||
const ACCOUNTS = [genAccount('a'), genAccount('b'), genAccount('c')] |
|||
|
|||
const CHECKED_IDS = [] |
|||
|
|||
stories.add('AccountsList', () => ( |
|||
<div style={{ maxWidth: 450 }}> |
|||
<AccountsList |
|||
title={text('title', 'this is an account list')} |
|||
accounts={ACCOUNTS} |
|||
checkedIds={CHECKED_IDS} |
|||
onToggleAccount={action('onToggleAccount')} |
|||
onUpdateAccount={action('onUpdateAccount')} |
|||
onSelectAll={action('onSelectAll')} |
|||
onUnselectAll={action('onUnselectAll')} |
|||
isLoading={boolean('isLoading', false)} |
|||
/> |
|||
</div> |
|||
)) |
@ -0,0 +1,16 @@ |
|||
// @flow
|
|||
|
|||
import React from 'react' |
|||
import Box from 'components/base/Box' |
|||
import Text from 'components/base/Text' |
|||
|
|||
const outerStyle = { width: 0 } |
|||
const innerStyle = { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } |
|||
|
|||
export default ({ children, ...p }: { children: any }) => ( |
|||
<Box grow horizontal> |
|||
<Box grow {...p} style={outerStyle}> |
|||
<Text style={innerStyle}>{children}</Text> |
|||
</Box> |
|||
</Box> |
|||
) |
@ -0,0 +1,7 @@ |
|||
// Github like focus style:
|
|||
// - focus states are not visible by default
|
|||
// - first time user hit tab, enable global tab to see focus states
|
|||
let IS_GLOBAL_TAB_ENABLED = false |
|||
|
|||
export const isGlobalTabEnabled = () => IS_GLOBAL_TAB_ENABLED |
|||
export const enableGlobalTab = () => (IS_GLOBAL_TAB_ENABLED = true) |
@ -1,8 +1,13 @@ |
|||
// @flow
|
|||
|
|||
const { NODE_ENV } = process.env |
|||
const { NODE_ENV, STORYBOOK_ENV } = process.env |
|||
|
|||
global.__ENV__ = NODE_ENV === 'development' ? NODE_ENV : 'production' |
|||
global.__DEV__ = global.__ENV__ === 'development' |
|||
global.__PROD__ = !global.__DEV__ |
|||
global.__STORYBOOK_ENV__ = STORYBOOK_ENV === '1' |
|||
global.__GLOBAL_STYLES__ = require('./styles/reset') |
|||
|
|||
if (STORYBOOK_ENV === '1') { |
|||
global.__APP_VERSION__ = '1.0.0' |
|||
} |
|||
|
Loading…
Reference in new issue