From ae74a8988fd6af872050aa1e48aa80f36bc4a139 Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Sat, 9 Mar 2024 11:21:50 +0100 Subject: [PATCH] Improve parent page button --- .../Topbar/components/ParentPageLink.astro | 33 ++++++++-- .../Topbar/components/ParentPagesButton.astro | 41 +++++++----- .../Topbar/components/ReturnToButton.astro | 65 +++++++++++++++++++ src/i18n/wordings-keys.ts | 5 +- 4 files changed, 119 insertions(+), 25 deletions(-) create mode 100644 src/components/AppLayout/components/Topbar/components/ReturnToButton.astro diff --git a/src/components/AppLayout/components/Topbar/components/ParentPageLink.astro b/src/components/AppLayout/components/Topbar/components/ParentPageLink.astro index df1808d..aa0f924 100644 --- a/src/components/AppLayout/components/Topbar/components/ParentPageLink.astro +++ b/src/components/AppLayout/components/Topbar/components/ParentPageLink.astro @@ -7,18 +7,21 @@ interface Props { } const { parentPage } = Astro.props; -const { getLocalizedMatch, getLocalizedUrl } = await getI18n(Astro.locals.currentLocale); +const { getLocalizedMatch, getLocalizedUrl, t } = await getI18n(Astro.locals.currentLocale); const translation = getLocalizedMatch(parentPage.translations); let href = ""; +let collectionLabel = ""; switch (parentPage.collection) { case Collections.Folders: href = getLocalizedUrl(`/folders/${parentPage.slug}`); + collectionLabel = t("header.nav.parentPages.collections.folder"); break; case Collections.Collectibles: href = getLocalizedUrl(`/collectibles/${parentPage.slug}`); + collectionLabel = t("header.nav.parentPages.collections.collectible"); break; default: @@ -29,9 +32,7 @@ switch (parentPage.collection) { {/* ------------------------------------------- HTML ------------------------------------------- */} -{/* TODO: Not use the tag but actual translation */} - -{parentPage.tag}{translation.name} +
{collectionLabel}

{translation.name}

{/* ------------------------------------------- CSS -------------------------------------------- */} @@ -39,12 +40,30 @@ switch (parentPage.collection) { a { display: flex; place-items: center; + gap: 0.5em; - & > span { - background-color: var(--color-base-250); + & > p { + text-decoration: underline dotted 0.1em; + text-decoration-color: transparent; + + transition-duration: 150ms; + transition-property: text-decoration-color, color; + } + + &:hover > p { + color: var(--color-base-750); + text-decoration-color: var(--color-base-650); + } + + &:active > p { + color: var(--color-base-650); + text-decoration-color: var(--color-base-550); + } + + & > div { + background-color: var(--color-base-300); border-radius: 9999px; padding: 0.5em 0.6em; - margin-right: 0.5em; font-size: 80%; } } diff --git a/src/components/AppLayout/components/Topbar/components/ParentPagesButton.astro b/src/components/AppLayout/components/Topbar/components/ParentPagesButton.astro index 74fae03..3e52b9e 100644 --- a/src/components/AppLayout/components/Topbar/components/ParentPagesButton.astro +++ b/src/components/AppLayout/components/Topbar/components/ParentPagesButton.astro @@ -4,6 +4,7 @@ import type { ParentPage } from "src/shared/payload/payload-sdk"; import ParentPageLink from "./ParentPageLink.astro"; import { Icon } from "astro-icon/components"; import { getI18n } from "src/i18n/i18n"; +import ReturnToButton from "./ReturnToButton.astro"; interface Props { parentPages: ParentPage[]; @@ -16,23 +17,29 @@ const { t } = await getI18n(Astro.locals.currentLocale); {/* ------------------------------------------- HTML ------------------------------------------- */} - -
- {/* TODO: Translate */} -

This content is part of these pages:

- {parentPages.map((parentPage) => )} -
-
- -

- { - t("header.nav.parentPages.label", { - count: parentPages.length, - }) - } -

-
-
+{ + parentPages.length === 1 && parentPages[0] ? ( + + ) : ( + +
+ {/* TODO: Translate */} +

{t("header.nav.parentPages.tooltip")}

+ {parentPages.map((parentPage) => ( + + ))} +
+
+ +

+ {t("header.nav.parentPages.label", { + count: parentPages.length, + })} +

+
+
+ ) +} {/* ------------------------------------------- CSS -------------------------------------------- */} diff --git a/src/components/AppLayout/components/Topbar/components/ReturnToButton.astro b/src/components/AppLayout/components/Topbar/components/ReturnToButton.astro new file mode 100644 index 0000000..44eb9e1 --- /dev/null +++ b/src/components/AppLayout/components/Topbar/components/ReturnToButton.astro @@ -0,0 +1,65 @@ +--- +import { Icon } from "astro-icon/components"; +import { getI18n } from "src/i18n/i18n"; +import { Collections, type ParentPage } from "src/shared/payload/payload-sdk"; + +interface Props { + parentPage: ParentPage; +} + +const { parentPage } = Astro.props; +const { getLocalizedMatch, getLocalizedUrl, t } = await getI18n(Astro.locals.currentLocale); + +const translation = getLocalizedMatch(parentPage.translations); + +let href = ""; +let collectionLabel = ""; +switch (parentPage.collection) { + case Collections.Folders: + href = getLocalizedUrl(`/folders/${parentPage.slug}`); + collectionLabel = t("header.nav.parentPages.collections.folder"); + break; + + case Collections.Collectibles: + href = getLocalizedUrl(`/collectibles/${parentPage.slug}`); + collectionLabel = t("header.nav.parentPages.collections.collectible"); + break; + + default: + href = "/404"; + break; +} +--- + +{/* ------------------------------------------- HTML ------------------------------------------- */} + + +
+ +

+ {collectionLabel} + {translation.name} +

+
+
+ +{/* ------------------------------------------- CSS -------------------------------------------- */} + + diff --git a/src/i18n/wordings-keys.ts b/src/i18n/wordings-keys.ts index 29fb2fc..74d366a 100644 --- a/src/i18n/wordings-keys.ts +++ b/src/i18n/wordings-keys.ts @@ -79,4 +79,7 @@ export type WordingKey = | "global.credits.translators" | "global.credits.proofreaders" | "global.credits.authors" - | "pages.tableOfContent"; + | "pages.tableOfContent" + | "header.nav.parentPages.collections.folder" + | "header.nav.parentPages.collections.collectible" + | "header.nav.parentPages.tooltip";