Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

EnvironmentMachineIcon.tsx

75 lines2.1 KB

1import type { EnvironmentMachineKind } from "@t3tools/contracts";
2import { CloudIcon, LaptopIcon, MonitorIcon, ServerIcon, type LucideProps } from "lucide-react";
3import type { FunctionComponent, SVGProps } from "react";
4​
5// Lucide has no Apple desktops, so these two are drawn to its grammar (24
6// unit grid, 2 unit stroke, round joins) and share its prop surface so callers
7// can swap freely.
8function LucideLike(props: SVGProps<SVGSVGElement>) {
9 return (
10 <svg
11 xmlns="http://www.w3.org/2000/svg"
12 width="24"
13 height="24"
14 viewBox="0 0 24 24"
15 fill="none"
16 stroke="currentColor"
17 strokeWidth="2"
18 strokeLinecap="round"
19 strokeLinejoin="round"
20 {...props}
21 />
22 );
24​
25/** A Mac mini: squat rounded slab with a front-edge LED. */
26export function MacMiniIcon(props: SVGProps<SVGSVGElement>) {
27 return (
28 <LucideLike {...props}>
29 <rect width="20" height="8" x="2" y="8" rx="2" />
30 <path d="M6 12h.01" />
31 </LucideLike>
32 );
34​
35/** A Mac Studio: the same slab twice as tall, ports along the front foot. */
36export function MacStudioIcon(props: SVGProps<SVGSVGElement>) {
37 return (
38 <LucideLike {...props}>
39 <rect width="18" height="14" x="3" y="5" rx="2" />
40 <path d="M7 15h.01M11 15h.01M15 15h.01" />
41 </LucideLike>
42 );
44​
45const ICON_BY_KIND: Record<EnvironmentMachineKind, FunctionComponent<LucideProps>> = {
46 server: ServerIcon,
47 cloud: CloudIcon,
48 desktop: MonitorIcon,
49 laptop: LaptopIcon,
50 "mac-mini": MacMiniIcon,
51 "mac-studio": MacStudioIcon,
52};
53​
54export const ENVIRONMENT_MACHINE_KIND_LABELS: Record<EnvironmentMachineKind, string> = {
55 server: "Server",
56 cloud: "Cloud VM",
57 desktop: "Desktop",
58 laptop: "Laptop",
59 "mac-mini": "Mac mini",
60 "mac-studio": "Mac Studio",
61};
62​
63export function environmentMachineIcon(
64 kind: EnvironmentMachineKind,
65): FunctionComponent<LucideProps> {
66 return ICON_BY_KIND[kind];
68​
69export function EnvironmentMachineIcon({
70 kind,
71 ...props
72}: LucideProps & { readonly kind: EnvironmentMachineKind }) {
73 const Icon = ICON_BY_KIND[kind];
74 return <Icon {...props} />;