-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(internet-header,docs): improve and document the internet header…
… main slot (#2280) Co-authored-by: Philipp Gfeller <[email protected]> Co-authored-by: Loïc Fürhoff <[email protected]>
- Loading branch information
1 parent
3509aaf
commit 4d0456f
Showing
10 changed files
with
174 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ernet-header/components/header/overrides-stories/header-custom-content.docs.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' /> |
8 changes: 8 additions & 0 deletions
8
...ents/internet-header/components/header/overrides-stories/header-custom-content.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.