@unitedstatespowersquadrons/components 1.3.2 → 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 +2 -2
- package/Badges/Date.tsx +15 -15
- package/Badges/LiveDate.tsx +27 -0
- package/Badges/index.ts +3 -2
- package/package.json +2 -1
package/Badges/Badge.tsx
CHANGED
package/Badges/Date.tsx
CHANGED
|
@@ -7,28 +7,28 @@ interface Props {
|
|
|
7
7
|
logo?: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export const dateBadgeColor = (diff: number) => {
|
|
11
|
+
// Age
|
|
12
|
+
if (diff <= -60 * 60 * 24 * 14) return "63a2c7";
|
|
13
|
+
else if (diff <= -60 * 60 * 24) return "blue";
|
|
14
|
+
else if (diff <= -60 * 60) return "green";
|
|
15
|
+
else if (diff <= -60) return "yellowgreen";
|
|
16
|
+
|
|
17
|
+
// Expiration Time
|
|
18
|
+
else if (diff <= 60) return "orange";
|
|
19
|
+
else if (diff <= 60 * 10) return "yellowgreen";
|
|
20
|
+
else if (diff <= 60 * 60) return "green";
|
|
21
|
+
else return "brightgreen";
|
|
22
|
+
};
|
|
23
|
+
|
|
10
24
|
const DateBadge = (props: Props) => {
|
|
11
25
|
const { timestamp, label, logo } = props;
|
|
12
26
|
|
|
13
27
|
const now = Math.floor(Date.now() / 1000);
|
|
14
28
|
const diff = timestamp - now;
|
|
15
29
|
|
|
16
|
-
const color = () => {
|
|
17
|
-
// Age
|
|
18
|
-
if (diff <= -60 * 60 * 24 * 14) return "63a2c7";
|
|
19
|
-
else if (diff <= -60 * 60 * 24) return "blue";
|
|
20
|
-
else if (diff <= -60 * 60) return "green";
|
|
21
|
-
else if (diff <= -60) return "yellowgreen";
|
|
22
|
-
|
|
23
|
-
// Expiration Time
|
|
24
|
-
else if (diff <= 60) return "orange";
|
|
25
|
-
else if (diff <= 60 * 10) return "yellowgreen";
|
|
26
|
-
else if (diff <= 60 * 60) return "green";
|
|
27
|
-
else return "brightgreen";
|
|
28
|
-
};
|
|
29
|
-
|
|
30
30
|
const params = new URLSearchParams();
|
|
31
|
-
params.set("color",
|
|
31
|
+
params.set("color", dateBadgeColor(diff));
|
|
32
32
|
if (label) params.set("label", label);
|
|
33
33
|
if (logo) params.set("logo", logo);
|
|
34
34
|
|
|
@@ -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/Badges/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Badge from "./Badge";
|
|
2
2
|
import Branch from "./Branch";
|
|
3
3
|
import Commit from "./Commit";
|
|
4
|
-
import Date from "./Date";
|
|
4
|
+
import Date, { dateBadgeColor } from "./Date";
|
|
5
5
|
import Dependency from "./Dependency";
|
|
6
6
|
import Gem from "./Gem";
|
|
7
7
|
import Npm from "./Npm";
|
|
@@ -14,7 +14,7 @@ import Tag from "./Tag";
|
|
|
14
14
|
export { default as Badge } from "./Badge";
|
|
15
15
|
export { default as BranchBadge } from "./Branch";
|
|
16
16
|
export { default as CommitBadge } from "./Commit";
|
|
17
|
-
export { default as DateBadge } from "./Date";
|
|
17
|
+
export { default as DateBadge, dateBadgeColor } from "./Date";
|
|
18
18
|
export { default as DependencyBadge } from "./Dependency";
|
|
19
19
|
export { default as GemBadge } from "./Gem";
|
|
20
20
|
export { default as NpmBadge } from "./Npm";
|
|
@@ -39,4 +39,5 @@ export default {
|
|
|
39
39
|
Repo,
|
|
40
40
|
Suite,
|
|
41
41
|
Tag,
|
|
42
|
+
dateBadgeColor,
|
|
42
43
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unitedstatespowersquadrons/components",
|
|
3
|
-
"version": "1.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",
|