Skip to content
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

chore(documentation-v7): migrate the internet header component stories #1822

Merged
merged 16 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
c5e25e5
chore(documentation-v7): add internet-header stories
alizedebray Jul 31, 2023
0c05776
feat: use docs.json for generated controls
gfellerph Aug 7, 2023
e9109a1
Merge branch 'main' into 1700-migrate-the-internet-header-component-s…
alizedebray Aug 11, 2023
f0a43c8
chore(documentation-v7): remove docs-json for internet header
alizedebray Aug 11, 2023
8b701dd
chore(documentation-v7): add internet header stories to the docs
alizedebray Aug 14, 2023
9008c23
Merge branch 'main' into 1700-migrate-the-internet-header-component-s…
alizedebray Aug 14, 2023
50b5c9e
fix(documentation-v7): add proper typings
alizedebray Aug 14, 2023
04acbe3
fix(documentation-v7): show stories in docs
alizedebray Aug 17, 2023
3448b39
Merge branch 'main' into 1700-migrate-the-internet-header-component-s…
alizedebray Aug 17, 2023
20dada4
fix(documentation-v7): remove copyrights
alizedebray Aug 17, 2023
22131aa
fix(documentation-v7): use ArgTypes instead of Controls
alizedebray Aug 17, 2023
6d9cd3f
Update packages/documentation-v7/src/stories/internet-header/migratio…
gfellerph Aug 17, 2023
de06430
Update packages/documentation-v7/src/stories/internet-header/migratio…
gfellerph Aug 17, 2023
d577bff
Update packages/documentation-v7/src/stories/internet-header/migratio…
gfellerph Aug 17, 2023
545717f
Update packages/documentation-v7/src/stories/internet-header/migratio…
gfellerph Aug 17, 2023
54edf58
Update packages/documentation-v7/src/stories/internet-header/migratio…
gfellerph Aug 17, 2023
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
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { defineCustomElements, JSX as LocalJSX } from '@swisspost/design-system-components/loader';
import { HTMLAttributes } from 'react';
import { defineCustomElements as defineInternetHeader } from '@swisspost/internet-header/loader';
import { defineCustomElements as definePostComponent } from '@swisspost/design-system-components/loader';
import { setStencilDocJson } from '@pxtrn/storybook-addon-docs-stencil';
import { StencilJsonDocs, StencilJsonDocsComponent } from '@pxtrn/storybook-addon-docs-stencil/dist/types';
import postComponentsDocJson from '@swisspost/design-system-components/dist/docs.json';
import internetHeaderDocJson from '@swisspost/internet-header/dist/docs.json';

type StencilToReact<T> = {
[P in keyof T]?: T[P] & Omit<HTMLAttributes<Element>, 'className'> & { class?: string };
};
defineInternetHeader(window);
definePostComponent(window);

declare global {
export namespace JSX {
interface IntrinsicElements extends StencilToReact<LocalJSX.IntrinsicElements> {}
}
}
if (postComponentsDocJson && internetHeaderDocJson) {
const jsonDocs: StencilJsonDocs = {
timestamp: postComponentsDocJson.timestamp,
compiler: postComponentsDocJson.compiler,
components: [
...postComponentsDocJson.components,
...internetHeaderDocJson.components
] as StencilJsonDocsComponent[],
};

defineCustomElements(window);
setStencilDocJson(jsonDocs);
}
14 changes: 2 additions & 12 deletions packages/documentation-v7/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { Preview } from '@storybook/web-components';

import {
extractArgTypes,
extractComponentDescription,
setStencilDocJson,
} from '@pxtrn/storybook-addon-docs-stencil';
import { StencilJsonDocs } from '@pxtrn/storybook-addon-docs-stencil/dist/types';
import { extractArgTypes, extractComponentDescription } from '@pxtrn/storybook-addon-docs-stencil';
import { format } from 'prettier';
import DocsLayout from './blocks/layout';
import { badgesConfig, prettierOptions, resetComponents } from './helpers';
Expand All @@ -18,10 +13,6 @@ import scss from 'react-syntax-highlighter/dist/esm/languages/prism/scss';

SyntaxHighlighter.registerLanguage('scss', scss);

import docJson from '@swisspost/design-system-components/dist/docs.json';

if (docJson) setStencilDocJson(docJson as StencilJsonDocs);

const preview: Preview = {
parameters: {
options: {
Expand All @@ -34,7 +25,7 @@ const preview: Preview = {
['Typography', 'Color', 'Layout', 'Elevation', 'Accessibility'],
'Components',
'Internet Header',
['Getting started', 'Migration Guide', 'Components', ['Header', 'Breadcrumbs', 'Footer']],
['Getting started', 'Migration Guide', 'Header Component', 'Breadcrumbs Component', 'Footer Component'],
'Intranet Header',
['Getting started'],
'Icons',
Expand All @@ -55,7 +46,6 @@ const preview: Preview = {
},
components: resetComponents,
extractArgTypes,
extractComponentDescription,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this line is correct or not or if you need to remove the import

},
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Canvas, ArgTypes, Meta } from '@storybook/blocks';
import * as InternetHeaderStories from './internet-header.stories';

<Meta of={InternetHeaderStories} />

# Header

<div className="lead">
Customizable navigation header tailored for Swiss Post customer-facing applications,
ensuring complete accessibility and responsiveness.
</div>

The `<swisspost-internet-header>` element needs
to be nested directly inside the `<body>` for the sticky scrolling to work.

If you want to render the header element with Angular,
have a look at [portals](https://medium.com/angular-in-depth/how-do-cdk-portals-work-7c097c14a494).

<a
className="btn btn-primary btn-animated"
href="/iframe.html?viewMode=story&id=internet-header-header-component--default"
target="_blank"
>
<span>Open Header in New Tab</span>
</a>

<Canvas of={InternetHeaderStories.Default} />

<div className="hide-col-default">
<ArgTypes of={InternetHeaderStories.Default} />
Copy link
Contributor Author

@alizedebray alizedebray Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used ArgTypes instead of Controls here because currently controls don't work on iframe demos, but an iframe is needed for the logo animation to work properly.

</div>

## Examples

### Custom Navigation Item

<Canvas of={InternetHeaderStories.CustomNavigation} />

### Custom Online Service Flyout

<Canvas of={InternetHeaderStories.CustomOnlineServiceFlyout} />

### Full Width

By default, on viewports with a width greater than 1440px, header content is padded right and left.
To make the header span the full width of the viewport, set the `full-width` property to `true`.

<a
className="btn btn-secondary btn-animated"
href="/iframe.html?viewMode=story&id=internet-header-header-component--full-width"
target="_blank"
>
<span>See Fullwidth Header</span>
</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
import { Args, Meta, StoryObj } from '@storybook/web-components';
import { html } from 'lit';
import { spread } from '@open-wc/lit-helpers';
import { BADGE } from '../../../../.storybook/constants';
import './internet-header.styles.scss';

const meta: Meta<HTMLSwisspostInternetHeaderElement> = {
title: 'Internet Header/Header Component',
component: 'swisspost-internet-header',
render: renderInternetHeader,
parameters: {
layout: 'fullscreen',
actions: {
handles: ['headerLoaded', 'languageChanged'],
},
badges: [BADGE.STABLE],
controls: {
exclude: ['config-proxy']
},
},
args: {
'project': 'test'
},
argTypes: {
activeRoute: {
name: 'active-route',
control: 'text',
},
customConfig: {
name: 'custom-config',
control: 'object',
},
language: {
control: 'select',
options: ['de', 'fr', 'it', 'en'],
},
languageCookieKey: {
name: 'language-cookie-key',
control: 'text',
},
languageLocalStorageKey: {
name: 'language-local-storage-key',
control: 'text',
},
languageSwitchOverrides: {
name: 'language-switch-overrides',
control: 'object',
},
osFlyoutOverrides: {
name: 'os-flyout-overrides',
control: 'object',
},
stickyness: {
control: 'select',
},
},
};

export default meta;

// DECORATORS
function mockPage(story: any) {
return html`
<div class="page-wrapper">
${story()}
<main class="container mt-huge-r">
<swisspost-internet-breadcrumbs/>
<h1 class="mt-huge-r mb-big-r bold">Swiss Post Internet Header</h1>
<p class="fake-content my-big"></p>
<p class="fake-content my-big"></p>
</main>
<swisspost-internet-footer/>
</div>
`;
}

// RENDERER
function renderInternetHeader(args: HTMLSwisspostInternetHeaderElement) {
const attributes = getAttributes(args, arg => arg !== null && arg !== undefined);
return html`
<swisspost-internet-header ${spread(attributes)}></swisspost-internet-header>
`;
}

// STORIES
type Story = StoryObj<HTMLSwisspostInternetHeaderElement>;

export const Default: Story = {
decorators: [ mockPage ],
parameters: {
docs: {
story: {
inline: false,
height: '40em',
},
},
},
};

export const FullWidth: Story = {
decorators: [ mockPage ],
args: {
fullWidth: true,
},
};

export const CustomNavigation: Story = {
args: {
customConfig: {
de: {
header: {
navMain: [
{
title: 'Meine Links (custom config)',
text: 'Meine Links',
url: '#',
flyout: [
{
title: 'Google',
linkList: [
{ url: 'https://maps.google.com', title: 'Google Maps', target: '_blank' },
{ url: 'https://translate.google.com', title: 'Google Translate' },
],
},
],
},
],
},
},
fr: {
header: {
navMain: [
{
title: 'Meine Links (custom config)',
text: 'Meine Links',
url: '#',
flyout: [
{
title: 'Google',
linkList: [
{ url: 'https://maps.google.com', title: 'Google Maps', target: '_blank' },
{ url: 'https://translate.google.com', title: 'Google Translate' },
],
},
],
},
],
},
},
it: {
header: {
navMain: [
{
title: 'Meine Links (custom config)',
text: 'Meine Links',
url: '#',
flyout: [
{
title: 'Google',
linkList: [
{ url: 'https://maps.google.com', title: 'Google Maps', target: '_blank' },
{ url: 'https://translate.google.com', title: 'Google Translate' },
],
},
],
},
],
},
},
en: {
header: {
navMain: [
{
title: 'Meine Links (custom config)',
text: 'Meine Links',
url: '#',
flyout: [
{
title: 'Google',
linkList: [
{ url: 'https://maps.google.com', title: 'Google Maps', target: '_blank' },
{ url: 'https://translate.google.com', title: 'Google Translate' },
],
},
],
},
],
},
},
},
},
};

export const CustomOnlineServiceFlyout: Story = {
args: {
osFlyoutOverrides: {
title: 'Custom OS Flyout',
text: 'Custom OS Flyout',
url: '#',
flyout: [
{
title: 'A title',
linkList: [
{
url: '#bla',
title: 'Another link',
},
],
},
{
title: 'Another column',
linkList: [
{
url: '#foo',
title: 'Foo',
},
],
},
],
},
},
};

// TODO: move to utils
const getAttributes = (args: Args, condition?: (arg: any) => boolean): Args => {
const attrs: { [key: string]: any } = {};

for (const key in args) {
if (args.hasOwnProperty(key) && condition && condition(args[key])) {
const attrKey = key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();

// Cast boolean false to string so it's displayed in the docs code block. False values are otherwise omitted
attrs[attrKey] = args[key] === false ? 'false' : args[key];
if (typeof args[key] === 'object') {
attrs[attrKey] = JSON.stringify(args[key]);
}
}
}

return attrs;
};
Comment on lines +224 to +241
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the move can be part of this PR

Loading
Loading