From 7ae2f25a2772a8a9df6d8bbbb7f84eb1880a38a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Fri, 13 Apr 2018 11:07:55 +0200 Subject: [PATCH] Add Top/Bottom Icon for Balance Summary --- src/components/BalanceSummary/BalanceInfos.js | 9 ++- src/components/base/Chart/refreshDraw.js | 9 ++- src/components/base/FormattedVal/index.js | 55 ++++++++++++++++--- src/icons/Bottom.js | 12 ++++ src/icons/Top.js | 12 ++++ 5 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 src/icons/Bottom.js create mode 100644 src/icons/Top.js diff --git a/src/components/BalanceSummary/BalanceInfos.js b/src/components/BalanceSummary/BalanceInfos.js index 8b3ad174..12129e59 100644 --- a/src/components/BalanceSummary/BalanceInfos.js +++ b/src/components/BalanceSummary/BalanceInfos.js @@ -42,10 +42,10 @@ export function BalanceSincePercent(props: BalanceSinceProps) { return ( {t(`time:since.${since}`)} @@ -58,10 +58,10 @@ export function BalanceSinceDiff(props: Props) { {t(`time:since.${since}`)} @@ -73,7 +73,6 @@ export function BalanceTotal(props: BalanceTotalProps) { return ( (p.isNegative ? p.theme.colors.alertRed : p.theme.colors.positiveGreen), + color: p => + p.withIcon + ? p.theme.colors.dark + : p.isNegative + ? p.theme.colors.alertRed + : p.theme.colors.positiveGreen, })`` +const I = ({ color, children }: { color: string, children: any }) => ( + {children} +) + type Props = { - val: number, + alwaysShowSign?: boolean, + disableRounding?: boolean, fiat?: string | null, isPercent?: boolean, - unit?: Unit | null, - alwaysShowSign?: boolean, showCode?: boolean, - disableRounding?: boolean, + unit?: Unit | null, + val: number, + withIcon?: boolean, } function FormattedVal(props: Props) { - const { val, disableRounding, fiat, isPercent, alwaysShowSign, showCode, ...p } = props - let { unit } = props + const { disableRounding, fiat, isPercent, alwaysShowSign, showCode, withIcon, ...p } = props + let { val, unit } = props if (isUndefined(val)) { throw new Error('FormattedVal require a `val` prop. Received `undefined`') @@ -45,6 +59,11 @@ function FormattedVal(props: Props) { } else if (!unit) { return '' } + + if (withIcon && isNegative) { + val *= -1 + } + text = formatCurrencyUnit(unit, val, { alwaysShowSign, disableRounding, @@ -53,8 +72,25 @@ function FormattedVal(props: Props) { } return ( - - {text} + + {withIcon ? ( + + + {isNegative ? ( + + + + ) : ( + + + + )} + + {text} + + ) : ( + text + )} ) } @@ -66,6 +102,7 @@ FormattedVal.defaultProps = { isPercent: false, showCode: false, unit: null, + withIcon: false, } export default FormattedVal diff --git a/src/icons/Bottom.js b/src/icons/Bottom.js new file mode 100644 index 00000000..cc14334a --- /dev/null +++ b/src/icons/Bottom.js @@ -0,0 +1,12 @@ +// @flow + +import React from 'react' + +export default ({ size, ...p }: { size: number }) => ( + + + +) diff --git a/src/icons/Top.js b/src/icons/Top.js new file mode 100644 index 00000000..68c48884 --- /dev/null +++ b/src/icons/Top.js @@ -0,0 +1,12 @@ +// @flow + +import React from 'react' + +export default ({ size, ...p }: { size: number }) => ( + + + +)