-
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.
feat(components): split post-collapsible and post-accordion-item (#2379)
Co-authored-by: Loïc Fürhoff <[email protected]> Co-authored-by: Philipp Gfeller <[email protected]>
- Loading branch information
1 parent
56a62a5
commit 80594fd
Showing
23 changed files
with
392 additions
and
301 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,6 @@ | ||
--- | ||
'@swisspost/design-system-components': patch | ||
'@swisspost/design-system-styles': patch | ||
--- | ||
|
||
Update the background color of accordion to be white on any background color other than white. The accordion background remains gray on white backgrounds. |
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-components': patch | ||
--- | ||
|
||
Added a payload to the `collapseChange` event of the `post-collapsible` component. This payload is a boolean: `true` if the collapsible was opened, `false` if it was closed. |
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-components': major | ||
'@swisspost/design-system-documentation': patch | ||
--- | ||
|
||
Restricted the post-collapsible component to the collapse behaviour only and created a post-accordion-item to use as children for the post-accordion component. |
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-components': patch | ||
--- | ||
|
||
Updated the post-accordion background to be white on light and gray backgrounds. |
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
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
packages/components/src/components/post-accordion-item/post-accordion-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,22 @@ | ||
@use '@swisspost/design-system-styles/components/accordion'; | ||
@use '@swisspost/design-system-styles/mixins/accordion' as accordion-mx; | ||
|
||
:host { | ||
display: block; | ||
} | ||
|
||
.accordion-button { | ||
cursor: pointer; | ||
|
||
> ::slotted(.text-truncate) { | ||
display: block; | ||
} | ||
} | ||
|
||
post-accordion-item::part(accordion-item) { | ||
@include accordion-mx.background-color; | ||
|
||
post-accordion-item + & { | ||
border-block-start: 0!important; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
packages/components/src/components/post-accordion-item/post-accordion-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,87 @@ | ||
import { Component, Element, h, Host, Listen, Method, Prop, State, Watch } from '@stencil/core'; | ||
import { version } from '../../../package.json'; | ||
import { checkEmptyOrOneOf } from '../../utils'; | ||
import { HEADING_LEVELS, HeadingLevel } from './heading-levels'; | ||
|
||
@Component({ | ||
tag: 'post-accordion-item', | ||
styleUrl: 'post-accordion-item.scss', | ||
shadow: true, | ||
}) | ||
export class PostAccordionItem { | ||
private collapsible: HTMLPostCollapsibleElement; | ||
|
||
@Element() host: HTMLPostAccordionItemElement; | ||
|
||
@State() id: string; | ||
@State() isOpen: boolean; | ||
|
||
/** | ||
* If `true`, the element is initially collapsed otherwise it is displayed. | ||
*/ | ||
@Prop() readonly collapsed?: boolean = false; | ||
|
||
/** | ||
* Defines the hierarchical level of the accordion item header within the headings structure. | ||
*/ | ||
@Prop() readonly headingLevel?: HeadingLevel = 2; | ||
|
||
@Watch('headingLevel') | ||
validateHeadingLevel(newValue = this.headingLevel) { | ||
checkEmptyOrOneOf( | ||
newValue, | ||
HEADING_LEVELS, | ||
'The `headingLevel` property of the `post-accordion-item` must be a number between 1 and 6.', | ||
); | ||
} | ||
|
||
connectedCallback() { | ||
this.validateHeadingLevel(); | ||
} | ||
|
||
componentWillLoad() { | ||
this.isOpen = !this.collapsed; | ||
this.id = this.host.id || `a${crypto.randomUUID()}`; | ||
} | ||
|
||
@Listen('collapseChange') | ||
onCollapseChange(event: CustomEvent<boolean>): void { | ||
this.isOpen = event.detail; | ||
} | ||
|
||
/** | ||
* Triggers the collapse programmatically. | ||
*/ | ||
@Method() | ||
async toggle(force?: boolean): Promise<boolean> { | ||
return this.collapsible.toggle(force); | ||
} | ||
|
||
render() { | ||
const HeadingTag = `h${this.headingLevel ?? 2}`; | ||
|
||
return ( | ||
<Host id={this.id} data-version={version}> | ||
<div part="accordion-item" class="accordion-item"> | ||
<HeadingTag class="accordion-header" id={`${this.id}--header`}> | ||
<button | ||
aria-controls={`${this.id}--collapse`} | ||
aria-expanded={`${this.isOpen}`} | ||
class={`accordion-button${this.isOpen ? '' : ' collapsed'}`} | ||
onClick={() => this.toggle()} | ||
type="button" | ||
> | ||
<slot name="header" /> | ||
</button> | ||
</HeadingTag> | ||
|
||
<post-collapsible collapsed={this.collapsed} ref={el => (this.collapsible = el)}> | ||
<div class="accordion-body"> | ||
<slot /> | ||
</div> | ||
</post-collapsible> | ||
</div> | ||
</Host> | ||
); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
packages/components/src/components/post-accordion-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,57 @@ | ||
# post-accordion-item | ||
|
||
|
||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
## Properties | ||
|
||
| Property | Attribute | Description | Type | Default | | ||
| -------------- | --------------- | ------------------------------------------------------------------------------------------ | ---------------------------- | ------- | | ||
| `collapsed` | `collapsed` | If `true`, the element is initially collapsed otherwise it is displayed. | `boolean` | `false` | | ||
| `headingLevel` | `heading-level` | Defines the hierarchical level of the accordion item header within the headings structure. | `1 \| 2 \| 3 \| 4 \| 5 \| 6` | `2` | | ||
|
||
|
||
## Methods | ||
|
||
### `toggle(force?: boolean) => Promise<boolean>` | ||
|
||
Triggers the collapse programmatically. | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
| ------- | --------- | ----------- | | ||
| `force` | `boolean` | | | ||
|
||
#### Returns | ||
|
||
Type: `Promise<boolean>` | ||
|
||
|
||
|
||
|
||
## Shadow Parts | ||
|
||
| Part | Description | | ||
| ------------------ | ----------- | | ||
| `"accordion-item"` | | | ||
|
||
|
||
## Dependencies | ||
|
||
### Depends on | ||
|
||
- [post-collapsible](../post-collapsible) | ||
|
||
### Graph | ||
```mermaid | ||
graph TD; | ||
post-accordion-item --> post-collapsible | ||
style post-accordion-item fill:#f9f,stroke:#333,stroke-width:4px | ||
``` | ||
|
||
---------------------------------------------- | ||
|
||
*Built with [StencilJS](https://stenciljs.com/)* |
Oops, something went wrong.