add: mobile banner.

This commit is contained in:
ItzNotABug committed 2024-09-20 20:53:29 +05:30
1 parent 5ff5c28a52
commit 71c7b6e711
2 files changed
+146 -2

No files matched your search

+142 -2
View File
@@ -3,9 +3,10 @@
import { Button } from '$lib/elements/forms/index';
import { hideNotification, shouldShowNotification } from '$lib/helpers/notifications';
import { app } from '$lib/stores/app';
import { type BottomModalAlertItem, bottomModalAlerts, dismissBottomModalAlert } from '$lib/stores/bottom-alerts';
import { type BottomModalAlertItem, bottomModalAlerts, dismissBottomModalAlert, hideAllModalAlerts } from '$lib/stores/bottom-alerts';
let currentIndex = 0;
let openModalOnMobile = false;
$: filteredModalAlerts = $bottomModalAlerts
.sort((a, b) => b.importance - a.importance)
@@ -35,7 +36,7 @@
</script>
{#if filteredModalAlerts.length > 0 && currentModalAlert}
<div class="main-alert-wrapper">
<div class="main-alert-wrapper is-not-mobile">
<div class="alert-container">
<article class="card">
{#key currentModalAlert.id}
@@ -136,6 +137,130 @@
</article>
</div>
</div>
<div class="main-alert-wrapper is-only-mobile" class:closed={!openModalOnMobile}>
{#if openModalOnMobile}
<div class="alert-container">
<article class="card">
{#key currentModalAlert.id}
<div class="content-wrapper u-flex-vertical u-gap-16">
{#if $app.themeInUse === 'dark'}
<img
src={currentModalAlert.src.dark}
alt={currentModalAlert.title}
class="showcase-image u-image-object-fit-contain u-block u-only-dark" />
{:else}
<img
src={currentModalAlert.src.light}
alt={currentModalAlert.title}
class="showcase-image u-image-object-fit-contain u-block u-only-light" />
{/if}
<div>
<button
class="icon-inline-tag"
on:click={() => handleClose(currentModalAlert)}>
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 20 20"
fill="none">
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M4.29289 4.29289C4.68342 3.90237 5.31658 3.90237 5.70711 4.29289L10 8.58579L14.2929 4.29289C14.6834 3.90237 15.3166 3.90237 15.7071 4.29289C16.0976 4.68342 16.0976 5.31658 15.7071 5.70711L11.4142 10L15.7071 14.2929C16.0976 14.6834 16.0976 15.3166 15.7071 15.7071C15.3166 16.0976 14.6834 16.0976 14.2929 15.7071L10 11.4142L5.70711 15.7071C5.31658 16.0976 4.68342 16.0976 4.29289 15.7071C3.90237 15.3166 3.90237 14.6834 4.29289 14.2929L8.58579 10L4.29289 5.70711C3.90237 5.31658 3.90237 4.68342 4.29289 4.29289Z"
fill="#97979B" />
</svg>
</button>
</div>
{#if filteredModalAlerts.length > 1}
<div class="u-flex u-main-space-between u-cross-center">
<span class="inline-tag feature-count-tag">
Feature {currentIndex + 1} of {filteredModalAlerts.length}
</span>
<div class="u-flex u-gap-10">
<button
class="icon-cheveron-left"
on:click={showPrevious}
disabled={currentIndex === 0}
class:active={currentIndex > 0} />
<button
class="icon-cheveron-right"
on:click={showNext}
disabled={currentIndex ===
filteredModalAlerts.length - 1}
class:active={currentIndex !==
filteredModalAlerts.length - 1} />
</div>
</div>
{/if}
<div class="u-flex-vertical u-gap-8 u-padding-inline-8">
<h3 class="body-text-2 u-bold">{currentModalAlert.title}</h3>
<span class="u-width-fit-content">
{#if currentModalAlert.isHtml}
{@html currentModalAlert.message}
{:else}
{currentModalAlert.message}
{/if}
</span>
</div>
<div
class="buttons u-flex u-flex-vertical-mobile u-gap-4 u-padding-inline-8 u-padding-block-8">
<Button
secondary
class="button"
href={currentModalAlert.cta.link}
external={!isCloud}
fullWidthMobile
on:click={() => handleClose(currentModalAlert)}>
{currentModalAlert.cta.text}
</Button>
{#if currentModalAlert.learnMore && currentModalAlert.learnMore.link}
<Button
text
class="button"
external
fullWidthMobile
href={currentModalAlert.learnMore.link}>
{currentModalAlert.learnMore.text
? currentModalAlert.learnMore.text
: 'Learn More'}
</Button>
{/if}
</div>
</div>
{/key}
</article>
</div>
{:else}
<button
class:showing={!openModalOnMobile}
class="card notification-card u-width-full-line"
on:click={() => openModalOnMobile = !openModalOnMobile}>
<div class="u-flex-vertical u-gap-4">
<div class="u-flex u-cross-center u-main-space-between">
<h3 class="body-text-2 u-bold">Early access</h3>
<button on:click={hideAllModalAlerts}>
<span class="icon-x" />
</button>
</div>
<span class="u-width-fit-content">
Opt-in to experiments, new features, and more.
</span>
</div>
</button>
{/if}
</div>
{/if}
<style>
@@ -208,6 +333,21 @@
transform: translate(-50%, -50%);
}
.main-alert-wrapper.closed {
backdrop-filter: unset;
}
.notification-card {
padding: var(--space-5, 10px) var(--space-6, 12px);
}
.main-alert-wrapper:has(.card.notification-card) {
bottom: 0;
top: unset;
min-height: auto;
padding-inline: 0.5rem;
}
.alert-container {
max-width: 289px;
}
+4
View File
@@ -29,6 +29,10 @@ export type BottomModalAlertItem = {
export const bottomModalAlerts = writable<BottomModalAlertItem[]>([]);
export const hideAllModalAlerts = () => {
bottomModalAlerts.update((all) => all.filter((t) => t.show = false));
}
export const dismissBottomModalAlert = (id: string) => {
bottomModalAlerts.update((all) => all.filter((t) => t.id !== id));
};