Skip to content

Commit

Permalink
feat: ✨ add StackBlitz component
Browse files Browse the repository at this point in the history
Thanks @matiasfha 🙏
  • Loading branch information
spences10 committed Sep 29, 2022
1 parent eff0a65 commit 67c5789
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 75 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sveltekit-embed",
"version": "0.0.5",
"version": "0.0.6",
"author": {
"name": "Scott Spence",
"email": "[email protected]",
Expand All @@ -18,7 +18,7 @@
"license": "MIT",
"scripts": {
"dev": "vite dev",
"build": "pnpm run sveltekit-embed && pnpm i -D sveltekit-embed && vite build",
"build": "pnpm un sveltekit-embed && pnpm i -D sveltekit-embed && vite build",
"package": "svelte-package",
"preview": "vite preview",
"test": "playwright test",
Expand Down Expand Up @@ -59,7 +59,7 @@
"svelte-check": "2.9.0",
"svelte-preprocess": "4.10.7",
"svelte2tsx": "0.5.19",
"sveltekit-embed": "0.0.5",
"sveltekit-embed": "^0.0.5",
"tailwindcss": "3.1.8",
"tslib": "2.4.0",
"typescript": "4.8.3",
Expand Down
17 changes: 11 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 37 additions & 37 deletions src/lib/components/stackblitz.svelte
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
<script lang="ts">
import GeneralObserver from "./general-observer.svelte"
export let width: string = '100'
export let height: string = '500'
export let id: string = ''
export let view: 'editor' | 'preview' | 'default' = 'default'
export let clickToLoad: boolean = true //ctl
export let hideNavigation: boolean = false //hideNavigation
export let hideExplorer: boolean = true
export let theme: string | 'light' | 'dark' | 'default' = 'dark'
export let file: string | undefined
import GeneralObserver from './general-observer.svelte'
let baseUrl = `https://stackblitz.com/edit/${id}?embed=1
const config = {
ctl: `${clickToLoad ? 1 : 0}`,
hideExplorer: `${hideExplorer ? 1 : 0}`,
hideNavigation: `${hideNavigation ? 1: 0}`,
theme
}
if(view !== 'default') {
config['view'] = view
}
if(file) {
config['file'] = file
}
const queryString = new URLSearchParams(config)
const src = `${baseUrl}&${queryString.toString()}`
export let width: string = '100'
export let height: string = '500'
export let id: string = ''
export let view: 'editor' | 'preview' | 'default' = 'default'
export let clickToLoad: boolean = true //ctl
export let hideNavigation: boolean = false //hideNavigation
export let hideExplorer: boolean = true
export let theme: string | 'light' | 'dark' | 'default' = 'dark'
export let file: string | undefined
let baseUrl = `https://stackblitz.com/edit/${id}?embed=1`
const config = {
ctl: `${clickToLoad ? 1 : 0}`,
hideExplorer: `${hideExplorer ? 1 : 0}`,
hideNavigation: `${hideNavigation ? 1 : 0}`,
theme,
}
if (view !== 'default') {
config['view'] = view
}
if (file) {
config['file'] = file
}
const queryString = new URLSearchParams(config)
const src = `${baseUrl}&${queryString.toString()}`
</script>

<GeneralObserver {height} {width}>
<iframe
{height}
class="stackblitz-sveltekit-embed"
title={`stackblitz-${id}`}
{src}
frameborder="no"
allowfullscreen
style={`
width: 100%;
`}
/>
<iframe
{height}
class="stackblitz-sveltekit-embed"
title={`stackblitz-${id}`}
{src}
frameborder="no"
allowfullscreen
style={`
width: 100%;
`}
/>
</GeneralObserver>
56 changes: 27 additions & 29 deletions src/routes/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
SimpleCast,
SoundCloud,
Spotify,
StackBlitz,
Tweet,
Vimeo,
YouTube,
StackBlitz
} from 'sveltekit-embed'
import { Head } from 'svead'
import { page } from '$app/stores'
Expand Down Expand Up @@ -261,6 +261,32 @@ Output:
height="180px"
/>

## StackBlitz

Props:

```ts
width: string = '100'
height: string = '500'
id: string = ''
view: 'editor' | 'preview' | 'default' = 'default'
clickToLoad: boolean = true
hideNavigation: boolean = false
hideExplorer: boolean = true
theme: string | 'light' | 'dark' | 'default' = 'dark'
file: string | undefined
```

Usage:

```html
<StackBlitz id="vitejs-vite-yyoood" theme="light" />
```

Output:

<StackBlitz id="vitejs-vite-yyoood" hideNavigation />

## Tweet

Props:
Expand Down Expand Up @@ -323,31 +349,3 @@ Usage:
Output:

<YouTube youTubeId="L7_z8rcbFPg" />


## StackBlitz

Props:

```ts

width: string = '100'
height: string = '500'
id: string = ''
view: 'editor' | 'preview' | 'default' = 'default'
clickToLoad: boolean = true
hideNavigation: boolean = false
hideExplorer: boolean = true
theme: string | 'light' | 'dark' | 'default' = 'dark'
file: string | undefined
```

Usage:

```html
<StackBlitz id="vitejs-vite-yyoood" theme="light"/>
```

Output:

<StackBlitz id="vitejs-vite-yyoood" hideNavigation />

0 comments on commit 67c5789

Please sign in to comment.