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

Accordion issues fixed #178

Merged
merged 4 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
14 changes: 7 additions & 7 deletions examples/wrapper-components/react-javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 20 additions & 33 deletions examples/wrapper-components/react-javascript/src/App.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions packages/components-vue/lib/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import type { JSX } from '@infineon/infineon-design-system-stencil';



export const IfxAccordion = /*@__PURE__*/ defineContainer<JSX.IfxAccordion>('ifx-accordion', undefined);
export const IfxAccordion = /*@__PURE__*/ defineContainer<JSX.IfxAccordion>('ifx-accordion', undefined, [
'autoCollapse'
]);


export const IfxAccordionItem = /*@__PURE__*/ defineContainer<JSX.IfxAccordionItem>('ifx-accordion-item', undefined, [
'caption',
'ifxItemOpened',
'ifxItemClosed'
'ifxItemOpen',
'ifxItemClose'
]);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
.accordion-wrapper {
display: flex;
flex-direction: column;
gap: 8px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const Template = (args) => {
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent volutpat, ligula eu aliquam bibendum, orci nisl cursus ipsum, nec egestas odio sapien eget neque.
</p>
`;
item.addEventListener('ifxItemOpened', action('ifxItemOpened'));
item.addEventListener('ifxItemClosed', action('ifxItemClosed'));
item.addEventListener('ifxItemOpen', action('ifxItemOpen'));
item.addEventListener('ifxItemClose', action('ifxItemClose'));

accordionElement.append(item);
}
Expand Down
21 changes: 12 additions & 9 deletions packages/components/src/components/accordion/accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
//ifxAccordion.tsx
import { Component, h, Listen, Element } from '@stencil/core';
import { Component, h, Listen, Element, Prop } from '@stencil/core';

@Component({
tag: 'ifx-accordion',
styleUrl: 'accordion.scss',
shadow: true,
})
export class IfxAccordion {
export class Accordion {
@Element() el: HTMLElement;
@Prop() autoCollapse: boolean = false;

@Listen('ifxItemOpened', { target: 'body' })
async onIfxItemOpened(event: CustomEvent) {
const items = Array.from(this.el.shadowRoot.querySelectorAll('ifx-accordion-item'));
for (const item of items) {
const itemElement = item as HTMLIfxAccordionItemElement;
if (itemElement !== event.target && (await itemElement.isOpen())) {
itemElement.close();
@Listen('ifxItemOpen')
async onItemOpen(event: CustomEvent) {
const items = Array.from(this.el.querySelectorAll('ifx-accordion-item'));
if(this.autoCollapse) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small performance fix: move this line one layer up so we don't query when auto collapse is false

for (const item of items) {
const itemElement = item as HTMLIfxAccordionItemElement;
if (itemElement !== event.target && (await itemElement.isOpen())) {
itemElement.close();
}
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions packages/components/src/components/accordion/accordionItem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
@use "~@infineon/design-system-tokens/dist/tokens";
@use "../../global/font.scss";

:host {
display: block;
}
// :host {
kaiwerther marked this conversation as resolved.
Show resolved Hide resolved
// display: block;
// }

.accordion-item {
border-radius: 3px;
Expand Down Expand Up @@ -37,13 +37,14 @@
transition: max-height 0.3s ease-in-out;
}

.accordion-content ::slotted(p) {
margin: 0;
padding: 0;
}

.inner-content {
padding: 24px;
white-space: pre-wrap;
/* wraps text at spaces and within words */
word-wrap: break-word;
/* breaks text within a word if necessary */
overflow-wrap: anywhere;
/* breaks text at arbitrary points when needed */
}

.accordion-icon {
Expand All @@ -54,5 +55,5 @@
}

.accordion-item.open .accordion-icon {
transform: rotate(90deg);
transform: rotate(-180deg);
}
14 changes: 7 additions & 7 deletions packages/components/src/components/accordion/accordionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import { Component, Prop, h, State, Event, EventEmitter, Method } from '@stencil
export class IfxAccordionItem {
@Prop() caption: string;
@State() open: boolean = false;
@Event() ifxItemOpened: EventEmitter;
@Event() ifxItemClosed: EventEmitter;
@Event() ifxItemOpen: EventEmitter;
@Event() ifxItemClose: EventEmitter;
private contentEl!: HTMLElement;

toggleOpen() {
this.open = !this.open;
if (this.open) {
this.ifxItemOpened.emit();
this.ifxItemOpen.emit();
} else {
this.ifxItemClosed.emit();
this.ifxItemClose.emit();
}
}

componentDidRender() {
componentDidUpdate() {
if (this.open) {
this.contentEl.style.maxHeight = `${this.contentEl.scrollHeight}px`;
} else {
Expand All @@ -33,7 +33,7 @@ export class IfxAccordionItem {
@Method()
async close() {
this.open = false;
this.ifxItemClosed.emit();
this.ifxItemClose.emit();
}

@Method()
Expand All @@ -46,7 +46,7 @@ export class IfxAccordionItem {
<div class={`accordion-item ${this.open ? 'open' : ''}`}>
<div class="accordion-title" onClick={() => this.toggleOpen()}>
<span class="accordion-icon">
<ifx-icon icon="chevron-right-12" />
<ifx-icon icon="chevron-down-12" />
</span>
<span class="accordion-caption">{this.caption}</span>
</div>
Expand Down
8 changes: 4 additions & 4 deletions packages/components/src/components/accordion/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

## Events

| Event | Description | Type |
| --------------- | ----------- | ------------------ |
| `ifxItemClosed` | | `CustomEvent<any>` |
| `ifxItemOpened` | | `CustomEvent<any>` |
| Event | Description | Type |
| -------------- | ----------- | ------------------ |
| `ifxItemClose` | | `CustomEvent<any>` |
| `ifxItemOpen` | | `CustomEvent<any>` |


## Methods
Expand Down