1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-21 23:39:37 +01:00
deka-dom-el/docs_src/components/pageUtils.html.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-11-10 17:15:59 +01:00
import { pages, styles } from "../ssr.js";
2023-11-23 16:30:20 +01:00
const host= "."+prevNext.name;
styles.css`
${host}{
2023-11-10 17:15:59 +01:00
display: grid;
grid-template-columns: 1fr 2fr 1fr;
margin-top: 1rem;
border-top: 1px solid var(--border);
}
2023-11-23 16:30:20 +01:00
${host} [rel=prev]{
2023-11-10 17:15:59 +01:00
grid-column: 1;
}
2023-11-23 16:30:20 +01:00
${host} [rel=next]{
2023-11-10 17:15:59 +01:00
grid-column: 3;
text-align: right;
}
`;
import { el } from "../../index.js";
2023-11-21 17:19:59 +01:00
/**
* @param {Object} attrs
* @param {string} attrs.textContent
* @param {string} [attrs.id]
* */
export function h3({ textContent, id }){
if(!id) id= "h-"+textContent.toLowerCase().replaceAll(/\s/g, "-").replaceAll(/[^a-z-]/g, "");
return el("h3", { id }).append(
2023-11-23 18:36:26 +01:00
el("a", { textContent: "#", href: "#"+id, tabIndex: -1 }),
2023-11-21 17:19:59 +01:00
" ", textContent
);
}
2023-11-10 17:15:59 +01:00
/**
* @param {import("../types.d.ts").Info} page
* */
export function prevNext(page){
const page_index= pages.indexOf(page);
return el("div", { className: prevNext.name }).append(
el(pageLink, { rel: "prev", page: pages[page_index-1] }),
el(pageLink, { rel: "next", page: pages[page_index+1] })
);
}
/**
* @param {Object} attrs
* @param {"prev"|"next"} attrs.rel
* @param {import("../types.d.ts").Info} [attrs.page]
* */
function pageLink({ rel, page }){
if(!page) return el();
let { href, title, description }= page;
return el("a", { rel, href, title: description }).append(
rel==="next" ?"(next) " : "",
title,
rel==="prev" ? " (previous)" : "",
);
}