Skip to content

Commit 71a76f8

Browse files
committed
Update component, add unit test, and update documentation
1 parent 25bd407 commit 71a76f8

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

src/lib/components/relive.svelte

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
<script lang="ts">
22
import GeneralObserver from './general-observer.svelte'
33
4-
export let reliveId: string
4+
export let reliveId: string = ''
55
export let width: string = '100%'
6+
7+
const defaultMargin: number = 2
68
</script>
79

810
<GeneralObserver>
9-
<iframe
10-
title={`relive-${reliveId}`}
11-
src={`https://www.relive.cc/view/${reliveId}/widget`}
12-
/>
11+
<div
12+
style={`
13+
position: relative;
14+
width: ${width};
15+
aspect-ratio: 1 / 0.7825;
16+
overflow: hidden;
17+
`}
18+
>
19+
<iframe
20+
title={`relive-${reliveId}`}
21+
src={`https://www.relive.cc/view/${reliveId}/widget`}
22+
scrolling="no"
23+
frameborder="0"
24+
allowfullscreen
25+
style={`
26+
position: absolute;
27+
top: -${defaultMargin}px;
28+
left: -${defaultMargin}px;
29+
width: calc(100% + ${defaultMargin * 2}px);
30+
height: calc(100% + ${defaultMargin * 2}px);
31+
`}
32+
/>
33+
</div>
1334
</GeneralObserver>
14-
15-
<style>
16-
iframe {
17-
/* 2 from margin + 1 from box-shadow */
18-
aspect-ratio: 1000 / calc(782.5 + 3);
19-
overflow: clip;
20-
width: 100%;
21-
}
22-
</style>

src/lib/components/relive.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Relive from '$lib/components/relive.svelte'
2+
import { cleanup, render } from '@testing-library/svelte'
3+
import { afterEach, describe, expect, it, vi } from 'vitest'
4+
5+
globalThis.IntersectionObserver = vi.fn(() => ({
6+
observe: () => null,
7+
unobserve: () => null,
8+
disconnect: () => null,
9+
})) as unknown as typeof globalThis.IntersectionObserver
10+
11+
describe('Relive', () => {
12+
afterEach(() => cleanup())
13+
14+
it('mounts', () => {
15+
const { container } = render(Relive)
16+
expect(container).toBeTruthy()
17+
})
18+
})

src/routes/+page.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,19 @@ Output:
256256

257257
## Relive
258258

259+
Props:
260+
261+
```ts
262+
reliveId: string = ''
263+
width: string = '100%'
264+
```
265+
266+
Usage:
267+
268+
```html
269+
<Relive reliveId="vAOZokmYVo6" />
270+
```
271+
259272
Output:
260273

261274
<Relive reliveId="vAOZokmYVo6" />

0 commit comments

Comments
 (0)