Repository navigation
fix(playground): show the saved framework before the page loads its scripts #4921
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f0e9412
fix(playground): show the saved framework before the page loads its s…
thetaPC eeb91b7
docs(playground): say the page's scripts instead of React in comments
thetaPC 321a398
refactor(playground): share the unselected toggle button look through…
thetaPC f717a6f
test(playground): check the framework list and storage key match FRAM…
thetaPC bbe8518
docs(playground): fix comma splices in the framework comments
thetaPC 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
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 was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/components/global/FrameworkSwitcher/styles.module.scss
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,27 @@ | ||
| @use '../../../css/mixins'; | ||
|
|
||
| .switcher { | ||
| display: flex; | ||
| } | ||
|
|
||
| /* | ||
| * The server renders the default framework as selected. Until the page's scripts | ||
| * load, a switcher marked `data-framework-pending` selects the reader's saved framework | ||
| * instead, if it offers that framework. | ||
| */ | ||
| @include mixins.each-saved-framework using ($saved, $shown) { | ||
| $offers: ':has([data-framework="#{$shown}"]:not(:disabled))'; | ||
| @if $saved != $shown { | ||
| $offers: '#{$offers}:not(:has([data-framework="#{$saved}"]:not(:disabled)))'; | ||
| } | ||
|
|
||
| :global(html[data-saved-framework='#{$saved}']) .switcher[data-framework-pending]#{$offers} { | ||
| [aria-selected='true'] { | ||
| @include mixins.toggle-button-unselected; | ||
| } | ||
|
|
||
| [data-framework='#{$shown}'] { | ||
| @include mixins.toggle-button-selected; | ||
| } | ||
| } | ||
| } |
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 was deleted.
Oops, something went wrong.
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,40 @@ | ||
| @use '../../../css/mixins'; | ||
|
|
||
| /* Matches the spacing of Docusaurus's tabs. */ | ||
| .container { | ||
| margin-bottom: var(--ifm-leading); | ||
| } | ||
|
|
||
| /* Scrolls sideways on narrow screens, as the playground toolbar does. */ | ||
| .switcher { | ||
| overflow-x: auto; | ||
| } | ||
|
|
||
| /* Matches the gap between Docusaurus's tabs and their panels in `src/css/theme/Tabs.scss`. */ | ||
| .panel { | ||
| margin-top: 0.75rem; | ||
| } | ||
|
|
||
| .panel > :last-child { | ||
| margin-bottom: 0; | ||
| } | ||
|
|
||
| /* | ||
| * The server renders the default framework's panel. Until the page's scripts | ||
| * load, a group marked `data-framework-pending` shows the reader's saved framework | ||
| * instead, if it has a panel for it. Its switcher does the same for the buttons. | ||
| */ | ||
| @include mixins.each-saved-framework using ($saved, $shown) { | ||
| $offers: ':has(> [data-framework="#{$shown}"])'; | ||
| @if $saved != $shown { | ||
| $offers: '#{$offers}:not(:has(> [data-framework="#{$saved}"]))'; | ||
| } | ||
|
|
||
| :global(html[data-saved-framework='#{$saved}']) .container[data-framework-pending]#{$offers} > .panel { | ||
| display: none; | ||
|
|
||
| &[data-framework='#{$shown}'] { | ||
| display: block; | ||
| } | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { readFileSync } from 'node:fs'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| // Needs the Docusaurus app to load, and these tests only read constants. | ||
| vi.mock('@docusaurus/theme-common', () => ({})); | ||
|
|
||
| import { FRAMEWORKS, STORAGE_KEY } from './frameworks'; | ||
|
|
||
| /* | ||
| * The stylesheets and the inline script in `docusaurus.config.js` show the | ||
| * reader's saved framework before the page's scripts load, so they can't import | ||
| * these values and repeat them instead. | ||
| */ | ||
| const read = (path: string) => readFileSync(new URL(path, import.meta.url), 'utf8'); | ||
|
|
||
| describe('frameworks outside the page scripts', () => { | ||
| it('lists every framework in the `each-saved-framework` mixin', () => { | ||
| const list = read('../css/_mixins.scss').match( | ||
| /@mixin each-saved-framework \{\s*@each \$framework in ([^{]+)\{/ | ||
| )?.[1]; | ||
|
|
||
| expect(list?.split(',').map((framework) => framework.trim())).toEqual(FRAMEWORKS.map(({ value }) => value)); | ||
| }); | ||
|
|
||
| it('reads the same storage key in the inline script', () => { | ||
| expect(read('../../docusaurus.config.js')).toContain(`localStorage.getItem('${STORAGE_KEY}')`); | ||
| }); | ||
| }); |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.