From 43d5d1568b1f448d3bb87aeffdcfd7d31376cafc Mon Sep 17 00:00:00 2001
From: DrMint <29893320+DrMint@users.noreply.github.com>
Date: Sat, 1 Jun 2024 11:48:48 +0200
Subject: [PATCH] Refacto JS parallax
---
README.md | 14 ++-
.../components/AppLayoutBackgroundImg.astro | 28 +----
.../AppLayout/components/Html.astro | 14 +++
.../RTUpload/components/RTAudio.astro | 2 +
src/pages/[locale]/dev/parallax.astro | 111 ------------------
.../folders/_components/FolderCard.astro | 1 -
6 files changed, 33 insertions(+), 137 deletions(-)
delete mode 100644 src/pages/[locale]/dev/parallax.astro
diff --git a/README.md b/README.md
index e66bf5d..0a9414c 100644
--- a/README.md
+++ b/README.md
@@ -132,6 +132,9 @@ A parallax effect is applied on the webpages' background image. This effect can
## CSS Utility classes
+- `.dark-theme`: force dark theming to the element and its children.
+- `.light-theme`: force light theming to the element and its children.
+
- `when-js`: only display element if JavaScript is available
- `when-no-js`: only display element if JavaScript is unavailable
@@ -140,21 +143,28 @@ A parallax effect is applied on the webpages' background image. This effect can
- `when-no-print`: only display when not printing
+- `font-serif`: by default, everything use sans-serif. Use this class to make the font serif.
+- `font-[size]`: apply size from font size system. Valid sizes are `xs`, `s`, `m`, `l`, `xl`, `2xl`, `3xl`, `4xl`, and `5xl`
+
- `hide-scrollbar`: hide the element scrollbar
- `texture-dots`: add a background paper like texture to the element
-
-- `font-serif`: by default, everything use sans-serif. Use this class to make the font serif.
- `high-contrast-text`: add a shadow around the text to increase perceived contrast.
- `prose`: apply typography rules. Useful for main text content
+- `error-message`: make the element flash with a red background.
+- `DEV_TODO`: completely hide the element. Useful if some element should remain in the codebase but shouldn't be visible on the page, such as WIP feature.
## CSS Component classes
- `pressable-icon`: used to make a SVG/Text look pressable
+- `pressable-link`: used to make links look pressable (text with underline)
- `pressable`: used to make a container look pressable
## CSS Global Variables
- `--color-base-X`: the current theme colors. X can be between 0 and 1000, available in increments of 50.
+- `--scroll-relative`: the current vertical scroll position. The value is between 0 (at the top of the page) to 1 (at the bottom of the page)
+- `--scroll-absolute`: the current vertical scroll position in px.
+- `--font-size-[size]`: apply size from font size system. Valid sizes are `xs`, `s`, `m`, `l`, `xl`, `2xl`, `3xl`, `4xl`, and `5xl`
## Translations
diff --git a/src/components/AppLayout/components/AppLayoutBackgroundImg.astro b/src/components/AppLayout/components/AppLayoutBackgroundImg.astro
index 46f5d86..69c9bd3 100644
--- a/src/components/AppLayout/components/AppLayoutBackgroundImg.astro
+++ b/src/components/AppLayout/components/AppLayoutBackgroundImg.astro
@@ -6,7 +6,6 @@ import type {
} from "src/shared/payload/payload-sdk";
import { getRandomId } from "src/utils/random";
import { sizesToSrcset } from "src/utils/img";
-import { UAParser } from "ua-parser-js";
interface Props {
img: EndpointImage | EndpointMediaThumbnail | EndpointScanImage;
@@ -24,11 +23,6 @@ const style = `
mask-image: linear-gradient( to bottom, rgba(0 0 0 / 30%) 0%, transparent 100% );
}
}`; // Required to be done like this because we can't insert variables in media queries with Astro.
-
-const userAgent = Astro.request.headers.get("user-agent") ?? "";
-const parser = new UAParser(userAgent);
-const isParallaxEnabled =
- parser.getDevice().type !== "mobile" && parser.getDevice().type !== "tablet";
---
{/* ------------------------------------------- HTML ------------------------------------------- */}
@@ -89,19 +83,19 @@ const isParallaxEnabled =
user-select: none;
animation: fadeIn 3s forwards;
+
+ @media (min-width: 650.5px) {
+ transform: translateY(calc(var(--scroll-absolute) * 0.4px));
+ }
}
{/* ------------------------------------------- JS --------------------------------------------- */}
-
-
-
diff --git a/src/components/AppLayout/components/Html.astro b/src/components/AppLayout/components/Html.astro
index f0d7039..2cd7c68 100644
--- a/src/components/AppLayout/components/Html.astro
+++ b/src/components/AppLayout/components/Html.astro
@@ -758,3 +758,17 @@ const { currentTheme } = Astro.locals;
});
});
+
+
diff --git a/src/components/RichText/components/RTUpload/components/RTAudio.astro b/src/components/RichText/components/RTUpload/components/RTAudio.astro
index cd4dbd2..b68996e 100644
--- a/src/components/RichText/components/RTUpload/components/RTAudio.astro
+++ b/src/components/RichText/components/RTUpload/components/RTAudio.astro
@@ -32,6 +32,8 @@ const { title } = getLocalizedMatch(value.translations);
+{/* ------------------------------------------- CSS -------------------------------------------- */}
+
diff --git a/src/pages/[locale]/folders/_components/FolderCard.astro b/src/pages/[locale]/folders/_components/FolderCard.astro
index b219406..26ab5f9 100644
--- a/src/pages/[locale]/folders/_components/FolderCard.astro
+++ b/src/pages/[locale]/folders/_components/FolderCard.astro
@@ -22,7 +22,6 @@ const { icon = "material-symbols:folder-outline", title, href } = Astro.props;