Skip to content

Commit

Permalink
feat(component): Add contact component (#9)
Browse files Browse the repository at this point in the history
Select a service from the list.
Render a clickable component with an icon and URL.
  • Loading branch information
5ouma authored Nov 8, 2024
1 parent 2aecf4d commit 7b7edac
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 0 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"@cxa/astro-inline-svg": "0.5.1",
"@iconify-json/mingcute": "1.2.1",
"@iconify-json/simple-icons": "1.2.11",
"astro": "4.16.10",
"astro-icon": "1.1.2",
"qrcode": "1.5.4",
Expand Down
45 changes: 45 additions & 0 deletions src/components/Contact/Contact.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
import { Icon } from "astro-icon/components";
import { getContact } from "../../libs/contact.ts";
import type { service } from "../../types/services.ts";
import "../../styles/global.css";
export type Props = { service: service; id: string };
const props = Astro.props;
const contact = getContact(props.service, props.id);
---

<a
href={contact.url}
target="_blank"
rel="noopener noreferrer"
aria-label={`Go to ${props.id} profile on ${props.service}`}
>
<Icon id="icon" name={contact.icon} />
<span>{props.id}</span>
</a>

<style>
a {
display: inline-flex;
align-items: center;
gap: 0.5rem;
text-decoration: none;
color: var(--foreground);
}

#icon {
width: 1.5rem;
height: auto;
}

span {
font-family: "LINE Seed JP";
font-size: 1rem;
font-style: normal;
font-weight: bold;
line-height: normal;
}
</style>
17 changes: 17 additions & 0 deletions src/components/Contact/Contact.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Contact from "./Contact.astro";
import * as stories from "./story.ts";

export default {
title: "Contact Links",
component: Contact,
};

export const Bluesky = { args: stories.Bluesky };
export const Facebook = { args: stories.Facebook };
export const GitHub = { args: stories.GitHub };
export const Instagram = { args: stories.Instagram };
export const Mastodon = { args: stories.Mastodon };
export const Misskey = { args: stories.Misskey };
export const Posts = { args: stories.Posts };
export const Twitter = { args: stories.Twitter };
export const Mail = { args: stories.Mail };
16 changes: 16 additions & 0 deletions src/components/Contact/Contact.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { experimental_AstroContainer as AstroContainer } from "astro/container";
import { describe, expect, test } from "vitest";

import Contact from "./Contact.astro";
import * as stories from "./story.ts";

describe("Contact", () => {
for (const [name, props] of Object.entries(stories)) {
test(name, async () => {
const container: AstroContainer = await AstroContainer.create();
const result: string = await container.renderToString(Contact, { props });

expect(result).toContain(`>${props.id}</span>`);
});
}
});
46 changes: 46 additions & 0 deletions src/components/Contact/story.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Props } from "./Contact.astro";

export const Bluesky: Props = {
service: "Bluesky",
id: "bsky.app",
};

export const Facebook: Props = {
service: "Facebook",
id: "facebook",
};

export const GitHub: Props = {
service: "GitHub",
id: "github",
};

export const Instagram: Props = {
service: "Instagram",
id: "instagram",
};

export const Mastodon: Props = {
service: "Mastodon",
id: "@[email protected]",
};

export const Misskey: Props = {
service: "Misskey",
id: "@[email protected]",
};

export const Posts: Props = {
service: "Posts",
id: "support",
};

export const Twitter: Props = {
service: "Twitter",
id: "twitter",
};

export const Mail: Props = {
service: "Mail",
id: "[email protected]",
};
11 changes: 11 additions & 0 deletions src/libs/contact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { type service, services } from "../types/services";

type contact = { url: string; icon: string };

export const getContact = (service: service, id: string): contact => {
const url: string =
service === "Mastodon" || service === "Misskey"
? `https://${id.split("@")[2]}/${id}`
: services[service].url + id;
return { url, icon: services[service].icon };
};
40 changes: 40 additions & 0 deletions src/types/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export const services = {
Bluesky: {
url: "https://bsky.app/profile/",
icon: "mingcute:bluesky-social-line",
},
Facebook: {
url: "https://www.facebook.com/",
icon: "mingcute:facebook-line",
},
GitHub: {
url: "https://github.com/",
icon: "mingcute:github-line",
},
Instagram: {
url: "https://www.instagram.com/",
icon: "mingcute:ins-line",
},
Mastodon: {
url: "",
icon: "mingcute:mastodon-line",
},
Misskey: {
url: "",
icon: "simple-icons:misskey",
},
Posts: {
url: "https://posts.cv/",
icon: "simple-icons:readdotcv",
},
Twitter: {
url: "https://twitter.com/",
icon: "mingcute:twitter-line",
},
Mail: {
url: "mailto:",
icon: "mingcute:mail-line",
},
};

export type service = keyof typeof services;

1 comment on commit 7b7edac

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bun.lockb

diff --git a/bun.lockb b/bun.lockb
index 78bfedb..df212f1 100755
--- a/bun.lockb
+++ b/bun.lockb
@@ -1,6 +1,6 @@
 # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
 # yarn lockfile v1
-# bun ./bun.lockb --hash: 7D6D70C0194F7DEF-fe2eb6d62d1bf0f4-A1186C6E81365936-33cf52ef6b45658c
+# bun ./bun.lockb --hash: 3838544D94CEA901-e458e99f25a47b33-618453C90FEF49BF-a60fefc138455849
 
 
 "@ampproject/remapping@^2.2.0", "@ampproject/remapping@^2.3.0":
@@ -369,7 +369,7 @@
   resolved "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.9.4.tgz"
   integrity sha512-8Y5wMhVIPaWe6jw2H+KlEm4wP/f7EW3810ZLmDlrEEy5KvBsb9ECEfu/kMWD484ijfQ8+nIi0giMgu9g1UAuuA==
 
-"@cxa/astro-inline-svg@^0.5.1":
+"@cxa/[email protected]":
   version "0.5.1"
   resolved "https://registry.npmjs.org/@cxa/astro-inline-svg/-/astro-inline-svg-0.5.1.tgz"
   integrity sha512-EGBr2L/Rxh6ukYWlx4qfzg9gdyBU7ZmWcScBApXfYfGw3MTIeSloyLNJR6bIgEvRWlkPNE4YiNf7h/hIAq0wRw==
@@ -542,13 +542,20 @@
   resolved "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.21.5.tgz"
   integrity sha512-tQd/1efJuzPC6rCFwEvLtci/xNFcTZknmXs98FYDfGE4wP9ClFV98nyKrzJKVPMhdDnjzLhdUyMX4PsQAPjwIw==
 
-"@iconify-json/mingcute@^1.2.1":
+"@iconify-json/[email protected]":
   version "1.2.1"
   resolved "https://registry.npmjs.org/@iconify-json/mingcute/-/mingcute-1.2.1.tgz"
   integrity sha512-rv682dBsjKUs1/AVg5tOegAunjCLuqyQufXU0D6Kbmgg5jMoUcl/9K2C+9MAiepBP0Eyb05YwXQvGaXMLPu/YA==
   dependencies:
     "@iconify/types" "*"
 
+"@iconify-json/simple-icons@^1.2.11":
+  version "1.2.11"
+  resolved "https://registry.npmjs.org/@iconify-json/simple-icons/-/simple-icons-1.2.11.tgz"
+  integrity sha512-AHCGDtBRqP+JzAbBzgO8uN/08CXxEmuaC6lQQZ3b5burKhRU12AJnJczwbUw2K5Mb/U85EpSUNhYMG3F28b8NA==
+  dependencies:
+    "@iconify/types" "*"
+
 "@iconify/tools@^4.0.5":
   version "4.0.7"
   resolved "https://registry.npmjs.org/@iconify/tools/-/tools-4.0.7.tgz"
@@ -1334,7 +1341,7 @@ [email protected], astro@^4.0.0:
   optionalDependencies:
     sharp "^0.33.3"
 
-astro-icon@^1.1.2:
+[email protected]:
   version "1.1.2"
   resolved "https://registry.npmjs.org/astro-icon/-/astro-icon-1.1.2.tgz"
   integrity sha512-2qAHBtZLYuFEIMP0Ck0edyLi5fQmJjwP2Qbv41f8L4KAJ2sra/dH7q5lCOn4q0DHVtS0w3tPG8UKQRits3UPcg==

Please sign in to comment.