Browse Source

Merge pull request #220 from meriadec/master

Flatten Storybook, update of BalanceInfos & Chart
master
Loëck Vézien 7 years ago
committed by GitHub
parent
commit
5712205ca3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/components/BalanceSummary/BalanceInfos.js
  2. 32
      src/components/BalanceSummary/index.js
  3. 22
      src/components/BalanceSummary/stories.js
  4. 4
      src/components/Breadcrumb/stories.js
  5. 1
      src/components/DashboardPage/AccountCard.js
  6. 4
      src/components/RecipientAddress/stories.js
  7. 4
      src/components/SelectAccount/stories.js
  8. 4
      src/components/TransactionsList/stories.js
  9. 4
      src/components/base/Bar/stories.js
  10. 4
      src/components/base/Button/stories.js
  11. 4
      src/components/base/CheckBox/stories.js
  12. 4
      src/components/base/GrowScroll/stories.js
  13. 4
      src/components/base/Input/stories.js
  14. 4
      src/components/base/Modal/stories.js
  15. 33
      src/components/base/NewChart/Tooltip.js
  16. 4
      src/components/base/NewChart/handleMouseEvents.js
  17. 20
      src/components/base/NewChart/index.js
  18. 28
      src/components/base/NewChart/refreshDraw.js
  19. 11
      src/components/base/NewChart/stories.js
  20. 4
      src/components/base/Pills/stories.js
  21. 4
      src/components/base/QRCode/stories.js
  22. 4
      src/components/base/Radio/stories.js
  23. 79
      src/components/base/Search/stories.js
  24. 4
      src/components/base/Tabs/stories.js
  25. 4
      src/components/base/Tooltip/stories.js

2
src/components/BalanceSummary/BalanceInfos.js

@ -43,7 +43,7 @@ export function BalanceSincePercent(props: BalanceSinceProps) {
<Box {...otherProps}>
<FormattedVal
isPercent
val={Math.floor((totalBalance - refBalance) / refBalance * 100)}
val={refBalance ? Math.floor((totalBalance - refBalance) / refBalance * 100) : 0}
alwaysShowSign
fontSize={7}
/>

32
src/components/BalanceSummary/index.js

@ -1,9 +1,8 @@
// @flow
import React, { Fragment } from 'react'
import moment from 'moment'
import { formatShort, getFiatUnit } from '@ledgerhq/currencies'
import { getFiatUnit } from '@ledgerhq/currencies'
import type { Accounts } from 'types/common'
@ -12,30 +11,6 @@ import Box, { Card } from 'components/base/Box'
import CalculateBalance from 'components/CalculateBalance'
import FormattedVal from 'components/base/FormattedVal'
function getTickCountX(selectedTime) {
switch (selectedTime) {
default:
case 'week':
return 7
case 'month':
return 10
case 'year':
return 13
}
}
function renderTickX(selectedTime) {
let format = 'MMM. D'
if (selectedTime === 'year') {
format = 'MMM.'
}
return t => moment(t).format(format)
}
type Props = {
counterValue: string,
chartColor: string,
@ -80,9 +55,8 @@ const BalanceSummary = ({
color={chartColor}
data={allBalances}
height={250}
nbTicksX={getTickCountX(selectedTime)}
renderTickX={renderTickX(selectedTime)}
renderTickY={t => formatShort(unit, t)}
unit={unit}
tickXScale={selectedTime}
renderTooltip={d => (
<FormattedVal
alwaysShowSign={false}

22
src/components/BalanceSummary/stories.js

@ -0,0 +1,22 @@
// @flow
import React from 'react'
import { storiesOf } from '@storybook/react'
import { number } from '@storybook/addon-knobs'
import { translate } from 'react-i18next'
import BalanceInfos from './BalanceInfos'
const stories = storiesOf('Components', module)
const BalanceInfosComp = translate()(BalanceInfos)
stories.add('BalanceInfos', () => (
<BalanceInfosComp
since="month"
counterValue="USD"
totalBalance={number('totalBalance', 1000, { min: 0 })}
sinceBalance={number('sinceBalance', 500, { min: 0 })}
refBalance={number('refBalance', 200, { min: 0 })}
/>
))

4
src/components/Breadcrumb/stories.js

@ -6,9 +6,9 @@ import { number } from '@storybook/addon-knobs'
import Breadcrumb from 'components/Breadcrumb'
const stories = storiesOf('Components/Breadcrumb', module)
const stories = storiesOf('Components', module)
stories.add('basic', () => (
stories.add('Breadcrumb', () => (
<Breadcrumb
currentStep={number('currentStep', 1, {
min: 1,

1
src/components/DashboardPage/AccountCard.js

@ -91,6 +91,7 @@ const AccountCard = ({
hideAxis
interactive={false}
id={`account-chart-${account.id}`}
unit={account.unit}
/>
</Box>
)}

4
src/components/RecipientAddress/stories.js

@ -6,7 +6,7 @@ import { boolean } from '@storybook/addon-knobs'
import RecipientAddress from 'components/RecipientAddress'
const stories = storiesOf('Components/RecipientAddress', module)
const stories = storiesOf('Components', module)
type State = {
value: any,
@ -27,7 +27,7 @@ class Wrapper extends PureComponent<any, State> {
}
}
stories.add('basic', () => (
stories.add('RecipientAddress', () => (
<Wrapper
render={({ onChange, value }) => (
<RecipientAddress

4
src/components/SelectAccount/stories.js

@ -8,7 +8,7 @@ import { getCurrencyByCoinType, getDefaultUnitByCoinType } from '@ledgerhq/curre
import { SelectAccount } from 'components/SelectAccount'
const chance = new Chance()
const stories = storiesOf('Components/SelectAccount', module)
const stories = storiesOf('Components', module)
const accounts = [...Array(20)].map(() => ({
id: chance.string(),
@ -48,7 +48,7 @@ class Wrapper extends PureComponent<any, State> {
}
}
stories.add('basic', () => (
stories.add('SelectAccount', () => (
<Wrapper
render={({ onChange, value }) => (
<SelectAccount onChange={onChange} value={value} accounts={accounts} t={k => k} />

4
src/components/TransactionsList/stories.js

@ -6,7 +6,7 @@ import { boolean } from '@storybook/addon-knobs'
import TransactionsList from 'components/TransactionsList'
const stories = storiesOf('Components/TransactionsList', module)
const stories = storiesOf('Components', module)
const transactions = [
{
@ -23,6 +23,6 @@ const transactions = [
},
]
stories.add('basic', () => (
stories.add('TransactionsList', () => (
<TransactionsList transactions={transactions} canShowMore={boolean('canShowMore')} />
))

4
src/components/base/Bar/stories.js

@ -7,6 +7,6 @@ import { storiesOf } from '@storybook/react'
import Bar from 'components/base/Bar'
const stories = storiesOf('Components/Bar', module)
const stories = storiesOf('Components', module)
stories.add('basic', () => <Bar size={number('size', 1)} color="grey" />)
stories.add('Bar', () => <Bar size={number('size', 1)} color="grey" />)

4
src/components/base/Button/stories.js

@ -6,7 +6,7 @@ import styled from 'styled-components'
import Button from 'components/base/Button'
const stories = storiesOf('Components/Button', module)
const stories = storiesOf('Components', module)
const Th = styled.th`
padding: 20px;
@ -17,7 +17,7 @@ const Td = styled.td`
min-width: 150px;
`
stories.add('all', () => (
stories.add('Button', () => (
<table border={1}>
<thead>
<tr>

4
src/components/base/CheckBox/stories.js

@ -5,8 +5,8 @@ import { action } from '@storybook/addon-actions'
import CheckBox from 'components/base/CheckBox'
const stories = storiesOf('Components/CheckBox', module)
const stories = storiesOf('Components', module)
stories.add('basic', () => (
stories.add('CheckBox', () => (
<CheckBox isChecked={boolean('isChecked', false)} onChange={action('onChange')} />
))

4
src/components/base/GrowScroll/stories.js

@ -7,9 +7,9 @@ import { boolean } from '@storybook/addon-knobs'
import Box from 'components/base/Box'
import GrowScroll from 'components/base/GrowScroll'
const stories = storiesOf('Components/GrowScroll', module)
const stories = storiesOf('Components', module)
stories.add('basic', () => {
stories.add('GrowScroll', () => {
const reverseColor = boolean('reverseColor', false)
return (

4
src/components/base/Input/stories.js

@ -5,6 +5,6 @@ import { storiesOf } from '@storybook/react'
import Input from 'components/base/Input'
const stories = storiesOf('Components/Input', module)
const stories = storiesOf('Components', module)
stories.add('basic', () => <Input placeholder="Foo bar" />)
stories.add('Input', () => <Input placeholder="Foo bar" />)

4
src/components/base/Modal/stories.js

@ -6,9 +6,9 @@ import { boolean } from '@storybook/addon-knobs'
import { Modal, ModalBody } from 'components/base/Modal'
const stories = storiesOf('Components/Modal', module)
const stories = storiesOf('Components', module)
stories.add('basic', () => {
stories.add('Modal', () => {
const isOpened = boolean('isOpened', true)
return (
<Modal

33
src/components/base/NewChart/Tooltip.js

@ -1,9 +1,12 @@
// @flow
import React, { Fragment } from 'react'
import React from 'react'
import type { Unit } from '@ledgerhq/currencies'
import { colors as themeColors } from 'styles/theme'
import { TooltipContainer } from 'components/base/Tooltip'
import FormattedVal from 'components/base/FormattedVal'
import type { Item } from './types'
@ -29,7 +32,17 @@ const Arrow = () => (
</svg>
)
const Tooltip = ({ d, renderTooltip }: { d: Item, renderTooltip?: Function }) => (
const Tooltip = ({
d,
renderTooltip,
fiat,
unit,
}: {
d: Item,
renderTooltip?: Function,
fiat?: string,
unit?: Unit,
}) => (
<div style={{ position: 'relative' }}>
<div
style={{
@ -45,12 +58,14 @@ const Tooltip = ({ d, renderTooltip }: { d: Item, renderTooltip?: Function }) =>
{renderTooltip ? (
renderTooltip(d)
) : (
<Fragment>
<div style={{ fontSize: 14 }}>
<b>{Math.round(d.value)}</b>
</div>
<span>{d.date}</span>
</Fragment>
<FormattedVal
alwaysShowSign={false}
color="white"
showCode
fiat={fiat}
unit={unit}
val={d.value}
/>
)}
</TooltipContainer>
<div style={{ background: 'red' }}>
@ -62,6 +77,8 @@ const Tooltip = ({ d, renderTooltip }: { d: Item, renderTooltip?: Function }) =>
Tooltip.defaultProps = {
renderTooltip: undefined,
fiat: undefined,
unit: undefined,
}
export default Tooltip

4
src/components/base/NewChart/handleMouseEvents.js

@ -26,7 +26,7 @@ export default function handleMouseEvents({
renderTooltip?: Function,
}) {
const { MARGINS, HEIGHT, WIDTH, NODES, DATA, x, y } = ctx
const { hideAxis } = props
const { hideAxis, unit } = props
const bisectDate = d3.bisector(d => d.parsedDate).left
@ -93,7 +93,7 @@ export default function handleMouseEvents({
.html(
renderToString(
<ThemeProvider theme={theme}>
<Tooltip renderTooltip={renderTooltip} d={d.ref} />
<Tooltip unit={unit} renderTooltip={renderTooltip} d={d.ref} />
</ThemeProvider>,
),
)

20
src/components/base/NewChart/index.js

@ -37,6 +37,8 @@ import React, { PureComponent } from 'react'
import * as d3 from 'd3'
import noop from 'lodash/noop'
import type { Unit } from '@ledgerhq/currencies'
import refreshNodes from './refreshNodes'
import refreshDraw from './refreshDraw'
import handleMouseEvents from './handleMouseEvents'
@ -46,27 +48,27 @@ import type { Data } from './types'
export type Props = {
data: Data, // eslint-disable-line react/no-unused-prop-types
unit: Unit, // eslint-disable-line react/no-unused-prop-types
id?: string, // eslint-disable-line react/no-unused-prop-types
height?: number,
tickXScale: string, // eslint-disable-line react/no-unused-prop-types
color?: string, // eslint-disable-line react/no-unused-prop-types
hideAxis?: boolean, // eslint-disable-line react/no-unused-prop-types
interactive?: boolean, // eslint-disable-line react/no-unused-prop-types
height: number,
dateFormat?: string, // eslint-disable-line react/no-unused-prop-types
id?: string, // eslint-disable-line react/no-unused-prop-types
nbTicksX: number, // eslint-disable-line react/no-unused-prop-types
interactive?: boolean, // eslint-disable-line react/no-unused-prop-types
renderTooltip?: Function, // eslint-disable-line react/no-unused-prop-types
renderTickX?: Function, // eslint-disable-line react/no-unused-prop-types
renderTickY?: Function, // eslint-disable-line react/no-unused-prop-types
}
class Chart extends PureComponent<Props> {
static defaultProps = {
id: 'chart',
color: '#000',
hideAxis: false,
interactive: true,
height: 400,
dateFormat: '%Y-%m-%d',
id: 'chart',
nbTicksX: 5,
tickXScale: 'month',
}
componentDidMount() {
@ -132,7 +134,7 @@ class Chart extends PureComponent<Props> {
}
// Derived draw variables
ctx.HEIGHT = Math.max(0, height - ctx.MARGINS.top - ctx.MARGINS.bottom)
ctx.HEIGHT = Math.max(0, (height || 0) - ctx.MARGINS.top - ctx.MARGINS.bottom)
ctx.WIDTH = Math.max(0, this._width - ctx.MARGINS.left - ctx.MARGINS.right)
// Scales and areas

28
src/components/base/NewChart/refreshDraw.js

@ -1,15 +1,41 @@
// @flow
import * as d3 from 'd3'
import moment from 'moment'
import { formatShort } from '@ledgerhq/currencies'
import { colors as themeColors } from 'styles/theme'
import type { Props } from '.'
import type { CTX } from './types'
const TICK_X_SCALE = {
week: 7,
month: 10,
year: 13,
default: 10,
}
function getTickXCount(tickXScale) {
return TICK_X_SCALE[tickXScale] || TICK_X_SCALE.default
}
const RENDER_TICK_X = {
year: 'MMM.',
default: 'MMM. D',
}
function getRenderTickX(selectedTime) {
return t => moment(t).format(RENDER_TICK_X[selectedTime] || RENDER_TICK_X.default)
}
export default function refreshDraw({ ctx, props }: { ctx: CTX, props: Props }) {
const { NODES, WIDTH, HEIGHT, MARGINS, COLORS, INVALIDATED, DATA, x, y } = ctx
const { hideAxis, interactive, renderTickX, renderTickY, nbTicksX } = props
const { hideAxis, interactive, tickXScale, unit } = props
const nbTicksX = getTickXCount(tickXScale)
const renderTickX = getRenderTickX(tickXScale)
const renderTickY = t => formatShort(unit, t)
const area = d3
.area()

11
src/components/base/NewChart/stories.js

@ -1,6 +1,7 @@
// @flow
import React, { Component, Fragment } from 'react'
import { getDefaultUnitByCoinType } from '@ledgerhq/currencies'
import Chance from 'chance'
import moment from 'moment'
import { storiesOf } from '@storybook/react'
@ -9,9 +10,10 @@ import { color } from '@storybook/addon-knobs/react'
import Chart from 'components/base/NewChart'
const stories = storiesOf('Components/Chart', module)
const stories = storiesOf('Components', module)
const data = generateRandomData(365)
const unit = getDefaultUnitByCoinType(0)
type State = {
start: number,
@ -45,14 +47,15 @@ class Wrapper extends Component<any, State> {
hideAxis={boolean('hideAxis', false)}
color={color('color', '#5f8ced')}
data={data.slice(start, stop)}
height={number('height', 300, { min: 100, max: 900 })}
height={number('height', 300)}
unit={unit}
/>
</Fragment>
)
}
}
stories.add('default', () => <Wrapper />)
stories.add('Chart', () => <Wrapper />)
function generateRandomData(n) {
const today = moment()
@ -62,7 +65,7 @@ function generateRandomData(n) {
while (!day.isSame(today)) {
data.push({
date: day.format('YYYY-MM-DD'),
value: chance.integer({ min: 0, max: 50e3 }),
value: chance.integer({ min: 0.5e8, max: 1e8 }),
})
day.add(1, 'day')
}

4
src/components/base/Pills/stories.js

@ -5,7 +5,7 @@ import { storiesOf } from '@storybook/react'
import Pills from 'components/base/Pills'
const stories = storiesOf('Components/Pills', module)
const stories = storiesOf('Components', module)
type State = {
key: string,
@ -32,4 +32,4 @@ class Wrapper extends PureComponent<any, State> {
}
}
stories.add('basic', () => <Wrapper />)
stories.add('Pills', () => <Wrapper />)

4
src/components/base/QRCode/stories.js

@ -7,6 +7,6 @@ import { text, number } from '@storybook/addon-knobs'
import QRCode from 'components/base/QRCode'
const stories = storiesOf('Components/QRCode', module)
const stories = storiesOf('Components', module)
stories.add('basic', () => <QRCode data={text('data', 'sample')} size={number('size', 200)} />)
stories.add('QRCode', () => <QRCode data={text('data', 'sample')} size={number('size', 200)} />)

4
src/components/base/Radio/stories.js

@ -5,8 +5,8 @@ import { boolean } from '@storybook/addon-knobs'
import Radio from 'components/base/Radio'
const stories = storiesOf('Components/Radio', module)
const stories = storiesOf('Components', module)
stories.add('basic', () => (
stories.add('Radio', () => (
<Radio isChecked={boolean('checked', false)} onChange={action('onChange')} />
))

79
src/components/base/Search/stories.js

@ -1,79 +0,0 @@
// @flow
import React from 'react'
import PropTypes from 'prop-types'
import { storiesOf } from '@storybook/react'
import { text, boolean } from '@storybook/addon-knobs'
import Search from 'components/base/Search'
const stories = storiesOf('Components/Search', module)
const items = [
{ key: 'aleksandr-grichtchouk', name: 'Aleksandr Grichtchouk' },
{ key: 'fabiano-caruana', name: 'Fabiano Caruana' },
{ key: 'garry-kasparov', name: 'Garry Kasparov' },
{ key: 'hikaru-nakamura', name: 'Hikaru Nakamura' },
{ key: 'levon-aronian', name: 'Levon Aronian' },
{ key: 'magnus-carlsen', name: 'Magnus Carlsen' },
{ key: 'maxime-vachier-lagrave', name: 'Maxime Vachier-Lagrave' },
{ key: 'shakhriyar-mamedyarov', name: 'Shakhriyar Mamedyarov' },
{ key: 'veselin-topalov', name: 'Veselin Topalov' },
{ key: 'viswanathan-anand', name: 'Viswanathan Anand' },
{ key: 'vladimir-kramnik', name: 'Vladimir Kramnik' },
]
const Wrapper = ({ children }) => (
<div>
<div style={{ opacity: 0.2 }}>{'(Change the search value in knobs)'}</div>
{children}
</div>
)
Wrapper.propTypes = {
children: PropTypes.any.isRequired,
}
stories.add('basic', () => {
const value = text('value', '')
const filterEmpty = boolean('filterEmpty', false)
return (
<Wrapper>
<Search
value={value}
items={items}
filterEmpty={filterEmpty}
fuseOptions={{
keys: ['name'],
}}
render={items => items.map(item => <div key={item.name}>{item.name}</div>)}
/>
</Wrapper>
)
})
stories.add('highlight matches', () => {
const value = text('value', '')
const filterEmpty = boolean('filterEmpty', false)
return (
<Wrapper>
<Search
value={value}
items={items}
filterEmpty={filterEmpty}
highlight
fuseOptions={{
keys: ['name'],
}}
renderHighlight={(text, key) => (
<b key={key} style={{ textDecoration: 'underline', color: 'red' }}>
{text}
</b>
)}
render={items =>
items.map(item => <div key={item.key}>{item.name_highlight || item.name}</div>)
}
/>
</Wrapper>
)
})

4
src/components/base/Tabs/stories.js

@ -6,9 +6,9 @@ import { storiesOf } from '@storybook/react'
import Tabs from 'components/base/Tabs'
const stories = storiesOf('Components/Tabs', module)
const stories = storiesOf('Components', module)
stories.add('basic', () => (
stories.add('Tabs', () => (
<Tabs
index={number('index', 0, {
min: 0,

4
src/components/base/Tooltip/stories.js

@ -5,6 +5,6 @@ import { storiesOf } from '@storybook/react'
import Tooltip from 'components/base/Tooltip'
const stories = storiesOf('Components/Tooltip', module)
const stories = storiesOf('Components', module)
stories.add('basic', () => <Tooltip render={() => <div>Oyo!</div>}>Hover me!</Tooltip>)
stories.add('Tooltip', () => <Tooltip render={() => <div>Oyo!</div>}>Hover me!</Tooltip>)

Loading…
Cancel
Save