@unitedstatespowersquadrons/components 1.3.3 → 1.3.4-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Badges/Badge.tsx CHANGED
@@ -5,8 +5,8 @@ interface Props {
5
5
  content: string;
6
6
  label?: string;
7
7
  color?: string;
8
- logo?: string;
9
- logoColor?: string;
8
+ logo?: string | undefined;
9
+ logoColor?: string | undefined;
10
10
  }
11
11
 
12
12
  const Badge = (props: Props) => {
@@ -0,0 +1,27 @@
1
+ import React from "react";
2
+ import TimeAgo from "javascript-time-ago";
3
+ import "javascript-time-ago/locale/en";
4
+ import Badge from "./Badge";
5
+ import { dateBadgeColor } from "./Date";
6
+
7
+ interface Props {
8
+ timestamp: number;
9
+ label?: string;
10
+ logo?: string;
11
+ }
12
+
13
+ const LiveDateBadge = (props: Props) => {
14
+ const { timestamp, label = "date", logo } = props;
15
+
16
+ const now = Math.floor(Date.now() / 1000);
17
+
18
+ const badgeTimestamp = Math.floor(new Date(timestamp).getTime() / 1000);
19
+ const badgeDate = new Date(badgeTimestamp * 1000);
20
+ const badgeDateDiff = badgeTimestamp - now;
21
+ const color = dateBadgeColor(badgeDateDiff);
22
+ const content = (new TimeAgo("en")).format(badgeDate);
23
+
24
+ return <Badge color={color} content={content} label={label} logo={logo} />;
25
+ };
26
+
27
+ export default LiveDateBadge;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitedstatespowersquadrons/components",
3
- "version": "1.3.3",
3
+ "version": "1.3.4-1",
4
4
  "description": "USPS shared React components library",
5
5
  "main": "index.tsx",
6
6
  "scripts": {
@@ -22,6 +22,7 @@
22
22
  "@types/rails__actioncable": "^6.1.11",
23
23
  "classnames": "^2.5.1",
24
24
  "immer": "^10.1.1",
25
+ "javascript-time-ago": "^2.6.4",
25
26
  "react": "^19.1.0",
26
27
  "react-dom": "^19.1.0",
27
28
  "react-jss": "^10.10.0",