[docs-infra] Add @focus and Linter to Automatically Apply#1303
[docs-infra] Add @focus and Linter to Automatically Apply#1303
@focus and Linter to Automatically Apply#1303Conversation
lintJavascriptDemoFocus ESLint RulelintJavascriptDemoFocus ESLint Rule
Deploy preview
PerformanceTotal duration: 15.17 ms ▼-2.02 ms(-11.8%) | Renders: 4 (+0) | Paint: 62.90 ms ▼-13.12 ms(-17.3%)
Bundle size
Check out the code infra dashboard for more information about this PR. |
lintJavascriptDemoFocus ESLint Rule@focus and Linter to Automatically Apply
There was a problem hiding this comment.
Even if it is about linting docs, this eslint rule should live in code-infra since the package is already configured with dependencies.
There was a problem hiding this comment.
I think docs related eslint custom rules should stay in docs-infra because will depend on other exports and utilities from docs-infra. Otherwise, if it is in code-infra, that would create a dependency on docs-infra. To maintain a separate release process, I don't think code-infra should depend on docs-infra. The code-infra eslint config allows us to extend the code-infra config cleanly.
I think we could improve the way that docs-infra depends on eslint. Maybe we should use optional peer dependancies so it uses the same versions from code-infra?
There was a problem hiding this comment.
I dont see any dependencies of docs infra being used in the eslint plugin. Till that time, I think it makes sense to be in code-infra.
| steps: | ||
| - run: | ||
| name: Build docs-infra for ESLint plugins | ||
| command: pnpm run docs:lib |
There was a problem hiding this comment.
Eslint plugins go in code-infra package: packages/code-infra/src/eslint/docsConfig.mjs
For now they're authored in plain javascript. We want to avoid making docs-infra a dependency of code-infra
…o docs-infra/add-linter
Preview Deploy
New:
@focusannotationAdds
@focus-start/@focus-endcomment annotations that mark the "important" portion of a code demo. When focus annotations are present, the code block becomes collapsible — unfocused regions are hidden behind an Expand/Collapse toggle so users see the relevant code first.Key behaviors:
@focus-start/@focus-endmark focused regions; everything outside collapses@padding Ncontrols how many context lines surround focused regions (default 2)@min Nsets the minimum visible lines before collapsing kicks in (default 6)@highlightand@highlight-text— highlighted lines inside a focused region usedata-frame-type="focus", outside usedata-frame-type="highlighted-unfocused"focusFramesMaxSize(18 lines) with a fade-out truncation indicatorNew:
lintJavascriptDemoFocusESLint pluginAn ESLint rule (
@mui/internal-docs-infra/demo-focus) that automatically inserts@focus-start/@focus-endannotations into demo files that export a default React component. It focuses the component body and collapses boilerplate (imports, type definitions, helpers).enhanceCodeEmphasisimprovements@highlight-textnow renders<mark>elements instead of<span data-hl>data-frame-indent) for CSS nestingCollapsible code UI
:checkedcheckbox)ResizeObserver-based scroll anchoring keeps focused code stable during expand/collapse transitionsoverflow-anchor: noneon changing content prevents browser scroll jumps during tab switchesparseSource/calculateFrameRangesupdatesfocus,focus-unfocused,padding-top,padding-bottomdata-frame-truncated="visible"/"hidden"for fade-out on large blocksOther changes
withDocsInfra: newemphasisOptionsoption for controlling focus behavior per-siteloadCodeVariant: passesemphasisConfigthrough the pipelinePrecomponent: forwardsdata-collapsibleattribute from code elementsBreaking changes
.frameinstead of only .line@highlight-textproduces<mark>elementsScreenshots
Improved animation
Screencast.From.2026-04-17.20-14-59.webm
Screencast.From.2026-04-13.13-31-07.webm