Skip to content

Instantly share code, notes, and snippets.

@trevorblades
Created April 10, 2019 20:56
Show Gist options
  • Save trevorblades/6c1823cca7224c848ac4492b3deaefb8 to your computer and use it in GitHub Desktop.
Save trevorblades/6c1823cca7224c848ac4492b3deaefb8 to your computer and use it in GitHub Desktop.
import PropTypes from 'prop-types';
import React from 'react';
import {formatMoney} from '../utils/format';
import {withTheme} from '@material-ui/core/styles';
function Diff(props) {
if (!props.value) {
return <span>Even</span>;
}
const {error, secondary} = props.theme.palette;
const color = props.value < 0 ? error.main : secondary.main;
const sign = props.value > 0 ? '+' : '-';
return (
<span style={{color}}>
{sign}
{formatMoney(Math.abs(props.value))}
</span>
);
}
Diff.propTypes = {
value: PropTypes.number.isRequired,
theme: PropTypes.object.isRequired
};
export default withTheme()(Diff);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment