Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit d2b6a45

Browse files
authored
feat: banner (#240)
1 parent 750aa5e commit d2b6a45

File tree

5 files changed

+136
-29
lines changed

5 files changed

+136
-29
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<script context="module">
2+
const banner_preferences = persisted(
3+
'svelte:banner-preferences',
4+
/** @type {Record<string, boolean>} */ ({})
5+
);
6+
</script>
7+
8+
<script>
9+
import { browser } from '$app/environment';
10+
import { onMount } from 'svelte';
11+
import { persisted } from 'svelte-local-storage-store';
12+
import Icon from './Icon.svelte';
13+
14+
/** Whether to show an arrow at the end */
15+
export let arrow = false;
16+
17+
/** Required for dismissing behavior e.g `<Banner id="svelte-5-runes" />` will make sure the banner
18+
* hidden only for this ID. Later if another banner is added, that will be visible by default.
19+
*
20+
* @type {string}
21+
*/
22+
export let id;
23+
24+
let height = 0;
25+
$: if (browser) {
26+
document.documentElement.style.setProperty(
27+
'--sk-banner-bottom-height',
28+
($banner_preferences[id] ? height : 0) + 'px'
29+
);
30+
}
31+
32+
onMount(() => {
33+
$banner_preferences[id] ??= true;
34+
});
35+
</script>
36+
37+
{#if $banner_preferences[id]}
38+
<div class="banner-bottom" bind:clientHeight={height}>
39+
<div class="main-area">
40+
<slot />
41+
42+
{#if arrow}
43+
<Icon name="arrow-right" size="1.2em" />
44+
{/if}
45+
</div>
46+
47+
<button class="close-button" on:click={() => ($banner_preferences[id] = false)}>
48+
<Icon name="close" />
49+
</button>
50+
</div>
51+
{/if}
52+
53+
<style>
54+
.banner-bottom {
55+
position: relative;
56+
57+
display: flex;
58+
justify-content: center;
59+
align-items: center;
60+
61+
overflow-y: auto;
62+
}
63+
64+
.banner-bottom {
65+
position: absolute;
66+
bottom: 0;
67+
left: 0;
68+
right: 0;
69+
z-index: 80;
70+
71+
width: 100%;
72+
height: max-content;
73+
}
74+
75+
.banner-bottom {
76+
text-align: center;
77+
background: var(--sk-theme-1-variant);
78+
color: white;
79+
padding: 8px;
80+
}
81+
82+
.banner-bottom :global(a) {
83+
color: hsl(0, 0%, 99%);
84+
}
85+
86+
button {
87+
position: absolute;
88+
top: 0;
89+
right: 1rem;
90+
91+
display: flex;
92+
align-items: center;
93+
94+
height: 100%;
95+
}
96+
97+
.main-area {
98+
display: flex;
99+
align-items: center;
100+
gap: 0.6rem;
101+
}
102+
103+
.main-area :global(svg) {
104+
transition: transform 0.2s var(--quint-out);
105+
}
106+
107+
.main-area:hover :global(svg) {
108+
transform: translateX(40%);
109+
}
110+
111+
div :global(a[href]) {
112+
text-decoration: none;
113+
}
114+
115+
@media screen and (max-width: 800px) {
116+
.banner-bottom {
117+
bottom: initial;
118+
top: 0;
119+
}
120+
121+
.main-area :global(svg) {
122+
display: none;
123+
}
124+
}
125+
</style>

packages/site-kit/src/lib/components/Shell.svelte

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ The main shell of the application. It provides a slot for the top navigation, th
1111
import '../styles/index.css';
1212
import Icons from './Icons.svelte';
1313
14-
/**
15-
* Height of the bottom banner. If '0px', the banner is not visible.
16-
*/
17-
export let banner_bottom_height = '0px';
1814
/**
1915
* Whether the navigation is visible.
2016
*/
@@ -60,15 +56,13 @@ The main shell of the application. It provides a slot for the top navigation, th
6056

6157
<div class="modal-overlay" class:visible={$overlay_open} aria-hidden="true" />
6258

63-
<main id="main" bind:this={main_el} style:--sk-banner-bottom-height={banner_bottom_height}>
59+
<main id="main" bind:this={main_el}>
6460
<slot />
6561
</main>
6662

67-
{#if banner_bottom_height !== '0px'}
68-
<div class="banner-bottom" style:--sk-banner-bottom-height={banner_bottom_height}>
69-
<slot name="banner-bottom" {banner_bottom_height} />
70-
</div>
71-
{/if}
63+
<div class="banner-bottom">
64+
<slot name="banner-bottom" />
65+
</div>
7266

7367
<style>
7468
.modal-overlay {
@@ -110,20 +104,6 @@ The main shell of the application. It provides a slot for the top navigation, th
110104
}
111105
}
112106
113-
.banner-bottom {
114-
position: absolute;
115-
bottom: 0;
116-
left: 0;
117-
right: 0;
118-
}
119-
120-
@media (max-width: 800px) {
121-
.banner-bottom {
122-
bottom: initial;
123-
top: 0;
124-
}
125-
}
126-
127107
:global(body) {
128108
font-size: 1.6rem !important;
129109
}

packages/site-kit/src/lib/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export { default as Icons } from './Icons.svelte';
33
export { default as Section } from './Section.svelte';
44
export { default as Shell } from './Shell.svelte';
55
export { default as ThemeToggle } from './ThemeToggle.svelte';
6+
export { default as Banner } from './Banner.svelte';
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export { mql } from './mql';
2-
export { nav_open, on_this_page_open, overlay_open, should_nav_autohide } from './nav';
3-
export { reduced_motion } from './reduced-motion';
4-
export { search_query, search_recent, searching } from './search';
5-
export { theme } from './theme';
1+
export { mql } from './mql.js';
2+
export { nav_open, on_this_page_open, overlay_open, should_nav_autohide } from './nav.js';
3+
export { reduced_motion } from './reduced-motion.js';
4+
export { search_query, search_recent, searching } from './search.js';
5+
export { theme } from './theme.js';

packages/site-kit/src/lib/styles/tokens.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
--sk-thick-border-width: 0.3rem;
1818
--sk-border-radius: 0.4rem;
1919
--sk-page-main-width: 80rem;
20+
--sk-banner-bottom-height: 0px;
2021

2122
/* typography */
2223
--sk-font: 'Overpass', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,

0 commit comments

Comments
 (0)