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

feat(components, components-angular): update the post-collapsible col… #3205

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a74d0fe
feat(components, components-angular): update the post-collapsible col…
alizedebray Jul 2, 2024
5283ad5
Merge branch 'main' into 2871-the-collapsed-arg-is-not-reflected-on-t…
alizedebray Jul 2, 2024
6b8095d
feat(components): add a post-collapsible-trigger
alizedebray Jul 2, 2024
7e1bf77
fix e2e
alizedebray Jul 3, 2024
a9fc771
Merge branch '3208-create-post-collapsible-trigger-component' into 28…
alizedebray Jul 3, 2024
9e21f18
Make "collapsed" mutable
alizedebray Jul 3, 2024
5b8d69d
fix accordion e2e
alizedebray Jul 3, 2024
28a4f9d
Merge branch '3208-create-post-collapsible-trigger-component' into 28…
alizedebray Jul 4, 2024
228c7a2
fix nested accordions
alizedebray Jul 4, 2024
8cf0f5d
Apply changes to the post-accordion-item
alizedebray Jul 4, 2024
ec9d849
Restrict post-collapsible-trigger content
alizedebray Jul 10, 2024
30f7912
Merge branch 'main' into 3208-create-post-collapsible-trigger-component
alizedebray Jul 10, 2024
dc76eca
Merge branch '3208-create-post-collapsible-trigger-component' into 28…
alizedebray Jul 10, 2024
072ffa1
Update packages/components/src/components/post-collapsible-trigger/po…
alizedebray Jul 15, 2024
aa90438
Apply requested changes
alizedebray Jul 15, 2024
269d522
Merge branch '3208-create-post-collapsible-trigger-component' of http…
alizedebray Jul 15, 2024
7e0295a
Update post-collapsible-trigger.tsx
alizedebray Jul 15, 2024
a0988c1
Update trigger from collapsible
alizedebray Jul 15, 2024
0f93a27
Fix code smell
alizedebray Jul 15, 2024
9310ac6
Merge branch 'main' into 3208-create-post-collapsible-trigger-component
alizedebray Jul 15, 2024
57558e5
Debounce the trigger update
alizedebray Jul 16, 2024
505889d
Merge branch '3208-create-post-collapsible-trigger-component' of http…
alizedebray Jul 16, 2024
9be2c76
Merge branch 'main' into 3208-create-post-collapsible-trigger-component
alizedebray Jul 16, 2024
129739c
Merge branch '3208-create-post-collapsible-trigger-component' of http…
alizedebray Jul 16, 2024
cbe8e03
Fix e2e
alizedebray Jul 16, 2024
0f17fa7
Merge branch '3208-create-post-collapsible-trigger-component' into 28…
alizedebray Jul 16, 2024
0f6771e
Merge branch 'main' into 2871-the-collapsed-arg-is-not-reflected-on-t…
alizedebray Jul 18, 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
7 changes: 7 additions & 0 deletions .changeset/plenty-experts-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@swisspost/design-system-documentation': patch
'@swisspost/design-system-components': patch
'@swisspost/design-system-components-angular': patch
---

Updated the `collapsed` property of the `post-collapsible` and `post-accordion-item` to toggle the content visibility throughout the component lifecycle, rather than only initially.
5 changes: 5 additions & 0 deletions .changeset/thin-eyes-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-components-angular-workspace': patch
---

Added a toggle button for the `post-collapsible`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import { Component } from '@angular/core';
selector: 'home-page',
templateUrl: './home.component.html',
})
export class HomeComponent {}
export class HomeComponent {
isCollapsed = false;
}
8 changes: 4 additions & 4 deletions packages/components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export namespace Components {
}
interface PostAccordionItem {
/**
* If `true`, the element is initially collapsed otherwise it is displayed.
* If `true`, the element is collapsed otherwise it is displayed.
*/
"collapsed"?: boolean;
/**
Expand Down Expand Up @@ -126,7 +126,7 @@ export namespace Components {
}
interface PostCollapsible {
/**
* If `true`, the element is initially collapsed otherwise it is displayed.
* If `true`, the element is collapsed otherwise it is displayed.
*/
"collapsed"?: boolean;
/**
Expand Down Expand Up @@ -535,7 +535,7 @@ declare namespace LocalJSX {
}
interface PostAccordionItem {
/**
* If `true`, the element is initially collapsed otherwise it is displayed.
* If `true`, the element is collapsed otherwise it is displayed.
*/
"collapsed"?: boolean;
/**
Expand Down Expand Up @@ -621,7 +621,7 @@ declare namespace LocalJSX {
}
interface PostCollapsible {
/**
* If `true`, the element is initially collapsed otherwise it is displayed.
* If `true`, the element is collapsed otherwise it is displayed.
*/
"collapsed"?: boolean;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ export class PostAccordionItem {
@Element() host: HTMLPostAccordionItemElement;

@State() id: string;
@State() isOpen: boolean;

/**
* If `true`, the element is initially collapsed otherwise it is displayed.
* If `true`, the element is collapsed otherwise it is displayed.
*/
@Prop() readonly collapsed?: boolean = false;
@Prop({ mutable: true }) collapsed?: boolean = false;

/**
* Defines the hierarchical level of the accordion item header within the headings structure.
Expand All @@ -46,14 +45,14 @@ export class PostAccordionItem {
}

componentWillLoad() {
this.isOpen = !this.collapsed;
this.id = this.host.id || `a${crypto.randomUUID()}`;
}

@Listen('postToggle')
// capture to make sure the "collapsed" property is updated before the event is consumed
@Listen('postToggle', { capture: true })
onCollapseToggle(event: CustomEvent<boolean>): void {
if ((event.target as HTMLElement).localName === 'post-accordion-item') {
this.isOpen = event.detail;
this.collapsed = !event.detail;
}
}

Expand All @@ -74,8 +73,8 @@ export class PostAccordionItem {
<HeadingTag class="accordion-header" id={`${this.id}--header`}>
<button
aria-controls={`${this.id}--collapse`}
aria-expanded={`${this.isOpen}`}
class={`accordion-button${this.isOpen ? '' : ' collapsed'}`}
aria-expanded={`${!this.collapsed}`}
class={`accordion-button${this.collapsed ? ' collapsed' : ''}`}
onClick={() => this.toggle()}
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

| Property | Attribute | Description | Type | Default |
| -------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- | ------- |
| `collapsed` | `collapsed` | If `true`, the element is initially collapsed otherwise it is displayed. | `boolean` | `false` |
| `collapsed` | `collapsed` | If `true`, the element is collapsed otherwise it is displayed. | `boolean` | `false` |
| `headingLevel` | `heading-level` | <span style="color:red">**[DEPRECATED]**</span> set the `heading-level` property on the parent `post-accordion` instead.<br/><br/>Defines the hierarchical level of the accordion item header within the headings structure. | `1 \| 2 \| 3 \| 4 \| 5 \| 6` | `2` |


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ export class PostCollapsible {
@Element() host: HTMLPostCollapsibleElement;

/**
* If `true`, the element is initially collapsed otherwise it is displayed.
* If `true`, the element is collapsed otherwise it is displayed.
*/
@Prop() readonly collapsed?: boolean = false;
@Prop({ mutable: true }) collapsed?: boolean = false;

@Watch('collapsed')
validateCollapsed(newValue = this.collapsed) {
collapsedChange() {
checkEmptyOrType(
newValue,
this.collapsed,
'boolean',
'The `collapsed` property of the `post-collapsible` must be a boolean.',
);

void this.toggle(!this.collapsed);
oliverschuerch marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -49,12 +51,8 @@ export class PostCollapsible {
*/
@Event() postToggle: EventEmitter<boolean>;

connectedCallback() {
this.validateCollapsed();
}

componentDidLoad() {
if (this.collapsed) void this.toggle(false);
this.collapsedChange();
this.isLoaded = true;

this.updateTriggers();
Expand All @@ -69,8 +67,9 @@ export class PostCollapsible {
async toggle(open = !this.isOpen): Promise<boolean> {
if (open === this.isOpen) return open;

this.isOpen = !this.isOpen;
if (this.isLoaded) this.postToggle.emit(this.isOpen);
this.isOpen = open;
oliverschuerch marked this conversation as resolved.
Show resolved Hide resolved
this.collapsed = !open;
if (this.isLoaded) this.postToggle.emit(open);

const animation = open ? expand(this.host) : collapse(this.host);

Expand All @@ -80,7 +79,7 @@ export class PostCollapsible {

animation.commitStyles();

return this.isOpen;
return open;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ----------- | ----------- | ------------------------------------------------------------------------ | --------- | ------- |
| `collapsed` | `collapsed` | If `true`, the element is initially collapsed otherwise it is displayed. | `boolean` | `false` |
| Property | Attribute | Description | Type | Default |
| ----------- | ----------- | -------------------------------------------------------------- | --------- | ------- |
| `collapsed` | `collapsed` | If `true`, the element is collapsed otherwise it is displayed. | `boolean` | `false` |


## Events
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useArgs } from '@storybook/preview-api';
import { StoryContext, StoryFn, StoryObj } from '@storybook/web-components';
import { html } from 'lit';
import { spreadArgs } from '@/utils';
Expand Down Expand Up @@ -31,16 +32,30 @@ function gap(story: StoryFn, context: StoryContext) {
}

//RENDERER
let ignoreToggle = true;
function renderCollapsible(
{ innerHTML, ...args }: Partial<HTMLPostCollapsibleElement>,
context: StoryContext<HTMLPostCollapsibleElement>,
) {
const [_, updateArgs] = useArgs();
const handleToggle = (e: CustomEvent<boolean>) => {
if (ignoreToggle) return;

const collapsed = !e.detail;
updateArgs({ collapsed });
};

// ignore the first toggle event after a collapsed arg update
ignoreToggle = true;
setTimeout(() => {
ignoreToggle = false;
}, 200);
return html`
<post-collapsible-trigger for=${context.id}>
<button class="btn btn-secondary">Toggle Collapsible</button>
</post-collapsible-trigger>

<post-collapsible id=${context.id} ${spreadArgs(args)}>
<post-collapsible id=${context.id} ${spreadArgs(args)} @postToggle="${handleToggle}">
${unsafeHTML(innerHTML)}
</post-collapsible>
`;
Expand Down