From aa0a48d43eec88b84792e07be6d55b0d12d8a39d Mon Sep 17 00:00:00 2001 From: "ccf-factory[bot]" Date: Fri, 27 Nov 2026 19:12:22 +0000 Subject: [PATCH 1/3] feat(tutorials): add Tabs, Cards, Steps, Callouts and Accordion MDX components --- src/components/tutorials/Accordion.tsx | 60 ++++++++++++ src/components/tutorials/Callout.tsx | 118 ++++++++++++++++++++++ src/components/tutorials/Cards.tsx | 115 ++++++++++++++++++++++ src/components/tutorials/Steps.tsx | 71 ++++++++++++++ src/components/tutorials/Tabs.tsx | 130 +++++++++++++++++++++++++ src/css/custom.css | 116 +++++++++++++++++++++- src/theme/MDXComponents/index.tsx | 25 ++++- 7 files changed, 632 insertions(+), 3 deletions(-) create mode 100644 src/components/tutorials/Accordion.tsx create mode 100644 src/components/tutorials/Callout.tsx create mode 100644 src/components/tutorials/Cards.tsx create mode 100644 src/components/tutorials/Steps.tsx create mode 100644 src/components/tutorials/Tabs.tsx diff --git a/src/components/tutorials/Accordion.tsx b/src/components/tutorials/Accordion.tsx new file mode 100644 index 0000000..1c5f69b --- /dev/null +++ b/src/components/tutorials/Accordion.tsx @@ -0,0 +1,60 @@ +// A question or a detail the reader opens only when they need it: what a flag does, what the +// output looks like. It keeps a tutorial short without hiding anything. Each item opens and +// closes on its own, drawn with the native details element so it works before the page's scripts +// load; AccordionGroup joins several items into one bordered list. src/theme/MDXComponents/index +// .tsx registers them as and , so tutorial pages use them without an +// import. The chevron's turn is styled in src/css/custom.css. +import React, {type ReactNode} from 'react'; +import clsx from 'clsx'; + +export type AccordionProps = { + /** The headline that stays visible, such as the question the item answers. */ + title: string; + /** Start open instead of collapsed. */ + defaultOpen?: boolean; + /** What the reader sees when the item is open. */ + children?: ReactNode; + /** Classes added to the item. */ + className?: string; +}; + +export default function Accordion({ + title, + defaultOpen, + children, + className, +}: AccordionProps): ReactNode { + return ( +
+ + {title} + + +
{children}
+
+ ); +} + +export type AccordionGroupProps = { + /** The items, in reading order: elements. */ + children?: ReactNode; + /** Classes added to the group. */ + className?: string; +}; + +export function AccordionGroup({children, className}: AccordionGroupProps): ReactNode { + return ( +
{children}
+ ); +} diff --git a/src/components/tutorials/Callout.tsx b/src/components/tutorials/Callout.tsx new file mode 100644 index 0000000..933ac1b --- /dev/null +++ b/src/components/tutorials/Callout.tsx @@ -0,0 +1,118 @@ +// The notes a tutorial makes beside its steps: a caveat before a destructive command, a shortcut +// worth knowing. The type picks the accent colour and the icon, following the five admonitions +// Docusaurus itself ships (note, tip, info, warning, danger). , , , +// and are with the type already set. src/theme/MDXComponents/index.tsx +// registers all six, so tutorial pages use them without an import. The accent colours live in +// src/css/custom.css, in the site's Infima palette. +import React, {type ReactNode} from 'react'; +import clsx from 'clsx'; + +export type CalloutType = 'note' | 'tip' | 'info' | 'warning' | 'danger'; + +export type CalloutProps = { + /** The kind of note: picks the accent colour and the icon. `note` by default. */ + type?: CalloutType; + /** A bold line before the text, such as the command the caveat is about. */ + title?: string; + /** What the reader needs to know. */ + children?: ReactNode; + /** Classes added to the callout. */ + className?: string; +}; + +const strokeWidth = 2; +const iconProps = { + 'aria-hidden': true, + viewBox: '0 0 24 24', + fill: 'none', + stroke: 'currentColor', + strokeWidth, + strokeLinecap: 'round', + strokeLinejoin: 'round', + className: 'h-5 w-5', +} as const; + +const icons: Record = { + note: ( + + + + + ), + tip: ( + + + + + + ), + info: ( + + + + + + ), + warning: ( + + + + + + ), + danger: ( + + + + + + ), +}; + +export function Callout({type = 'note', title, children, className}: CalloutProps): ReactNode { + return ( +
+ {icons[type]} +
+ {title ?
{title}
: null} + {children} +
+
+ ); +} + +export default Callout; + +type CalloutContentProps = Omit; + +/** A side note that does not change what the reader does. */ +export function Note(props: CalloutContentProps): ReactNode { + return ; +} + +/** A shortcut or trick worth knowing. */ +export function Tip(props: CalloutContentProps): ReactNode { + return ; +} + +/** Background that helps the reader understand the step. */ +export function Info(props: CalloutContentProps): ReactNode { + return ; +} + +/** Something easy to get wrong; the step still works if the reader heeds it. */ +export function Warning(props: CalloutContentProps): ReactNode { + return ; +} + +/** Harm if ignored: lost data, a revoked credential, a broken deployment. */ +export function Danger(props: CalloutContentProps): ReactNode { + return ; +} diff --git a/src/components/tutorials/Cards.tsx b/src/components/tutorials/Cards.tsx new file mode 100644 index 0000000..9442470 --- /dev/null +++ b/src/components/tutorials/Cards.tsx @@ -0,0 +1,115 @@ +// A link shown as a clickable card: the "what to do next" at the end of a tutorial step, or the +// links between tutorials. CardGroup lays several cards out in a responsive grid. An internal +// href (starting with a single /) links through Docusaurus's Link, so navigating does not reload +// the site; any other href opens in a new tab. src/theme/MDXComponents/index.tsx registers them +// as and , so tutorial pages use them without an import. +import React, {type ReactNode} from 'react'; +import Link from '@docusaurus/Link'; +import clsx from 'clsx'; + +export type CardProps = { + /** The card's headline: where the link leads. */ + title: string; + /** Where the card links. Omit it for a card that only holds text. */ + href?: string; + /** A short glyph before the title, such as an emoji. The site has no icon set to draw from. */ + icon?: string; + /** One or two lines saying what the reader finds there. */ + children?: ReactNode; + /** Classes added to the card. */ + className?: string; +}; + +// A root-relative href names a page of this site; // would be a protocol-relative external one. +function isInternalHref(href: string): boolean { + return href.startsWith('/') && !href.startsWith('//'); +} + +const cardBox = clsx( + 'ccf-card group block rounded-[var(--ifm-global-radius)] border p-4 no-underline', + 'border-[var(--ifm-color-emphasis-300)] bg-[var(--ifm-background-surface-color)]', + 'text-[var(--ifm-font-color-base)] transition-[border-color]', + 'hover:border-[var(--ifm-color-primary)] hover:no-underline', +); + +export default function Card({title, href, icon, children, className}: CardProps): ReactNode { + const heading = ( + + {icon ? ( + + ) : null} + {title} + {href ? ( + + ) : null} + + ); + const body = ( + <> + {heading} + {children ? ( + {children} + ) : null} + + ); + if (href && isInternalHref(href)) { + return ( + + {body} + + ); + } + if (href) { + return ( + + {body} + + ); + } + return
{body}
; +} + +export type CardGroupProps = { + /** How many columns a wide screen shows; 2 by default. Cards stack into one column below. */ + cols?: 1 | 2 | 3 | 4; + /** The cards, in reading order. */ + children?: ReactNode; + /** Classes added to the group. */ + className?: string; +}; + +// Written out so Tailwind can see each class: a class name built at runtime would be purged. +const gridCols: Record = { + 1: 'sm:grid-cols-1', + 2: 'sm:grid-cols-2', + 3: 'sm:grid-cols-3', + 4: 'sm:grid-cols-4', +}; + +export function CardGroup({cols = 2, children, className}: CardGroupProps): ReactNode { + return ( +
+ {children} +
+ ); +} diff --git a/src/components/tutorials/Steps.tsx b/src/components/tutorials/Steps.tsx new file mode 100644 index 0000000..dd19416 --- /dev/null +++ b/src/components/tutorials/Steps.tsx @@ -0,0 +1,71 @@ +// A tutorial task broken into numbered stages, read top to bottom. The circle numbers each step +// and the line joins the circles, so the reader sees how far they have come. The content of a +// step is ordinary Markdown, so a step can hold commands (CopyBlock), prose or a callout. +// src/theme/MDXComponents/index.tsx registers them as and , so tutorial pages use +// them without an import. The circle and the connecting line are drawn in src/css/custom.css. +import React, {type ReactElement, type ReactNode, isValidElement} from 'react'; +import clsx from 'clsx'; + +export type StepProps = { + /** The step's headline, in a few words: what the reader does in this step. */ + title: string; + /** What the step asks the reader to do. */ + children?: ReactNode; +}; + +/** + * One step of a Steps list. It only carries its headline and its content: the list draws the + * number and the connecting line, so a left outside a list still reads. + */ +export function Step({title, children}: StepProps): ReactNode { + return ( + <> +
{title}
+ {children} + + ); +} + +export type StepsProps = { + /** The steps, in reading order: elements, anything else is skipped. */ + children?: ReactNode; + /** Classes added to the list. */ + className?: string; +}; + +// The children, in order, ignoring the text and whitespace MDX leaves between them. +function stepElements(children: ReactNode): ReactElement[] { + return React.Children.toArray(children).filter( + (child): child is ReactElement => + isValidElement(child) && typeof child.props.title === 'string', + ); +} + +export default function Steps({children, className}: StepsProps): ReactNode { + const steps = stepElements(children); + if (steps.length === 0) { + return null; + } + return ( +
    + {steps.map((step, index) => ( +
  1. + +
    +
    {step.props.title}
    + {step.props.children} +
    +
  2. + ))} +
+ ); +} diff --git a/src/components/tutorials/Tabs.tsx b/src/components/tutorials/Tabs.tsx new file mode 100644 index 0000000..a9580f3 --- /dev/null +++ b/src/components/tutorials/Tabs.tsx @@ -0,0 +1,130 @@ +// The variants of one tutorial step, shown as tabs so the page stays short: install with npm or +// with yarn, run on Ubuntu or on RHEL. The reader opens the one that matches their setup and +// skips the rest. Clicking a tab switches the panel; on the tab row the arrow keys move the +// selection and Home and End jump to either end. src/theme/MDXComponents/index.tsx registers them +// as and , so tutorial pages use them without an import. +import React, { + type KeyboardEvent, + type ReactElement, + type ReactNode, + isValidElement, + useId, + useRef, + useState, +} from 'react'; +import clsx from 'clsx'; +import {clampTab, initialTab, nextTab} from './codeGroupTabs.mjs'; + +export type TabProps = { + /** The tab's label, such as `Ubuntu` or `Install with yarn`. */ + title: string; + /** What the tab shows while it is selected. */ + children?: ReactNode; +}; + +/** + * One tab of a Tabs group. It only carries its label and its content: the group draws the row of + * tabs and shows the selected one's children, so a left outside a group still reads. + */ +export function Tab({children}: TabProps): ReactNode { + return <>{children}; +} + +export type TabsProps = { + /** The tabs, in tab order: elements, anything else is skipped. */ + children?: ReactNode; + /** Label of the tab to open first; the first tab when it matches none. */ + defaultTab?: string; + /** Classes added to the group. */ + className?: string; +}; + +// The children, in order, ignoring the text and whitespace MDX leaves between them. +function tabElements(children: ReactNode): ReactElement[] { + return React.Children.toArray(children).filter( + (child): child is ReactElement => + isValidElement(child) && typeof child.props.title === 'string', + ); +} + +export default function Tabs({children, defaultTab, className}: TabsProps): ReactNode { + const tabs = tabElements(children); + const group = useId(); + const buttons = useRef<(HTMLButtonElement | null)[]>([]); + const [selected, setSelected] = useState(() => + initialTab( + tabs.map((tab) => ({title: tab.props.title})), + defaultTab, + ), + ); + if (tabs.length === 0) { + return null; + } + const active = clampTab(selected, tabs.length); + + // The same keyboard contract as CodeGroup's tab row, decided in codeGroupTabs.mjs, where + // `yarn test` covers it. + function onSelectKey(event: KeyboardEvent) { + const moved = nextTab(active, event.key, tabs.length); + if (moved === undefined) { + return; + } + event.preventDefault(); + setSelected(moved); + buttons.current[moved]?.focus(); + } + + return ( +
+
tab.props.title).join(', ')} + onKeyDown={onSelectKey} + className="flex flex-wrap gap-1 border-b border-[var(--ifm-color-emphasis-300)] bg-[var(--ifm-color-emphasis-100)] px-2 pt-2" + > + {tabs.map((tab, index) => { + const isSelected = index === active; + return ( + + ); + })} +
+
+ {tabs[active].props.children} +
+
+ ); +} diff --git a/src/css/custom.css b/src/css/custom.css index 83cd575..233a0af 100644 --- a/src/css/custom.css +++ b/src/css/custom.css @@ -37,7 +37,8 @@ } /* The tutorial blocks (src/components/tutorials) read the site's Infima variables, so they follow - the light and dark themes on their own. These two rules reach into Docusaurus's code block. */ + the light and dark themes on their own. The first two rules reach into Docusaurus's code block; + the rest style the callouts, the step list and the accordion. */ /* A reader is meant to copy these snippets, so their buttons stay visible instead of fading in only when the block is hovered. !important beats the theme's own hover opacity rules. */ @@ -52,3 +53,116 @@ box-shadow: none; margin-bottom: 0; } + +/* Callouts: the five accents follow Infima's own semantic palette (the -darker tones the theme + uses for buttons and alerts), darkened further in light mode so the icon and the left border + read on a white page and lightened in dark mode to read on a black one. */ +.ccf-callout { + border-left-color: var(--ccf-callout-accent); + background-color: color-mix(in srgb, var(--ccf-callout-accent) 12%, var(--ifm-background-surface-color)); +} +.ccf-callout--note { + --ccf-callout-accent: var(--ifm-color-secondary-darkest); +} +.ccf-callout--tip { + --ccf-callout-accent: var(--ifm-color-success-darker); +} +.ccf-callout--info { + --ccf-callout-accent: var(--ifm-color-info-darker); +} +.ccf-callout--warning { + --ccf-callout-accent: var(--ifm-color-warning-darker); +} +.ccf-callout--danger { + --ccf-callout-accent: var(--ifm-color-danger-darker); +} +[data-theme='dark'] .ccf-callout--note { + --ccf-callout-accent: var(--ifm-color-secondary); +} +[data-theme='dark'] .ccf-callout--tip { + --ccf-callout-accent: var(--ifm-color-success-light); +} +[data-theme='dark'] .ccf-callout--info { + --ccf-callout-accent: var(--ifm-color-info-light); +} +[data-theme='dark'] .ccf-callout--warning { + --ccf-callout-accent: var(--ifm-color-warning-light); +} +[data-theme='dark'] .ccf-callout--danger { + --ccf-callout-accent: var(--ifm-color-danger-light); +} +/* The writer's last paragraph should not leave the callout taller than its padding. */ +.ccf-callout-body > :last-child { + margin-bottom: 0; +} + +/* Steps: the line that joins one step's number circle to the next. The circle is 1.75rem wide, + so the 2px line sits at its middle; the list item's bottom padding is the gap it crosses. */ +.ccf-step:not(:last-child)::before { + content: ''; + position: absolute; + left: 13px; + top: 2rem; + bottom: 0; + width: 2px; + background-color: var(--ifm-color-emphasis-300); +} +.ccf-step-body > :last-child { + margin-bottom: 0; +} + +/* Accordion: one bordered item on its own; inside a group, the group wears the border and the + items are separated by a line. */ +.ccf-accordion { + border: 1px solid var(--ifm-color-emphasis-300); + border-radius: var(--ifm-global-radius); + background-color: var(--ifm-background-surface-color); +} +.ccf-accordion-group { + border: 1px solid var(--ifm-color-emphasis-300); + border-radius: var(--ifm-global-radius); + background-color: var(--ifm-background-surface-color); + overflow: hidden; +} +.ccf-accordion-group > .ccf-accordion { + border: 0; + border-radius: 0; + border-bottom: 1px solid var(--ifm-color-emphasis-300); + background-color: transparent; +} +.ccf-accordion-group > .ccf-accordion:last-child { + border-bottom: 0; +} +/* The summary is the whole clickable row; list-style hides the disclosure marker in Firefox and + the ::-webkit-details-marker rule hides it in Safari. */ +.ccf-accordion-summary { + display: flex; + align-items: center; + justify-content: space-between; + gap: 0.75rem; + padding: 0.75rem 1rem; + cursor: pointer; + list-style: none; + user-select: none; +} +.ccf-accordion-summary::-webkit-details-marker { + display: none; +} +.ccf-accordion-chevron { + transition: transform var(--ifm-transition-fast) var(--ifm-transition-timing-default); +} +.ccf-accordion[open] .ccf-accordion-chevron { + transform: rotate(90deg); +} +.ccf-accordion-body { + border-top: 1px solid var(--ifm-color-emphasis-300); + padding: 0.75rem 1rem; +} +.ccf-accordion-body > :last-child { + margin-bottom: 0; +} + +/* A tab panel, like the step and the callout body, should not carry its last paragraph's margin. */ +.ccf-tabs-panel > :last-child { + margin-bottom: 0; +} diff --git a/src/theme/MDXComponents/index.tsx b/src/theme/MDXComponents/index.tsx index 4e94a5a..7518c7f 100644 --- a/src/theme/MDXComponents/index.tsx +++ b/src/theme/MDXComponents/index.tsx @@ -1,12 +1,33 @@ // Registers the tutorial components on every page's MDX scope, so a tutorial page writes -// and without importing them. Docusaurus reads the MDX component scope -// from this module, and the wrapper keeps the theme's own mappings (code, a, ul, admonition...). +// , , /, /, /, the callouts +// (, , , , , or ) and / +// without importing them. Docusaurus reads the MDX component scope from this +// module, and the wrapper keeps the theme's own mappings (code, a, ul, admonition...). import MDXComponents from '@theme-original/MDXComponents'; import CopyBlock from '@site/src/components/tutorials/CopyBlock'; import CodeGroup from '@site/src/components/tutorials/CodeGroup'; +import Tabs, {Tab} from '@site/src/components/tutorials/Tabs'; +import Card, {CardGroup} from '@site/src/components/tutorials/Cards'; +import Steps, {Step} from '@site/src/components/tutorials/Steps'; +import Callout, {Danger, Info, Note, Tip, Warning} from '@site/src/components/tutorials/Callout'; +import Accordion, {AccordionGroup} from '@site/src/components/tutorials/Accordion'; export default { ...MDXComponents, CopyBlock, CodeGroup, + Tabs, + Tab, + Card, + CardGroup, + Steps, + Step, + Callout, + Note, + Tip, + Info, + Warning, + Danger, + Accordion, + AccordionGroup, }; From 86bc551e223a922aa210a0e453ed1d939738c1c7 Mon Sep 17 00:00:00 2001 From: "ccf-factory[bot]" Date: Fri, 27 Nov 2026 19:20:53 +0000 Subject: [PATCH 2/3] self-review: address pass 1 findings --- package.json | 2 +- src/components/tutorials/Cards.tsx | 6 +--- src/components/tutorials/Steps.tsx | 15 +++----- src/components/tutorials/Tabs.tsx | 15 +++----- src/components/tutorials/cardLink.mjs | 14 ++++++++ src/components/tutorials/cardLink.test.mjs | 17 +++++++++ src/components/tutorials/titledChildren.mjs | 18 ++++++++++ .../tutorials/titledChildren.test.mjs | 35 +++++++++++++++++++ 8 files changed, 96 insertions(+), 26 deletions(-) create mode 100644 src/components/tutorials/cardLink.mjs create mode 100644 src/components/tutorials/cardLink.test.mjs create mode 100644 src/components/tutorials/titledChildren.mjs create mode 100644 src/components/tutorials/titledChildren.test.mjs diff --git a/package.json b/package.json index 172754c..210b016 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "write-translations": "docusaurus write-translations", "write-heading-ids": "docusaurus write-heading-ids", "typecheck": "tsc", - "test": "node --test scripts/openapi-display.test.mjs scripts/gen-config-ref.test.mjs scripts/sync-catalog.test.mjs src/components/tutorials/snippetText.test.mjs src/components/tutorials/codeGroupTabs.test.mjs", + "test": "node --test scripts/openapi-display.test.mjs scripts/gen-config-ref.test.mjs scripts/sync-catalog.test.mjs src/components/tutorials/snippetText.test.mjs src/components/tutorials/codeGroupTabs.test.mjs src/components/tutorials/titledChildren.test.mjs src/components/tutorials/cardLink.test.mjs", "spellcheck": "cspell \"**/*.md\" \"**/*.mdx\" --no-progress" }, "dependencies": { diff --git a/src/components/tutorials/Cards.tsx b/src/components/tutorials/Cards.tsx index 9442470..7104a3e 100644 --- a/src/components/tutorials/Cards.tsx +++ b/src/components/tutorials/Cards.tsx @@ -6,6 +6,7 @@ import React, {type ReactNode} from 'react'; import Link from '@docusaurus/Link'; import clsx from 'clsx'; +import {isInternalHref} from './cardLink.mjs'; export type CardProps = { /** The card's headline: where the link leads. */ @@ -20,11 +21,6 @@ export type CardProps = { className?: string; }; -// A root-relative href names a page of this site; // would be a protocol-relative external one. -function isInternalHref(href: string): boolean { - return href.startsWith('/') && !href.startsWith('//'); -} - const cardBox = clsx( 'ccf-card group block rounded-[var(--ifm-global-radius)] border p-4 no-underline', 'border-[var(--ifm-color-emphasis-300)] bg-[var(--ifm-background-surface-color)]', diff --git a/src/components/tutorials/Steps.tsx b/src/components/tutorials/Steps.tsx index dd19416..c2ac449 100644 --- a/src/components/tutorials/Steps.tsx +++ b/src/components/tutorials/Steps.tsx @@ -3,8 +3,9 @@ // step is ordinary Markdown, so a step can hold commands (CopyBlock), prose or a callout. // src/theme/MDXComponents/index.tsx registers them as and , so tutorial pages use // them without an import. The circle and the connecting line are drawn in src/css/custom.css. -import React, {type ReactElement, type ReactNode, isValidElement} from 'react'; +import React, {type ReactElement, type ReactNode} from 'react'; import clsx from 'clsx'; +import {titledChildren} from './titledChildren.mjs'; export type StepProps = { /** The step's headline, in a few words: what the reader does in this step. */ @@ -33,16 +34,10 @@ export type StepsProps = { className?: string; }; -// The children, in order, ignoring the text and whitespace MDX leaves between them. -function stepElements(children: ReactNode): ReactElement[] { - return React.Children.toArray(children).filter( - (child): child is ReactElement => - isValidElement(child) && typeof child.props.title === 'string', - ); -} - export default function Steps({children, className}: StepsProps): ReactNode { - const steps = stepElements(children); + // The children, in order; titledChildren skips the text and whitespace MDX leaves + // between them, and what no number could be given to. + const steps = titledChildren(children) as ReactElement[]; if (steps.length === 0) { return null; } diff --git a/src/components/tutorials/Tabs.tsx b/src/components/tutorials/Tabs.tsx index a9580f3..886d12d 100644 --- a/src/components/tutorials/Tabs.tsx +++ b/src/components/tutorials/Tabs.tsx @@ -7,13 +7,13 @@ import React, { type KeyboardEvent, type ReactElement, type ReactNode, - isValidElement, useId, useRef, useState, } from 'react'; import clsx from 'clsx'; import {clampTab, initialTab, nextTab} from './codeGroupTabs.mjs'; +import {titledChildren} from './titledChildren.mjs'; export type TabProps = { /** The tab's label, such as `Ubuntu` or `Install with yarn`. */ @@ -39,16 +39,10 @@ export type TabsProps = { className?: string; }; -// The children, in order, ignoring the text and whitespace MDX leaves between them. -function tabElements(children: ReactNode): ReactElement[] { - return React.Children.toArray(children).filter( - (child): child is ReactElement => - isValidElement(child) && typeof child.props.title === 'string', - ); -} - export default function Tabs({children, defaultTab, className}: TabsProps): ReactNode { - const tabs = tabElements(children); + // The children, in order; titledChildren skips the text and whitespace MDX leaves + // between them, and what no tab row could label. + const tabs = titledChildren(children) as ReactElement[]; const group = useId(); const buttons = useRef<(HTMLButtonElement | null)[]>([]); const [selected, setSelected] = useState(() => @@ -121,6 +115,7 @@ export default function Tabs({children, defaultTab, className}: TabsProps): Reac id={`${group}-panel`} role="tabpanel" aria-labelledby={`${group}-tab-${active}`} + tabIndex={0} className="ccf-tabs-panel px-4 pt-3" > {tabs[active].props.children} diff --git a/src/components/tutorials/cardLink.mjs b/src/components/tutorials/cardLink.mjs new file mode 100644 index 0000000..1858d05 --- /dev/null +++ b/src/components/tutorials/cardLink.mjs @@ -0,0 +1,14 @@ +// Where a Card's href leads. Plain ESM with JSDoc types, like snippetText.mjs, so `yarn test` can +// cover the internal-versus-external decision without a browser. + +/** + * Whether a card's href names a page of this site: root-relative (so Docusaurus's Link navigates + * in place), and not protocol-relative: `//example.com/x` looks root-relative but a browser reads + * it as the host example.com, so it stays an external link opening in a new tab. + * + * @param {string | undefined} href The card's href, if it has one. + * @returns {boolean} True when the card should link through Link. + */ +export function isInternalHref(href) { + return href !== undefined && href.startsWith('/') && !href.startsWith('//'); +} diff --git a/src/components/tutorials/cardLink.test.mjs b/src/components/tutorials/cardLink.test.mjs new file mode 100644 index 0000000..e6b65bd --- /dev/null +++ b/src/components/tutorials/cardLink.test.mjs @@ -0,0 +1,17 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {isInternalHref} from './cardLink.mjs'; + +test('a root-relative href names a page of this site', () => { + assert.equal(isInternalHref('/tutorials'), true); + assert.equal(isInternalHref('/docs/tutorials/smoke'), true); +}); + +test('anything else is external, or no link at all', () => { + assert.equal(isInternalHref('https://github.com/compliance-framework'), false); + assert.equal(isInternalHref('mailto:team@example.com'), false); + assert.equal(isInternalHref('tutorials'), false); + // Looks root-relative, but a browser reads the host from it: it must stay external. + assert.equal(isInternalHref('//example.com/docs'), false); + assert.equal(isInternalHref(undefined), false); +}); diff --git a/src/components/tutorials/titledChildren.mjs b/src/components/tutorials/titledChildren.mjs new file mode 100644 index 0000000..116a19b --- /dev/null +++ b/src/components/tutorials/titledChildren.mjs @@ -0,0 +1,18 @@ +// The titled children of a Tabs or Steps group. Plain ESM with JSDoc types, like snippetText.mjs, +// so `yarn test` can cover what counts as a titled child without a browser. +import {Children, isValidElement} from 'react'; + +/** + * The children that are elements carrying a string title, in order. MDX leaves text and + * whitespace between the elements, and an element without a usable title (a mistyped name, a + * title given as a number) cannot be labelled, so both are skipped: the group shows the children + * it can label rather than half-rendering the others. + * + * @param {import('react').ReactNode} children The group's children. + * @returns {Array<{props: {title: string}}>} The titled children, in order. + */ +export function titledChildren(children) { + return Children.toArray(children).filter( + (child) => isValidElement(child) && typeof child.props?.title === 'string', + ); +} diff --git a/src/components/tutorials/titledChildren.test.mjs b/src/components/tutorials/titledChildren.test.mjs new file mode 100644 index 0000000..d1979ef --- /dev/null +++ b/src/components/tutorials/titledChildren.test.mjs @@ -0,0 +1,35 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {createElement} from 'react'; +import {titledChildren} from './titledChildren.mjs'; + +function Marker() { + return null; +} + +test('keeps the elements with a string title, in order', () => { + const first = createElement(Marker, {title: 'Ubuntu'}, 'one'); + const second = createElement(Marker, {title: 'RHEL'}, 'two'); + const children = [' ', first, null, false, 'stray', second, undefined]; + assert.deepEqual( + titledChildren(children).map((child) => child.props.title), + ['Ubuntu', 'RHEL'], + ); +}); + +test('drops elements a group cannot label', () => { + const titled = createElement(Marker, {title: 'Ubuntu'}); + const numberTitle = createElement(Marker, {title: 2}); + const noTitle = createElement(Marker, {}); + const paragraph = createElement('p', null, 'not a marker'); + assert.deepEqual( + titledChildren([titled, numberTitle, noTitle, paragraph]).map((child) => child.props.title), + ['Ubuntu'], + ); +}); + +test('returns nothing when no child is a titled element', () => { + assert.deepEqual(titledChildren(undefined), []); + assert.deepEqual(titledChildren('just text'), []); + assert.deepEqual(titledChildren([null, false]), []); +}); From 2782f556a1f334d25edf07df6691e86e85dbea95 Mon Sep 17 00:00:00 2001 From: "ccf-factory[bot]" Date: Fri, 27 Nov 2026 19:27:19 +0000 Subject: [PATCH 3/3] self-review: address pass 2 findings --- src/components/tutorials/Cards.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/tutorials/Cards.tsx b/src/components/tutorials/Cards.tsx index 7104a3e..0932c00 100644 --- a/src/components/tutorials/Cards.tsx +++ b/src/components/tutorials/Cards.tsx @@ -58,7 +58,9 @@ export default function Card({title, href, icon, children, className}: CardProps <> {heading} {children ? ( - {children} + // A div, not a span: MDX hands the children as

elements, and a

may not sit + // inside a phrasing-only . +

{children}
) : null} );