From cc5cb683137af0300ea62881578e79c18a96d16e Mon Sep 17 00:00:00 2001 From: Diego Diaz Date: Thu, 29 Oct 2026 23:01:42 -0500 Subject: [PATCH 1/6] =?UTF-8?q?fix(website):=20=F0=9F=90=9B=20blur=20the?= =?UTF-8?q?=20docs=20header=20in=20Chromium=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lightning CSS, Vite 8's CSS minifier, kept only the -webkit-backdrop-filter of the header (written after the unprefixed one), which Chromium ignores. Write the standard property alone and let it add the prefix Safari needs. --- website/src/components/docs/chrome.module.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/src/components/docs/chrome.module.css b/website/src/components/docs/chrome.module.css index 6c3b548..b497c79 100644 --- a/website/src/components/docs/chrome.module.css +++ b/website/src/components/docs/chrome.module.css @@ -5,8 +5,10 @@ top: 0; z-index: 50; background: var(--bg-blur); + /* No hand-written -webkit- copy: Lightning CSS (Vite 8) adds the prefix + Safari needs, and with both it kept only the prefixed one, so Chromium + didn't blur. */ backdrop-filter: saturate(180%) blur(12px); - -webkit-backdrop-filter: saturate(180%) blur(12px); border-bottom: 1px solid var(--gray3); } From 881ff01735d053ddc6b9d2b654a244921446d612 Mon Sep 17 00:00:00 2001 From: Diego Diaz Date: Thu, 29 Oct 2026 23:02:43 -0500 Subject: [PATCH 2/6] =?UTF-8?q?feat(website):=20=E2=9C=A8=20color=20the=20?= =?UTF-8?q?changelog=20by=20kind=20of=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each section of a release (breaking changes, features, fixes, deprecations) gets its color, from its heading, both in the curated notes and in the ones changelogithub writes: the heading, a rule along its list and the bullets. A legend under the filters names the colors. --- website/src/lib/github.ts | 35 ++++++++++- website/src/routes/docs/changelog/index.tsx | 19 +++++- website/src/routes/docs/pages.module.css | 68 +++++++++++++++++++++ 3 files changed, 120 insertions(+), 2 deletions(-) diff --git a/website/src/lib/github.ts b/website/src/lib/github.ts index e60115e..47d60b1 100644 --- a/website/src/lib/github.ts +++ b/website/src/lib/github.ts @@ -12,6 +12,39 @@ export interface ReleaseNotes { /** The notes of each published release, by version (the tag without its `v`). */ export type Releases = Record; +/** The kinds of change a release's sections list, as the changelog colors them. */ +export type ChangeKind = "breaking" | "deprecated" | "feature" | "fix" | "perf" | "docs"; + +// A section's kind, from its heading: the curated notes say "Breaking changes", +// "Features", "Fixes"โ€ฆ, changelogithub "๐Ÿšจ Breaking Changes", "๐Ÿš€ Features", +// "๐Ÿž Bug Fixes", "๐ŸŽ Performance". The first match wins. +const KINDS: [ChangeKind, RegExp][] = [ + ["breaking", /breaking/i], + ["deprecated", /deprecat/i], + ["feature", /feature|\bnew\b|\badded\b/i], + ["fix", /\bfix/i], + ["perf", /perf/i], + ["docs", /\bdocs?\b|documentation/i], +]; + +/** + * Marks each heading of a known kind, and the lists under it until the next + * heading, with `data-kind` so the changelog can color them. Other headings + * ("View changes on GitHub") and the lists under them stay as they are. + */ +export const markKinds = (html: string) => { + let kind: ChangeKind | undefined; + return html.replace( + /<(h[1-6])([^>]*)>([\s\S]*?)<\/\1>|])/g, + (match, tag?: string, attrs?: string, inner?: string) => { + if (!tag) return kind ? `
    ]*>/g, "").replace(/&[#\w]+;/g, " "); + kind = KINDS.find(([, pattern]) => pattern.test(text))?.[0]; + return kind ? `<${tag}${attrs} data-kind="${kind}">${inner}` : match; + }, + ); +}; + const RELEASES = "https://api.github.com/repos/diecodev/qwik-sonner/releases"; const PER_PAGE = 100; @@ -57,7 +90,7 @@ export const readReleases = async (): Promise => { .filter((release) => !release.draft && release.tag_name.startsWith("v")) .map((release) => [ release.tag_name.slice(1), - { html: release.body_html?.trim() ?? "", url: release.html_url }, + { html: markKinds(release.body_html?.trim() ?? ""), url: release.html_url }, ]), ); } catch (error) { diff --git a/website/src/routes/docs/changelog/index.tsx b/website/src/routes/docs/changelog/index.tsx index 96e58e8..7712f91 100644 --- a/website/src/routes/docs/changelog/index.tsx +++ b/website/src/routes/docs/changelog/index.tsx @@ -1,6 +1,6 @@ import { component$, useSignal } from "@qwik.dev/core"; import { Link, type DocumentHead } from "@qwik.dev/router"; -import type { Releases } from "~/lib/github"; +import type { ChangeKind, Releases } from "~/lib/github"; import { majorOf, newestFirst, NPM, tagsOf } from "~/lib/release"; import { GITHUB_URL, NPM_URL } from "~/lib/versions"; import styles from "../pages.module.css"; @@ -14,6 +14,15 @@ const FILTERS = [ type Filter = (typeof FILTERS)[number]["id"]; +// The kinds the notes are colored by (see lib/github.ts); performance and docs +// sections stay gray. +const LEGEND: { kind: ChangeKind; label: string }[] = [ + { kind: "breaking", label: "Breaking change" }, + { kind: "feature", label: "Feature" }, + { kind: "fix", label: "Fix" }, + { kind: "deprecated", label: "Deprecated" }, +]; + // The notes of each GitHub release: vite.config.ts reads them when the site // builds and defines `__RELEASES__` with them, so only this page carries them. declare const __RELEASES__: Releases; @@ -86,6 +95,14 @@ export default component$(() => { ))} +
    + {LEGEND.map(({ kind, label }) => ( + + {label} + + ))} +
    + {versions.length === 0 ? (

    npm couldn't be read when this page was built, so there are no versions to show. diff --git a/website/src/routes/docs/pages.module.css b/website/src/routes/docs/pages.module.css index 3a2d39b..8654a00 100644 --- a/website/src/routes/docs/pages.module.css +++ b/website/src/routes/docs/pages.module.css @@ -404,6 +404,74 @@ margin: 2px 0; } +/* A color per kind of change (`data-kind`, set by lib/github.ts), as in the legend */ +.release .notes :global([data-kind]), +.legendItem { + --k: var(--gray9); +} + +.release .notes :global([data-kind="breaking"]), +.legendItem[data-kind="breaking"] { + --k: var(--error-text); +} + +.release .notes :global([data-kind="feature"]), +.legendItem[data-kind="feature"] { + --k: var(--success-text); +} + +.release .notes :global([data-kind="fix"]), +.legendItem[data-kind="fix"] { + --k: var(--info-text); +} + +.release .notes :global([data-kind="deprecated"]), +.legendItem[data-kind="deprecated"] { + --k: var(--warning-text); +} + +.release .notes :global(:is(h1, h2, h3, h4, h5, h6)[data-kind]) { + display: flex; + align-items: center; + gap: 8px; + color: var(--k); +} + +.release .notes :global(:is(h1, h2, h3, h4, h5, h6)[data-kind])::before, +.legendItem::before { + content: ""; + flex: none; + width: 8px; + height: 8px; + border-radius: 50%; + background: var(--k); +} + +.release .notes :global(ul[data-kind]) { + margin-left: 3px; + padding-left: 19px; + border-left: 2px solid color-mix(in srgb, var(--k) 45%, transparent); +} + +.release .notes :global(ul[data-kind] > li)::marker { + color: var(--k); +} + +.legend { + display: flex; + flex-wrap: wrap; + gap: 6px 18px; + margin: -16px 0 28px; + font-size: 13px; + color: var(--gray11); +} + +.legendItem { + display: inline-flex; + align-items: center; + gap: 7px; +} + .release .notes :global(samp) { font-family: var(--font-mono); font-size: 12px; From 87437befbf0873f02f50c61e92a94f172c97b49a Mon Sep 17 00:00:00 2001 From: Diego Diaz Date: Thu, 29 Oct 2026 23:03:47 -0500 Subject: [PATCH 3/6] =?UTF-8?q?feat(website):=20=E2=9C=A8=20scroll=20smoot?= =?UTF-8?q?hly=20to=20sections=20of=20the=20same=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Links to a section of the page you're on (the table of contents, heading anchors, /page/#section) scroll smoothly; page changes still start at the top at once, and prefers-reduced-motion keeps the jump. A sync$ click handler sets scroll-behavior only for those links, since the router scrolls page changes with the same calls. --- website/src/components/SiteShell.tsx | 39 +++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/website/src/components/SiteShell.tsx b/website/src/components/SiteShell.tsx index d6f3ecc..dc2fee7 100644 --- a/website/src/components/SiteShell.tsx +++ b/website/src/components/SiteShell.tsx @@ -1,4 +1,11 @@ -import { component$, Slot, useContextProvider, useSignal } from "@qwik.dev/core"; +import { + component$, + Slot, + sync$, + useContextProvider, + useOnDocument, + useSignal, +} from "@qwik.dev/core"; import { Toaster } from "qwik-sonner"; import { SECONDARY_TOASTER, @@ -24,6 +31,36 @@ export const SiteShell = component$(() => { }; useContextProvider(ToasterControlsContext, controls); + // Links to a section of the same page (the table of contents, heading + // anchors, `/page/#section`) scroll smoothly. Only those: the router also + // scrolls on page changes (to the top, or back), and a global + // `scroll-behavior: smooth` would animate those too. `sync$`, so the style is + // set before the browser or the router scrolls; it's removed once the scroll + // ends (or after a while, where `scrollend` isn't supported). + useOnDocument( + "click", + sync$((event: MouseEvent) => { + if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) { + return; + } + const link = (event.target as Element | null)?.closest?.("a[href*='#']"); + if ( + !(link instanceof HTMLAnchorElement) || + !link.hash || + link.origin !== location.origin || + link.pathname !== location.pathname || + matchMedia("(prefers-reduced-motion: reduce)").matches + ) { + return; + } + const root = document.documentElement; + root.style.scrollBehavior = "smooth"; + const reset = () => root.style.removeProperty("scroll-behavior"); + addEventListener("scrollend", reset, { once: true }); + setTimeout(reset, 1500); + }), + ); + return ( <> {/* From b29a68026d1541de011b9bf3b61aa6bc3549253b Mon Sep 17 00:00:00 2001 From: Diego Diaz Date: Thu, 29 Oct 2026 23:06:18 -0500 Subject: [PATCH 4/6] =?UTF-8?q?feat(website):=20=E2=9C=A8=20drop=20the=20p?= =?UTF-8?q?re-release=20banner=20and=20stick=20the=20old-line=20one=20unde?= =?UTF-8?q?r=20the=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current docs no longer show the "v2 is in beta" banner: the header's badge and the install instructions already say it. The banner on the docs of an older line now sticks with the header, on one line at any width (a shorter text on narrow screens), and the sticky sidebar, table of contents, mobile menu and heading anchors start below both (--docs-top). --- website/src/components/docs/chrome.module.css | 26 ++++++-- website/src/components/docs/chrome.tsx | 62 +++++++------------ website/src/components/docs/ui.module.css | 2 +- website/src/routes/docs/docs.module.css | 14 +++++ website/src/routes/docs/layout.tsx | 11 +++- website/src/routes/docs/pages.module.css | 2 +- 6 files changed, 66 insertions(+), 51 deletions(-) diff --git a/website/src/components/docs/chrome.module.css b/website/src/components/docs/chrome.module.css index b497c79..5916dab 100644 --- a/website/src/components/docs/chrome.module.css +++ b/website/src/components/docs/chrome.module.css @@ -391,14 +391,28 @@ white-space: nowrap; } -.bannerLink span { +.bannerArrow { transition: transform 200ms var(--ease-out); } -.bannerLink:hover span { +.bannerLink:hover .bannerArrow { transform: translateX(3px); } +.bannerShort { + display: none; +} + +@media (max-width: 999px) { + .bannerLong { + display: none; + } + + .bannerShort { + display: inline; + } +} + @keyframes banner-in { from { opacity: 0; @@ -410,9 +424,9 @@ .sidebar { position: sticky; - top: 56px; + top: var(--docs-top, 56px); align-self: start; - max-height: calc(100dvh - 56px); + max-height: calc(100dvh - var(--docs-top, 56px)); overflow-y: auto; padding: 28px 8px 48px 0; scrollbar-width: thin; @@ -463,7 +477,7 @@ @media (max-width: 900px) { .sidebar { position: fixed; - inset: 56px 0 0; + inset: var(--docs-top, 56px) 0 0; z-index: 40; max-height: none; padding: 20px 20px 48px; @@ -497,7 +511,7 @@ .toc { position: sticky; - top: 56px; + top: var(--docs-top, 56px); align-self: start; padding: 32px 0 48px; font-size: 13px; diff --git a/website/src/components/docs/chrome.tsx b/website/src/components/docs/chrome.tsx index 023c8ec..11c9370 100644 --- a/website/src/components/docs/chrome.tsx +++ b/website/src/components/docs/chrome.tsx @@ -16,7 +16,6 @@ import { VERSIONS, type VersionId, } from "~/lib/versions"; -import { LATEST, majorOf } from "~/lib/release"; import { Logo } from "../Logo"; import { QwikV2Badge } from "../QwikV2Badge"; import { ThemeToggle } from "../ThemeToggle"; @@ -178,52 +177,35 @@ export const DocsHeader = component$<{ version: VersionId; navOpen: Signal(({ version }) => { const loc = useLocation(); const v = VERSIONS[version]; const current = VERSIONS[CURRENT_VERSION]; - if (version !== CURRENT_VERSION) { - return ( -

    -

    + return ( +

    + {/* One line at any width (it sticks under the header): a shorter text on narrow screens. */} +

    + You're reading the docs for qwik-sonner {v.version}, the {v.qwik} ( {v.qwikPackage}) line. It no longer receives new features. -

    - - Go to the {current.qwik} docs ({CURRENT_VERSION}) - -
    - ); - } - - if (v.status === "prerelease") { - // While `latest` is still an older major, say what a plain install gets. - const olderLatest = LATEST !== null && majorOf(LATEST) < v.major ? LATEST : null; - return ( -
    -

    - - {CURRENT_VERSION} is in {v.tag ?? "pre-release"} ({v.version}). - {" "} - Install it with {v.spec} - {olderLatest ? ( - <> - {" "} - โ€” plain qwik-sonner still resolves to {olderLatest} - - ) : null} - . -

    - - Installation - - -
    - ); - } - - return null; + + + Docs for {v.version} ({v.qwik}) + +

    + + + Go to the {current.qwik} docs ({CURRENT_VERSION}) + + {current.qwik} docs + + +
    + ); }); /* Sidebar ----------------------------------------------------------------- */ diff --git a/website/src/components/docs/ui.module.css b/website/src/components/docs/ui.module.css index 3a71d72..e8362e6 100644 --- a/website/src/components/docs/ui.module.css +++ b/website/src/components/docs/ui.module.css @@ -2,7 +2,7 @@ .heading { position: relative; - scroll-margin-top: 88px; + scroll-margin-top: calc(var(--docs-top, 56px) + 32px); } .anchor { diff --git a/website/src/routes/docs/docs.module.css b/website/src/routes/docs/docs.module.css index e860f8c..8f581b7 100644 --- a/website/src/routes/docs/docs.module.css +++ b/website/src/routes/docs/docs.module.css @@ -1,7 +1,21 @@ .shell { + /* Height of what sticks at the top: the header, plus the banner on the docs + of an older line. Sticky and fixed parts of the page start below it. */ + --docs-top: 56px; min-height: 100dvh; } +.shell[data-banner] { + /* the 57px header (its border included) and the one-line banner */ + --docs-top: 98px; +} + +.top { + position: sticky; + top: 0; + z-index: 50; +} + .skip { position: absolute; left: 12px; diff --git a/website/src/routes/docs/layout.tsx b/website/src/routes/docs/layout.tsx index 0b19cb5..8fbdc51 100644 --- a/website/src/routes/docs/layout.tsx +++ b/website/src/routes/docs/layout.tsx @@ -21,6 +21,8 @@ export default component$(() => { const pageVersion = versionFromPath(pathname); // Unversioned pages (the changelog) borrow the current version's navigation. const version = pageVersion ?? CURRENT_VERSION; + // The docs of an older line say so under the header. + const banner = pageVersion !== null && pageVersion !== CURRENT_VERSION; const group = DOCS_NAV[version].find((g) => g.items.some((i) => i.href === pathname)); const editUrl = `${GITHUB_URL}/edit/v2/website/src/routes${pathname}index.tsx`; @@ -30,12 +32,15 @@ export default component$(() => { }); return ( -
    +
    Skip to content - - {pageVersion ? : null} + {/* The banner sticks with the header, so it stays in view. */} +
    + + {banner ? : null} +
    diff --git a/website/src/routes/docs/pages.module.css b/website/src/routes/docs/pages.module.css index 8654a00..e07771e 100644 --- a/website/src/routes/docs/pages.module.css +++ b/website/src/routes/docs/pages.module.css @@ -338,7 +338,7 @@ @media (min-width: 641px) { .releaseAside { position: sticky; - top: 80px; + top: calc(var(--docs-top, 56px) + 24px); align-self: start; } } From e1517f05ad991a0e23cdf2b8affddb23bf445649 Mon Sep 17 00:00:00 2001 From: Diego Diaz Date: Thu, 29 Oct 2026 23:09:36 -0500 Subject: [PATCH 5/6] =?UTF-8?q?feat(website):=20=E2=9C=A8=20serve=20the=20?= =?UTF-8?q?current=20docs=20at=20/docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current line's docs move from /docs/v2/โ€ฆ to /docs/โ€ฆ, and an older line keeps /docs/v/โ€ฆ (/docs/v1/โ€ฆ). vercel.json redirects /docs/v2/โ€ฆ to /docs/โ€ฆ for the links already out there. The paths come from CURRENT_VERSION (versions.ts), and website/README.md says what to move when a new major ships. --- README.md | 2 +- vercel.json | 4 +- website/README.md | 14 +- website/adapters/ssg/vite.config.ts | 3 - website/src/components/Hero.tsx | 2 +- website/src/components/QwikV2Badge.tsx | 2 +- website/src/lib/docs-nav.ts | 3 +- website/src/lib/versions.ts | 17 +- .../routes/docs/{v2 => }/advanced/index.tsx | 6 +- website/src/routes/docs/changelog/index.tsx | 2 +- .../{v2 => }/examples/examples.module.css | 0 .../routes/docs/{v2 => }/examples/index.tsx | 2 +- website/src/routes/docs/index.tsx | 213 ++++++++++++++++-- .../routes/docs/{v2 => }/migration/index.tsx | 12 +- .../routes/docs/{v2 => }/options/index.tsx | 2 +- .../routes/docs/{v2 => }/styling/index.tsx | 0 .../src/routes/docs/{v2 => }/toast/index.tsx | 6 +- .../routes/docs/{v2 => }/toaster/index.tsx | 6 +- website/src/routes/docs/v1/index.tsx | 2 +- website/src/routes/docs/v2/index.tsx | 201 ----------------- website/src/routes/index.tsx | 2 +- 21 files changed, 246 insertions(+), 255 deletions(-) rename website/src/routes/docs/{v2 => }/advanced/index.tsx (97%) rename website/src/routes/docs/{v2 => }/examples/examples.module.css (100%) rename website/src/routes/docs/{v2 => }/examples/index.tsx (99%) rename website/src/routes/docs/{v2 => }/migration/index.tsx (93%) rename website/src/routes/docs/{v2 => }/options/index.tsx (99%) rename website/src/routes/docs/{v2 => }/styling/index.tsx (100%) rename website/src/routes/docs/{v2 => }/toast/index.tsx (98%) rename website/src/routes/docs/{v2 => }/toaster/index.tsx (98%) delete mode 100644 website/src/routes/docs/v2/index.tsx diff --git a/README.md b/README.md index b6d6632..0926396 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ https://github.com/diecodev/qwik-sonner/assets/51871681/e7a7e4a6-c422-44b2-af7e- # qwik-sonner [![npm](https://img.shields.io/npm/v/qwik-sonner?label=npm&color=111)](https://www.npmjs.com/package/qwik-sonner) -[![Qwik v2](https://img.shields.io/npm/v/qwik-sonner/beta?label=qwik%20v2&color=ac7ef4)](https://qwik-sonner.dieco.dev/docs/v2/) +[![Qwik v2](https://img.shields.io/npm/v/qwik-sonner/beta?label=qwik%20v2&color=ac7ef4)](https://qwik-sonner.dieco.dev/docs/) An opinionated toast component for qwik. Based on [emilkowalski](https://github.com/emilkowalski)'s React [implementation](https://sonner.emilkowal.ski/). diff --git a/vercel.json b/vercel.json index 9310637..2ba3e0d 100644 --- a/vercel.json +++ b/vercel.json @@ -7,8 +7,8 @@ "outputDirectory": "website/dist", "trailingSlash": true, "redirects": [ - { "source": "/docs", "destination": "/docs/v2/", "permanent": true }, - { "source": "/docs/", "destination": "/docs/v2/", "permanent": true } + { "source": "/docs/v2", "destination": "/docs/", "permanent": true }, + { "source": "/docs/v2/:path*", "destination": "/docs/:path*", "permanent": true } ], "headers": [ { diff --git a/website/README.md b/website/README.md index 85af7f9..5e7c645 100644 --- a/website/README.md +++ b/website/README.md @@ -65,6 +65,14 @@ The build settings live in [`vercel.json`](../vercel.json) at the repo root: pnpm is the one in the root `package.json`'s `packageManager`: the CI's setup installs it, and Vercel reads it for the previews. -`trailingSlash` matches the URLs of the pages (`/docs/v2/toast/`), `/docs` redirects to the current -docs, `404.html` answers missing pages, and `/build/` and `/assets/` (hashed file names) are cached -for a year. +`trailingSlash` matches the URLs of the pages (`/docs/toast/`), `/docs/v2/โ€ฆ` redirects to `/docs/โ€ฆ` +(see below), `404.html` answers missing pages, and `/build/` and `/assets/` (hashed file names) are +cached for a year. + +## Docs URLs + +The current line's docs live at `/docs/โ€ฆ` (`src/routes/docs/`), an older line's at `/docs/v/โ€ฆ` +(`src/routes/docs/v1/`), and `vercel.json` redirects `/docs/v/โ€ฆ` to `/docs/โ€ฆ`, so both +addresses work. The paths come from `CURRENT_VERSION` in `src/lib/versions.ts`. When a new major +ships: move the current pages into `src/routes/docs/v/`, put the new ones in `src/routes/docs/`, +set `CURRENT_VERSION`, and point the redirects in `vercel.json` at the new major. diff --git a/website/adapters/ssg/vite.config.ts b/website/adapters/ssg/vite.config.ts index a885ab4..aee992d 100644 --- a/website/adapters/ssg/vite.config.ts +++ b/website/adapters/ssg/vite.config.ts @@ -14,9 +14,6 @@ export default extendConfig(baseConfig, () => { plugins: [ ssgAdapter({ origin: "https://qwik-sonner.dieco.dev", - // `/docs` only redirects: vercel.json answers it in production, and a - // redirect can't be prerendered. - exclude: ["/docs"], }), ], }; diff --git a/website/src/components/Hero.tsx b/website/src/components/Hero.tsx index 30b4158..b52d3b9 100644 --- a/website/src/components/Hero.tsx +++ b/website/src/components/Hero.tsx @@ -28,7 +28,7 @@ export const Hero = component$(() => { > Render a toast - + Documentation diff --git a/website/src/components/QwikV2Badge.tsx b/website/src/components/QwikV2Badge.tsx index 2d7c074..ef81465 100644 --- a/website/src/components/QwikV2Badge.tsx +++ b/website/src/components/QwikV2Badge.tsx @@ -24,7 +24,7 @@ export const QwikV2Badge = component$<{ size?: "sm" | "md" }>(({ size = "md" }) return ( > = { /** URL of the page in `target` that best matches `pathname`. */ export const equivalentHref = (pathname: string, target: VersionId) => { - const match = /^\/docs\/v\d+\/([^/]+)?/.exec(pathname); + // `/docs//` on the current line, `/docs/v//` on an older one + const match = /^\/docs\/(?:v\d+\/)?([^/]+)?/.exec(pathname); const slug = match?.[1] ?? ""; const mapped = EQUIVALENT_SLUG[target][slug] ?? ""; return `${VERSIONS[target].basePath}/${mapped ? `${mapped}/` : ""}`; diff --git a/website/src/lib/versions.ts b/website/src/lib/versions.ts index a35e269..f50c98a 100644 --- a/website/src/lib/versions.ts +++ b/website/src/lib/versions.ts @@ -12,10 +12,15 @@ export interface DocsVersion extends Line { status: "stable" | "prerelease" | "legacy"; /** Text of the status pill: `Stable`, the dist-tag (`beta`, `rc`) or `Legacy`. */ statusLabel: string; - basePath: `/docs/${VersionId}`; + /** `/docs` for the current line, `/docs/v1` for an older one */ + basePath: "/docs" | `/docs/${VersionId}`; } -/** Newest docs line โ€” what `/docs` redirects to and what other versions link to. */ +/** + * Newest docs line: its pages live at `/docs/โ€ฆ` (routes/docs/), the older lines' at `/docs/v/โ€ฆ` + * (routes/docs/v/), and vercel.json sends `/docs/v/โ€ฆ` of the current line to `/docs/โ€ฆ`. When a + * new major ships, move the current pages to routes/docs/v/ and the new ones to routes/docs/. + */ export const CURRENT_VERSION: VersionId = "v2"; export const VERSION_ORDER: VersionId[] = ["v2", "v1"]; @@ -30,7 +35,7 @@ const docsVersion = (id: VersionId, line: Line, qwik: string, qwikPackage: strin status, statusLabel: status === "legacy" ? "Legacy" : status === "stable" ? "Stable" : (line.tag ?? "Pre-release"), - basePath: `/docs/${id}`, + basePath: id === CURRENT_VERSION ? "/docs" : `/docs/${id}`, }; }; @@ -40,9 +45,13 @@ export const VERSIONS: Record = { v1: docsVersion("v1", V1, "Qwik 1", "@builder.io/qwik"), }; +/** The docs line a page belongs to; `null` for pages of none (the changelog) and outside the docs. */ export const versionFromPath = (pathname: string): VersionId | null => { const match = /^\/docs\/(v\d+)(\/|$)/.exec(pathname); - return match && match[1] in VERSIONS ? (match[1] as VersionId) : null; + if (match) return match[1] in VERSIONS ? (match[1] as VersionId) : null; + return /^\/docs(\/|$)/.test(pathname) && !pathname.startsWith("/docs/changelog") + ? CURRENT_VERSION + : null; }; export const GITHUB_URL = "https://github.com/diecodev/qwik-sonner"; diff --git a/website/src/routes/docs/v2/advanced/index.tsx b/website/src/routes/docs/advanced/index.tsx similarity index 97% rename from website/src/routes/docs/v2/advanced/index.tsx rename to website/src/routes/docs/advanced/index.tsx index 59f4781..5ade580 100644 --- a/website/src/routes/docs/v2/advanced/index.tsx +++ b/website/src/routes/docs/advanced/index.tsx @@ -3,7 +3,7 @@ import { Link, type DocumentHead } from "@qwik.dev/router"; import { CodeBlock } from "~/components/CodeBlock"; import { H2, H3 } from "~/components/docs/ui"; import { GITHUB_URL } from "~/lib/versions"; -import styles from "../../pages.module.css"; +import styles from "../pages.module.css"; const multiCode = `// Unnamed: renders every toast without a toasterId @@ -106,11 +106,11 @@ export default component$(() => {
  • With the headless entry, add the{" "} - popover reset yourself. + popover reset yourself.

- See it next to a real dialog in the examples. + See it next to a real dialog in the examples.

useSonner()

diff --git a/website/src/routes/docs/changelog/index.tsx b/website/src/routes/docs/changelog/index.tsx index 7712f91..ef14bdc 100644 --- a/website/src/routes/docs/changelog/index.tsx +++ b/website/src/routes/docs/changelog/index.tsx @@ -157,7 +157,7 @@ export default component$(() => { {release.previous ? "Commits" : "Source"}
{!release.newestOfMajor ? null : release.major >= 2 ? ( - Migration guide + Migration guide ) : release.major === 1 ? ( v1 docs ) : null} diff --git a/website/src/routes/docs/v2/examples/examples.module.css b/website/src/routes/docs/examples/examples.module.css similarity index 100% rename from website/src/routes/docs/v2/examples/examples.module.css rename to website/src/routes/docs/examples/examples.module.css diff --git a/website/src/routes/docs/v2/examples/index.tsx b/website/src/routes/docs/examples/index.tsx similarity index 99% rename from website/src/routes/docs/v2/examples/index.tsx rename to website/src/routes/docs/examples/index.tsx index 1186a5c..7d71753 100644 --- a/website/src/routes/docs/v2/examples/index.tsx +++ b/website/src/routes/docs/examples/index.tsx @@ -4,7 +4,7 @@ import { toast, useSonner } from "qwik-sonner"; import { CodeBlock } from "~/components/CodeBlock"; import { Callout, Demo, H2 } from "~/components/docs/ui"; import { SECONDARY_TOASTER } from "~/lib/toaster-context"; -import styles from "../../pages.module.css"; +import styles from "../pages.module.css"; import ex from "./examples.module.css"; /* Undo ------------------------------------------------------------------- */ diff --git a/website/src/routes/docs/index.tsx b/website/src/routes/docs/index.tsx index 8da659a..6e12922 100644 --- a/website/src/routes/docs/index.tsx +++ b/website/src/routes/docs/index.tsx @@ -1,24 +1,201 @@ -import { component$ } from "@qwik.dev/core"; -import type { DocumentHead, RequestHandler } from "@qwik.dev/router"; -import { Link } from "@qwik.dev/router"; -import { CURRENT_VERSION, VERSIONS } from "~/lib/versions"; +import { $, component$ } from "@qwik.dev/core"; +import { Link, type DocumentHead } from "@qwik.dev/router"; +import { toast } from "qwik-sonner"; +import { CodeBlock } from "~/components/CodeBlock"; +import { QwikV2Badge } from "~/components/QwikV2Badge"; +import { Callout, Demo, H2, InstallTabs } from "~/components/docs/ui"; +import { LATEST, majorOf } from "~/lib/release"; +import { VERSIONS } from "~/lib/versions"; +import styles from "./pages.module.css"; -const target = `${VERSIONS[CURRENT_VERSION].basePath}/`; +const layoutCode = `import { component$, Slot } from "@qwik.dev/core"; +import { Toaster } from "qwik-sonner"; -// `/docs` always means "the newest docs". In production the site is static and -// vercel.json does this redirect; this handler covers `pnpm dev`. -export const onGet: RequestHandler = ({ redirect }) => { - throw redirect(308, target); -}; +export default component$(() => { + return ( + <> + + + + ); +});`; + +const pageCode = `import { component$ } from "@qwik.dev/core"; +import { toast } from "qwik-sonner"; + +export default component$(() => { + return ( + + ); +});`; + +const entriesCode = `// Styled (default) โ€” ships sonner's stylesheet via useStyles$ +import { Toaster, toast } from "qwik-sonner"; + +// Headless โ€” same API and markup, no styles +import { Toaster, toast } from "qwik-sonner/headless";`; + +const undo = $(() => { + toast.success("Change reverted"); +}); + +export default component$(() => { + const v2 = VERSIONS.v2; + const v1 = VERSIONS.v1; + // A plain `npm install qwik-sonner` still gets the Qwik 1 line. + const latestIsV1 = LATEST !== null && majorOf(LATEST) === 1; + + return ( + <> +

Introduction

+

+ An opinionated toast component for Qwik. A resumable port of{" "} + + sonner + {" "} + by Emil Kowalski: render one {""}, call toast() from + anywhere, ship zero hydration. +

+ + + + + + + + +

Installation

+

+ Version 2 targets Qwik 2: @qwik.dev/core 2.0.0-rc.4 or later. + {v2.prerelease ? ( + <> + {" "} + While it's a pre-release it's published under the {v2.tag} dist-tag, so + name the tag explicitly: + + ) : null} +

+ +
+ Release status on npm + +
+ +

+ @builder.io/qwik apps need qwik-sonner 1.x: install {v1.spec} + {latestIsV1 ? ( + <> + {" "} + (also what a plain npm install qwik-sonner gives you today) + + ) : null} + . See the v1 documentation, or the{" "} + migration guide when you move to Qwik 2. +

+
+ +

Quick start

+

+ Render the Toaster once, in your root layout, then call toast(){" "} + from any component. +

+ + + +

Styled or headless

+

+ The default entry injects sonner's stylesheet. qwik-sonner/headless renders the + exact same markup and data-sonner-* attributes without any CSS, for when you + want to own the look entirely. +

+ + +

Differences from sonner

+

+ The API mirrors sonner as closely as Qwik's resumability allows. What changes is how + functions cross the server/client boundary: +

+
+
sonner (React)
+
qwik-sonner
+ onClick: () => โ€ฆ + onClick$: $(() => โ€ฆ) + onDismiss / onAutoClose + onDismiss$ / onAutoClose$ + event.preventDefault() + action.preventDefault: true + className / classNames + class / classes + Re-render with new props + {"position={signal}"} +
+

+ Callbacks stored on a toast must be QRLs โ€” wrap them in $(). Toaster props that + should change after the page loaded (position, theme,{" "} + richColors, dir, invert) accept a Signal + . +

-// Fallback page, should a request ever reach the route itself. -export default component$(() => ( -

- The documentation moved to {target}. -

-)); +

Next steps

+
+ + toast() + Every way to create, update and dismiss toasts. + + + {""} + Position, theme, stacking and every prop. + + + Examples + Undo, forms, uploads, dialogs and more. + + + Styling + Classes, CSS variables, unstyled and headless. + +
+ + ); +}); export const head: DocumentHead = { - title: "Documentation โ€” qwik-sonner", - meta: [{ httpEquiv: "refresh", content: `0; url=${target}` }], + title: "Introduction โ€” qwik-sonner", + meta: [ + { + name: "description", + content: "Install qwik-sonner for Qwik 2 and render your first toast.", + }, + ], + frontmatter: { + toc: [ + { id: "installation", title: "Installation" }, + { id: "quick-start", title: "Quick start" }, + { id: "entry-points", title: "Styled or headless" }, + { id: "differences", title: "Differences from sonner" }, + { id: "next", title: "Next steps" }, + ], + }, }; diff --git a/website/src/routes/docs/v2/migration/index.tsx b/website/src/routes/docs/migration/index.tsx similarity index 93% rename from website/src/routes/docs/v2/migration/index.tsx rename to website/src/routes/docs/migration/index.tsx index b440386..cf12cba 100644 --- a/website/src/routes/docs/v2/migration/index.tsx +++ b/website/src/routes/docs/migration/index.tsx @@ -3,7 +3,7 @@ import { Link, type DocumentHead } from "@qwik.dev/router"; import { CodeBlock } from "~/components/CodeBlock"; import { Callout, H2, H3, InstallTabs } from "~/components/docs/ui"; import { VERSIONS } from "~/lib/versions"; -import styles from "../../pages.module.css"; +import styles from "../pages.module.css"; const htmlBefore = `// v1 โ€” string parsed as (sanitized) HTML toast("Saved to drafts");`; @@ -106,7 +106,7 @@ export default component$(() => {
  • Markup and styles follow sonner 2's data-sonner-* contract. Custom CSS that targeted v1's markup may need new selectors โ€” see{" "} - data attributes. + data attributes.
  • important: true no longer makes a toast aria-live="assertive". @@ -136,24 +136,24 @@ export default component$(() => { v1 recommended rendering the Toaster before the rest of the page to avoid rendering glitches. v2 subscribes when Qwik boots, so it can go anywhere in the root layout โ€” but keep it in a server-rendered layout (see{" "} - known issues). + known issues).

    Worth adopting