Skip to content

docs: create version switch toolbar button (v1) #6271

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 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .storybook/addons/version-switch/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../components/VersionSwitch.js';
60 changes: 60 additions & 0 deletions .storybook/components/VersionSwitch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { IconButton } from '@storybook/components';
import { addons, types } from '@storybook/manager-api';
import { ActionSheet, Button, ThemeProvider } from '@ui5/webcomponents-react';
import * as React from 'react';

const ADDON_ID = 'version-switch';
const TOOL_ID = `${ADDON_ID}/toolbar`;

addons.register(ADDON_ID, (api) => {
addons.add(TOOL_ID, {
type: types.TOOLEXTRA,
title: 'Version Switch',
render: () => {
const [open, setOpen] = React.useState(false);

const handleVersionSelect = (e) => {
const { slug } = e.target.dataset;
window.location.href = `https://sap.github.io/ui5-webcomponents-react/${slug}/`;
};

const activeVersionSlug =
window.location.pathname.replace('/ui5-webcomponents-react/', '').replaceAll('/', '') || 'nightly';
const activeVersion = activeVersionSlug.at(0).toUpperCase() + activeVersionSlug.slice(1);
return (
<ThemeProvider>
<IconButton
active
key={TOOL_ID}
id={TOOL_ID}
title="Version Switch"
style={{ order: -1 }}
onClick={() => {
setOpen(true);
}}
>
Version: {activeVersion}
</IconButton>
<ActionSheet
placementType="Bottom"
open={open}
opener={TOOL_ID}
onAfterClose={() => {
setOpen(false);
}}
>
<Button onClick={handleVersionSelect} data-slug={'v2'}>
Version 2
</Button>
<Button onClick={handleVersionSelect} data-slug={'v1'}>
Version 1
</Button>
<Button onClick={handleVersionSelect} data-slug={'nightly'}>
🚧 Nightly
</Button>
</ActionSheet>
</ThemeProvider>
);
}
});
});
1 change: 1 addition & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isChromatic } from './utils';
const isDevMode = process.env.NODE_ENV === 'development';

const addons = [
'./addons/version-switch',
{
name: '@storybook/addon-essentials',
options: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start:storybook": "storybook dev -p 6006",
"setup": "lerna run build:i18n && lerna run build:css && lerna run build:css-bundle && rimraf node_modules/@types/mocha",
"build": "yarn setup && tsc --build && lerna run build:client && lerna run build:wrapper && lerna run build:ssr",
"build:storybook": "lerna run build:i18n && yarn create-cypress-commands-docs && storybook build -o .out",
"build:storybook": "yarn build && yarn create-cypress-commands-docs && storybook build -o .out",
"build:storybook-sitemap": "node ./scripts/create-storybook-sitemap.js --directory .out",
"test:prepare": "rimraf temp && lerna run build",
"test:cypress": "cypress run --component --browser chrome",
Expand Down
Loading