GeezerVison is showing github.com — feat(site): simplify the docs header menu and move the V1 notice into… · drpr/opencode@1df721d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: services/site/src/component/site/css-variants.json +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 | "data-menu-align": "edge", | 17 | 17 | "data-wide-align": null, | 18 | 18 | "data-nav-numbers": "1", | 19 | | - "data-docs-nav": "split", | | 19 | + "data-docs-nav": "combined", | 20 | 20 | "data-section-menu": "list", | 21 | 21 | "data-docs-variants": "typography-4 lists-3 blockquote-2 callout-3 tabs-6 code-6 codeTitle-6 codeLines-6 codeDiff-6 terminal-6 fileTree-6 steps-2 cards-3 tables-5 badges-4 details-2 media-2 api-7 config-6 cli-6 pagination-4 breadcrumbs-3 search-4 switchers-2 editLink-4 feedback-5 inlineCode-6", | 22 | 22 | "data-status-bars": "4", | | 41 | 41 | ["[data-component=\"hero-install\"][data-mode=\"row\"]", "data-style", "inline"], | 42 | 42 | ["[data-component=\"hero\"][data-design~=\"hero\"]", "data-title-size", "fitted"], | 43 | 43 | ["[data-component=\"page-title\"]", "data-sticky", null], | 44 | | - ["[data-component=\"docs-version-notice\"]", "data-variant", "frosted top"], | | 44 | + ["[data-component=\"docs-version-notice\"]", "data-variant", "inverted"], | 45 | 45 | ["[data-component=\"products\"]", "data-tone", "color"], | 46 | 46 | ["[data-component=\"badges\"]", "data-style", "sans"], | 47 | 47 | ["[data-component=\"badges\"]", "data-layout", "tabs"], | |
Collapse file Copy file name to clipboardExpand all lines: services/site/src/component/site/docs-lockup.css +2-17Lines changed: 2 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 56 | 56 | position: relative; | 57 | 57 | display: inline-flex; | 58 | 58 | align-items: center; | 59 | | - gap: 6px; | | 59 | + /* Label and chevron are one button, so the chevron sits close, as in the product navs. */ | | 60 | + gap: 4px; | 60 | 61 |
| 61 | 62 | /* OpenTUI Mono's caps sit 0.325px below its line box's centre; this puts them on the logo's centre. */ | 62 | 63 | padding: 0 6px 0.65px; | | 439 | 440 | } | 440 | 441 | } | 441 | 442 |
| 442 | | -/* The section word also opens the OpenCode product menu on hover (packages/nav-menus), so hovered, open and pressed it | 443 | | - takes the one name fill every OpenCode nav shares (--nav-name-hover), never a darker one; the chevron keeps its own | 444 | | - states for the sections menu. */ | 445 | | -[data-site] [data-component="docs-lockup"] [data-slot="word"][data-nav-product] { | 446 | | - @media (hover: hover) and (pointer: fine) { | 447 | | - &:hover { | 448 | | - background: var(--nav-name-hover); | 449 | | - } | 450 | | - } | 451 | | - | 452 | | - &:active, | 453 | | - &[aria-expanded="true"] { | 454 | | - background: var(--nav-name-hover); | 455 | | - } | 456 | | -} | 457 | | - | 458 | 443 | /* The logo before the lockup stays a plain link (no fill); its keyboard ring, drawn around the mark | 459 | 444 | (site.css), is 2px like the segments'. */ | 460 | 445 | [data-site] | |
Collapse file Copy file name to clipboardExpand all lines: services/site/src/component/site/docs-lockup.tsx +22-37Lines changed: 22 additions & 37 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,8 +40,8 @@ type Item = { | 40 | 40 | /** | 41 | 41 | * Settings › Docs switcher › lockup: the docs section word after the site's logo, like the Data and | 42 | 42 | * Console headers (public/nav-demo/switcher.js). One button opens a menu of the docs sections, where | 43 | | - * "Docs" has a submenu of versions. On an older version, "/ V1" after the word shows it and switches | 44 | | - * back. The menus are always in the page, hidden while closed, so pages that never hydrate (the docs) | | 43 | + * "Docs" has a submenu of versions. On the V1 docs the word reads "V1 docs" and the same menu marks V1 | | 44 | + * under "Docs". The menus are always in the page, hidden while closed, so pages that never hydrate (the docs) | 45 | 45 | * can open them from a delegated listener (src/docs/client.ts). | 46 | 46 | */ | 47 | 47 | export function DocsLockup(props: { | @@ -63,10 +63,18 @@ export function DocsLockup(props: { | 63 | 63 | } | 64 | 64 | }) { | 65 | 65 | const i18n = useI18n() | | 66 | + // On the V1 docs the product name says so: "V1 docs", with the same chevron and menu as the latest docs. | | 67 | + const v1 = () => props.version?.current === "v1" | 66 | 68 | const name = (label: string) => | 67 | | - label === "Docs" | 68 | | - ? docsSectionName(i18n, label) | 69 | | - : i18n.t("docs.lockup.sectionDocs", { section: docsSectionName(i18n, label) }) | | 69 | + v1() | | 70 | + ? i18n.t("docs.lockup.sectionDocs", { section: "V1" }) | | 71 | + : label === "Docs" | | 72 | + ? docsSectionName(i18n, label) | | 73 | + : i18n.t("docs.lockup.sectionDocs", { section: docsSectionName(i18n, label) }) | | 74 | + // The sections menu names each section's docs: "CLI docs", "API docs". The main docs are about OpenCode | | 75 | + // itself, so they're "OpenCode docs" rather than "Docs docs". | | 76 | + const menuName = (label: string) => | | 77 | + i18n.t("docs.lockup.sectionDocs", { section: label === "Docs" ? "OpenCode" : docsSectionName(i18n, label) }) | 70 | 78 | // V1 is a version, not a section: "Docs" has a submenu of versions, V2 (these docs) and V1 (the old | 71 | 79 | // docs site). The /docs demo can pass its own (?version= switches in place). | 72 | 80 | const sections = () => docsProducts.filter((product) => product.label !== "V1") | @@ -115,8 +123,8 @@ export function DocsLockup(props: { | 115 | 123 | triggerLabel={(label) => i18n.t("docs.lockup.switchLabel", { name: name(label) })} | 116 | 124 | items={sections().map((product) => ({ | 117 | 125 | id: product.label, | 118 | | - label: docsSectionName(i18n, product.label), | 119 | | - ariaLabel: name(product.label), | | 126 | + label: menuName(product.label), | | 127 | + ariaLabel: menuName(product.label), | 120 | 128 | href: props.href?.(product.label) ?? product.href, | 121 | 129 | sub: | 122 | 130 | product.label !== "Docs" | @@ -132,30 +140,8 @@ export function DocsLockup(props: { | 132 | 140 | }))} | 133 | 141 | current={props.current} | 134 | 142 | onSelect={props.onSelect} | 135 | | - split={{ label: i18n.t("docs.lockup.switch"), onSelect: props.onSelect }} | | 143 | + split={{ label: i18n.t("docs.lockup.switch"), onSelect: props.onSelect, href: v1() ? v1DocsUrl() : undefined }} | 136 | 144 | /> | 137 | | - {/* Only the main docs have versions, and only an older one shows here. */} | 138 | | - <Show when={props.current === "Docs" && props.version?.current !== "latest" && props.version}> | 139 | | - {(version) => ( | 140 | | - <> | 141 | | - <span data-slot="separator" aria-hidden="true"> | 142 | | - | | 143 | | - </span> | 144 | | - <Dropdown | 145 | | - id={`docs-version-menu${suffix}`} | 146 | | - variant="version" | 147 | | - menuLabel={i18n.t("docs.version.label")} | 148 | | - trigger={(id) => docsVersions.find((item) => item.id === id)!.label} | 149 | | - triggerLabel={(id) => | 150 | | - i18n.t("docs.version.switch", { version: docsVersions.find((item) => item.id === id)!.label }) | 151 | | - } | 152 | | - items={versionItems(version())} | 153 | | - current={version().current} | 154 | | - onSelect={(id) => version().onSelect(id as DocsVersion)} | 155 | | - /> | 156 | | - </> | 157 | | - )} | 158 | | - </Show> | 159 | 145 | </div> | 160 | 146 | ) | 161 | 147 | if (props.inline) return lockup() | @@ -186,8 +172,11 @@ function Dropdown(props: { | 186 | 172 | items: Item[] | 187 | 173 | current: string | 188 | 174 | onSelect?: (id: string) => void | 189 | | - /** Settings › Docs nav › split: the word links to the section's home; `label` names the chevron. */ | 190 | | - split?: { label: string; onSelect?: (id: string) => void } | | 175 | + /** | | 176 | + * Settings › Docs nav › split: the word links to the section's home (or `href`, the V1 docs' home); | | 177 | + * `label` names the chevron. | | 178 | + */ | | 179 | + split?: { label: string; onSelect?: (id: string) => void; href?: string } | 191 | 180 | }) { | 192 | 181 | const i18n = useI18n() | 193 | 182 | const [open, setOpen] = createSignal(false) | @@ -323,11 +312,7 @@ function Dropdown(props: { | 323 | 312 | <a | 324 | 313 | data-slot="word" | 325 | 314 | data-design="docsNav sectionMenuStyle menuActive menuColor menuAlign docsSubmenu" | 326 | | - href={props.items[currentIndex()].href} | 327 | | - data-nav-product="docs" | 328 | | - data-nav-product-chevron="none" | 329 | | - aria-haspopup="menu" | 330 | | - aria-expanded="false" | | 315 | + href={split().href ?? props.items[currentIndex()].href} | 331 | 316 | aria-label={i18n.t("docs.lockup.home", { name: props.trigger(props.items[currentIndex()].id) })} | 332 | 317 | onClick={(event) => { | 333 | 318 | close() | |
Collapse file Copy file name to clipboard +24-3Lines changed: 24 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import "./docs-version-notice.css" | 2 | 2 | import { useI18n } from "~/context/i18n" | | 3 | +import { Show } from "solid-js" | 3 | 4 | import { siteSettings } from "./settings" | 4 | 5 |
| 5 | | -/** On the V1 docs: a bar at the top of the content column, with a way back to the latest docs. */ | 6 | | -export function DocsVersionNotice(props: { latest: string; onLatest?: () => void }) { | | 6 | +/** | | 7 | + * On the V1 docs: a bar with a way back to the latest docs, at the top of the content column, or in the | | 8 | + * logo row (`placement="header"`, the docs), where the sentence shortens with "…" before the link does. | | 9 | + * On phones the header placement is a bar on the screen's bottom edge saying only "V1 docs" (docs.css). | | 10 | + */ | | 11 | +export function DocsVersionNotice(props: { latest: string; onLatest?: () => void; placement?: "header" }) { | 7 | 12 | const i18n = useI18n() | 8 | 13 | return ( | 9 | 14 | <aside | 10 | 15 | data-component="docs-version-notice" | 11 | 16 | data-variant={siteSettings.docsVersionNotice} | 12 | 17 | data-design="docsVersionNotice" | | 18 | + data-placement={props.placement} | 13 | 19 | aria-label={i18n.t("docs.version.label")} | 14 | 20 | > | 15 | 21 | <span data-slot="badge">V1</span> | | 22 | + <Show when={props.placement}> | | 23 | + <span data-slot="short">{i18n.t("docs.version.v1Docs")}</span> | | 24 | + </Show> | 16 | 25 | <p> | 17 | | - {i18n.t("docs.version.notice")}{" "} | | 26 | + <span data-slot="sentence">{i18n.t("docs.version.notice")}</span>{" "} | 18 | 27 | <a | 19 | 28 | href={props.latest} | 20 | 29 | onClick={(event) => { | @@ -24,8 +33,20 @@ export function DocsVersionNotice(props: { latest: string; onLatest?: () => void | 24 | 33 | }} | 25 | 34 | > | 26 | 35 | {i18n.t("docs.version.switchToLatest")} | | 36 | + <Show when={props.placement}> | | 37 | + <LinkChevron /> | | 38 | + </Show> | 27 | 39 | </a> | 28 | 40 | </p> | 29 | 41 | </aside> | 30 | 42 | ) | 31 | 43 | } | | 44 | + | | 45 | +/** The 16px chevron after the logo row's links, toward the reading direction (mirrored in RTL by CSS). */ | | 46 | +export function LinkChevron() { | | 47 | + return ( | | 48 | + <svg data-slot="link-chevron" width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"> | | 49 | + <path d="M6 4L10 8L6 12" stroke="currentColor" stroke-width="1.5" stroke-linecap="square" /> | | 50 | + </svg> | | 51 | + ) | | 52 | +} |
Collapse file Copy file name to clipboardExpand all lines: services/site/src/component/site/settings-defaults.json +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 352 | 352 | "consoleCopyColumns": "2 columns", | 353 | 353 | "docsSwitcher": "lockup", | 354 | 354 | "docsSubmenu": "flyout", | 355 | | - "docsNav": "split", | 356 | | - "docsVersionNotice": "frosted top", | | 355 | + "docsNav": "combined", | | 356 | + "docsVersionNotice": "inverted", | 357 | 357 | "terminalInstall": "button", | 358 | 358 | "carouselPreset": "four across", | 359 | 359 | "carousel": { | |
Collapse file Copy file name to clipboardExpand all lines: services/site/src/component/site/settings.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1051,8 +1051,8 @@ function createSchema() { | 1051 | 1051 | consoleCopyColumns: z.enum(sectionColumns).catch("2 columns"), | 1052 | 1052 | docsSwitcher: z.enum(docsSwitchers).catch("lockup"), | 1053 | 1053 | docsSubmenu: z.enum(docsSubmenus).catch("flyout"), | 1054 | | - docsNav: z.enum(docsNavs).catch("split"), | 1055 | | - docsVersionNotice: z.enum(docsVersionNotices).catch("frosted top"), | | 1054 | + docsNav: z.enum(docsNavs).catch("combined"), | | 1055 | + docsVersionNotice: z.enum(docsVersionNotices).catch("inverted"), | 1056 | 1056 | terminalInstall: z.enum(terminalInstalls).catch("button"), | 1057 | 1057 | carouselPreset: z.enum(carouselPresetNames).catch("four across"), | 1058 | 1058 | carousel: z | |
Collapse file Copy file name to clipboardExpand all lines: services/site/src/docs/client.ts +30-2Lines changed: 30 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -128,6 +128,23 @@ function enter(menu: HTMLElement) { | 128 | 128 | menu.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 140, easing: "ease-out" }) | 129 | 129 | } | 130 | 130 |
| | 131 | +// The versions flyout appears softly beside "Docs": a 140ms fade with a 3px nudge from the row it opens | | 132 | +// from, on the strong ease-out, transform and opacity only. Only its first showing in an open menu | | 133 | +// animates; coming back to "Docs" shows it at once, and it hides at once. Reduced motion shows it at once. | | 134 | +let flown = false | | 135 | +function flyIn(submenu: HTMLElement) { | | 136 | + if (flown || matchMedia("(prefers-reduced-motion: reduce)").matches) return | | 137 | + flown = true | | 138 | + const from = `translateX(${html.dir === "rtl" ? 3 : -3}px)` | | 139 | + submenu.animate( | | 140 | + [ | | 141 | + { opacity: 0, transform: from }, | | 142 | + { opacity: 1, transform: "translateX(0)" }, | | 143 | + ], | | 144 | + { duration: 140, easing: "cubic-bezier(0.23, 1, 0.32, 1)" }, | | 145 | + ) | | 146 | +} | | 147 | + | 131 | 148 | // The docs lockup (component/site/docs-lockup.tsx): the chevron opens the sections menu, where "Docs" | 132 | 149 | // has its versions in a flyout beside it, or nested under it on phones and touch screens. An older | 133 | 150 | // version adds a second menu, of the versions, so each dropdown in it opens on its own. | @@ -177,6 +194,7 @@ function openLockup(root: HTMLElement, focus?: "first" | "last" | "current") { | 177 | 194 | } | 178 | 195 |
| 179 | 196 | function closeLockup(refocus?: boolean) { | | 197 | + flown = false | 180 | 198 | if (!lockup) return | 181 | 199 | const root = lockup | 182 | 200 | lockup = undefined | @@ -185,7 +203,10 @@ function closeLockup(refocus?: boolean) { | 185 | 203 | $$("[aria-haspopup=menu]:not([role=menuitem], [data-nav-product])", root).forEach((button) => | 186 | 204 | button.setAttribute("aria-expanded", "false"), | 187 | 205 | ) | 188 | | - if (refocus) ($("[data-slot=toggle]", root) ?? $("[data-slot=trigger]", root))?.focus() | | 206 | + if (refocus) | | 207 | + $$("[data-slot=toggle], [data-slot=trigger]", root) | | 208 | + .find((button) => button.offsetParent) | | 209 | + ?.focus() | 189 | 210 | } | 190 | 211 |
| 191 | 212 | function toggleSub(root: HTMLElement, open: boolean, focus?: boolean) { | @@ -196,7 +217,7 @@ function toggleSub(root: HTMLElement, open: boolean, focus?: boolean) { | 196 | 217 | parent.toggleAttribute("data-open", open) | 197 | 218 | const submenu = $("[data-slot=submenu]", parent)! | 198 | 219 | submenu.hidden = !open | 199 | | - if (opening && menuOf(root).dataset.submenu === "flyout") enter(submenu) | | 220 | + if (opening && menuOf(root).dataset.submenu === "flyout") flyIn(submenu) | 200 | 221 | $$("[aria-expanded]", parent).forEach((item) => item.setAttribute("aria-expanded", String(open))) | 201 | 222 | if (open && focus) | 202 | 223 | ($('[aria-current="page"]', $("[data-slot=submenu]", parent)!) ?? $("[data-slot=submenu] a", parent))?.focus() | @@ -210,6 +231,13 @@ on("click", (event) => { | 210 | 231 | return lockup === root ? closeLockup() : openLockup(root) | 211 | 232 | const expand = target.closest("[data-slot=expand]") | 212 | 233 | if (expand) return toggleSub(root, expand.getAttribute("aria-expanded") !== "true") | | 234 | + // Nested (phones, touch and narrow windows): tapping "Docs" opens and closes its versions in place, | | 235 | + // like its "›", instead of leaving for the docs home, which V2 still links. The flyout keeps the link. | | 236 | + const parent = target.closest("[data-slot=parent] > [role=menuitem]") | | 237 | + if (parent && menuOf(root).dataset.submenu === "nested") { | | 238 | + event.preventDefault() | | 239 | + return toggleSub(root, parent.getAttribute("aria-expanded") !== "true") | | 240 | + } | 213 | 241 | if (target.closest("a")) closeLockup() | 214 | 242 | }) | 215 | 243 |
| |
Collapse file Copy file name to clipboardExpand all lines: services/site/src/docs/layouts/DocsLayout.tsx +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -83,7 +83,7 @@ export function DocsLayout(props: { | 83 | 83 | const contents = props.headings | 84 | 84 | .filter((heading) => heading.depth === 2 || heading.depth === 3) | 85 | 85 | .map((heading) => ({ id: heading.slug, title: heading.text, level: heading.depth as 2 | 3 })) | 86 | | - // The lockup's versions: this page in each (the versions menu, and "| V1" on V1 pages). | | 86 | + // The lockup's versions: this page in each (the versions menu under "Docs"; V1 pages read "V1 docs"). | 87 | 87 | const version = () => | 88 | 88 | props.versions && { | 89 | 89 | current: props.set.id, | @@ -187,6 +187,11 @@ export function DocsLayout(props: { | 187 | 187 | </div> | 188 | 188 | </div> | 189 | 189 | </aside> | | 190 | + {/* V1: the notice sits in the logo row, after the sidebar's label so it can start past a long one | | 191 | + (docs.css); phones show it as a bar on the screen's bottom edge. */} | | 192 | + <Show when={props.set.id === "v1" && props.versions}> | | 193 | + {(versions) => <DocsVersionNotice latest={versions().latest} placement="header" />} | | 194 | + </Show> | 190 | 195 | {/* Mobile layout: the Contents rail folded into a bar stuck under the | 191 | 196 | section row from load. It names the section being read (client.ts swaps the label as you scroll) | 192 | 197 | and keeps "Contents" in its accessible name. Hidden beside the rail on wide screens. */} | @@ -213,9 +218,6 @@ export function DocsLayout(props: { | 213 | 218 |
| 214 | 219 | <main data-component="content" id="content" tabindex={-1}> | 215 | 220 | <div data-slot="page"> | 216 | | - <Show when={props.set.id === "v1" && props.versions}> | 217 | | - {(versions) => <DocsVersionNotice latest={versions().latest} />} | 218 | | - </Show> | 219 | 221 | <article | 220 | 222 | data-component="docs-article" | 221 | 223 | data-section="article" | |
|