Skip to content

Commit 1df7924

Browse files
docs: create version switch toolbar button (v1) (#6271)
Co-authored-by: Marcus Notheis <[email protected]>
1 parent 940597d commit 1df7924

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../../components/VersionSwitch.js';
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { IconButton } from '@storybook/components';
2+
import { addons, types } from '@storybook/manager-api';
3+
import { ActionSheet, Button, ThemeProvider } from '@ui5/webcomponents-react';
4+
import * as React from 'react';
5+
6+
const ADDON_ID = 'version-switch';
7+
const TOOL_ID = `${ADDON_ID}/toolbar`;
8+
9+
addons.register(ADDON_ID, (api) => {
10+
addons.add(TOOL_ID, {
11+
type: types.TOOLEXTRA,
12+
title: 'Version Switch',
13+
render: () => {
14+
const [open, setOpen] = React.useState(false);
15+
16+
const handleVersionSelect = (e) => {
17+
const { slug } = e.target.dataset;
18+
window.location.href = `https://sap.github.io/ui5-webcomponents-react/${slug}/`;
19+
};
20+
21+
const activeVersionSlug =
22+
window.location.pathname.replace('/ui5-webcomponents-react/', '').replaceAll('/', '') || 'nightly';
23+
const activeVersion = activeVersionSlug.at(0).toUpperCase() + activeVersionSlug.slice(1);
24+
return (
25+
<ThemeProvider>
26+
<IconButton
27+
active
28+
key={TOOL_ID}
29+
id={TOOL_ID}
30+
title="Version Switch"
31+
style={{ order: -1 }}
32+
onClick={() => {
33+
setOpen(true);
34+
}}
35+
>
36+
Version: {activeVersion}
37+
</IconButton>
38+
<ActionSheet
39+
placementType="Bottom"
40+
open={open}
41+
opener={TOOL_ID}
42+
onAfterClose={() => {
43+
setOpen(false);
44+
}}
45+
>
46+
<Button onClick={handleVersionSelect} data-slug={'v2'}>
47+
Version 2
48+
</Button>
49+
<Button onClick={handleVersionSelect} data-slug={'v1'}>
50+
Version 1
51+
</Button>
52+
<Button onClick={handleVersionSelect} data-slug={'nightly'}>
53+
🚧 Nightly
54+
</Button>
55+
</ActionSheet>
56+
</ThemeProvider>
57+
);
58+
}
59+
});
60+
});

.storybook/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { isChromatic } from './utils';
66
const isDevMode = process.env.NODE_ENV === 'development';
77

88
const addons = [
9+
'./addons/version-switch',
910
{
1011
name: '@storybook/addon-essentials',
1112
options: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"start:storybook": "storybook dev -p 6006",
1212
"setup": "lerna run build:i18n && lerna run build:css && lerna run build:css-bundle && rimraf node_modules/@types/mocha",
1313
"build": "yarn setup && tsc --build && lerna run build:client && lerna run build:wrapper && lerna run build:ssr",
14-
"build:storybook": "lerna run build:i18n && yarn create-cypress-commands-docs && storybook build -o .out",
14+
"build:storybook": "yarn build && yarn create-cypress-commands-docs && storybook build -o .out",
1515
"build:storybook-sitemap": "node ./scripts/create-storybook-sitemap.js --directory .out",
1616
"test:prepare": "rimraf temp && lerna run build",
1717
"test:cypress": "cypress run --component --browser chrome",

0 commit comments

Comments
 (0)