Skip to content

Commit

Permalink
Add spinner to playground
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin committed Nov 27, 2023
1 parent b3075f0 commit e10d311
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/playground/src/react/standalone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import {
useToastController,
webLightTheme,
} from "@fluentui/react-components";
import { FunctionComponent, useCallback, useEffect, useId, useMemo, useState } from "react";
import {
FunctionComponent,
ReactNode,
useCallback,
useEffect,
useId,
useMemo,
useState,
} from "react";
import { createRoot } from "react-dom/client";
import { createBrowserHost } from "../browser-host.js";
import { LibraryImportOptions } from "../core.js";
Expand All @@ -19,6 +27,8 @@ import { Playground, PlaygroundProps, PlaygroundSaveData } from "./playground.js
export interface ReactPlaygroundConfig extends Partial<PlaygroundProps> {
readonly libraries: readonly string[];
readonly importConfig?: LibraryImportOptions;
/** Content to show while the playground data is loading(Libraries) */
readonly fallback?: ReactNode;
}

interface StandalonePlaygroundContext {
Expand Down Expand Up @@ -80,7 +90,7 @@ export const StandalonePlayground: FunctionComponent<ReactPlaygroundConfig> = (c
[context]
);
if (context === undefined || fixedOptions === undefined) {
return <></>;
return config.fallback;
}

const options: PlaygroundProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Spinner } from "@fluentui/react-components";
import style from "./loading-spinner.module.css";

export interface LoadingSpinnerProps {
message?: string;
}
export const LoadingSpinner = ({ message }: LoadingSpinnerProps) => {
return (
<div className={style["container"]}>
<Spinner />
<div>{message}</div>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { SwaggerUIViewer } from "@typespec/playground/react/viewers";
import { FunctionComponent, useMemo } from "react";
import { VersionData } from "./import-map";
import { LoadingSpinner } from "./loading-spinner";

import "@typespec/playground/style.css";

Expand Down Expand Up @@ -52,6 +53,7 @@ export const WebsitePlayground = ({ versionData }: WebsitePlaygroundProps) => {
importConfig={{ useShim: true }}
editorOptions={editorOptions}
footer={<PlaygroundFooter versionData={versionData} />}
fallback={<LoadingSpinner message="Loading libraries..." />}
/>
);
};
Expand Down
7 changes: 6 additions & 1 deletion packages/website/src/pages/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
import "@typespec/playground/style.css";
import { FluentLayout } from "../components/fluent-layout/fluent-layout";
import { VersionData, loadImportMap } from "../components/playground-component/import-map";
import { LoadingSpinner } from "../components/playground-component/loading-spinner";

export default function PlaygroundPage() {
return (
Expand Down Expand Up @@ -34,5 +35,9 @@ const AsyncPlayground = () => {
});
}, []);

return mod && <mod.WebsitePlayground versionData={mod.versionData} />;
return mod ? (
<mod.WebsitePlayground versionData={mod.versionData} />
) : (
<LoadingSpinner message="Loading playground..." />
);
};

0 comments on commit e10d311

Please sign in to comment.