Files
sorsfonalak/services/frontend/src/components/MoonChip.tsx
T

59 lines
1.8 KiB
TypeScript
Raw Normal View History

import Link from "next/link";
import { SIGNS } from "@/lib/astro";
import { SIGN_IN, withArticle } from "@/lib/skyText";
import type { SkyNow } from "@/lib/types";
/** The Moon as it is lit now: the lit part on the right while waxing, on the left while waning. */
export function MoonPhaseIcon({
illumination,
waxing,
}: {
illumination: number;
waxing: boolean;
}) {
const r = 8.5;
const k = Math.min(1, Math.max(0, illumination));
const rx = Math.abs(1 - 2 * k) * r;
// The outer edge on the lit side, then the terminator back.
const outer = waxing ? 1 : 0;
const terminator = waxing ? (k > 0.5 ? 1 : 0) : k > 0.5 ? 0 : 1;
const d = `M12 ${12 - r}A${r} ${r} 0 0 ${outer} 12 ${12 + r}A${rx} ${r} 0 0 ${terminator} 12 ${12 - r}Z`;
return (
<svg className="moon-phase-icon" viewBox="0 0 24 24" aria-hidden="true">
<circle cx="12" cy="12" r={r} className="moon-dark" />
<path d={d} className="moon-lit" />
</svg>
);
}
/**
* "Ma: Hold a ♉ Bikában" in the header (the moon calendar behind it). Narrow
* screens show the phase and the sign's glyph only.
*/
export function MoonChip({ sky }: { sky: SkyNow }) {
const moon = sky.moon;
const sign = moon.position.sign;
const where = withArticle(SIGN_IN[sign] ?? sign);
return (
<Link
href="/holdnaptar"
className="moon-chip"
aria-label={`Ma a Hold ${where} jár: holdnaptár`}
>
<MoonPhaseIcon illumination={moon.illumination} waxing={moon.waxing} />
<span className="moon-chip-text" aria-hidden="true">
Ma: Hold {where.split(" ")[0]}{" "}
</span>
<span className="moon-chip-glyph sym" aria-hidden="true">
{SIGNS[sign]?.glyph}
{"︎"}
</span>
<span className="moon-chip-text" aria-hidden="true">
{" "}
{SIGN_IN[sign]}
</span>
</Link>
);
}