Skip to content

feat(tutorials): copy-pastable CopyBlock and CodeGroup for tutorial pages - #210

Merged
ccf-factory-reviewer[bot] merged 5 commits into
mainfrom
factory/stack/wi_2fa6b8bf808100304f9a/1
Nov 28, 2026
Merged

ccf-factory-reviewer[bot] merged 5 commits into
mainfrom
factory/stack/wi_2fa6b8bf808100304f9a/1

Conversation

@ccf-factory

@ccf-factory ccf-factory Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Closes #206 — part 2 of 4 of #204, stacked on #205.

What this adds

Two components for the tutorial pages, both usable in a .mdx page with no per-page import:

  • <CopyBlock> (src/components/tutorials/CopyBlock.tsx) — one copy-pastable snippet: commands, config or file contents. It is Docusaurus's own @theme/CodeBlock underneath, so it keeps the site's prism github/dracula highlighting and Docusaurus's built-in copy button (which copies metadata.code, so the clipboard gets exactly what is on screen). On top of that: a title row (the file the snippet goes in, or what running the command does) and a copy button that stays visible instead of fading in only on hover. Give it code="..." or an indented text child: snippetText drops the blank lines the MDX literal adds and the indentation every line shares, so the reader copies what they read.
  • <CodeGroup> (src/components/tutorials/CodeGroup.tsx) — the files of one step as tabs (items={[{title, code, language}]}, optional defaultTab). The selected file renders as a CopyBlock, so every file keeps its own copy button. The tabs are a tablist with roving focus and Arrow / Home / End navigation.

Registering them for MDX: not markdown.mdxPageImports

The issue suggested markdown.mdxPageImports. That option does not exist: Docusaurus 3.9.2's markdown config is format, parseFrontMatter, mermaid, emoji, preprocessor, mdx1Compat, remarkRehypeOptions, anchors, hooks (@docusaurus/types/src/markdown.d.ts and the Joi schema in @docusaurus/core/lib/server/configValidation.js), and it is absent from docusaurus main too. The supported way to put components on every page's MDX scope is wrapping @theme/MDXComponents, so src/theme/MDXComponents/index.tsx does exactly that and keeps the theme's own mappings (code, a, ul, admonition…). The repo already uses @theme-original wrappers (src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx), and docusaurus.config.ts is therefore untouched. Docusaurus has one MDX component scope, so the two tags are available on every instance's pages.

Styling

Tailwind utilities on the components, with the site's Infima variables for colour (bg-[var(--ifm-background-surface-color)], border-[var(--ifm-color-emphasis-300)], text-[var(--ifm-font-color-secondary)], …), so both themes come from the variables the site already flips at [data-theme='dark']; the code area is the prism github/dracula pair from themeConfig.prism. Two rules in src/css/custom.css reach into the theme's code block: keep the copy button visible, and let the group's chrome replace the inner block's own border, radius, shadow and margin. No new dependencies, and themeConfig.prism is unchanged.

Verification

  • yarn test (49 tests, including 8 new ones for snippetText), yarn typecheck, yarn spellcheck and yarn build pass.
  • Every acceptance criterion checked in Chromium against yarn serve of the build, on a scratch .mdx page (not committed): both components render with no import; each block's copy button puts the exact text on the clipboard (navigator.clipboard.readText() compared with the expected snippet, for code and for an indented text child); CodeGroup switches between its files through the tabs and each file copies its own text, also after ArrowRight; light mode shows the github code background (#f6f8fa) and dark mode the dracula one (#282a36) through the site's own colour toggle; no console or page errors. Screenshots of that page are in the run's artifacts rather than committed: the components have no page of their own until Showcase the tutorial components and document how to write tutorials #208 adds the showcase.
  • No CCF UI screenshots: nothing here touches the UI, so no temporary environment was needed.

Decisions

  • Built on @theme/CodeBlock rather than a second prism-react-renderer instance: one code-block implementation site-wide, on-demand prism languages, and the copy text is the theme's own metadata.code.
  • CopyBlock.tsx, not the issue's CodeBlock.tsx: the file is named after the tag authors write, and CodeBlock is Docusaurus's component.
  • snippetText lives in snippetText.mjs (plain ESM with JSDoc, like scripts/*.mjs, which docusaurus.config.ts already imports) so yarn test can cover it; package.json's test script lists the new test file. No dependency or lockfile change.
  • CodeGroup renders only the selected file, so a group shows one copy button, and the panel has no title row because the tab already names the file.

Open questions for reviewers

  • Should the site add themeConfig.prism.additionalLanguages: ['bash'] (perhaps also docker, hcl)? prism-react-renderer ships no shell grammar, so language="sh" snippets render as plain text — as the site's 34 existing sh, shell and bash fences do today. It changes how every code block on the site renders, so it is left out here.
  • The components' tab and selection logic has no unit test: the repo has no React test setup and adding one means devDependencies, which this PR leaves alone. It is covered by the browser check above, and by Showcase the tutorial components and document how to write tutorials #208's showcase page once that lands.

Scope

The general unversioned site plus the shared components — no tutorial content, no other components. #207 adds the rest of the MDX component set and #208 the showcase and authoring guide, so nothing here duplicates them. No released version line is touched.

Files: src/components/tutorials/CopyBlock.tsx, CodeGroup.tsx, snippetText.mjs, snippetText.test.mjs, src/theme/MDXComponents/index.tsx, src/css/custom.css, package.json (test script only).

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: f00f0ddc-67b0-468e-8c97-5d7361ff7954

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ccf-factory

ccf-factory Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

🏭 Tracked by CCF Factory — view

@ccf-factory-reviewer ccf-factory-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccf-review: REQUEST_CHANGES

1 Must-fix, 1 Should-fix.

Stack (base-chain): #209 → #210

Comment thread src/components/tutorials/CodeGroup.tsx Resolved
Comment thread src/components/tutorials/CodeGroup.tsx Resolved

@ccf-factory-reviewer ccf-factory-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccf-review: APPROVE

Re-review at 5d98cf0: both round-1 findings are fixed, verified, and their threads resolved; no new findings in the delta.

  • CORE-TEST-001 (untested tab logic): the decisions now live in codeGroupTabs.mjs as three plain-ESM helpers (initialTab, clampTab, nextTab), tested in codeGroupTabs.test.mjs (wrap-around both ends, Home/End, unhandled key, defaultTab matching nothing and empty items, the clamp), registered in package.json's test script. yarn test: 57/57 pass locally at this head.
  • Tailwind shadow: shadow-[shadow:var(--ifm-global-shadow-lw)] compiles to a real box-shadow declaration in the built CSS (confirmed in build/assets/css/styles.*.css), so the group renders the shadow custom.css drops from the inner block.

Checks at this head: CI build success; local yarn build, yarn typecheck, yarn spellcheck clean. i18n: single en locale, no translation tree, no hardcoded UI strings (copy-button labels go through Docusaurus translate). versioning: instances.yaml parses, every *_versions.json is one version per minor line, and the diff touches no versioned files. style: no .md/.mdx page in the diff, so no STYLE.md skeleton applies. The title prop and clean-btn hook on @theme/CodeBlock were verified against the pinned Docusaurus 3.9.2 sources.

Stack (base-chain): #209 → #210

@ccf-factory-reviewer
ccf-factory-reviewer Bot force-pushed the factory/stack/wi_2fa6b8bf808100304f9a/1 branch from 5d98cf0 to 31d2176 Compare November 27, 2026 20:19

@ccf-factory-reviewer ccf-factory-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccf-review: REQUEST_CHANGES

3 Must-fix.

Stack (base-chain): #210 → #211 → #212

Checks

  • build: the PR's build check is SUCCESS on the head reviewed; at the stack head yarn install, yarn test (62 pass), yarn typecheck, yarn spellcheck (0 issues) and yarn build also pass locally, and tests/typecheck/spellcheck pass at this PR's head too.
  • i18n: i18n.locales is ['en'] only and no i18n/ tree exists, so the only locale is the one built; nothing half-translated; DOCS-TRANS-001 not applicable.
  • versioning: instances.yaml is untouched by the stack (and validates during the build); no *_versions.json or *_versioned_docs file changes, so no released line is touched and no minor line is duplicated.
  • style: docs-style checklist run against STYLE.md on the changed pages.
  • source verification (DOCS-ACC-001): every setting, CLI command/flag, config field and path the diff adds was checked against the source repo it documents (instances.yaml) with gh api ...?ref=<branch>; no docs page or memory was trusted.

@gusfcarvalho

Copy link
Copy Markdown
Contributor

No need to include a ccf-skills PR.

@ccf-factory-reviewer ccf-factory-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccf-review: REQUEST_CHANGES

3 Must-fix open, 1 Nit (reported, not posted). No new threads: this is round 2 at the same head (31d2176, no new commits since round 1), and the three Must-fix threads opened in round 1 are still unresolved.

Stack (base-chain): #210 → #211 → #212

Still open from round 1 (Must-fix, DOCS-ACC-001)

The head has not moved, so none of these is fixed: src/components/tutorials/snippetText.test.mjs still contains all three fixtures. Re-verified in round 2 against the source the fixtures imitate — compliance-framework/api at its default branch, with gh api …?ref=main, not against another docs page.

  • src/components/tutorials/snippetText.test.mjs:8 (8aa330b06681) — ccf evidence list. cmd/root.go names the binary api and adds run, authz, oscal, users, seed, migrate, bootstrap, dashboards, digest, riskdigest: there is no ccf binary, no evidence command, and no such command anywhere in the org's CLI. Still stands.
  • src/components/tutorials/snippetText.test.mjs:18 (013955ce9f4a) — plugins: as a list of {name, namespace}. pkg/agentconfig/types.go declares Config.Plugins map[string]*Plugin, keyed by the plugin identifier, whose fields are enabled, protocol_version, schedule, source, policies, config, labels, policy_data, policy_behavior: no name, no namespace, no list form. A tutorial author copying this fixture documents a config the agent does not read. Still stands.
  • src/components/tutorials/snippetText.test.mjs:31 (69a1348577b0) — ccf catalog apply c.yaml --dry-run. No catalog apply command exists and --dry-run appears on no catalog command; the site's own api/cli-reference.md documents api digest test --dry-run as the only --dry-run. Still stands.

Fix, as said in round 1: either use commands and a config shape the documented source has (api dashboards export f.json; plugins: as a map keyed by plugin identifier with source:), or keep the fixtures plainly about the docs repo — yarn build, compliance.yaml, the way the showcase page does. These are node --test fixtures for the dedent helper, so the assertions stay identical either way; what matters is that this file is the first thing a tutorial author reads when they want to know what a CopyBlock snippet looks like, and it teaches a CLI and a config the product does not have.

Checks and verification (round 2)

Re-run at this head in the review workspace: yarn test 57 pass / 0 fail, yarn typecheck and yarn spellcheck clean; the PR's build check is SUCCESS at this head. instances.yaml, *_versioned_docs/ and *_versions.json are untouched (versioning); i18n.locales is ['en'] alone, nothing half-translated (i18n); the new page text and CSS follow STYLE.md (style).

What the components claim held up: CopyBlock really is Docusaurus's own CodeBlock with a title row, and the copy button it promises is in the client bundle (build/assets/js/6556.*.js carries "Copy code to clipboard"), so .ccf-copy-block button.clean-btn reaches a real element after hydration rather than a hoped-for one; initialTab/clampTab/nextTab are genuinely tested for the wrap-around, the unmatched defaultTab and the hot-reload clamp; snippetText's dedent is tested for tabs, shared indentation and inner blank lines. The language values the JSDoc suggests (sh, yaml, json) match STYLE.md's own convention — the fact that the site cannot highlight sh is the site's Prism gap, reported once on #212, not a fault here.

One Nit, reported rather than posted: src/components/tutorials/CodeGroup.tsx:93 gives its role="tabpanel" no tabIndex, so unlike Tabs.tsx:119 its panel cannot be reached with Tab and the copy button inside it is mouse-only (83b40402b0be).

Once the three fixtures are changed, this is good to merge: the components themselves are sound, and both PRs above it are already approved.

Review (DOCS-ACC-001): the fixtures taught 'ccf evidence list',
'ccf catalog apply --dry-run' and a plugins list with name/namespace.
The documented CLI is the 'api' binary (api dashboards export,
api digest test --dry-run) and agentconfig.Config keys plugins by
identifier (plugins: { k8s: { enabled: ... } }). Fixtures now use
those real forms.

@ccf-factory-reviewer ccf-factory-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccf-review: APPROVE

1 Nit (reported, not posted). The three Must-fix threads from the review that requested changes are fixed at this head (9d1ce79) and resolved.

Stack (base-chain): #210 → #211 → #212

Re-review at 9d1ce79

One new commit since the review that requested changes: 9d1ce79 test(tutorials): keep snippet fixtures to real CLI commands and config, touching only src/components/tutorials/snippetText.test.mjs. It replaces the three Must-fix fixtures. All three were re-verified independently against the source they imitate — compliance-framework/api at its default branch with gh api …?ref=main, not against another docs page or the fix commit's own words: api dashboards export f.json is real (cmd/root.go:20 names the root command api and cmd/root.go:147 adds dashboards.RootCmd; cmd/dashboards/export.go:19 defines export); api digest test --dry-run is real (cmd/digest.go:41, digestTestCmd.Flags().BoolVar(&dryRun, "dry-run", …)); plugins: { k8s: { enabled: true } } matches pkg/agentconfig/types.go:50 (Config.Plugins map[string]*Plugin) and types.go:102 (Plugin.Enabled). The threads are resolved. No new product claim elsewhere in the diff: the remaining fixture strings (kubectl get pods, name: k8s, version: 1, port: 8080) are plain dedent material.

Checks and verification

  • build: the PR's build check is SUCCESS at this head (Spellcheck too); locally yarn test is 57 pass / 0 fail — the new fixtures pass the dedent cases unchanged, whose assertions are identical to before — and yarn typecheck is clean.
  • versioning: the diff touches no instances.yaml, *_versioned_docs/ or *_versions.json; released lines stay untouched.
  • i18n: i18n.locales is ['en'] alone and there is no i18n/ directory, so nothing is half-translated (DOCS-TRANS-001 not engaged).
  • style: no page text in this PR; the new comments and CSS follow the conventions of the files they sit in (docs-style checklist has nothing to bite on).
  • One Nit, reported rather than posted: src/components/tutorials/CodeGroup.tsx:93 gives its role="tabpanel" no tabIndex, so unlike Tabs.tsx:118 its panel cannot be reached with Tab and the copy button inside it is mouse-only (48475cace8dd).

With the three Must-fix findings fixed and re-verified against the source, and nothing blocking left, this is good to merge.

@ccf-factory-reviewer
ccf-factory-reviewer Bot merged commit 0286991 into main Nov 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add copy-pastable interactive code blocks for tutorials

1 participant