Skip to content

Commit

Permalink
Load hello world sample by default in the playground
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin committed Dec 11, 2023
1 parent e52a32c commit fd649bc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/playground-website/samples/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
const packageRoot = resolve(__dirname, "..");

await buildSamples_experimental(packageRoot, resolve(__dirname, "dist/samples.js"), {
"Hello World": {
filename: "samples/hello.tsp",
preferredEmitter: "@typespec/openapi3",
},
"API versioning": {
filename: "samples/versioning.tsp",
preferredEmitter: "@typespec/openapi3",
Expand Down
11 changes: 11 additions & 0 deletions packages/playground-website/samples/hello.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "@typespec/http";

@service
namespace Hello.World;

model World {
planet: string;
age: int32;
}

op hello(): World;
1 change: 1 addition & 0 deletions packages/playground-website/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export const TypeSpecPlaygroundConfig = {
"@typespec/protobuf",
],
samples,
defaultSample: "Hello World" satisfies keyof typeof samples,
} as const;
8 changes: 7 additions & 1 deletion packages/playground/src/react/standalone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export interface ReactPlaygroundConfig extends Partial<PlaygroundProps> {
readonly importConfig?: LibraryImportOptions;
/** Content to show while the playground data is loading(Libraries) */
readonly fallback?: ReactNode;

/** If no sample or other code is said to be loaded in the playground state load this sample instead. */
readonly defaultSample?: string;
}

interface StandalonePlaygroundContext {
Expand Down Expand Up @@ -85,7 +88,10 @@ export const StandalonePlayground: FunctionComponent<ReactPlaygroundConfig> = (c
defaultContent: context.initialState.content,
defaultEmitter: context.initialState.emitter ?? config.defaultEmitter,
defaultCompilerOptions: context.initialState.options,
defaultSampleName: context.initialState.sampleName,
defaultSampleName:
context.initialState.sampleName ?? context.initialState.content === undefined
? config.defaultSample
: undefined,
},
[context]
);
Expand Down

0 comments on commit fd649bc

Please sign in to comment.