@unitedstatespowersquadrons/components 1.2.36 → 1.3.0-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.
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import { shields } from "./remotes";
3
+
4
+ interface Props {
5
+ content: string;
6
+ label?: string;
7
+ color?: string;
8
+ logo?: string;
9
+ logoColor?: string;
10
+ }
11
+
12
+ const Badge = (props: Props) => {
13
+ const { content, label, color = "gray", logo, logoColor } = props;
14
+
15
+ const main = [label, content, color].filter(Boolean).join("-");
16
+ const params = new URLSearchParams();
17
+ if (logo) params.set("logo", logo);
18
+ if (logoColor) params.set("logoColor", logoColor);
19
+ const query = params.toString();
20
+ const src = `${shields}/badge/${main}${query ? `?${query}` : ""}`;
21
+
22
+ return <img src={src} />;
23
+ };
24
+
25
+ export default Badge;
@@ -0,0 +1,33 @@
1
+ import React from "react";
2
+ import { github, shields } from "./remotes";
3
+ import { badgeify } from "./helpers";
4
+
5
+ interface Props {
6
+ branch: string;
7
+ primaryBranch?: "main" | "master";
8
+ repo?: string;
9
+ }
10
+
11
+ const BranchBadge = (props: Props) => {
12
+ const { branch, primaryBranch = "main", repo } = props;
13
+
14
+ const effectiveRepo = branch === primaryBranch ? undefined : repo;
15
+ const color = branch === primaryBranch ? "blue" : "orange";
16
+ const name = badgeify(branch)!;
17
+
18
+ const img = (
19
+ <img src={`${shields}/badge/${name}-${color}?logo=git&logoColor=white`} />
20
+ );
21
+ if (!effectiveRepo) return img;
22
+
23
+ return(
24
+ <a
25
+ href={`${github}/${effectiveRepo}/compare/${branch}?expand=1`}
26
+ rel="noreferrer" target="_blank"
27
+ >
28
+ {img}
29
+ </a>
30
+ );
31
+ };
32
+
33
+ export default BranchBadge;
@@ -0,0 +1,27 @@
1
+ import React from "react";
2
+ import { github, shields } from "./remotes";
3
+
4
+ interface Props {
5
+ commit: string;
6
+ repo?: string;
7
+ }
8
+
9
+ const CommitBadge = (props: Props) => {
10
+ const { commit, repo } = props;
11
+
12
+ const img = (
13
+ <img src={`${shields}/badge/sha-${commit.slice(0, 12)}-purple`} />
14
+ );
15
+ if (!repo) return img;
16
+
17
+ return(
18
+ <a
19
+ href={`${github}/${repo}/commit/${commit}`}
20
+ rel="noreferrer" target="_blank"
21
+ >
22
+ {img}
23
+ </a>
24
+ );
25
+ };
26
+
27
+ export default CommitBadge;
@@ -0,0 +1,38 @@
1
+ import React from "react";
2
+ import { shields } from "./remotes";
3
+
4
+ interface Props {
5
+ timestamp: number;
6
+ label?: string;
7
+ logo?: string;
8
+ }
9
+
10
+ const DateBadge = (props: Props) => {
11
+ const { timestamp, label, logo } = props;
12
+
13
+ const now = Math.floor(Date.now() / 1000);
14
+ const diff = timestamp - now;
15
+
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
+ const params = new URLSearchParams();
31
+ params.set("color", color());
32
+ if (label) params.set("label", label);
33
+ if (logo) params.set("logo", logo);
34
+
35
+ return <img src={`${shields}/date/${timestamp}?${params.toString()}`} />;
36
+ };
37
+
38
+ export default DateBadge;
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import TagBadge from "./Tag";
3
+
4
+ interface Props {
5
+ value: string;
6
+ label: string;
7
+ logo: string;
8
+ }
9
+
10
+ const DependencyBadge = (props: Props) => {
11
+ const { value, label, logo } = props;
12
+
13
+ return <TagBadge label={label} logo={logo} version={value} />;
14
+ };
15
+
16
+ export default DependencyBadge;
package/Badges/Gem.tsx ADDED
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import { shields } from "./remotes";
3
+
4
+ interface Props {
5
+ gem: string;
6
+ includePrereleases?: boolean;
7
+ }
8
+
9
+ const GemBadge = (props: Props) => {
10
+ const { gem, includePrereleases } = props;
11
+
12
+ const pre = includePrereleases ? "&include_prereleases" : "";
13
+
14
+ return(
15
+ <a href={`https://rubygems.org/gems/${gem}`} rel="noreferrer" target="_blank">
16
+ <img src={`${shields}/gem/v/${gem}?logo=rubygems&logoColor=white${pre}`} />
17
+ </a>
18
+ );
19
+ };
20
+
21
+ export default GemBadge;
package/Badges/Npm.tsx ADDED
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { shields } from "./remotes";
3
+
4
+ interface Props {
5
+ npm: string;
6
+ includePrereleases?: boolean;
7
+ }
8
+
9
+ const NpmBadge = (props: Props) => {
10
+ const { npm, includePrereleases } = props;
11
+
12
+ const pre = includePrereleases ? "&include_prereleases" : "";
13
+ const pkg = `@unitedstatespowersquadrons/${npm}`;
14
+
15
+ return(
16
+ <a href={`https://www.npmjs.com/package/${pkg}`} rel="noreferrer" target="_blank">
17
+ <img src={`${shields}/npm/v/${pkg}?logo=typescript&logoColor=white${pre}`} />
18
+ </a>
19
+ );
20
+ };
21
+
22
+ export default NpmBadge;
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import Badge from "./Badge";
3
+ import { github } from "./remotes";
4
+ import { versionColor } from "./helpers";
5
+
6
+ interface Props {
7
+ php: string;
8
+ version: string;
9
+ }
10
+
11
+ const PhpLibraryBadge = (props: Props) => {
12
+ const { php, version } = props;
13
+
14
+ return(
15
+ <a href={`${github}/${php}`} rel="noreferrer" target="_blank">
16
+ <Badge
17
+ color={versionColor(version)} content={version}
18
+ label="library" logo="php" logoColor="white"
19
+ />
20
+ </a>
21
+ );
22
+ };
23
+
24
+ export default PhpLibraryBadge;
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import Badge from "./Badge";
3
+ import { ReachableStatus } from "./types";
4
+
5
+ interface Props {
6
+ host: string;
7
+ reachable?: ReachableStatus;
8
+ }
9
+
10
+ const ReachableBadge = (props: Props) => {
11
+ const { host, reachable } = props;
12
+
13
+ const status = reachable?.status;
14
+ const reason = reachable?.reason || "Error";
15
+
16
+ const badge = status
17
+ ? <Badge color="brightgreen" content="Reachable" label={host} />
18
+ : <Badge color="red" content={reason} label={host} />;
19
+
20
+ return(
21
+ <a
22
+ href={`https://${host}.aws.usps.org`}
23
+ rel="noreferrer" target="_blank"
24
+ >
25
+ {badge}
26
+ </a>
27
+ );
28
+ };
29
+
30
+ export default ReachableBadge;
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import { github, shields } from "./remotes";
3
+
4
+ interface Props {
5
+ repo: string;
6
+ }
7
+
8
+ const RepoBadge = (props: Props) => {
9
+ const { repo } = props;
10
+
11
+ return(
12
+ <a href={`${github}/${repo}`} rel="noreferrer" target="_blank">
13
+ <img src={`${shields}/badge/repo-gray?logo=github`} />
14
+ </a>
15
+ );
16
+ };
17
+
18
+ export default RepoBadge;
@@ -0,0 +1,72 @@
1
+ import React from "react";
2
+ import { github, shields } from "./remotes";
3
+ import { badgeify } from "./helpers";
4
+ import { CheckSuite } from "./types";
5
+
6
+ interface Props {
7
+ suite?: CheckSuite;
8
+ repo?: string;
9
+ }
10
+
11
+ const SuiteBadge = (props: Props) => {
12
+ const { suite, repo } = props;
13
+
14
+ if (!suite || !suite.status) return null;
15
+
16
+ const suiteBadgeColor = () => {
17
+ if (suite.skip_ci) return "lightgray";
18
+
19
+ switch (suite.status) {
20
+ case "queued":
21
+ case "in_progress":
22
+ case "requested":
23
+ case "waiting":
24
+ case "pending":
25
+ return "yellow";
26
+ case "completed":
27
+ switch (suite.conclusion) {
28
+ case "success": return "brightgreen";
29
+ case "failure":
30
+ case "timed_out":
31
+ case "action_required": return "red";
32
+ case "cancelled": return "orange";
33
+ default: return "lightgray";
34
+ }
35
+ default:
36
+ return "lightgray";
37
+ }
38
+ };
39
+
40
+ const titleize = (text: string) =>
41
+ text.replace(/(^|\s)\S/g, t => t.toUpperCase());
42
+
43
+ const branch = badgeify(suite.head_branch);
44
+ const description = suite.skip_ci
45
+ ? "Skipped"
46
+ : suite.status === "completed"
47
+ ? badgeify(titleize(suite.conclusion || ""))
48
+ : badgeify(titleize(suite.status));
49
+ const color = suiteBadgeColor();
50
+
51
+ const img = (
52
+ <img
53
+ src={
54
+ `${shields}/badge/`
55
+ + `${branch}-${description || "Unknown"}-${color}`
56
+ + "?logo=github"
57
+ }
58
+ />
59
+ );
60
+ if (!repo || suite.conclusion === "success") return img;
61
+
62
+ return(
63
+ <a
64
+ href={`${github}/${repo}/actions/workflows/main.yml`}
65
+ rel="noreferrer" target="_blank"
66
+ >
67
+ {img}
68
+ </a>
69
+ );
70
+ };
71
+
72
+ export default SuiteBadge;
package/Badges/Tag.tsx ADDED
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import Badge from "./Badge";
3
+ import { badgeify, versionColor } from "./helpers";
4
+
5
+ interface Props {
6
+ version: string;
7
+ label?: string;
8
+ logo?: string;
9
+ }
10
+
11
+ const TagBadge = (props: Props) => {
12
+ const { version, label, logo } = props;
13
+
14
+ const badgeLabel = label ? badgeify(label) : undefined;
15
+
16
+ return(
17
+ <Badge
18
+ content={version} {...badgeLabel ? { label: badgeLabel } : {}}
19
+ color={versionColor(version)} {...logo ? { logo } : {}}
20
+ />
21
+ );
22
+ };
23
+
24
+ export default TagBadge;
@@ -0,0 +1,5 @@
1
+ export const badgeify = (text?: string) =>
2
+ text?.replaceAll("-", "--")?.replaceAll("_", "__")?.replaceAll(" ", "_");
3
+
4
+ export const versionColor = (version: string) =>
5
+ version.slice(0, 2) === "v0" ? "orange" : "blue";
@@ -0,0 +1,40 @@
1
+ import Badge from "./Badge";
2
+ import Branch from "./Branch";
3
+ import Commit from "./Commit";
4
+ import Date from "./Date";
5
+ import Dependency from "./Dependency";
6
+ import Gem from "./Gem";
7
+ import Npm from "./Npm";
8
+ import PhpLibrary from "./PhpLibrary";
9
+ import Reachable from "./Reachable";
10
+ import Repo from "./Repo";
11
+ import Suite from "./Suite";
12
+ import Tag from "./Tag";
13
+
14
+ export { default as Badge } from "./Badge";
15
+ export { default as BranchBadge } from "./Branch";
16
+ export { default as CommitBadge } from "./Commit";
17
+ export { default as DateBadge } from "./Date";
18
+ export { default as DependencyBadge } from "./Dependency";
19
+ export { default as GemBadge } from "./Gem";
20
+ export { default as NpmBadge } from "./Npm";
21
+ export { default as PhpLibraryBadge } from "./PhpLibrary";
22
+ export { default as ReachableBadge } from "./Reachable";
23
+ export { default as RepoBadge } from "./Repo";
24
+ export { default as SuiteBadge } from "./Suite";
25
+ export { default as TagBadge } from "./Tag";
26
+
27
+ export default {
28
+ Badge,
29
+ Branch,
30
+ Commit,
31
+ Date,
32
+ Dependency,
33
+ Gem,
34
+ Npm,
35
+ PhpLibrary,
36
+ Reachable,
37
+ Repo,
38
+ Suite,
39
+ Tag,
40
+ };
@@ -0,0 +1,2 @@
1
+ export const shields = "https://img.shields.io";
2
+ export const github = "https://github.com/unitedstatespowersquadrons";
@@ -0,0 +1,13 @@
1
+ export interface CheckSuite {
2
+ head_branch: string;
3
+ head_sha?: string;
4
+ status: string;
5
+ conclusion?: string;
6
+ updated_at?: string;
7
+ skip_ci: boolean;
8
+ }
9
+
10
+ export interface ReachableStatus {
11
+ status: boolean;
12
+ reason?: string;
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitedstatespowersquadrons/components",
3
- "version": "1.2.36",
3
+ "version": "1.3.0-1",
4
4
  "description": "USPS shared React components library",
5
5
  "main": "index.tsx",
6
6
  "scripts": {