-
Notifications
You must be signed in to change notification settings - Fork 21
feat(internet-header): allow to use p tags instead of heading tags #5907
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
Open
gfellerph
wants to merge
2
commits into
main
Choose a base branch
from
5620-remove-h-tags-from-post-header
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
| --- | ||
| '@swisspost/design-system-components': minor | ||
| '@swisspost/design-system-documentation': minor | ||
| --- | ||
|
|
||
| Added the possibility to use paragraphs instead of headings for the post-header component. This enables project to fully control the heading structure of the document. |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import type { StoryObj } from '@storybook/web-components-vite'; | ||
| import { MetaComponent } from '@root/types'; | ||
| import { html } from 'lit'; | ||
| import { nothing } from 'lit'; | ||
| import { fakeContent } from '@/utils'; | ||
| import { html, unsafeStatic } from 'lit/static-html.js'; | ||
|
|
||
| const meta: MetaComponent = { | ||
| id: '27a2e64d-55ba-492d-ab79-5f7c5e818498', | ||
|
|
@@ -20,6 +21,7 @@ const meta: MetaComponent = { | |
| title: 'Application title', | ||
| metaNavigation: true, | ||
| customControls: true, | ||
| useHeadings: false, | ||
| }, | ||
| argTypes: { | ||
| title: { | ||
|
|
@@ -42,6 +44,17 @@ const meta: MetaComponent = { | |
| category: 'Content', | ||
| }, | ||
| }, | ||
| useHeadings: { | ||
| name: 'Use headings', | ||
| description: 'Whether or not to use headings for the title and megadropdown titles.', | ||
| control: { | ||
| type: 'boolean', | ||
| }, | ||
| table: { | ||
| category: 'Content', | ||
| }, | ||
| defaultValue: { summary: true }, | ||
|
||
| }, | ||
| customControls: { | ||
| name: 'Custom controls', | ||
| description: 'Whether or not the custom controls are displayed ("search" and "login").', | ||
|
|
@@ -65,6 +78,35 @@ export default meta; | |
|
|
||
| type Story = StoryObj; | ||
|
|
||
| /** | ||
| * Get the heading element based on the provided parameters. | ||
| * @param useHeadings Whether to use semantic headings (h1, h2, etc.) or not. | ||
| * @param headingLevel The level of the heading (e.g., "h1", "h2", etc.). | ||
| * @param content The content to be displayed inside the heading. | ||
| * @param attributes Additional attributes to be added to the heading element. | ||
| * @returns A TemplateResult representing the heading element. | ||
| */ | ||
| const getHeading = ( | ||
| useHeadings: boolean, | ||
| headingLevel: string, | ||
| content: string, | ||
| attributes?: Record<string, string>, | ||
| ) => { | ||
| const attrs = attributes | ||
| ? unsafeStatic( | ||
| Object.entries(attributes) | ||
| .map(([key, value]) => `${key}="${value}"`) | ||
| .join(' '), | ||
| ) | ||
| : ''; | ||
|
|
||
| const headingTag = unsafeStatic(headingLevel); | ||
|
|
||
| return useHeadings | ||
| ? html`<${headingTag} ${attrs}>${unsafeStatic(content)}</${headingTag}>` | ||
| : html`<p class="${headingLevel}" ${attrs}>${unsafeStatic(content)}</p>`; | ||
| }; | ||
|
|
||
| export const Default: Story = { | ||
| render: args => { | ||
| return html`<post-header> | ||
|
|
@@ -103,11 +145,9 @@ export const Default: Story = { | |
| </post-language-switch> | ||
|
|
||
| ${args.title | ||
| ? html` | ||
| <!-- Application title (optional) --> | ||
| <h1 slot="title">${args.title}</h1> | ||
| ` | ||
| : ''} | ||
| ? html` <!-- Application title (optional) --> | ||
| ${getHeading(args.useHeadings, 'h1', args.title, { slot: 'title' })}` | ||
| : nothing} | ||
| ${args.customControls | ||
| ? html` | ||
| <!-- Custom content (optional) --> | ||
|
|
@@ -134,7 +174,8 @@ export const Default: Story = { | |
| <post-icon aria-hidden="true" name="arrowleft"></post-icon> Back | ||
| </button> | ||
| <post-list title-hidden=""> | ||
| <h2>Main Navigation</h2> | ||
| ${getHeading(args.useHeadings, 'h2', 'Main Navigation')} | ||
|
|
||
| <!-- Link only level 1 --> | ||
| <post-list-item slot="post-list-item"><a href="/letters">Letters</a></post-list-item> | ||
| <post-list-item slot="post-list-item"><a href="/packages">Packages</a></post-list-item> | ||
|
|
@@ -148,9 +189,12 @@ export const Default: Story = { | |
| Back | ||
| </button> | ||
| <post-closebutton slot="close-button">Close</post-closebutton> | ||
| <h2 slot="megadropdown-title">Letters title</h2> | ||
|
|
||
| ${getHeading(args.useHeadings, 'h2', 'Letters title', { | ||
| slot: 'megadropdown-title', | ||
| })} | ||
| <post-list> | ||
| <h3>Send letters</h3> | ||
| ${getHeading(args.useHeadings, 'h3', 'Send letters')} | ||
| <post-list-item slot="post-list-item" | ||
| ><a href="/sch">Letters Switzerland</a></post-list-item | ||
| > | ||
|
|
@@ -163,7 +207,7 @@ export const Default: Story = { | |
| > | ||
| </post-list> | ||
| <post-list> | ||
| <h3><a href="/step-by-step">Step by step</a></h3> | ||
| ${getHeading(args.useHeadings, 'h3', '<a href="/step-by-step">Step by step</a>')} | ||
| <post-list-item slot="post-list-item" | ||
| ><a href="/sch">Packages Switzerland</a></post-list-item | ||
| > | ||
|
|
@@ -185,9 +229,12 @@ export const Default: Story = { | |
| Back | ||
| </button> | ||
| <post-closebutton slot="close-button">Close</post-closebutton> | ||
| <h2 slot="megadropdown-title">Packages title</h2> | ||
|
|
||
| ${getHeading(args.useHeadings, 'h2', 'Packages title', { | ||
| slot: 'megadropdown-title', | ||
| })} | ||
| <post-list> | ||
| <h3>Send packages</h3> | ||
| ${getHeading(args.useHeadings, 'h3', 'Send packages')} | ||
| <post-list-item slot="post-list-item" | ||
| ><a href="/sch">Packages Switzerland</a></post-list-item | ||
| > | ||
|
|
@@ -200,7 +247,7 @@ export const Default: Story = { | |
| > | ||
| </post-list> | ||
| <post-list> | ||
| <h3><a href="/step-by-step">Step by step</a></h3> | ||
| ${getHeading(args.useHeadings, 'h3', '<a href="/step-by-step">Step by step</a>')} | ||
| <post-list-item slot="post-list-item" | ||
| ><a href="/sch">Packages Switzerland</a></post-list-item | ||
| > | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it's a bit dangerous to let people put whichever class they want here. In our CSS for instance, we set
.megadropdown h2, .megadropdown > h2todisplay: noneand letting users choose which title size they want might result in a hidden title. Also, it opens the possibility for users to derive from the intended design.What do you think? Should we skip those classes and target the "fake" headings another way in CSS?