Skip to content

Instantly share code, notes, and snippets.

@fliptheweb
Forked from davidgilbertson/Price-with-usage.jsx
Created March 20, 2017 04:36
Show Gist options
  • Save fliptheweb/62d6e6c0e88c8c041a34d4d59e351432 to your computer and use it in GitHub Desktop.
Save fliptheweb/62d6e6c0e88c8c041a34d4d59e351432 to your computer and use it in GitHub Desktop.
const Price = (props) => {
const price = props.children.toLocaleString('en', {
style: props.showSymbol ? 'currency' : undefined,
currency: props.showSymbol ? 'USD' : undefined,
maximumFractionDigits: props.showDecimals ? 2 : 0,
});
return <span className={props.className}>{price}</span>
};
Price.propTypes = {
className: React.PropTypes.string,
children: React.PropTypes.number,
showDecimals: React.PropTypes.bool,
showSymbol: React.PropTypes.bool,
};
Price.defaultProps = {
children: 0,
showDecimals: true,
showSymbol: true,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment