-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(component): Add homepage component (#7)
Generate a QR code for the homepage URL. Render a clickable component and a URL with it.
- Loading branch information
Showing
8 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
import Svg from "@cxa/astro-inline-svg"; | ||
import { Icon } from "astro-icon/components"; | ||
import "../../styles/global.css"; | ||
import { generateQRCode } from "../../libs/qrcode.ts"; | ||
export type Props = { url: string }; | ||
const props = Astro.props; | ||
const url = new URL(props.url); | ||
const qrCode: string = await generateQRCode(props.url); | ||
--- | ||
|
||
<a | ||
href={props.url} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
aria-label={`Visit ${url.hostname}`} | ||
> | ||
<Svg id="qr" raw={qrCode} /> | ||
<div> | ||
<Icon id="icon" name="mingcute:home-3-line" /> | ||
<span aria-hidden="true"> | ||
{`${url.hostname}${url.pathname === "/" ? "" : url.pathname}`} | ||
</span> | ||
</div> | ||
</a> | ||
|
||
<style> | ||
a { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 0.3rem; | ||
text-decoration: none; | ||
} | ||
|
||
#qr { | ||
path { | ||
stroke: var(--foreground); | ||
} | ||
width: 6rem; | ||
height: auto; | ||
} | ||
|
||
div { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 0.3rem; | ||
color: var(--foreground); | ||
} | ||
|
||
#icon { | ||
width: 1rem; | ||
height: auto; | ||
} | ||
|
||
span { | ||
font-family: "LINE Seed JP", sans-serif; | ||
font-size: 0.75rem; | ||
font-style: normal; | ||
font-weight: normal; | ||
line-height: normal; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Homepage from "./Homepage.astro"; | ||
import * as stories from "./story.ts"; | ||
|
||
export default { | ||
title: "Homepage", | ||
component: Homepage, | ||
}; | ||
|
||
export const Domain = { args: stories.Domain }; | ||
export const Path = { args: stories.Path }; | ||
export const Japanese = { args: stories.Japanese }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { experimental_AstroContainer as AstroContainer } from "astro/container"; | ||
import { describe, expect, test } from "vitest"; | ||
|
||
import Homepage from "./Homepage.astro"; | ||
import * as stories from "./story.ts"; | ||
|
||
describe("Homepage", () => { | ||
for (const [name, props] of Object.entries(stories)) { | ||
test(name, async () => { | ||
const container: AstroContainer = await AstroContainer.create(); | ||
const result: string = await container.renderToString(Homepage, { | ||
props, | ||
}); | ||
const url = new URL(props.url); | ||
|
||
expect(result).toContain( | ||
`> ${encodeURI(url.hostname)}${ | ||
url.pathname === "/" ? "" : url.pathname | ||
} </span>`, | ||
); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { Props } from "./Homepage.astro"; | ||
|
||
export const Domain: Props = { url: "https://example.com" }; | ||
export const Path: Props = { url: "https://www.example.com/path" }; | ||
export const Japanese: Props = { url: "https://www.example.com/パス" }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import QRCode from "qrcode"; | ||
|
||
export const generateQRCode = async (url: string): Promise<string> => | ||
await QRCode.toString(url, { | ||
type: "svg", | ||
margin: 0, | ||
color: { light: "#00000000" }, | ||
}); |
bc4ab6e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bun.lockb