artifacts.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. "use client";
  2. import { useEffect, useMemo, useState } from "react";
  3. import { Eyebrow, SampleNote, TextLink } from "./ui";
  4. import { useT } from "@/components/locale-provider";
  5. import { projects } from "@/config/site";
  6. import { cn } from "@/lib/utils";
  7. // Each tab's label and prompt live in messages/ (artifacts.tabs).
  8. const TABS = [{ id: "chart" }, { id: "table" }, { id: "forecast" }] as const;
  9. type TabId = (typeof TABS)[number]["id"];
  10. const REGIONS = [
  11. { name: "us-east-1", value: 4820 },
  12. { name: "us-west-2", value: 2310 },
  13. { name: "eu-west-1", value: 1540 },
  14. { name: "ap-ne-1", value: 960 },
  15. { name: "eu-c-1", value: 610 },
  16. ];
  17. const INSTANCES = [
  18. { id: "i-0d3f42", type: "g5.xlarge", cpu: 88 },
  19. { id: "i-04be19", type: "c7i.xlarge", cpu: 71 },
  20. { id: "i-09c6a0", type: "r7g.2xlarge", cpu: 54 },
  21. { id: "i-0a71c3", type: "m7g.large", cpu: 38 },
  22. { id: "i-0f2d88", type: "t4g.medium", cpu: 12 },
  23. ];
  24. const ACTUAL = [8.1, 8.6, 9.4, 9.1, 10.2, 10.9];
  25. const FORECAST = [11.3, 11.9, 12.2, 12.9, 13.4, 14.1];
  26. function RegionChart() {
  27. const { artifacts: t } = useT();
  28. const [hover, setHover] = useState<number | null>(null);
  29. const max = REGIONS[0].value;
  30. return (
  31. <div className="flex h-full flex-col">
  32. <p className="mb-1.5 flex justify-between text-[11.5px] text-muted">
  33. <span className="font-medium text-ink">{t.costByRegion}</span>
  34. <span className="tabular-nums">
  35. {hover === null
  36. ? "$10,240"
  37. : `$${REGIONS[hover].value.toLocaleString()}`}
  38. </span>
  39. </p>
  40. <div
  41. className="flex min-h-0 flex-1 items-end gap-1.5"
  42. onPointerLeave={() => setHover(null)}
  43. >
  44. {REGIONS.map((r, i) => (
  45. <button
  46. key={r.name}
  47. aria-label={`${r.name}: $${r.value.toLocaleString()}`}
  48. className="flex h-full min-w-0 flex-1 flex-col items-center justify-end gap-1"
  49. type="button"
  50. onFocus={() => setHover(i)}
  51. onPointerEnter={() => setHover(i)}
  52. >
  53. <span
  54. className={cn(
  55. "w-full origin-bottom rounded-[6px] transition-opacity duration-300 [animation:grow_.8s_cubic-bezier(.2,.9,.25,1.05)_both]",
  56. hover === null || hover === i ? "opacity-100" : "opacity-35",
  57. )}
  58. style={{
  59. height: `${(r.value / max) * 100}%`,
  60. animationDelay: `${i * 60}ms`,
  61. background:
  62. "linear-gradient(180deg, var(--glacier), color-mix(in oklab, var(--glacier) 55%, var(--sky)))",
  63. }}
  64. />
  65. <span className="w-full truncate text-center text-[9.5px] text-muted">
  66. {r.name}
  67. </span>
  68. </button>
  69. ))}
  70. </div>
  71. </div>
  72. );
  73. }
  74. function InstanceTable() {
  75. const { artifacts: t } = useT();
  76. const [dir, setDir] = useState<1 | -1>(-1);
  77. const rows = useMemo(
  78. () => [...INSTANCES].sort((a, b) => (a.cpu - b.cpu) * dir),
  79. [dir],
  80. );
  81. return (
  82. <div className="flex h-full flex-col text-[11.5px]">
  83. <div className="grid grid-cols-[1fr_1.2fr_1fr] border-b border-line pb-1 text-muted">
  84. <span>{t.instance}</span>
  85. <span>{t.type}</span>
  86. <button
  87. className="text-left hover:text-ink"
  88. type="button"
  89. onClick={() => setDir((d) => (d === 1 ? -1 : 1))}
  90. >
  91. CPU {dir === -1 ? "↓" : "↑"}
  92. </button>
  93. </div>
  94. {/* Rows that don't fit wrap into a hidden second column: only whole rows show. */}
  95. <ul className="flex min-h-0 flex-1 flex-col flex-wrap overflow-hidden">
  96. {rows.map((r, i) => (
  97. <li
  98. key={r.id}
  99. className="grid w-full grid-cols-[1fr_1.2fr_1fr] items-center border-b border-line/70 py-[5px] [animation:rise_.4s_ease_both]"
  100. style={{ animationDelay: `${i * 40}ms` }}
  101. >
  102. <span className="font-mono text-[10.5px] text-glacier-ink">
  103. {r.id}
  104. </span>
  105. <span className="truncate">{r.type}</span>
  106. <span className="flex items-center gap-1.5">
  107. <span className="h-1 flex-1 overflow-hidden rounded-full bg-line">
  108. <span
  109. className={cn(
  110. "block h-full rounded-full",
  111. r.cpu > 80 ? "bg-ember" : "bg-glacier",
  112. )}
  113. style={{ width: `${r.cpu}%` }}
  114. />
  115. </span>
  116. <span className="w-7 text-right tabular-nums text-muted">
  117. {r.cpu}%
  118. </span>
  119. </span>
  120. </li>
  121. ))}
  122. </ul>
  123. </div>
  124. );
  125. }
  126. function ForecastChart() {
  127. const { artifacts: t } = useT();
  128. const all = [...ACTUAL, ...FORECAST];
  129. const px = (i: number) => (i / (all.length - 1)) * 300;
  130. const py = (v: number) => 92 - ((v - 7) / 8.5) * 84;
  131. const line = (pts: number[], offset = 0) =>
  132. pts
  133. .map(
  134. (v, i) =>
  135. `${i ? "L" : "M"}${px(i + offset).toFixed(1)} ${py(v).toFixed(1)}`,
  136. )
  137. .join(" ");
  138. const band = [
  139. ...FORECAST.map(
  140. (v, i) =>
  141. `${i ? "L" : "M"}${px(i + 6).toFixed(1)} ${py(v * (1 + 0.022 * (i + 1))).toFixed(1)}`,
  142. ),
  143. ...[...FORECAST]
  144. .reverse()
  145. .map(
  146. (v, j) =>
  147. `L${px(11 - j).toFixed(1)} ${py(v * (1 - 0.022 * (6 - j))).toFixed(1)}`,
  148. ),
  149. "Z",
  150. ].join(" ");
  151. return (
  152. <div className="flex h-full flex-col">
  153. <p className="mb-1 flex justify-between text-[11.5px] text-muted">
  154. <span className="font-medium text-ink">{t.monthly}</span>
  155. <span>{t.byMarch}</span>
  156. </p>
  157. <svg
  158. aria-label={t.forecast}
  159. className="min-h-0 w-full flex-1"
  160. preserveAspectRatio="none"
  161. role="img"
  162. viewBox="0 0 300 96"
  163. >
  164. <path
  165. className="[animation:fade-in_.8s_.5s_ease_both]"
  166. d={band}
  167. fill="var(--ember)"
  168. fillOpacity="0.16"
  169. />
  170. <path
  171. className="[animation:draw_.9s_ease_both]"
  172. d={line(ACTUAL)}
  173. fill="none"
  174. pathLength={1}
  175. stroke="var(--glacier)"
  176. strokeDasharray="1 1"
  177. strokeLinecap="round"
  178. strokeWidth="2.4"
  179. />
  180. <path
  181. className="[animation:fade-in_.6s_.8s_ease_both]"
  182. d={line([ACTUAL[5], ...FORECAST], 5)}
  183. fill="none"
  184. stroke="var(--ember)"
  185. strokeDasharray="5 5"
  186. strokeWidth="2"
  187. vectorEffect="non-scaling-stroke"
  188. />
  189. </svg>
  190. </div>
  191. );
  192. }
  193. /** Amazon Q artifacts: ask, and the answer arrives as interactive UI. */
  194. export function ArtifactsCard() {
  195. const {
  196. artifacts: copy,
  197. common: { open, sample },
  198. } = useT();
  199. const [active, setActive] = useState<TabId>("chart");
  200. const [busy, setBusy] = useState(false);
  201. const index = TABS.findIndex((t) => t.id === active);
  202. useEffect(() => {
  203. if (!busy) return;
  204. const t = window.setTimeout(() => setBusy(false), 520);
  205. return () => window.clearTimeout(t);
  206. }, [busy, active]);
  207. return (
  208. <div className="flex h-full flex-col gap-4 p-5 sm:flex-row sm:gap-5 sm:p-6">
  209. <div className="flex flex-col sm:w-[40%] sm:shrink-0">
  210. <Eyebrow className="text-glacier-ink">AWS · Amazon Q</Eyebrow>
  211. <div className="mt-1 flex items-baseline justify-between gap-3">
  212. <h2 className="title text-[26px] lg:text-[28px]">Q artifacts</h2>
  213. <TextLink
  214. className="sm:hidden"
  215. cursor={open}
  216. href={projects.artifacts.href}
  217. label={copy.docsLabel}
  218. >
  219. {copy.docs}
  220. </TextLink>
  221. </div>
  222. <p className="mt-2 text-[15px] leading-snug text-muted">{copy.pitch}</p>
  223. <div className="mt-auto pt-3 max-sm:hidden">
  224. <TextLink
  225. cursor={open}
  226. href={projects.artifacts.href}
  227. label={copy.readDocsLabel}
  228. >
  229. {copy.readDocs}
  230. </TextLink>
  231. </div>
  232. </div>
  233. {/* Like FinOps: closer to the edge than the text, concentric corners. */}
  234. <div
  235. className="-mx-2.5 -mb-2.5 flex min-h-0 flex-1 flex-col gap-2 rounded-[14px] bg-inset p-2.5 ring-1 ring-line ring-inset [container-type:size] sm:mx-0 sm:-my-3 sm:-mr-3 sm:rounded-[16px]"
  236. data-nodrag
  237. >
  238. <div
  239. className="relative grid grid-cols-3 rounded-full bg-ink/[0.06] p-0.5 dark:bg-white/[0.07]"
  240. role="tablist"
  241. >
  242. <span
  243. aria-hidden
  244. className="lg absolute inset-y-0.5 left-0.5 w-[calc((100%-4px)/3)] rounded-full shadow-[0_2px_8px_-2px_rgb(0_0_0/0.2)] [--glass-tint:color-mix(in_oklab,var(--card)_80%,transparent)] transition-transform duration-500 ease-[cubic-bezier(.3,1.35,.5,1)] [--lg-blur:0px] [backdrop-filter:none] dark:[--glass-tint:rgb(255_255_255/0.15)]"
  245. style={{ transform: `translateX(${index * 100}%)` }}
  246. />
  247. {TABS.map((t) => (
  248. <button
  249. key={t.id}
  250. aria-selected={t.id === active}
  251. className={cn(
  252. "relative z-10 h-7 rounded-full text-[12px] font-medium transition-colors",
  253. t.id === active ? "text-ink" : "text-muted hover:text-ink",
  254. )}
  255. data-cursor={copy.ask}
  256. role="tab"
  257. type="button"
  258. onClick={() => {
  259. if (t.id === active) return;
  260. setActive(t.id);
  261. setBusy(true);
  262. }}
  263. >
  264. {copy.tabs[t.id].label}
  265. </button>
  266. ))}
  267. </div>
  268. <p className="ml-auto max-w-[90%] truncate rounded-[14px] rounded-br-[5px] bg-glacier-ink px-2.5 py-1 text-[11.5px] text-white [@container(height<185px)]:hidden dark:text-[#06223a]">
  269. {copy.tabs[active].prompt}
  270. </p>
  271. <div className="relative min-h-0 flex-1 rounded-[14px] bg-card/75 p-2.5 dark:bg-black/25">
  272. {busy ? (
  273. <div className="h-full animate-shimmer rounded-[10px] bg-[linear-gradient(90deg,transparent,color-mix(in_oklab,var(--glacier)_14%,transparent),transparent)] bg-[length:200%_100%]" />
  274. ) : (
  275. <div
  276. key={active}
  277. className="h-full [animation:rise_.45s_cubic-bezier(.2,.8,.2,1)_both]"
  278. >
  279. {active === "chart" && <RegionChart />}
  280. {active === "table" && <InstanceTable />}
  281. {active === "forecast" && <ForecastChart />}
  282. </div>
  283. )}
  284. </div>
  285. <SampleNote className="text-right">{sample}</SampleNote>
  286. </div>
  287. </div>
  288. );
  289. }