Skip to content

Commit 94cbdf2

Browse files
committed
add missing files
1 parent 24435d4 commit 94cbdf2

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

src/components/tabs/Tab.svelte

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script>
2+
export let title;
3+
export let active = false;
4+
export let onTabSelected;
5+
</script>
6+
7+
<div class="tab" class:active={active} on:click={onTabSelected}>
8+
{title}
9+
</div>
10+
11+
<style>
12+
.tab {
13+
padding: 10px 20px;
14+
cursor: pointer;
15+
}
16+
.tab.active {
17+
background-color: #f0f0f0;
18+
}
19+
</style>

src/components/tabs/Tabs.svelte

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<script>
2+
import { writable } from 'svelte/store';
3+
import Tab from './Tab.svelte';
4+
5+
export let tabs = [];
6+
let activeTab = tabs[0]?.title;
7+
const activeContent = writable('');
8+
9+
$: activeContent.set(tabs.find(tab => tab.title === activeTab)?.content);
10+
11+
function selectTab(tabTitle) {
12+
activeTab = tabTitle;
13+
}
14+
</script>
15+
16+
<div class="tabs">
17+
{#each tabs as tab}
18+
<Tab {tab.title} active={tab.title === activeTab} onTabSelected={() => selectTab(tab.title)} />
19+
{/each}
20+
</div>
21+
22+
<div class="tab-content">
23+
<svelte:component this={$activeContent} />
24+
</div>
25+
26+
<style>
27+
.tabs {
28+
display: flex;
29+
justify-content: space-around;
30+
border-bottom: 1px solid #ccc;
31+
}
32+
.tab-content {
33+
padding: 20px;
34+
}
35+
</style>

src/utils.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export function generateBackground(event) {
2+
if(!event) return
3+
const dTag = event.tags.find(tag => tag[0] === 'd');
4+
return dTag ? generateColorFromTag(dTag[1]) : '#defaultColor';
5+
}
6+
7+
export function generateColorFromTag(str) {
8+
let hash = 0;
9+
for (let i = 0; i < str.length; i++) {
10+
const char = str.charCodeAt(i);
11+
hash = ((hash << 5) - hash) + char;
12+
hash &= hash; // Convert to 32bit integer
13+
}
14+
15+
let color = '#';
16+
for (let i = 0; i < 3; i++) {
17+
let value = (hash >> (i * 8)) & 255;
18+
// Normalize the value to get a pastel color
19+
value = (value % 128) + 127; // Ensure the color is always light
20+
color += ('00' + value.toString(16)).substr(-2);
21+
}
22+
return color;
23+
}

0 commit comments

Comments
 (0)