Skip to content

Commit b78b140

Browse files
authored
Merge pull request #756 from ryoppippi/feature/tweet-dark
feat(tweet): darkmode support
2 parents e40a06e + d7ec5e0 commit b78b140

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

apps/web/src/routes/+page.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,17 +680,24 @@ Props:
680680

681681
```ts
682682
tweetLink: string = '';
683+
theme: string = 'dark' | 'light' = 'light';
683684
```
684685

685686
Usage:
686687

687688
```html
688-
<Tweet tweetLink="adamwathan/status/959078631434731521" />
689+
<Tweet
690+
tweetLink="adamwathan/status/959078631434731521"
691+
theme="dark"
692+
/>
689693
```
690694

691695
Output:
692696

693-
<Tweet tweetLink="adamwathan/status/959078631434731521" />
697+
<Tweet
698+
tweetLink="adamwathan/status/959078631434731521"
699+
theme="dark"
700+
/>
694701

695702
## Vimeo
696703

packages/sveltekit-embed/src/lib/components/tweet.svelte

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
<script lang="ts">
22
interface Props {
33
tweetLink?: string;
4+
theme?: 'light' | 'dark';
45
}
56
6-
let { tweetLink = '' }: Props = $props();
7+
let { tweetLink = '', theme = 'light' }: Props = $props();
78
8-
let twitter_widgets_script: HTMLScriptElement | null = null;
9+
let twitter_widgets_script = $state.raw<HTMLScriptElement | null>(
10+
null,
11+
);
912
1013
const load_twitter_widgets_script = () => {
14+
if (
15+
document.querySelector(
16+
'script[src*="platform.twitter.com/widgets.js"]',
17+
)
18+
) {
19+
return;
20+
}
21+
1122
if (twitter_widgets_script) return;
23+
1224
twitter_widgets_script = document.createElement('script');
1325
twitter_widgets_script.src =
1426
'https://platform.twitter.com/widgets.js';
@@ -17,22 +29,25 @@
1729
};
1830
1931
const remove_twitter_widget_script = () => {
20-
if (twitter_widgets_script) {
21-
document.head.removeChild(twitter_widgets_script);
22-
twitter_widgets_script = null;
23-
}
32+
if (!twitter_widgets_script) return;
33+
document.head.removeChild(twitter_widgets_script);
34+
twitter_widgets_script = null;
2435
};
2536
26-
$effect(() => {
37+
$effect.root(() => {
2738
load_twitter_widgets_script();
2839
return () => {
2940
remove_twitter_widget_script();
3041
};
3142
});
3243
</script>
3344

34-
<div class="tweet-wrapper">
35-
<blockquote class="twitter-tweet">
45+
<div
46+
class="tweet-wrapper"
47+
data-theme={theme}
48+
data-loaded={twitter_widgets_script != null}
49+
>
50+
<blockquote class="twitter-tweet" data-theme={theme}>
3651
<a href={`https://twitter.com/${tweetLink}`}>Loading Tweet...</a>
3752
</blockquote>
3853
</div>
@@ -42,6 +57,12 @@
4257
display: flex;
4358
justify-content: center;
4459
margin-bottom: 12px;
60+
border-radius: 13px;
61+
overflow: hidden;
62+
}
63+
64+
.tweet-wrapper :global(iframe) {
65+
border-radius: 13px !important;
4566
}
4667
4768
.twitter-tweet {

0 commit comments

Comments
 (0)