Skip to content

Commit

Permalink
add missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Feb 13, 2024
1 parent 24435d4 commit 94cbdf2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/components/tabs/Tab.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
export let title;
export let active = false;
export let onTabSelected;
</script>

<div class="tab" class:active={active} on:click={onTabSelected}>
{title}
</div>

<style>
.tab {
padding: 10px 20px;
cursor: pointer;
}
.tab.active {
background-color: #f0f0f0;
}
</style>
35 changes: 35 additions & 0 deletions src/components/tabs/Tabs.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<script>
import { writable } from 'svelte/store';
import Tab from './Tab.svelte';
export let tabs = [];
let activeTab = tabs[0]?.title;
const activeContent = writable('');
$: activeContent.set(tabs.find(tab => tab.title === activeTab)?.content);
function selectTab(tabTitle) {
activeTab = tabTitle;
}
</script>
<div class="tabs">
{#each tabs as tab}
<Tab {tab.title} active={tab.title === activeTab} onTabSelected={() => selectTab(tab.title)} />
{/each}
</div>
<div class="tab-content">
<svelte:component this={$activeContent} />
</div>
<style>
.tabs {
display: flex;
justify-content: space-around;
border-bottom: 1px solid #ccc;
}
.tab-content {
padding: 20px;
}
</style>
23 changes: 23 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export function generateBackground(event) {
if(!event) return
const dTag = event.tags.find(tag => tag[0] === 'd');
return dTag ? generateColorFromTag(dTag[1]) : '#defaultColor';
}

export function generateColorFromTag(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash &= hash; // Convert to 32bit integer
}

let color = '#';
for (let i = 0; i < 3; i++) {
let value = (hash >> (i * 8)) & 255;
// Normalize the value to get a pastel color
value = (value % 128) + 127; // Ensure the color is always light
color += ('00' + value.toString(16)).substr(-2);
}
return color;
}

0 comments on commit 94cbdf2

Please sign in to comment.