app-empty-transcript.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from "react";
  2. import { palette } from "./app-model.js";
  3. import { ShimmerText, useShimmerFrame } from "./app-motion.js";
  4. const h = React.createElement as (
  5. type: React.ElementType | string,
  6. props?: Record<string, unknown> | null,
  7. ...children: React.ReactNode[]
  8. ) => React.ReactElement;
  9. export const ZCODE_LOGO_LINES = [
  10. "███████╗ ██████╗ ██████╗ ██████╗ ███████╗",
  11. " ███╔╝██╔════╝██╔═══██╗██╔══██╗██╔════╝",
  12. " ███╔╝ ██║ ██║ ██║██║ ██║█████╗ ",
  13. " ███╔╝ ██║ ██║ ██║██║ ██║██╔══╝ ",
  14. "███████╗╚██████╗╚██████╔╝██████╔╝███████╗",
  15. "╚══════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝",
  16. ] as const;
  17. const EMPTY_TRANSCRIPT_LOGO_MIN_HEIGHT = ZCODE_LOGO_LINES.length;
  18. export function EmptyTranscriptLogo({
  19. animated = false,
  20. }: {
  21. animated?: boolean;
  22. } = {}): React.ReactElement {
  23. if (animated) {
  24. return h(AnimatedEmptyTranscriptLogo);
  25. }
  26. return renderLogoContent({ animated: false });
  27. }
  28. function AnimatedEmptyTranscriptLogo(): React.ReactElement {
  29. const frameMs = useShimmerFrame(true);
  30. return renderLogoContent({ animated: true, frameMs });
  31. }
  32. function renderLogoContent(input: { animated: boolean; frameMs?: number }): React.ReactElement {
  33. return h(
  34. "box",
  35. {
  36. style: {
  37. alignItems: "center",
  38. flexDirection: "column",
  39. flexGrow: 1,
  40. justifyContent: "center",
  41. minHeight: EMPTY_TRANSCRIPT_LOGO_MIN_HEIGHT,
  42. width: "100%",
  43. },
  44. },
  45. ...ZCODE_LOGO_LINES.map((line, index) =>
  46. renderLogoText({
  47. animated: input.animated,
  48. baseColor: palette.accent,
  49. frameMs: input.frameMs,
  50. key: `zcode-logo-${index}`,
  51. text: line,
  52. }),
  53. ),
  54. );
  55. }
  56. function renderLogoText(input: {
  57. animated: boolean;
  58. baseColor: string;
  59. frameMs?: number;
  60. key: string;
  61. text: string;
  62. }): React.ReactElement {
  63. if (!input.animated) {
  64. return h("text", { key: input.key, style: { fg: input.baseColor } }, input.text);
  65. }
  66. return h(ShimmerText, {
  67. animated: true,
  68. baseColor: input.baseColor,
  69. frameMs: input.frameMs,
  70. highlightColor: palette.text,
  71. key: input.key,
  72. text: input.text,
  73. });
  74. }