Skip to content

Commit

Permalink
feat(documentation): add possibility to open all demos full screen (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alizedebray authored Aug 30, 2023
1 parent ceb9cb1 commit 0e8e27b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-apes-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-documentation': patch
---

Added the possibility to open each demo in full screen.
1 change: 1 addition & 0 deletions packages/documentation/.storybook/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './bages-config';
export * from './open-full-screen-demo';
export * from './prettier-options';
export * from './reset-sb-styled-components';
12 changes: 12 additions & 0 deletions packages/documentation/.storybook/helpers/open-full-screen-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const openFullScreenDemo = (e: Event) => {
const target = e.target as HTMLButtonElement;
const canvas = target.closest('.docs-story');
const story = canvas?.querySelector('.sb-story');
const iframeId = story?.id?.replace('story--', '');

if (iframeId) {
window.open(`/iframe.html?id=${iframeId}`,'_blank');
} else {
alert('The full screen demo is not available.');
}
};
12 changes: 10 additions & 2 deletions packages/documentation/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Preview } from '@storybook/web-components';
import './cypress-storybook/client';
import { extractArgTypes } from '@pxtrn/storybook-addon-docs-stencil';
import { format } from 'prettier';
import DocsLayout from './blocks/layout';
import { badgesConfig, prettierOptions, resetComponents } from './helpers';
import { badgesConfig, openFullScreenDemo, prettierOptions, resetComponents } from './helpers';
import './helpers/register-web-components';
import './cypress-storybook/client';

import './styles/preview.scss';

Expand Down Expand Up @@ -46,6 +46,14 @@ const preview: Preview = {
},
docs: {
container: DocsLayout,
canvas: {
additionalActions: [
{
title: 'View full screen',
onClick: openFullScreenDemo,
},
],
},
source: {
excludeDecorators: true,
transform: (snippet: string) => format(snippet, prettierOptions),
Expand Down

0 comments on commit 0e8e27b

Please sign in to comment.