Skip to content

Commit 064b529

Browse files
committed
docs(SDK): add docs for using SDK in Solid
1 parent 0a9d0bb commit 064b529

10 files changed

Lines changed: 119 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Add this code to your page:
119119
- [Client-side!](https://livecodes.io/docs/why#client-side)
120120
- Very [configurable](https://livecodes.io/docs/configuration/)
121121
- Developer-friendly build-free environment
122-
- Powerful [SDK](https://livecodes.io/docs/sdk/) (available for [vanilla JavaScript, TypeScript](https://livecodes.io/docs/sdk/js-ts), [React](https://livecodes.io/docs/sdk/react), [Vue](https://livecodes.io/docs/sdk/vue) and [Svelte](https://livecodes.io/docs/sdk/svelte))
122+
- Powerful [SDK](https://livecodes.io/docs/sdk/) (available for [vanilla JavaScript, TypeScript](https://livecodes.io/docs/sdk/js-ts), [React](https://livecodes.io/docs/sdk/react), [Vue](https://livecodes.io/docs/sdk/vue), [Svelte](https://livecodes.io/docs/sdk/svelte) and [Solid](https://livecodes.io/docs/sdk/solid))
123123
- Comprehensive [Documentations](https://livecodes.io/docs/)
124124
- Focused on [privacy and security](https://livecodes.io/docs/features/security)
125125
- Free and [Open-Source](https://livecodes.io/docs/license)
@@ -156,7 +156,7 @@ createPlayground('#container', {
156156
});
157157
```
158158

159-
The [JavaScript SDK](https://livecodes.io/docs/sdk/js-ts) is framework/library agnostic. However, wrapper components are also provided for popular libraries (currently [React](https://livecodes.io/docs/sdk/react) and [Vue](https://livecodes.io/docs/sdk/vue)). The SDK can be used in [Svelte](https://livecodes.io/docs/sdk/svelte) directly without wrappers. [TypeScript support](https://livecodes.io/docs/sdk/js-ts#typescript-types) provides type-safety and a great developer experience.
159+
The [JavaScript SDK](https://livecodes.io/docs/sdk/js-ts) is framework/library agnostic. However, wrapper components are also provided for popular libraries (currently [React](https://livecodes.io/docs/sdk/react) and [Vue](https://livecodes.io/docs/sdk/vue)). The SDK can be used in [Svelte](https://livecodes.io/docs/sdk/svelte) and [Solid](https://livecodes.io/docs/sdk/solid) directly without wrappers. [TypeScript support](https://livecodes.io/docs/sdk/js-ts#typescript-types) provides type-safety and a great developer experience.
160160

161161
React SDK example: ([open in LiveCodes](https://livecodes.io/?x=code/N4IgLglmA2CmIC4QBkIDdYGED2ATWAzgAQBKsAhgMZhEDKAIgNJH4C22IANCPgZQE4QADpGwA7RCC4gAFhVySAPK1hhyRSjPL8CqgLwAdEAFUAKgDEAtAA4jRAPQA+A2OWr1Y8isMg0EWADuQtj8YHaU4mCwYmA+ARC4YDJ6+H6UsJbxiTKcRBBiUBDk0JZ8xbB6AIwAdAAMdk7SMmCs0ACCYGA6ktDkYgDmPtHhvQQEPkbSav0EiADaALrcVJAYAKK4UCGSfIIi0qzaANYArkKIoL0DJ+T98EjNrdIRMdFgkiAAvtwEYACecAuICu-Rud0klDGz0ibw+3xAu2E7wQlz6oNu9xAACsCAAPaGvGKSCCsYKhIioDA4XhEABm-GwrCIAHJoOhYBFePZ+BRqMyANwGfguIUuF6-DTiWkQfpEPREYCisREIiHfinIQIBVKlUqkFg2Ba5lqo64bABMTMzg63UvKIxI0AYiIAAlYNBoNgiAB1ELQXAAQitNu+Ss+guFYnFNAACr0-v0GScxLg5UQABQASjljiIikpWDwhElYmlg2ALzLnyIfkCPh5BBO0DCIAcjgjLlguLJNHwtPITdj8cT2GTuA7EnhvwBhDkqlmCEWPwESIXS5AkIIMYbqg+3CEDPSYxCa6WG5Ov0ZtFUkAGC+A8JJPfv8P+QkIF1fhDA9+BaINkhvoQK77NwdqwkgXzcBgOgQOIkgAMwIVM2DYNAv7ROQABGcAKEgxTQNIKzshC4gEGh8A-GoYAXhCnq6AonyfEAA))
162162

docs/docs/sdk/index.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The Software Development Kit (SDK) provides an easy, yet powerful, interface to
1010

1111
The SDK is provided as a light-weight ([less than 5kb gzipped](https://bundlephobia.com/package/livecodes)), zero-dependencies [npm package](#npm-package), that is also available from [CDNs](#cdn). It can be used to create playgrounds with a wide variety of [configurations](../configuration/configuration-object.mdx) and [embed options](js-ts.mdx#embed-options). In addition, [SDK methods](js-ts.mdx#sdk-methods) allow programmatic communication and control of the playgrounds during runtime.
1212

13-
The [JavaScript SDK](js-ts.mdx) is framework/library agnostic. However, wrapper components are also provided for popular libraries (currently [React](react.mdx) and [Vue](vue.mdx)). The SDK can be used in [Svelte](svelte.mdx) directly without wrappers. [TypeScript support](js-ts.mdx#typescript-types) provides type-safety and a great developer experience.
13+
The [JavaScript SDK](js-ts.mdx) is framework/library agnostic. However, wrapper components are also provided for popular libraries (currently [React](react.mdx) and [Vue](vue.mdx)). The SDK can be used in [Svelte](svelte.mdx) and [Solid](solid.mdx) directly without wrappers. [TypeScript support](js-ts.mdx#typescript-types) provides type-safety and a great developer experience.
1414

1515
## SDK Demo
1616

@@ -106,6 +106,8 @@ The SDK is currently provided in the following variations:
106106

107107
- [Svelte](./svelte.mdx)
108108

109+
- [Solid](./solid.mdx)
110+
109111
## Headless Mode
110112

111113
The SDK also has a [headless mode](./headless.mdx). In this mode, no visible output is displayed in the embedding web page. However, all [SDK methods](../sdk/js-ts.mdx#sdk-methods) are accessible. This provides the power of leveraging the wide range of features and language support offered by LiveCodes, while retaining full control over the UI.

docs/docs/sdk/react.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,5 @@ export const reactSDKDemo = {
148148
- [JS/TS SDK](./js-ts.mdx)
149149
- [Vue SDK](./vue.mdx)
150150
- [Using SDK in Svelte](./svelte.mdx)
151+
- [Using SDK in Solid](./solid.mdx)
151152
- [Embedded Playgrounds](../features/embeds.mdx)

docs/docs/sdk/solid.mdx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Solid
2+
3+
import LiveCodes from '../../src/components/LiveCodes.tsx';
4+
import RunInLiveCodes from '../../src/components/RunInLiveCodes.tsx';
5+
6+
The [JS/TS SDK](js-ts.mdx) can be used directly in [Solid](https://www.solidjs.com/) components without the need for any wrappers.
7+
8+
## Installation
9+
10+
Please refer to the [SDK installation](./index.mdx#installation) section.
11+
12+
## Usage
13+
14+
This is an example of using the LiveCodes TS SDK in a Solid component:
15+
16+
```tsx title="App.tsx"
17+
import { onCleanup } from 'solid-js';
18+
import { createPlayground, type Playground, type EmbedOptions } from 'livecodes';
19+
20+
export default function App() {
21+
let playground: Playground | null = null;
22+
23+
const options: EmbedOptions = {
24+
params: {
25+
html: '<h1>Hello World!</h1>',
26+
css: 'h1 {color: blue;}',
27+
js: 'console.log("Hello, Solid!")',
28+
console: 'open',
29+
},
30+
};
31+
32+
const onMounted = (container: HTMLElement) => {
33+
createPlayground(container, options).then((sdk) => {
34+
playground = sdk; // now the SDK is available
35+
});
36+
};
37+
onCleanup(() => playground?.destroy());
38+
39+
return <div ref={onMounted}></div>;
40+
}
41+
```
42+
43+
export const solidSDKDemo = {
44+
"solid.tsx": `import { onCleanup } from 'solid-js';
45+
import { createPlayground, type Playground, type EmbedOptions } from 'livecodes';
46+
47+
export default function App() {
48+
let playground: Playground | null = null;
49+
50+
const options: EmbedOptions = {
51+
params: {
52+
html: '<h1>Hello World!</h1>',
53+
css: 'h1 {color: blue;}',
54+
js: 'console.log("Hello, Solid!")',
55+
console: 'open',
56+
},
57+
};
58+
59+
const onMounted = (container: HTMLElement) => {
60+
createPlayground(container, options).then((sdk) => {
61+
playground = sdk; // now the SDK is available
62+
});
63+
};
64+
onCleanup(() => playground?.destroy());
65+
66+
return <div ref={onMounted}></div>;
67+
}
68+
`,
69+
};
70+
71+
<RunInLiveCodes params={solidSDKDemo}></RunInLiveCodes>
72+
73+
[Embed options](./js-ts.mdx#embed-options), [SDK methods](./js-ts.mdx#sdk-methods) and [TypeScript types](./js-ts.mdx#typescript-types) are available as described in the [JS/TS SDK documentations](./js-ts.mdx).
74+
75+
## Demo
76+
77+
<LiveCodes params={solidSDKDemo} height="80vh" />
78+
79+
## Related
80+
81+
- [SDK Installation](./index.mdx#installation)
82+
- [JS/TS SDK](./js-ts.mdx)
83+
- [React SDK](./react.mdx)
84+
- [Vue SDK](./vue.mdx)
85+
- [Using SDK in Svelte](./svelte.mdx)
86+
- [Embedded Playgrounds](../features/embeds.mdx)

docs/docs/sdk/svelte.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,5 @@ However, it is recommended to cleanup when the node is unmounted, like that:
9797
- [JS/TS SDK](./js-ts.mdx)
9898
- [React SDK](./react.mdx)
9999
- [Vue SDK](./vue.mdx)
100+
- [Using SDK in Solid](./solid.mdx)
100101
- [Embedded Playgrounds](../features/embeds.mdx)

docs/docs/sdk/vue.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,5 @@ export const vueSDKDemo = {
163163
- [JS/TS SDK](./js-ts.mdx)
164164
- [React SDK](./react.mdx)
165165
- [Using SDK in Svelte](./svelte.mdx)
166+
- [Using SDK in Solid](./solid.mdx)
166167
- [Embedded Playgrounds](../features/embeds.mdx)

docs/sidebars.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const sidebars: SidebarsConfig = {
8585
type: 'doc',
8686
id: 'sdk/index',
8787
},
88-
items: ['sdk/js-ts', 'sdk/react', 'sdk/vue', 'sdk/svelte', 'sdk/headless'],
88+
items: ['sdk/js-ts', 'sdk/react', 'sdk/vue', 'sdk/svelte', 'sdk/solid', 'sdk/headless'],
8989
},
9090
{
9191
type: 'category',

docs/src/components/HomepageFeatures.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ const FeatureList3: FeatureItem[] = [
151151
<Link to="./sdk/">SDK</Link> facilitates <Link to="./features/embeds">embedding</Link>{' '}
152152
playgrounds and allows easy <Link to="./sdk/js-ts#sdk-methods">communication</Link> with
153153
them. The SDK is available for <Link to="./sdk/js-ts">vanilla JS/TS</Link>,{' '}
154-
<Link to="./sdk/react">React</Link>, <Link to="./sdk/vue">Vue</Link> and{' '}
155-
<Link to="./sdk/svelte">Svelte</Link>. There is also a{' '}
156-
<Link to="./sdk/headless">headless mode</Link> for full control over the UI.
154+
<Link to="./sdk/react">React</Link>, <Link to="./sdk/vue">Vue</Link>,{' '}
155+
<Link to="./sdk/svelte">Svelte</Link> and <Link to="./sdk/solid">Solid</Link>. There is also
156+
a <Link to="./sdk/headless">headless mode</Link> for full control over the UI.
157157
</>
158158
),
159159
},

docs/src/components/LiveCodes.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ onMount(() => {
7171
7272
<div bind:this="{container}"></div>
7373
74+
`.trimStart();
75+
76+
const solidCode = `
77+
import { createPlayground, type EmbedOptions } from 'livecodes';
78+
79+
export default function App() {
80+
const options: EmbedOptions = ${stringify(options)};
81+
const onMounted = (container: HTMLElement) => {
82+
createPlayground(container, options);
83+
};
84+
85+
return <div ref={onMounted}></div>;
86+
}
87+
7488
`.trimStart();
7589

7690
return (
@@ -96,6 +110,7 @@ onMount(() => {
96110
react={reactCode}
97111
vue={vueCode}
98112
svelte={svelteCode}
113+
solid={solidCode}
99114
></ShowCode>
100115
)}
101116
</>

docs/src/components/ShowCode.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ export default function ShowCode(props: {
1414
react: string;
1515
vue: string;
1616
svelte: string;
17+
solid: string;
1718
}): ReactNode {
1819
const [jsCode, setJsCode] = useState(props.js);
1920
const [tsCode, setTsCode] = useState(props.ts);
2021
const [reactCode, setReactCode] = useState(props.react);
2122
const [vueCode, setVueCode] = useState(props.vue);
2223
const [svelteCode, setSvelteCode] = useState(props.svelte);
24+
const [solidCode, setSolidCode] = useState(props.solid);
2325

2426
const codeBlockTitleHeight = '3.7rem';
2527
const [codeCollapsed, setCodeCollapsed] = useState(true);
@@ -57,6 +59,7 @@ export default function ShowCode(props: {
5759
setReactCode(format(reactCode, 'jsx'));
5860
setVueCode(format(vueCode, 'html'));
5961
setSvelteCode(format(svelteCode, 'html'));
62+
setSolidCode(format(solidCode, 'tsx'));
6063
}
6164
}, []);
6265

@@ -97,6 +100,9 @@ export default function ShowCode(props: {
97100
<TabItem value="svelte" label="Svelte" attributes={{ onMouseDown: resize }}>
98101
<CodeBlock language="html">{svelteCode}</CodeBlock>
99102
</TabItem>
103+
<TabItem value="solid" label="Solid" attributes={{ onMouseDown: resize }}>
104+
<CodeBlock language="tsx">{solidCode}</CodeBlock>
105+
</TabItem>
100106
</Tabs>
101107
</div>
102108
</div>

0 commit comments

Comments
 (0)