Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down
4 changes: 2 additions & 2 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
14 changes: 11 additions & 3 deletions website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<n>/…`
(`src/routes/docs/v1/`), and `vercel.json` redirects `/docs/v<current>/…` 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<n>/`, put the new ones in `src/routes/docs/`,
set `CURRENT_VERSION`, and point the redirects in `vercel.json` at the new major.
3 changes: 0 additions & 3 deletions website/adapters/ssg/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}),
],
};
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const Hero = component$(() => {
>
Render a toast
</button>
<Link class={styles.button} href="/docs/v2/">
<Link class={styles.button} href="/docs/">
Documentation
</Link>
<a class={styles.button} href={GITHUB_URL} target="_blank" rel="noreferrer">
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/QwikV2Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const QwikV2Badge = component$<{ size?: "sm" | "md" }>(({ size = "md" })

return (
<Link
href="/docs/v2/#installation"
href="/docs/#installation"
class={styles.badge}
data-size={size}
data-channel={channel}
Expand Down
39 changes: 38 additions & 1 deletion website/src/components/SiteShell.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 (
<>
{/*
Expand Down
30 changes: 23 additions & 7 deletions website/src/components/docs/chrome.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -389,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;
Expand All @@ -408,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;
Expand Down Expand Up @@ -461,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;
Expand Down Expand Up @@ -495,7 +511,7 @@

.toc {
position: sticky;
top: 56px;
top: var(--docs-top, 56px);
align-self: start;
padding: 32px 0 48px;
font-size: 13px;
Expand Down
62 changes: 22 additions & 40 deletions website/src/components/docs/chrome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -178,52 +177,35 @@ export const DocsHeader = component$<{ version: VersionId; navOpen: Signal<boole

/* Version banner ---------------------------------------------------------- */

/** Shown on the docs of an older line, pointing to the current one. */
export const VersionBanner = component$<{ version: VersionId }>(({ version }) => {
const loc = useLocation();
const v = VERSIONS[version];
const current = VERSIONS[CURRENT_VERSION];

if (version !== CURRENT_VERSION) {
return (
<div class={styles.banner} data-tone="warning" role="note">
<p>
return (
<div class={styles.banner} data-tone="warning" role="note">
{/* One line at any width (it sticks under the header): a shorter text on narrow screens. */}
<p>
<span class={styles.bannerLong}>
You're reading the docs for <strong>qwik-sonner {v.version}</strong>, the {v.qwik} (
<code>{v.qwikPackage}</code>) line. It no longer receives new features.
</p>
<Link href={equivalentHref(loc.url.pathname, CURRENT_VERSION)} class={styles.bannerLink}>
Go to the {current.qwik} docs ({CURRENT_VERSION})<span aria-hidden="true">→</span>
</Link>
</div>
);
}

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 (
<div class={styles.banner} data-tone="info" role="note">
<p>
<strong>
{CURRENT_VERSION} is in {v.tag ?? "pre-release"} ({v.version}).
</strong>{" "}
Install it with <code>{v.spec}</code>
{olderLatest ? (
<>
{" "}
— plain <code>qwik-sonner</code> still resolves to {olderLatest}
</>
) : null}
.
</p>
<Link href={`${v.basePath}/#installation`} class={styles.bannerLink}>
Installation
<span aria-hidden="true">→</span>
</Link>
</div>
);
}

return null;
</span>
<span class={styles.bannerShort}>
Docs for <strong>{v.version}</strong> ({v.qwik})
</span>
</p>
<Link href={equivalentHref(loc.url.pathname, CURRENT_VERSION)} class={styles.bannerLink}>
<span class={styles.bannerLong}>
Go to the {current.qwik} docs ({CURRENT_VERSION})
</span>
<span class={styles.bannerShort}>{current.qwik} docs</span>
<span aria-hidden="true" class={styles.bannerArrow}>
→
</span>
</Link>
</div>
);
});

/* Sidebar ----------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/docs/ui.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.heading {
position: relative;
scroll-margin-top: 88px;
scroll-margin-top: calc(var(--docs-top, 56px) + 32px);
}

.anchor {
Expand Down
7 changes: 7 additions & 0 deletions website/src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
--warning-bg: hsl(49, 100%, 97%);
--warning-border: hsl(49, 91%, 84%);
--warning-text: hsl(31, 92%, 45%);
/* changelog markers: breaking changes and new features (the rest stay gray) */
--log-breaking: #b45309;
--log-new: #2563eb;
--error-bg: hsl(359, 100%, 97%);
--error-border: hsl(359, 100%, 94%);
--error-text: hsl(360, 100%, 45%);
Expand Down Expand Up @@ -97,6 +100,8 @@
--warning-bg: hsl(64, 100%, 6%);
--warning-border: hsl(60, 100%, 9%);
--warning-text: hsl(46, 87%, 65%);
--log-breaking: #fbbf24;
--log-new: #6ea8ff;
--error-bg: hsl(358, 76%, 10%);
--error-border: hsl(357, 89%, 16%);
--error-text: hsl(358, 100%, 81%);
Expand Down Expand Up @@ -137,6 +142,8 @@
--warning-bg: hsl(64, 100%, 6%);
--warning-border: hsl(60, 100%, 9%);
--warning-text: hsl(46, 87%, 65%);
--log-breaking: #fbbf24;
--log-new: #6ea8ff;
--error-bg: hsl(358, 76%, 10%);
--error-border: hsl(357, 89%, 16%);
--error-text: hsl(358, 100%, 81%);
Expand Down
3 changes: 2 additions & 1 deletion website/src/lib/docs-nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const EQUIVALENT_SLUG: Record<VersionId, Record<string, string>> = {

/** 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/<slug>/` on the current line, `/docs/v<n>/<slug>/` 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}/` : ""}`;
Expand Down
35 changes: 34 additions & 1 deletion website/src/lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,39 @@ export interface ReleaseNotes {
/** The notes of each published release, by version (the tag without its `v`). */
export type Releases = Record<string, ReleaseNotes>;

/** 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>|<ul(?=[\s>])/g,
(match, tag?: string, attrs?: string, inner?: string) => {
if (!tag) return kind ? `<ul data-kind="${kind}"` : match;
const text = inner!.replace(/<[^>]*>/g, "").replace(/&[#\w]+;/g, " ");
kind = KINDS.find(([, pattern]) => pattern.test(text))?.[0];
return kind ? `<${tag}${attrs} data-kind="${kind}">${inner}</${tag}>` : match;
},
);
};

const RELEASES = "https://api.github.com/repos/diecodev/qwik-sonner/releases";
const PER_PAGE = 100;

Expand Down Expand Up @@ -57,7 +90,7 @@ export const readReleases = async (): Promise<Releases> => {
.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) {
Expand Down
Loading
Loading