Update RSD docs integration

This commit is contained in:
Ronan Berder
2026-06-24 19:07:23 +08:00
parent bbdfe1d272
commit a8c066306b
6 changed files with 67 additions and 47 deletions
+26 -10
View File
@@ -4,11 +4,22 @@
Use the CLI to copy Basecoat component assets into your project. It can install CSS, JavaScript, and the matching Nunjucks or Jinja macros for components that ship template helpers.
<CodeGroup defaultTab="npm">
<Code title="npm" lang="bash">{`npx basecoat-cli add dialog`}</Code>
<Code title="pnpm" lang="bash">{`pnpm dlx basecoat-cli add dialog`}</Code>
<Code title="bun" lang="bash">{`bunx basecoat-cli add dialog`}</Code>
<Code title="yarn" lang="bash">{`yarn dlx basecoat-cli add dialog`}</Code>
<CodeGroup>
```bash title="npm"
npx basecoat-cli add dialog
```
```bash title="pnpm"
pnpm dlx basecoat-cli add dialog
```
```bash title="bun"
bunx basecoat-cli add dialog
```
```bash title="yarn"
yarn dlx basecoat-cli add dialog
```
</CodeGroup>
The CLI asks which template engine you use and where it should copy JavaScript and macro files.
@@ -17,8 +28,9 @@ The CLI asks which template engine you use and where it should copy JavaScript a
Nunjucks and Jinja macros are optional helpers for components with larger HTML structures. They generate the same semantic Basecoat markup shown in the component docs.
<CodeGroup defaultTab="Nunjucks">
<Code title="Nunjucks" lang="jinja">{`{% from "select.njk" import select %}
<CodeGroup>
```jinja title="Nunjucks"
{% from "select.njk" import select %}
{{ select(
name="fruit",
items=[
@@ -26,8 +38,11 @@ Nunjucks and Jinja macros are optional helpers for components with larger HTML s
{ value: "banana", label: "Banana" },
{ value: "blueberry", label: "Blueberry" }
]
) }}`}</Code>
<Code title="Jinja" lang="jinja">{`{% from "select.html.jinja" import select %}
) }}
```
```jinja title="Jinja"
{% from "select.html.jinja" import select %}
{{ select(
name="fruit",
items=[
@@ -35,7 +50,8 @@ Nunjucks and Jinja macros are optional helpers for components with larger HTML s
{ "value": "banana", "label": "Banana" },
{ "value": "blueberry", "label": "Blueberry" }
]
) }}`}</Code>
) }}
```
</CodeGroup>
### Public Macros
+16 -5
View File
@@ -81,11 +81,22 @@ Basecoat is authored for Tailwind CSS. Install Tailwind first if your project do
</Step>
<Step title="Install Basecoat">
<CodeGroup defaultTab="npm">
<Code title="npm" lang="bash">{`npm install basecoat-css`}</Code>
<Code title="pnpm" lang="bash">{`pnpm add basecoat-css`}</Code>
<Code title="bun" lang="bash">{`bun add basecoat-css`}</Code>
<Code title="yarn" lang="bash">{`yarn add basecoat-css`}</Code>
<CodeGroup>
```bash title="npm"
npm install basecoat-css
```
```bash title="pnpm"
pnpm add basecoat-css
```
```bash title="bun"
bun add basecoat-css
```
```bash title="yarn"
yarn add basecoat-css
```
</CodeGroup>
If you are not using a bundler, copy or serve the files you need from `node_modules/basecoat-css/dist`.
+8 -25
View File
@@ -83,46 +83,29 @@ const styleUrls = {
<script is:inline>
(() => {
const pageKey = (href) => {
const key = (href) => {
const url = new URL(href, window.location.origin);
return `${url.pathname.replace(/\/$/, "")}${url.search}`;
};
const updateSidebarState = () => {
const sidebar = document.getElementById("sidebar");
if (!sidebar) return;
const currentKey = pageKey(window.location.href);
sidebar.querySelectorAll("a[href]").forEach((link) => {
const isCurrent = pageKey(link.href) === currentKey;
const syncSidebar = () => {
for (const link of document.querySelectorAll("#sidebar a[href]")) {
const isCurrent = key(link.href) === key(window.location.href);
if (isCurrent) {
link.setAttribute("aria-current", "page");
link.closest("details")?.setAttribute("open", "");
} else {
link.removeAttribute("aria-current");
}
});
}
};
document.addEventListener("DOMContentLoaded", () => {
const content = document.getElementById("content");
if (!content) return;
document.body.setAttribute("hx-boost", "true");
document.body.setAttribute("hx-target", "#content");
document.body.setAttribute("hx-select", "#content");
document.body.setAttribute("hx-swap", "outerHTML");
document.body.setAttribute("hx-push-url", "true");
window.htmx?.process(document.body);
updateSidebarState();
});
document.addEventListener("DOMContentLoaded", syncSidebar);
document.addEventListener("htmx:afterSettle", () => {
window.basecoat?.initAll?.();
updateSidebarState();
syncSidebar();
});
window.addEventListener("popstate", updateSidebarState);
window.addEventListener("popstate", syncSidebar);
})();
</script>