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(internet-header,docs): improve and document the internet header main slot #2280

Merged
merged 22 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3cb10a3
feat(internet-header): update main slot
alizedebray Nov 16, 2023
addfa59
feat(docs): documentation the internet-header main slot
alizedebray Nov 16, 2023
ed8c7bc
feat(internet-header): add e2e tests for the main slot
alizedebray Nov 17, 2023
5c30ac6
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
alizedebray Nov 17, 2023
32d03ad
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
alizedebray Nov 20, 2023
1f67189
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
gfellerph Nov 21, 2023
30d3915
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
alizedebray Nov 27, 2023
fca43bb
chore(internet-header): apply changes
alizedebray Nov 27, 2023
d2c4f71
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
alizedebray Nov 29, 2023
9f074b0
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
alizedebray Nov 29, 2023
9ca3f10
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
imagoiq Nov 30, 2023
8fecd43
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
imagoiq Nov 30, 2023
df3fbb7
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
imagoiq Nov 30, 2023
422fcd1
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
imagoiq Dec 5, 2023
16c1bfd
Update packages/internet-header/src/components/post-internet-header/p…
alizedebray Dec 11, 2023
1ca1d4e
Update packages/internet-header/src/components/post-internet-header/p…
alizedebray Dec 11, 2023
ef95df8
remove innerHTML control
alizedebray Dec 11, 2023
df110ba
Merge branch '2048-header-re-animate-and-document-main-slot' of https…
alizedebray Dec 11, 2023
cfc1fca
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
alizedebray Dec 11, 2023
2138132
update story title
alizedebray Dec 11, 2023
52a2a75
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
alizedebray Dec 20, 2023
9066900
Merge branch 'main' into 2048-header-re-animate-and-document-main-slot
alizedebray Jan 4, 2024
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
5 changes: 5 additions & 0 deletions .changeset/clean-dodos-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/internet-header': patch
---

Improve the main navigation slot placement and styling.
5 changes: 5 additions & 0 deletions .changeset/many-pets-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-documentation': minor
---

Add a page on how to add custom content to the internet header main navigation.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Args, Meta, StoryObj } from '@storybook/web-components';
import { BADGE } from '../../../../../../.storybook/constants';
import { html } from 'lit';
import { spread } from '@open-wc/lit-helpers';
import { getAttributes } from '../../../../../utils';
import { spreadArgs } from '../../../../../utils';
import customConfig from './config/custom-config';
import osFlyoutOverrides from './config/os-flyout-overrides';
import languageSwitchOverrides from './config/language-switch-overrides';
Expand Down Expand Up @@ -172,10 +171,9 @@ const meta: Meta = {
],
};

function render(args: Args) {
const attributes = getAttributes(args, arg => arg !== null && arg !== undefined);
function render({ innerHMTL, ...args }: Args) {
return html`
<swisspost-internet-header ${spread(attributes)}></swisspost-internet-header>
<swisspost-internet-header ${spreadArgs(args)}></swisspost-internet-header>
`;
}

Expand Down Expand Up @@ -217,3 +215,9 @@ export const OSFlyoutOverrides: Story = {
},
},
};

export const CustomContent: Story = {
args: {
innerHTML: `<p class="mx-regular mb-0" slot="main">Hello, User!</p>`,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Meta, Canvas, Controls } from '@storybook/blocks';
import * as HeaderStories from './header-custom-content.stories';
import '../header.scss';

<Meta of={HeaderStories} />

<div className="container">
<h1>Internet Header with Custom Content</h1>
<p className="lead">When you need to add your own content to the main navigation.</p>
</div>

<Canvas of={HeaderStories.Default} sourceState='shown' />
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as HeaderStories from '../header.stories';

export default {
...HeaderStories.default,
title: 'Components/Internet Header/Header/Custom Content',
};

export const Default = HeaderStories.CustomContent;
101 changes: 101 additions & 0 deletions packages/internet-header/cypress/e2e/main-slot.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { prepare } from '../support/prepare-story';

describe('main-navigation', () => {
describe('slotted element: false', () => {
beforeEach(() => {
prepare('Internet Header/Header', 'Default');
});

it('should not have any custom content', () => {
cy.get('swisspost-internet-header').find('[slot=main]').should('not.exist');
cy.get('swisspost-internet-header')
.shadow()
.find('.main-navigation-custom-content')
.should('not.exist');
});
});

describe('slotted element: true', () => {
beforeEach(() => {
prepare('Internet Header/Header/Custom Content', 'Default');

cy.get('swisspost-internet-header').find('[slot=main]').as('slotted-element');
cy.get('swisspost-internet-header')
.shadow()
.find('.main-navigation-custom-content')
.as('custom-content');
});

it('should have custom content', () => {
cy.get('@slotted-element').should('exist');
cy.get('@custom-content').should('exist');
});

it('should show custom content on mobile', () => {
cy.viewport('iphone-6+');
cy.get('@custom-content').should('exist');
});

it('should show custom content before the search', () => {
cy.get('@custom-content').next().should('have.prop', 'tagName').should('eq', 'POST-SEARCH');
});

it('should show custom content before the login when the search is disabled', () => {
cy.changeArg('search', false);

cy.get('@custom-content')
.next()
.should('have.prop', 'tagName')
.should('eq', 'POST-KLP-LOGIN-WIDGET');
});

it('should show custom content before the language switch when the search, login and meta are disabled', () => {
cy.changeArg('meta', false);
cy.changeArg('search', false);
cy.changeArg('login', false);

cy.get('@custom-content')
.next()
.should('have.prop', 'tagName')
.should('eq', 'POST-LANGUAGE-SWITCH');
});

it('should show a border on the left of the custom content', () => {
cy.get('@custom-content').should('not.have.css', 'border-left-width', '0px');
});

it('should not stretched the header when the slotted element is high', () => {
cy.get('@custom-content')
.invoke('outerHeight')
.then(headerHeight => {
if (typeof headerHeight === 'undefined')
throw new Error('No Height found for .main-navigation-custom-content');

cy.get('@slotted-element').invoke('css', 'height', `${headerHeight + 100}px`);
cy.get('@custom-content').invoke('outerHeight').should('eq', headerHeight);
});
});

it('should not squash other navigation elements when the slotted element is wide', async () => {
cy.document().then(document => {
cy.get('@slotted-element').invoke('css', 'width', `${document.body.clientWidth}px`);
});

cy.get('swisspost-internet-header')
.shadow()
.get('#post-internet-header-search-button, #post-klp-login-widget')
.then($navigationControls => {
cy.get('.main-link').then($mainLinks =>
$mainLinks.toArray().concat($navigationControls.toArray()),
);
})
.each($el => {
cy.wrap($el).should(() => {
const { scrollWidth, clientWidth } = $el.get(0);
expect(clientWidth).not.to.equal(0);
expect(scrollWidth).not.to.be.greaterThan(clientWidth);
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
display: flex;

& > .main-navigation-controls {
flex: 0 0 auto;
flex: 0 1 auto;
}
}

Expand Down Expand Up @@ -108,9 +108,17 @@

& > * {
border-left: 1px solid color.$gray-10;
flex: 0 0 auto;
}
}

.main-navigation-custom-content {
max-height: var(--header-height);
display: flex;
align-items: center;
flex-shrink: 1;
}

.menu-button {
display: flex;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class PostInternetHeader {

@State() activeFlyout: string | null = null;
@State() activeDropdownElement: DropdownElement | null = null;
@State() isMainSlotEmpty = true;
@Element() host: HTMLSwisspostInternetHeaderElement;

/**
Expand Down Expand Up @@ -431,6 +432,11 @@ export class PostInternetHeader {
);
}

private handleMainSlotChange(e: Event) {
const mainSlot = e.target as HTMLSlotElement;
this.isMainSlotEmpty = mainSlot.assignedElements().length === 0;
}

render() {
if (!state.localizedConfig?.header) {
console.error(new Error('Internet Header: Config cannot be loaded'));
Expand Down Expand Up @@ -505,6 +511,9 @@ export class PostInternetHeader {
</If>
</post-main-navigation>
<div class="main-navigation-controls">
<div class="main-navigation-custom-content" hidden={this.isMainSlotEmpty}>
<slot name="main" onSlotchange={e => this.handleMainSlotChange(e)}></slot>
</div>
<If condition={this.search}>
<post-search onDropdownToggled={e => this.handleDropdownToggled(e)}></post-search>
</If>
Expand All @@ -520,7 +529,6 @@ export class PostInternetHeader {
mode="dropdown"
></post-language-switch>
</If>
<slot name="main"></slot>
</div>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
display: block;
min-width: 0;
height: var(--header-height);
flex-shrink: 0;
}

:host(.no-animation) {
Expand Down
30 changes: 15 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading