@storybook/addon-links 11.0.0-alpha.0 → 11.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/dist/_browser-chunks/{chunk-PZ2KFUGG.js → chunk-2NZOTHER.js} +1 -1
- package/dist/_browser-chunks/{chunk-LAYPZ6CY.js → chunk-72HWH2ZD.js} +7 -4
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -2
- package/dist/preview.js +2 -2
- package/dist/react/index.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -78,7 +78,6 @@ export const third = () => <LinkTo story="index">Go back</LinkTo>;
|
|
|
78
78
|
## hrefTo function
|
|
79
79
|
|
|
80
80
|
If you want to get an URL for a particular story, you may use `hrefTo` function. It returns a promise, which resolves to string containing a relative URL:
|
|
81
|
-
|
|
82
81
|
```js
|
|
83
82
|
import { hrefTo } from '@storybook/addon-links';
|
|
84
83
|
import { action } from 'storybook/actions';
|
|
@@ -94,6 +93,22 @@ export const log = () => {
|
|
|
94
93
|
};
|
|
95
94
|
```
|
|
96
95
|
|
|
96
|
+
## hrefToSync function
|
|
97
|
+
|
|
98
|
+
If you want to render native links to other stories so you can middle-click or command-click to open them in a new tab, you can use the `hrefToSync` function. This returns a string containing the URL immediately:
|
|
99
|
+
```js
|
|
100
|
+
import { hrefToSync } from '@storybook/addon-links';
|
|
101
|
+
|
|
102
|
+
export default {
|
|
103
|
+
title: 'HrefSync',
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const log = () => {
|
|
107
|
+
const url = hrefToSync('HrefSync', 'log');
|
|
108
|
+
return <a href={url}>Link to this story</a>;
|
|
109
|
+
};
|
|
110
|
+
```
|
|
111
|
+
|
|
97
112
|
## withLinks decorator
|
|
98
113
|
|
|
99
114
|
`withLinks` decorator enables a declarative way of defining story links, using data attributes.
|
|
@@ -16,10 +16,12 @@ function parseQuery(queryString) {
|
|
|
16
16
|
}
|
|
17
17
|
return query;
|
|
18
18
|
}
|
|
19
|
-
var navigate = (params) => addons.getChannel().emit(SELECT_STORY, params),
|
|
20
|
-
let { location } = document,
|
|
21
|
-
|
|
22
|
-
}
|
|
19
|
+
var navigate = (params) => addons.getChannel().emit(SELECT_STORY, params), generateStoryUrl = (title, name) => {
|
|
20
|
+
let { location } = document, query = parseQuery(location.search), existingId = query.id ?? query.path?.match(/^\/story\/(.+)$/)?.[1], titleToLink = title || existingId?.split("--", 2)[0] || "", path = `/story/${toId(titleToLink, name)}`, sbPath = location.pathname.replace(/iframe\.html$/, "");
|
|
21
|
+
return `${location.origin + sbPath}?${Object.entries({ path }).map((item) => `${item[0]}=${item[1]}`).join("&")}`;
|
|
22
|
+
}, hrefTo = (title, name) => new Promise((resolve) => {
|
|
23
|
+
resolve(generateStoryUrl(title, name));
|
|
24
|
+
}), hrefToSync = (title, name) => generateStoryUrl(title, name), valueOrCall = (args) => (value) => typeof value == "function" ? value(...args) : value, linkTo = (idOrTitle, nameInput) => (...args) => {
|
|
23
25
|
let resolver = valueOrCall(args), title = resolver(idOrTitle), name = nameInput ? resolver(nameInput) : !1;
|
|
24
26
|
title?.match(/--/) && !name ? navigate({ storyId: title }) : name && title ? navigate({ kind: title, story: name }) : title ? navigate({ kind: title }) : name && navigate({ story: name });
|
|
25
27
|
}, linksListener = (e) => {
|
|
@@ -41,6 +43,7 @@ var navigate = (params) => addons.getChannel().emit(SELECT_STORY, params), hrefT
|
|
|
41
43
|
export {
|
|
42
44
|
navigate,
|
|
43
45
|
hrefTo,
|
|
46
|
+
hrefToSync,
|
|
44
47
|
linkTo,
|
|
45
48
|
withLinks
|
|
46
49
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -11,11 +11,12 @@ interface ParamsCombo {
|
|
|
11
11
|
name?: StoryName;
|
|
12
12
|
}
|
|
13
13
|
declare const navigate: (params: ParamsId | ParamsCombo) => void;
|
|
14
|
-
declare const hrefTo: (title: ComponentTitle, name: StoryName) => Promise<string>;
|
|
14
|
+
declare const hrefTo: (title: ComponentTitle | undefined, name: StoryName) => Promise<string>;
|
|
15
|
+
declare const hrefToSync: (title: ComponentTitle | undefined, name: StoryName) => string;
|
|
15
16
|
declare const linkTo: (idOrTitle: string | ((...args: any[]) => string), nameInput?: string | ((...args: any[]) => string)) => (...args: any[]) => void;
|
|
16
17
|
declare const withLinks: (...args: any) => any;
|
|
17
18
|
//#endregion
|
|
18
19
|
//#region code/addons/links/.dts-emit/code/addons/links/src/index.d.ts
|
|
19
20
|
declare function _default(): import("storybook/internal/csf").PreviewAddon<import("storybook/internal/csf").AddonTypes>;
|
|
20
21
|
//#endregion
|
|
21
|
-
export { _default as default, hrefTo, linkTo, navigate, withLinks };
|
|
22
|
+
export { _default as default, hrefTo, hrefToSync, linkTo, navigate, withLinks };
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
index_default
|
|
3
|
-
} from "./_browser-chunks/chunk-
|
|
3
|
+
} from "./_browser-chunks/chunk-2NZOTHER.js";
|
|
4
4
|
import {
|
|
5
5
|
hrefTo,
|
|
6
|
+
hrefToSync,
|
|
6
7
|
linkTo,
|
|
7
8
|
navigate,
|
|
8
9
|
withLinks
|
|
9
|
-
} from "./_browser-chunks/chunk-
|
|
10
|
+
} from "./_browser-chunks/chunk-72HWH2ZD.js";
|
|
10
11
|
import "./_browser-chunks/chunk-FX5LXYO2.js";
|
|
11
12
|
export {
|
|
12
13
|
index_default as default,
|
|
13
14
|
hrefTo,
|
|
15
|
+
hrefToSync,
|
|
14
16
|
linkTo,
|
|
15
17
|
navigate,
|
|
16
18
|
withLinks
|
package/dist/preview.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
decorators
|
|
3
|
-
} from "./_browser-chunks/chunk-
|
|
4
|
-
import "./_browser-chunks/chunk-
|
|
3
|
+
} from "./_browser-chunks/chunk-2NZOTHER.js";
|
|
4
|
+
import "./_browser-chunks/chunk-72HWH2ZD.js";
|
|
5
5
|
import "./_browser-chunks/chunk-FX5LXYO2.js";
|
|
6
6
|
export {
|
|
7
7
|
decorators
|
package/dist/react/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/addon-links",
|
|
3
|
-
"version": "11.0.0-alpha.
|
|
3
|
+
"version": "11.0.0-alpha.2",
|
|
4
4
|
"description": "Storybook Links: Link stories together to build demos and prototypes with your UI components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"typescript": "^6.0.3"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@types/react": "^
|
|
63
|
-
"react": "^
|
|
64
|
-
"storybook": "^11.0.0-alpha.
|
|
62
|
+
"@types/react": "^18.0.0 || ^19.0.0",
|
|
63
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
64
|
+
"storybook": "^11.0.0-alpha.2"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@types/react": {
|