-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat(components): create post-list component #3812
Open
myrta2302
wants to merge
44
commits into
main
Choose a base branch
from
3544-component-list
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 all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
0fb21fa
Merge branch 'main' into chore/2884-switch-hydrated-selector-from-cla…
oliverschuerch 4bcf3c2
chore(components): switch hydrated flag from class to attribute
oliverschuerch 6c13f1d
chore(documentation): remove unnecessary card-control specific docs s…
oliverschuerch eed1543
chore(documentation): remove hydrated class in popover stories
oliverschuerch 47877e4
chore(documentation): remove hydrated class in tooltip stories
oliverschuerch e1fe416
refactor(documentation): replace hydrated class selector with data-hy…
oliverschuerch 019c0e6
chore(header): update stencil.config so it uses the attribute data-hy…
oliverschuerch 4839b44
refactor(documentation): update header e2e and snapshot tests, so the…
oliverschuerch 291b98e
test(header): update tests, so they use the attribute data-hydrated i…
oliverschuerch d5b13e9
test(documentation): update custom commands `getComponents` and `getS…
oliverschuerch e269d75
chore: add changesets
oliverschuerch b2914cd
Merge branch 'main' into chore/2884-switch-hydrated-selector-from-cla…
oliverschuerch 16c1016
feat(components): create post-list / post-list-item component
myrta2302 f4e3f4f
Update post-list-item.tsx
myrta2302 714f1dc
Update post-list.scss
myrta2302 3d36361
Update post-list.tsx
myrta2302 8d7a1ec
removed comments
myrta2302 116f04e
Merge branch '3544-component-list' of https://github.com/swisspost/de…
myrta2302 6f2ed41
restored h
myrta2302 265597f
Merge branch 'main' into 3544-component-list
myrta2302 19b9f7d
Revert index.html
myrta2302 27534b4
revert index.html
myrta2302 fa111f2
Update .changeset/fast-bats-poke.md
myrta2302 b98702d
Update packages/components/src/components/post-list-item/post-list-it…
myrta2302 ba074af
Update packages/components/src/components/post-list/post-list.tsx
myrta2302 3d08b64
Update packages/documentation/src/stories/components/list/list.snapsh…
myrta2302 8ec6731
Update packages/documentation/src/stories/components/list/list.storie…
myrta2302 b5f8ec2
Update packages/documentation/src/stories/components/list/list.storie…
myrta2302 3fed679
review comments updates
myrta2302 e8b9e27
review comments update
myrta2302 894a6b4
Merge branch 'main' into 3544-component-list
myrta2302 b915f96
merged to main
myrta2302 ad56068
removed file
myrta2302 4219a99
Delete packages/styles/src/components/validation.scss
myrta2302 4f82b32
fix linting errors
myrta2302 f20110e
review comments update
myrta2302 22e7f79
Merge branch 'main' into 3544-component-list
alizedebray 2c7d761
review comments update
myrta2302 7bf44b2
removed index.html change
myrta2302 f677f24
review comments update
myrta2302 6c8b70d
Revert "review comments update"
myrta2302 53dc609
review comments update
myrta2302 4ad3dfa
restored id
myrta2302 00f1c2e
Merge branch 'main' into 3544-component-list
myrta2302 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 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-documentation': minor | ||
'@swisspost/design-system-components': minor | ||
--- | ||
|
||
Created the `post-list` and `post-list-item` components. |
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,60 @@ | ||
describe('PostList Component', { baseUrl: null, includeShadowDom: false }, () => { | ||
beforeEach(() => { | ||
// Visit the page where the component is rendered | ||
cy.visit('./cypress/fixtures/post-list.test.html'); | ||
}); | ||
|
||
it('should render the post-list component', () => { | ||
// Check if the post-list component is rendered | ||
cy.get('post-list').should('exist'); | ||
}); | ||
|
||
it('should have an id for the first div in post-list', () => { | ||
// Ensure the first div inside post-list has an id attribute | ||
cy.get('post-list') | ||
.find('div') | ||
.first() | ||
.should('have.attr', 'id') | ||
.and('not.be.empty') | ||
.then($div => { | ||
const id = $div['id']; | ||
cy.log(`First div ID: ${id}`); | ||
}); | ||
}); | ||
|
||
it('should throw an error if the title is missing', () => { | ||
// Check for the mandatory title accessibility error if no title is provided | ||
cy.on('uncaught:exception', err => { | ||
expect(err.message).to.include( | ||
'Please provide a title to the list component. Title is mandatory for accessibility purposes.', | ||
); | ||
return false; | ||
}); | ||
cy.get('post-list').within(() => { | ||
cy.get('[slot="post-list-item"]').first().invoke('remove'); | ||
}); | ||
}); | ||
|
||
it('should hide the title when title-hidden is set', () => { | ||
// Set the `title-hidden` property and check if the title is hidden | ||
cy.get('post-list').invoke('attr', 'title-hidden', true); | ||
cy.get('post-list div').first().should('have.class', 'visually-hidden'); | ||
}); | ||
|
||
it('should render horizontally when the horizontal attribute is set', () => { | ||
// Set the `horizontal` property and verify if the list has a horizontal layout | ||
cy.get('post-list').invoke('attr', 'horizontal', true); | ||
cy.get('post-list').should('have.attr', 'horizontal', 'true'); | ||
}); | ||
|
||
it('should ensure post-list-item components have the correct slot and role', () => { | ||
// Verify that the `post-list-item` components have the correct slot and role attributes | ||
cy.get('post-list').within(() => { | ||
cy.get('post-list-item').each($el => { | ||
cy.wrap($el) | ||
.should('have.attr', 'slot', 'post-list-item') | ||
.and('have.attr', 'role', 'listitem'); | ||
}); | ||
}); | ||
}); | ||
}); |
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,19 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Document</title> | ||
<script src="../../dist/post-components/post-components.esm.js" type="module"></script> | ||
</head> | ||
<body> | ||
<post-list> | ||
<h3>TITLE</h3> | ||
<post-list-item><post-tag>Title 1</post-tag></post-list-item> | ||
<post-list-item><post-tag>Title 2</post-tag></post-list-item> | ||
<post-list-item><post-tag>Title 3</post-tag></post-list-item> | ||
<post-list-item><post-tag>Title 4</post-tag></post-list-item> | ||
<post-list-item><post-tag>Title 5</post-tag></post-list-item> | ||
</post-list> | ||
</body> | ||
</html> |
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
3 changes: 3 additions & 0 deletions
3
packages/components/src/components/post-list-item/post-list-item.scss
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,3 @@ | ||
:host { | ||
display: flex; | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/components/src/components/post-list-item/post-list-item.tsx
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,26 @@ | ||
import { Component, Element, Host, h } from '@stencil/core'; | ||
|
||
/** | ||
* @slot default- Slot for placing the content of the list item. | ||
*/ | ||
|
||
@Component({ | ||
tag: 'post-list-item', | ||
styleUrl: 'post-list-item.scss', | ||
shadow: true, | ||
}) | ||
export class PostListItem { | ||
@Element() host: HTMLPostListItemElement; | ||
|
||
connectedCallback() { | ||
this.host.setAttribute('slot', 'post-list-item'); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Host role="listitem"> | ||
<slot></slot> | ||
</Host> | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/components/src/components/post-list-item/readme.md
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,17 @@ | ||
# post-list-item | ||
|
||
|
||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
## Slots | ||
|
||
| Slot | Description | | ||
| ----------------------------------------------------------- | ----------- | | ||
| `"default- Slot for placing the content of the list item."` | | | ||
|
||
|
||
---------------------------------------------- | ||
|
||
*Built with [StencilJS](https://stenciljs.com/)* |
27 changes: 27 additions & 0 deletions
27
packages/components/src/components/post-list/post-list.scss
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,27 @@ | ||
@use '@swisspost/design-system-styles/core' as post; | ||
|
||
post-list { | ||
display: flex; | ||
gap: var(--post-list-title-gap); | ||
flex-direction: column; | ||
align-items: flex-start; | ||
|
||
& > div[role='list'] { | ||
flex-direction: column; | ||
display: flex; | ||
gap: var(--post-list-item-gap); | ||
} | ||
|
||
&[horizontal]:not([horizontal='false']) { | ||
flex-direction: row; | ||
align-items: baseline; | ||
& > div[role='list'] { | ||
flex-direction: row; | ||
align-items: center; | ||
} | ||
} | ||
|
||
> .list-title.visually-hidden { | ||
@include post.visually-hidden(); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
packages/components/src/components/post-list/post-list.tsx
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,69 @@ | ||||||
import { Component, Element, Prop, Host, State, h } from '@stencil/core'; | ||||||
import { version } from '@root/package.json'; | ||||||
|
||||||
/** | ||||||
* @slot default - Slot for placing the list title. | ||||||
* @slot post-list-item - Slot for placing post-list-item components. | ||||||
*/ | ||||||
|
||||||
@Component({ | ||||||
tag: 'post-list', | ||||||
styleUrl: 'post-list.scss', | ||||||
shadow: false, | ||||||
}) | ||||||
export class PostList { | ||||||
@Element() host: HTMLPostListElement; | ||||||
|
||||||
/** | ||||||
* The unique title of the list that is also referenced in the labelledby | ||||||
*/ | ||||||
@State() uuid: string; | ||||||
|
||||||
/** | ||||||
* If `true`, the list title will be hidden. Otherwise, it will be displayed.` | ||||||
*/ | ||||||
@Prop() readonly titleHidden: boolean = false; | ||||||
|
||||||
/** | ||||||
* The list can become horizontal by setting `horizontal="true"` or just `horizontal` | ||||||
*/ | ||||||
@Prop() readonly horizontal: boolean = false; | ||||||
|
||||||
titleEl: HTMLElement; | ||||||
|
||||||
componentWillLoad() { | ||||||
/** | ||||||
* Get the id set on the host element or use a random id by default | ||||||
*/ | ||||||
this.uuid = `list-${crypto.randomUUID()}`; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
componentDidLoad() { | ||||||
this.checkTitle(); | ||||||
} | ||||||
|
||||||
private checkTitle() { | ||||||
if (!this.titleEl.innerText) { | ||||||
throw new Error( | ||||||
'Please provide a title to the list component. Title is mandatory for accessibility purposes.', | ||||||
); | ||||||
} | ||||||
} | ||||||
|
||||||
render() { | ||||||
return ( | ||||||
<Host data-version={version}> | ||||||
<div | ||||||
ref={el => (this.titleEl = el)} | ||||||
id={this.uuid} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
class={`list-title${this.titleHidden ? ' visually-hidden' : ''}`} | ||||||
> | ||||||
<slot></slot> | ||||||
</div> | ||||||
<div role="list" aria-labelledby={this.uuid}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<slot name="post-list-item"></slot> | ||||||
</div> | ||||||
</Host> | ||||||
); | ||||||
} | ||||||
} |
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,26 @@ | ||
# post-list | ||
|
||
|
||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
## Properties | ||
|
||
| Property | Attribute | Description | Type | Default | | ||
| ------------- | -------------- | ---------------------------------------------------------------------------------- | --------- | ------- | | ||
| `horizontal` | `horizontal` | The list can become horizontal by setting `horizontal="true"` or just `horizontal` | `boolean` | `false` | | ||
| `titleHidden` | `title-hidden` | If `true`, the list title will be hidden. Otherwise, it will be displayed.` | `boolean` | `false` | | ||
|
||
|
||
## Slots | ||
|
||
| Slot | Description | | ||
| ------------------ | ------------------------------------------- | | ||
| `"default"` | Slot for placing the list title. | | ||
| `"post-list-item"` | Slot for placing post-list-item components. | | ||
|
||
|
||
---------------------------------------------- | ||
|
||
*Built with [StencilJS](https://stenciljs.com/)* |
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
7 changes: 7 additions & 0 deletions
7
packages/documentation/cypress/snapshots/components/list.snapshot.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,7 @@ | ||
describe('List', () => { | ||
it('default', () => { | ||
cy.visit('/iframe.html?id=snapshots--list'); | ||
cy.get('post-list', { timeout: 30000 }).should('be.visible'); | ||
cy.percySnapshot('List', { widths: [1440] }); | ||
}); | ||
}); |
Oops, something went wrong.
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.