Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@
<style>
.repl-outer {
position: relative;
height: calc(100% - var(--sk-nav-height) - var(--sk-banner-bottom-height));
height: calc(100dvh - var(--sk-nav-height) - var(--sk-banner-bottom-height));
height: calc(100% - var(--sk-nav-height) - var(--sk-banner-height));
height: calc(100dvh - var(--sk-nav-height) - var(--sk-banner-height));
overflow: hidden;
background-color: var(--sk-back-1);
box-sizing: border-box;
Expand Down
16 changes: 13 additions & 3 deletions apps/svelte.dev/src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { docs, index } from '$lib/server/content';
import { fetchBanner } from '@sveltejs/site-kit/components';
import type { NavigationLink } from '@sveltejs/site-kit';
import type { BannerData, NavigationLink } from '@sveltejs/site-kit';

const nav_links: NavigationLink[] = [
{
Expand Down Expand Up @@ -52,8 +51,19 @@ const sections: Record<string, string> = {
search: 'Search'
};

const banner: BannerData = {
id: 'sveltehack2024',
start: new Date('22 Oct, 2024 00:00:00 UTC'),
end: new Date('15 December, 2024 23:59:59 UTC'),
arrow: true,
content: {
lg: 'Cast runes, win prizes: SvelteHack 2024',
sm: 'SvelteHack 2024'
},
href: 'https://hack.sveltesociety.dev/2024'
};

export const load = async ({ url, fetch }) => {
const banner = await fetchBanner('svelte.dev', fetch);
const nav_title = sections[url.pathname.split('/')[1]!] ?? '';

return {
Expand Down
10 changes: 6 additions & 4 deletions apps/svelte.dev/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import '@sveltejs/site-kit/styles/index.css';
import { browser } from '$app/environment';
import { page } from '$app/stores';
import { Shell, Banners } from '@sveltejs/site-kit/components';
import { Shell, Banner } from '@sveltejs/site-kit/components';
import { Nav } from '@sveltejs/site-kit/nav';
import { Search, SearchBox } from '@sveltejs/site-kit/search';
import { SearchBox } from '@sveltejs/site-kit/search';
import { injectSpeedInsights } from '@vercel/speed-insights/sveltekit';
import { beforeNavigate } from '$app/navigation';

Expand Down Expand Up @@ -45,8 +45,10 @@
{@render layout_children()}
{/snippet}

{#snippet banner_bottom()}
<Banners data={data.banner} />
{#snippet banner()}
{#if data.banner}
<Banner banner={data.banner} />
{/if}
{/snippet}
</Shell>

Expand Down
38 changes: 0 additions & 38 deletions apps/svelte.dev/src/routes/banner.json/+server.js

This file was deleted.

2 changes: 1 addition & 1 deletion apps/svelte.dev/src/routes/docs/[...path]/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
.toc-container {
display: block;
width: var(--sidebar-width);
height: calc(100vh - var(--sk-nav-height) - var(--sk-banner-bottom-height));
height: calc(100vh - var(--sk-nav-height) - var(--sk-banner-height));
position: fixed;
left: 0;
top: var(--sk-nav-height);
Expand Down
146 changes: 64 additions & 82 deletions packages/site-kit/src/lib/components/Banner.svelte
Original file line number Diff line number Diff line change
@@ -1,138 +1,120 @@
<script lang="ts">
import { onMount } from 'svelte';
import { quintOut } from 'svelte/easing';
import { fade } from 'svelte/transition';
import { persisted } from 'svelte-persisted-store';
import Icon from './Icon.svelte';
import type { BannerData } from '../types';
import { browser } from '$app/environment';

interface Props {
/** Whether to show an arrow at the end */
arrow?: boolean;
/** Link to the event. It must be an absolute path (https://svelte.dev/blog/runes instead of /blog/runes) */
href: string;
content: {
lg?: string;
sm?: string;
};
close?: () => void;
}
let { banner }: { banner: BannerData } = $props();

const hidden = persisted<Record<string, boolean>>('svelte:hidden-banners', {});
const time = +new Date();

let { arrow = false, href, content }: Props = $props();
let visible = $derived(
browser && !$hidden[banner.id] && time > +banner.start && time < +banner.end
);

let show = $state(false);
onMount(() => {
setTimeout(() => {
show = true;
}, 300);
$effect(() => {
document.documentElement.style.setProperty('--sk-banner-height', visible ? '4.2rem' : '0px');
});
</script>

{#if show}
<div class="banner-bottom" transition:fade={{ duration: 400, easing: quintOut }}>
<div class="main-area">
<a {href}>
{#if content.lg}
<span class="lg">{content.lg}</span>
{/if}
{#if visible}
<div class="banner" transition:fade={{ duration: 400, easing: quintOut }}>
<a href={banner.href}>
{#if banner.content.lg}
<span class="large">{banner.content.lg}</span>
{/if}

{#if content.sm}
<span class="sm">{content.sm}</span>
{/if}
</a>
{#if banner.content.sm}
<span class="small">{banner.content.sm}</span>
{/if}

{#if arrow}
{#if banner.arrow}
<Icon name="arrow-right" size="1.2em" />
{/if}
</div>

<button class="close-button" onclick={() => close?.()}>
</a>

<button
aria-label="Dismiss"
class="raised primary"
onclick={() => {
$hidden[banner.id] = true;
}}
>
<Icon name="close" />
</button>
</div>
{/if}

<style>
.banner-bottom {
.banner {
position: fixed;
bottom: 0;
top: 0;
left: 0;
right: 0;
z-index: 80;

display: flex;
justify-content: center;
align-items: center;

font: var(--sk-font-ui-medium);
overflow-y: auto;

width: 100%;
height: max-content;
}

.banner-bottom {
text-align: center;
height: var(--sk-banner-height);
background: var(--sk-theme-1-variant);
color: white;
padding: 8px;
}

.banner-bottom :global(a) {
color: hsl(0, 0%, 99%);
padding: 0 4rem;
}

button {
position: absolute;
top: 0;
right: 1rem;

display: flex;
align-items: center;

right: var(--sk-page-padding-side);
height: 100%;
width: 3.2rem;
height: 3.2rem;
}

.main-area {
display: flex;
align-items: center;
gap: 0.6rem;
}

.main-area :global(svg) {
transition: transform 0.2s var(--quint-out);
a {
position: relative;
color: inherit;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: pre;
text-align: center;
line-height: 1;
}

.main-area:hover :global(svg) {
transform: translateX(40%);
span {
position: relative;
top: 0.05em;
}

div :global(a[href]) {
text-decoration: none;
padding: 0;
.large {
display: none;
}

a .lg {
.small {
display: initial;
}

a .sm {
display: none;
}

@media screen and (max-width: 799px) {
.banner-bottom {
bottom: initial;
top: 0;
@media (min-width: 800px) {
.banner {
top: initial;
bottom: 0;
}

.main-area :global(svg) {
display: none;
button {
right: 1rem;
}

a .lg {
display: none;
.large {
display: initial;
}

a .sm {
display: initial;
.small {
display: none;
}
}
</style>
Loading
Loading