|
19 | 19 | > This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your [workspace](https://app.speakeasy.com/org/speakeasy-self/speakeasy-self). Delete this section before > publishing to a package manager.
|
20 | 20 |
|
21 | 21 | <div align="center">
|
22 |
| - <img src="https://github.com/user-attachments/assets/f5ab386f-39bb-4ae2-aa0d-54e2f95b656d" alt="Description" width="750"/> |
| 22 | + <picture> |
| 23 | + <source media="(prefers-color-scheme: dark)" srcset="./images/code-samples-demo-dark.webm"> |
| 24 | + <img alt="animation of viewing code, switching programming languages, and copying the displayed text" src="./images/code-samples-demo-light.webm"> |
| 25 | + </picture> |
23 | 26 | <p><em>CodeSamples React Component in Action</em></p>
|
24 | 27 | </div>
|
25 | 28 |
|
|
28 | 31 |
|
29 | 32 | Speakeasy Code Samples API: REST APIs for retrieving SDK usage snippets from the Speakeasy Code Samples API.
|
30 | 33 |
|
| 34 | + |
31 | 35 | For more information about the API: [The Speakeasy Platform Documentation](/docs)
|
32 | 36 | <!-- End Summary [summary] -->
|
33 | 37 |
|
34 | 38 | <!-- Start Table of Contents [toc] -->
|
35 | 39 | ## Table of Contents
|
36 | 40 | <!-- $toc-max-depth=2 -->
|
37 |
| -* [@speakeasyapi/code-samples](#speakeasyapicode-samples) |
38 | 41 | * [SDK Installation](#sdk-installation)
|
39 | 42 | * [Requirements](#requirements)
|
40 | 43 | * [SDK Example Usage](#sdk-example-usage)
|
@@ -148,46 +151,39 @@ run();
|
148 | 151 | ### React Component
|
149 | 152 |
|
150 | 153 | This library includes a React component that fetches and highlights code
|
151 |
| -snippets using `highlight.js`. Along with displaying the snippet, it shows a |
| 154 | +snippets using `codehike`. Along with displaying the snippet, it shows a |
152 | 155 | loading state during fetching and provides a fallback view if an error occurs.
|
153 | 156 |
|
154 | 157 | ```tsx
|
155 | 158 | import { SpeakeasyCodeSamplesCore } from "@speakeasyapi/code-samples/core";
|
156 | 159 | import {
|
157 |
| - CodeSample, |
| 160 | + CodeSampleFilenameTitle, |
| 161 | + CodeSamplesViewer, |
158 | 162 | SpeakeasyCodeSamplesProvider,
|
159 | 163 | } from "@speakeasyapi/code-samples/react";
|
160 |
| -import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; |
161 |
| - |
162 |
| -const queryClient = new QueryClient(); |
163 | 164 |
|
164 | 165 | const speakeasyCodeSamples = new SpeakeasyCodeSamplesCore({
|
165 | 166 | apiKey: "<YOUR_API_KEY_HERE>",
|
166 | 167 | registryUrl: "https://spec.speakeasy.com/org/ws/my-source",
|
167 | 168 | });
|
168 | 169 |
|
169 |
| -// Retries are handled by the underlying SDK. |
170 |
| -queryClient.setQueryDefaults(["@speakeasyapi/code-samples"], { retry: false }); |
171 |
| - |
172 |
| -queryClient.setMutationDefaults(["@speakeasyapi/code-samples"], { |
173 |
| - retry: false, |
174 |
| -}); |
175 |
| - |
176 | 170 | function App() {
|
177 | 171 | return (
|
178 |
| - <QueryClientProvider client={queryClient}> |
179 |
| - <SpeakeasyCodeSamplesProvider client={speakeasyCodeSamples}> |
180 |
| - <CodeSample operationId="getPetById" language="typescript" /> |
181 |
| - </SpeakeasyCodeSamplesProvider> |
182 |
| - </QueryClientProvider> |
| 172 | + <SpeakeasyCodeSamplesProvider client={speakeasyCodeSamples}> |
| 173 | + <CodeSamplesViewer |
| 174 | + copyable |
| 175 | + defaultLang={"typescript"} |
| 176 | + title={CodeSampleFilenameTitle} |
| 177 | + operation={"getPassageText"} |
| 178 | + // client={speakeasyCodeSamples} |
| 179 | + // 👆optional, if you want to pass the client directly |
| 180 | + // instead of using the provider |
| 181 | + /> |
| 182 | + </SpeakeasyCodeSamplesProvider> |
183 | 183 | );
|
184 | 184 | }
|
185 | 185 | ```
|
186 | 186 |
|
187 |
| -> [!NOTE] |
188 |
| -> To apply styles to the highlighted code, import a `highlight.js` theme CSS |
189 |
| -> file into your project using methods like a `<link>` tag. |
190 |
| -
|
191 | 187 | <!-- Start Authentication [security] -->
|
192 | 188 | ## Authentication
|
193 | 189 |
|
|
0 commit comments