provider-family-responsive.fixture.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import { BUILTIN_MODEL_PROVIDER_IDS } from "@zcode/shared";
  4. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  5. import {
  6. ProviderFamilyHeader,
  7. ProviderFamilyPlanModeSwitch,
  8. } from "@/settings/model-provider-section/ProviderFamilyModeHeader.js";
  9. import type { ModelProviderNavItem } from "@/settings/model-provider-section/constants.js";
  10. import { TooltipProvider } from "@/components/ui/tooltip.js";
  11. import "@/styles.css";
  12. const params = new URLSearchParams(location.search);
  13. const name = params.get("name") ?? "北京智谱华章科技股份有限公司";
  14. const common = {
  15. oauthProviderId: "bigmodel" as const,
  16. label: name,
  17. providerName: "BigModel",
  18. provider: null,
  19. status: "purchased" as const,
  20. statusActive: true,
  21. };
  22. const items: ModelProviderNavItem[] = [
  23. {
  24. ...common,
  25. key: "team",
  26. type: "teamPlan",
  27. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelCodingPlan,
  28. teamPlanName: name,
  29. },
  30. {
  31. ...common,
  32. key: "start",
  33. type: "codingPlan",
  34. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  35. },
  36. ];
  37. document.documentElement.className =
  38. params.get("theme") === "light" ? "light theme-zai-light" : "dark theme-zai-dark";
  39. function Fixture() {
  40. const [selected, setSelected] = useState(items[0]!);
  41. return (
  42. <ZCodeIntlProvider initialLocale={params.get("locale") === "zh-CN" ? "zh-CN" : "en-US"}>
  43. <main
  44. style={{
  45. padding: 16,
  46. width: "100%",
  47. minHeight: "100vh",
  48. maxWidth: Number(params.get("panel") ?? 1000),
  49. background: "var(--color-background)",
  50. color: "var(--color-foreground)",
  51. }}
  52. >
  53. <section data-testid="panel" style={{ marginLeft: 48, padding: 16 }}>
  54. <ProviderFamilyHeader
  55. selectedNavItem={selected}
  56. trailingAction={
  57. <ProviderFamilyPlanModeSwitch
  58. selectedNavItem={selected}
  59. navigationItems={items}
  60. startPlanSubscriptionCount={1}
  61. onSelectNavItem={setSelected}
  62. />
  63. }
  64. />
  65. </section>
  66. <output data-testid="selected">{selected.key}</output>
  67. </main>
  68. </ZCodeIntlProvider>
  69. );
  70. }
  71. createRoot(document.getElementById("root")!).render(
  72. <TooltipProvider>
  73. <Fixture />
  74. </TooltipProvider>,
  75. );