Improve parent page button
This commit is contained in:
parent
902af3aa9f
commit
ae74a8988f
|
@ -7,18 +7,21 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { parentPage } = Astro.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);
|
const translation = getLocalizedMatch(parentPage.translations);
|
||||||
|
|
||||||
let href = "";
|
let href = "";
|
||||||
|
let collectionLabel = "";
|
||||||
switch (parentPage.collection) {
|
switch (parentPage.collection) {
|
||||||
case Collections.Folders:
|
case Collections.Folders:
|
||||||
href = getLocalizedUrl(`/folders/${parentPage.slug}`);
|
href = getLocalizedUrl(`/folders/${parentPage.slug}`);
|
||||||
|
collectionLabel = t("header.nav.parentPages.collections.folder");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Collections.Collectibles:
|
case Collections.Collectibles:
|
||||||
href = getLocalizedUrl(`/collectibles/${parentPage.slug}`);
|
href = getLocalizedUrl(`/collectibles/${parentPage.slug}`);
|
||||||
|
collectionLabel = t("header.nav.parentPages.collections.collectible");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -29,9 +32,7 @@ switch (parentPage.collection) {
|
||||||
|
|
||||||
{/* ------------------------------------------- HTML ------------------------------------------- */}
|
{/* ------------------------------------------- HTML ------------------------------------------- */}
|
||||||
|
|
||||||
{/* TODO: Not use the tag but actual translation */}
|
<a href={href}><div>{collectionLabel}</div><p>{translation.name}</p></a>
|
||||||
|
|
||||||
<a href={href}><span>{parentPage.tag}</span>{translation.name}</a>
|
|
||||||
|
|
||||||
{/* ------------------------------------------- CSS -------------------------------------------- */}
|
{/* ------------------------------------------- CSS -------------------------------------------- */}
|
||||||
|
|
||||||
|
@ -39,12 +40,30 @@ switch (parentPage.collection) {
|
||||||
a {
|
a {
|
||||||
display: flex;
|
display: flex;
|
||||||
place-items: center;
|
place-items: center;
|
||||||
|
gap: 0.5em;
|
||||||
|
|
||||||
& > span {
|
& > p {
|
||||||
background-color: var(--color-base-250);
|
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;
|
border-radius: 9999px;
|
||||||
padding: 0.5em 0.6em;
|
padding: 0.5em 0.6em;
|
||||||
margin-right: 0.5em;
|
|
||||||
font-size: 80%;
|
font-size: 80%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import type { ParentPage } from "src/shared/payload/payload-sdk";
|
||||||
import ParentPageLink from "./ParentPageLink.astro";
|
import ParentPageLink from "./ParentPageLink.astro";
|
||||||
import { Icon } from "astro-icon/components";
|
import { Icon } from "astro-icon/components";
|
||||||
import { getI18n } from "src/i18n/i18n";
|
import { getI18n } from "src/i18n/i18n";
|
||||||
|
import ReturnToButton from "./ReturnToButton.astro";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
parentPages: ParentPage[];
|
parentPages: ParentPage[];
|
||||||
|
@ -16,23 +17,29 @@ const { t } = await getI18n(Astro.locals.currentLocale);
|
||||||
|
|
||||||
{/* ------------------------------------------- HTML ------------------------------------------- */}
|
{/* ------------------------------------------- HTML ------------------------------------------- */}
|
||||||
|
|
||||||
<Tooltip trigger="click">
|
{
|
||||||
<div id="tooltip-content" slot="tooltip-content">
|
parentPages.length === 1 && parentPages[0] ? (
|
||||||
{/* TODO: Translate */}
|
<ReturnToButton parentPage={parentPages[0]} />
|
||||||
<p>This content is part of these pages:</p>
|
) : (
|
||||||
{parentPages.map((parentPage) => <ParentPageLink parentPage={parentPage} />)}
|
<Tooltip trigger="click">
|
||||||
</div>
|
<div id="tooltip-content" slot="tooltip-content">
|
||||||
<div class="pressable-label">
|
{/* TODO: Translate */}
|
||||||
<Icon name="material-symbols:keyboard-return" />
|
<p>{t("header.nav.parentPages.tooltip")}</p>
|
||||||
<p>
|
{parentPages.map((parentPage) => (
|
||||||
{
|
<ParentPageLink parentPage={parentPage} />
|
||||||
t("header.nav.parentPages.label", {
|
))}
|
||||||
count: parentPages.length,
|
</div>
|
||||||
})
|
<div class="pressable-label">
|
||||||
}
|
<Icon name="material-symbols:keyboard-return" />
|
||||||
</p>
|
<p>
|
||||||
</div>
|
{t("header.nav.parentPages.label", {
|
||||||
</Tooltip>
|
count: parentPages.length,
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/* ------------------------------------------- CSS -------------------------------------------- */}
|
{/* ------------------------------------------- CSS -------------------------------------------- */}
|
||||||
|
|
||||||
|
|
|
@ -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 ------------------------------------------- */}
|
||||||
|
|
||||||
|
<a href={href}>
|
||||||
|
<div class="pressable-label">
|
||||||
|
<Icon name="material-symbols:keyboard-return" />
|
||||||
|
<p>
|
||||||
|
<span>{collectionLabel}</span>
|
||||||
|
{translation.name}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
{/* ------------------------------------------- CSS -------------------------------------------- */}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
div {
|
||||||
|
height: 16px;
|
||||||
|
|
||||||
|
& > p {
|
||||||
|
display: flex;
|
||||||
|
place-items: center;
|
||||||
|
gap: 0.5em;
|
||||||
|
|
||||||
|
span {
|
||||||
|
border: 1px solid var(--color-base-1000);
|
||||||
|
border-radius: 9999px;
|
||||||
|
padding: 0.3em 0.5em;
|
||||||
|
font-size: 80%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -79,4 +79,7 @@ export type WordingKey =
|
||||||
| "global.credits.translators"
|
| "global.credits.translators"
|
||||||
| "global.credits.proofreaders"
|
| "global.credits.proofreaders"
|
||||||
| "global.credits.authors"
|
| "global.credits.authors"
|
||||||
| "pages.tableOfContent";
|
| "pages.tableOfContent"
|
||||||
|
| "header.nav.parentPages.collections.folder"
|
||||||
|
| "header.nav.parentPages.collections.collectible"
|
||||||
|
| "header.nav.parentPages.tooltip";
|
||||||
|
|
Loading…
Reference in New Issue