Skip to content

Commit

Permalink
feat: support thousands separator
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinEberhardt committed Jun 13, 2018
1 parent e446aa4 commit 1213cea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
</style>
</head>
<body>
<applause-button multiclap="true" url="google.com"/>
<applause-button multiclap="true" url="applause-button.com/"/>
</body>
</html>
8 changes: 6 additions & 2 deletions src/applause-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const updateClaps = (claps, url) =>

const arrayOfSize = size => new Array(size).fill(undefined);

const formatClaps = claps => claps.toLocaleString("en");

// toggle a CSS class to re-trigger animations
const toggleClass = (element, cls) => {
element.classList.remove(cls);
Expand Down Expand Up @@ -120,7 +122,9 @@ class ApplauseButton extends HTMLCustomElement {
this._updateClaps();

setTimeout(() => {
this._countElement.innerHTML = Number(this._countElement.innerHTML) + 1;
this._countElement.innerHTML = formatClaps(
Number(this._countElement.innerHTML) + 1
);
}, 250);

if (this.multiclap) {
Expand All @@ -136,7 +140,7 @@ class ApplauseButton extends HTMLCustomElement {
this.classList.remove("loading");
const clapCount = Number(claps);
if (clapCount > 0) {
this._countElement.innerHTML = Number(claps);
this._countElement.innerHTML = formatClaps(Number(claps));
}
});

Expand Down

0 comments on commit 1213cea

Please sign in to comment.