Skip to content

Commit b9102a5

Browse files
authored
feat(ScoobieLink): Propagate v-panel param (#503)
1 parent 398cf43 commit b9102a5

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ export const MyFirstInlineCode = () => (
345345

346346
Render an internal link with the same opinions as our [MdxProvider](#mdxprovider):
347347

348-
- Internal links pass through the `v` URL parameter for UI version switching
348+
- Internal links pass through the `v` and `v-panel` URL parameters for UI version switching
349349

350350
Unlike [SmartTextLink](#smarttextlink), this is not bound to a parent [Text] as it has no underlying [TextLink].
351351
It can be used to make complex components navigable rather than just sections of text.
@@ -398,7 +398,7 @@ export const Component = () => (
398398

399399
Render all underlying links as follows:
400400

401-
- Internal links pass through the `v` URL parameter for UI version switching
401+
- Internal links pass through the `v` and `v-panel` URL parameters for UI version switching
402402
- External links open in a new tab
403403
- Links with a [`download` attribute] prompt the user with a file download
404404

src/private/url.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ describe('parseInternalHref', () => {
3636
});
3737
});
3838

39+
it('preferences the v-panel URL parameter from location', () => {
40+
const to = parseInternalHref('/hello?v-panel=v1&b=b1', {
41+
pathname: '/',
42+
search: '?a=1&v-panel=2&b=3',
43+
});
44+
45+
expect(to).toEqual({
46+
hash: '',
47+
pathname: '/hello',
48+
search: 'v-panel=2&b=b1',
49+
});
50+
});
51+
3952
describe.each(['/page-1', '/page-1/'])(
4053
'given pathname %s',
4154
(inputPathname) => {

src/private/url.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ const URLSearchParams = url.URLSearchParams ?? window.URLSearchParams;
55

66
const EXAMPLE_BASE_URL = 'https://example.com';
77

8-
const parseVersionParam = (search: string) => {
8+
const parseVersionParams = (search: string) => {
99
const urlSearchParams = new URLSearchParams(search);
1010

11-
return urlSearchParams.get('v');
11+
return {
12+
v: urlSearchParams.get('v'),
13+
vPanel: urlSearchParams.get('v-panel'),
14+
};
1215
};
1316

1417
const hrefToUrl = (href: string, pathname: string) => {
@@ -32,11 +35,14 @@ export const parseInternalHref = (
3235
) => {
3336
const { hash, pathname, searchParams } = hrefToUrl(href, location.pathname);
3437

35-
const v = parseVersionParam(location.search);
38+
const { v, vPanel } = parseVersionParams(location.search);
3639

3740
if (v !== null) {
3841
searchParams.set('v', v);
3942
}
43+
if (vPanel !== null) {
44+
searchParams.set('v-panel', vPanel);
45+
}
4046

4147
const search = searchParams.toString();
4248

0 commit comments

Comments
 (0)