Skip to content

Commit 071aa94

Browse files
MarcusNotheisLukas742
authored andcommitted
docs: create version switch toolbar button (#6259)
1 parent 940597d commit 071aa94

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { IconButton } from '@storybook/components';
2+
import { addons, types } from '@storybook/manager-api';
3+
import { ActionSheet, Button } 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+
return (
21+
<>
22+
<IconButton
23+
active
24+
key={TOOL_ID}
25+
id={TOOL_ID}
26+
title="Version Switch"
27+
style={{ order: -1 }}
28+
onClick={() => {
29+
setOpen(true);
30+
}}
31+
>
32+
Version
33+
</IconButton>
34+
<ActionSheet
35+
placement="Bottom"
36+
open={open}
37+
opener={TOOL_ID}
38+
onClose={() => {
39+
setOpen(false);
40+
}}
41+
>
42+
<Button onClick={handleVersionSelect} data-slug={'v2'}>
43+
Version 2
44+
</Button>
45+
<Button onClick={handleVersionSelect} data-slug={'v1'}>
46+
Version 1
47+
</Button>
48+
<Button onClick={handleVersionSelect} data-slug={'nightly'}>
49+
🚧 Nightly
50+
</Button>
51+
</ActionSheet>
52+
</>
53+
);
54+
}
55+
});
56+
});

.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: {

0 commit comments

Comments
 (0)