diff --git a/src/lib/components/billing/gradientBanner.svelte b/src/lib/components/billing/gradientBanner.svelte index 7f9b62a64..8b61fff3d 100644 --- a/src/lib/components/billing/gradientBanner.svelte +++ b/src/lib/components/billing/gradientBanner.svelte @@ -7,6 +7,8 @@ import PinkBackground from '$lib/images/pink-background.svg'; import { bannerSpacing } from '$lib/layout/headerAlert.svelte'; import { createEventDispatcher, onMount, onDestroy } from 'svelte'; + import { headerAlert } from '$lib/stores/headerAlert'; + import { ProfileMode, resolvedProfile } from '$lib/profiles/index.svelte'; export let variant: 'gradient' | 'image' = 'gradient'; @@ -16,12 +18,13 @@ const queryLayoutElements = () => ({ header: document.querySelector('main > header'), sidebar: document.querySelector('main > div > nav'), - content: document.querySelector('main > div > section') + content: document.querySelector('main > div > section'), + contentDiv: document.querySelector('main > .content') }); const setNavigationHeight = () => { const alertHeight = container?.getBoundingClientRect()?.height || 0; - const { header, sidebar, content } = queryLayoutElements(); + const { header, sidebar, content, contentDiv } = queryLayoutElements(); const headerHeight = header?.getBoundingClientRect().height || 0; const offset = alertHeight + (!$isTabletViewport && header ? headerHeight : 0); @@ -35,11 +38,18 @@ // for sidebar and sub-navigation! bannerSpacing.set(`${alertHeight}px`); + headerAlert.setTopSpacing(alertHeight); } if (content) { content.style.paddingBlockStart = `${alertHeight}px`; } + + if (contentDiv && resolvedProfile.id === ProfileMode.STUDIO) { + const headerHeight = header?.getBoundingClientRect().height ?? 0; + // push the content enough to show the borders of the content view! + contentDiv.style.marginBlockStart = `${alertHeight + headerHeight}px`; + } }; onMount(setNavigationHeight); diff --git a/src/lib/layout/headerAlert.svelte b/src/lib/layout/headerAlert.svelte index bb428cdcf..3338cfca9 100644 --- a/src/lib/layout/headerAlert.svelte +++ b/src/lib/layout/headerAlert.svelte @@ -1,6 +1,7 @@ @@ -12,6 +13,8 @@ import { Icon } from '@appwrite.io/pink-svelte'; import { IconX } from '@appwrite.io/pink-icons-svelte'; import { afterNavigate } from '$app/navigation'; + import { headerAlert } from '$lib/stores/headerAlert'; + import { ProfileMode, resolvedProfile } from '$lib/profiles/index.svelte'; export let title: string; export let type: 'info' | 'success' | 'warning' | 'error' | 'default' = 'info'; @@ -31,12 +34,15 @@ const header: HTMLHeadingElement = document.querySelector('main > header'); const sidebar: HTMLElement = document.querySelector('main > div > nav'); const contentSection: HTMLElement = document.querySelector('main > div > section'); + const contentDiv: HTMLElement = document.querySelector('main > .content'); if (alertHeight) { // for sidebar and sub-navigation! bannerSpacing.set(`${alertHeight}px`); + headerAlert.setTopSpacing(alertHeight); } else { bannerSpacing.set(undefined); + headerAlert.setTopSpacing(0); } if (header) { @@ -54,6 +60,12 @@ if (contentSection) { contentSection.style.paddingBlockStart = `${alertHeight}px`; } + + if (contentDiv && resolvedProfile.id === ProfileMode.STUDIO) { + const headerHeight = header?.getBoundingClientRect().height ?? 0; + // push the content enough to show the borders of the content view! + contentDiv.style.marginBlockStart = `${alertHeight + headerHeight}px`; + } } onMount(() => { diff --git a/src/lib/stores/headerAlert.ts b/src/lib/stores/headerAlert.ts index 48d1f0c0c..b765a23fc 100644 --- a/src/lib/stores/headerAlert.ts +++ b/src/lib/stores/headerAlert.ts @@ -9,11 +9,13 @@ export type HeaderAlert = { }; export type HeaderAlertStore = { + top: number; components: HeaderAlert[]; }; function createHeaderAlertStore() { - const { subscribe, update, set } = writable({ + const { set, update, subscribe } = writable({ + top: 0, components: [] }); @@ -48,14 +50,23 @@ function createHeaderAlertStore() { }); return component as HeaderAlert; }, - isShowing: (): boolean => { - let showing = false; + setTopSpacing: (value: number) => { + update((n) => { + return { + ...n, + top: value + }; + }); + }, + getTopSpacing: (): number => { + let top = 0; update((n) => { if (n.components.length === 0) return n; - showing = n.components.some((c) => c.show); + top = n.top; return n; }); - return showing; + + return top; } }; } diff --git a/src/lib/studio/studio-widget.ts b/src/lib/studio/studio-widget.ts index b93e8bf12..0a856e937 100644 --- a/src/lib/studio/studio-widget.ts +++ b/src/lib/studio/studio-widget.ts @@ -12,7 +12,6 @@ import { headerAlert } from '$lib/stores/headerAlert'; const COMPONENT_SELECTOR = 'imagine-web-components-wrapper[data-appwrite-studio]'; const STYLE_ATTRIBUTE = 'data-appwrite-studio-style'; -const BLOCK_BANNER_OFFSET = 96; const BLOCK_START_BASE_OFFSET = 48; export const CDN_URL = env?.PUBLIC_IMAGINE_CDN_URL + '/web-components.js'; export const CDN_CSS_URL = env?.PUBLIC_IMAGINE_CDN_URL + '/web-components.css'; @@ -196,7 +195,7 @@ function updatePosition() { return; } - const bannerOffset = headerAlert.isShowing() ? BLOCK_BANNER_OFFSET : 0; + const bannerOffset = headerAlert.getTopSpacing(); const rect = anchorElement.getBoundingClientRect(); const { offsetX, offsetY } = currentOptions;