-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Scaladoc: interactive toggle for capture checking content #26877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bracevac
wants to merge
1
commit into
scala:main
Choose a base branch
from
dotty-staging:ob/scaladoc-feature-toggle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* Interactive toggles for experimental language features (e.g. capture checking). | ||
| * | ||
| * Signature fragments that depend on such a feature are rendered twice by | ||
| * scaladoc: a `.feature-on` variant (with the feature's annotations) and a | ||
| * `.feature-off` variant (without them), wrapped in a `.feature-<id>` span. | ||
| * CSS displays exactly one of the two variants, keyed on a `<id>-hidden` | ||
| * class on the root element that is maintained here. | ||
| * | ||
| * Like theme.js, this script is loaded without `defer` so the stored | ||
| * preference is applied before first paint. | ||
| */ | ||
| ; (function () { | ||
| const supportsLocalStorage = (() => { | ||
| try { | ||
| localStorage.setItem('test', 'test'); | ||
| localStorage.removeItem('test'); | ||
| return true; | ||
| } catch (e) { | ||
| return false; | ||
| } | ||
| })(); | ||
|
|
||
| const features = [ | ||
| { | ||
| name: "capture checking", | ||
| storageKey: "hide-cc", | ||
| rootClass: "cc-hidden", | ||
| toggleId: "cc-toggle", | ||
| mobileToggleId: "mobile-cc-toggle", | ||
| }, | ||
| ]; | ||
|
|
||
| features.forEach(feature => { | ||
| let hidden = | ||
| supportsLocalStorage && localStorage.getItem(feature.storageKey) === "true"; | ||
|
|
||
| /* Applied ASAP so we don't get a flash of feature-specific content before | ||
| * the stored preference kicks in */ | ||
| document.documentElement.classList.toggle(feature.rootClass, hidden); | ||
|
|
||
| window.addEventListener("DOMContentLoaded", () => { | ||
| const toggle = document.getElementById(feature.toggleId); | ||
| const mobileToggle = document.getElementById(feature.mobileToggleId); | ||
|
|
||
| function render() { | ||
| document.documentElement.classList.toggle(feature.rootClass, hidden); | ||
| if (toggle !== null) { | ||
| toggle.classList.toggle("feature-toggle-off", hidden); | ||
| toggle.setAttribute("aria-pressed", !hidden); | ||
| } | ||
| if (mobileToggle !== null) { | ||
| mobileToggle.textContent = (hidden ? "Show " : "Hide ") + feature.name; | ||
| } | ||
| } | ||
|
|
||
| function flip() { | ||
| hidden = !hidden; | ||
| supportsLocalStorage && localStorage.setItem(feature.storageKey, hidden); | ||
| render(); | ||
| /* Let other components (e.g. the inheritance diagram, whose labels are | ||
| * measured at render time) react to the changed feature state */ | ||
| window.dispatchEvent(new CustomEvent("feature-toggled")); | ||
| } | ||
|
|
||
| toggle && toggle.addEventListener("click", flip); | ||
| mobileToggle && mobileToggle.addEventListener("click", flip); | ||
| render(); | ||
| }); | ||
| }); | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
scaladoc/resources/dotty_res/styles/theme/components/feature-toggle.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* Interactive toggles for experimental language features (e.g. capture checking). | ||
| * | ||
| * Signature fragments that depend on a toggleable feature carry both variants | ||
| * in the DOM (see featureToggles.js); these rules display exactly one of them. | ||
| * By default the feature's annotations are shown; a `<id>-hidden` class on the | ||
| * root element (e.g. `cc-hidden`) swaps every fragment to its plain variant. | ||
| */ | ||
|
|
||
| .feature-off { | ||
| display: none; | ||
| } | ||
|
|
||
| :root.cc-hidden .feature-cc > .feature-on { | ||
| display: none; | ||
| } | ||
|
|
||
| :root.cc-hidden .feature-cc > .feature-off { | ||
| display: inline; | ||
| } | ||
|
|
||
| /* The header button toggling capture checking annotations */ | ||
|
|
||
| #cc-toggle { | ||
| border: 1px solid var(--border-default); | ||
| border-radius: 4px; | ||
| background: none; | ||
| padding: calc(0.5 * var(--base-spacing)) calc(1 * var(--base-spacing)); | ||
| font-family: var(--code-font-family); | ||
| font-size: 14px; | ||
| line-height: 16px; | ||
| } | ||
|
|
||
| #cc-toggle.feature-toggle-off { | ||
| text-decoration: line-through; | ||
| opacity: 0.6; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a tad more descriptive for the average beginner? 😇