Skip to content

Commit

Permalink
Add FichePermaLink component
Browse files Browse the repository at this point in the history
  • Loading branch information
hrenaud committed Mar 5, 2024
1 parent b222d95 commit 926516c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/MarkdownDisplay.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getLangFromUrl, useTranslations } from "@i18n/utils";
import { formatDate } from "@js/utils";
import type { CollectionEntry } from "astro:content";
import Card from "./Card";
import FichePermaLink from "./fiches/FichePermaLink.astro";
import FicheVersionDisplay from "./fiches/FicheVersionDisplay.astro";
import FichesMetasDisplay from "./fiches/FichesMetasDisplay.astro";
import FichesTableValidation from "./fiches/FichesTableValidation.astro";
Expand All @@ -24,13 +25,14 @@ const t = useTranslations(lang);
{
type === Card.FICHES && (
<>
<i>
Mise à jour le{" "}
<i class="flex items-center">
{t("Mise à jour le")}{" "}
{formatDate(entry.data.updatedAt || entry.data.updatedAt)}
</i>
<span class="hidden" data-pagefind-filter="type">
{t("Bonnes pratiques")}
</span>
<FichePermaLink entry={entry} />
<h1 class="flex flex-col items-start gap-2 lg:col-span-2 lg:flex-row lg:items-center lg:gap-0">
<span class="badge mr-2 whitespace-nowrap border-primary bg-primary">
{REF_NAME} {entry.data["refID"]}
Expand Down Expand Up @@ -85,6 +87,7 @@ const t = useTranslations(lang);
<FicheVersionDisplay versions={entry.data["versions"]} />
)
}
{/* CONTENT */}
<slot />
{
type === Card.FICHES && (
Expand Down
40 changes: 40 additions & 0 deletions src/components/fiches/FichePermaLink.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
import { getLangFromUrl, useTranslations } from "@i18n/utils";
import { Icon } from "astro-icon/components";
const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang);
const alertMessage = t("Lien copié");
---

<div class="z-50 mt-4 lg:mt-0 lg:text-right">
<a
target="_blank"
class="copyLink btn btn-responsive btn-outline relative inline-flex items-center justify-end gap-4 font-normal no-underline"
>
<Icon name="tabler:share" size={20} />
<span>{t("Permalien")}</span>
</a>
</div>
<script define:vars={{ alertMessage: alertMessage }}>
const buttons = document.querySelectorAll("a.copyLink");
buttons.forEach((button) => {
button.addEventListener("click", (e) => {
copyLink(e);
});
});
const copyLink = (e) => {
navigator.clipboard.writeText(window.location.href);
e.target.insertAdjacentHTML(
"afterend",
"<div class='linktooltips-container font-bold'>" +
alertMessage +
"</div>",
);
setTimeout(() => {
document
.querySelectorAll(".linktooltips-container")
.forEach((el) => el.remove());
}, 3000);
};
</script>
5 changes: 5 additions & 0 deletions src/i18n/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,18 @@ export const ui = {
Fort: "Fort",
Moyen: "Moyen",
Faible: "Faible",
"Mise à jour le": "Mise à jour le",

// src/components/fiches/FichesFilter.astro
Afficher: "Afficher",
Masquer: "Masquer",
"les filtres": "les filtres",
Catégories: "Catégories",

// src/components/fiches/FichePermaLink.astro
Permalien: "Permalien",
"Lien copié": "Lien copié",

// src/components/fiches/FichesTableValidation.astro
"Principe de validation": "Principe de validation",
"Le nombre": "Le nombre",
Expand Down
3 changes: 3 additions & 0 deletions src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@
.btn {
@apply cursor-pointer rounded-lg p-3 px-4 normal-case no-underline duration-100 hover:drop-shadow-lg;
}
.btn-responsive {
@apply rounded-md p-1 px-2 hover:drop-shadow-md lg:rounded-lg lg:p-3 lg:px-4 hover:lg:drop-shadow-lg;
}
.btn-bg {
@apply bg-primary text-primary-content hover:bg-primary-focus;
}
Expand Down

0 comments on commit 926516c

Please sign in to comment.