Skip to content
This repository was archived by the owner on Nov 2, 2024. It is now read-only.
This repository was archived by the owner on Nov 2, 2024. It is now read-only.

improve how to generate dynamic slot content in the carousel #2

@thescientist13

Description

@thescientist13

currently the carousel component needs to know how many slots are being provided in order to dynamically bind everything together.

<pe-carousel slots$=${this.content.length}>
  ${ this.content.map(this.generateSlotTemplate) }
</pe-carousel>
generateCarouselContent() {
  return new Array(this.slots).fill(null).map((item, index) => {
    const isActiveSlot = index === this.activeIndex ? 'active-slot' : 'slot';

    return html`
      <div class$="${isActiveSlot}"><slot name$="slide${index + 1}"></slot>
    `;
  });
}

Not sure if there would be any performance issues query for number of <slot> elements internally within the component itself instead, i.e.

generateCarouselContent() {
  const slots = this.$('slot');

  return slots.length.map((item, index) => {
    const isActiveSlot = index === this.activeIndex ? 'active-slot' : 'slot';

    return html`
      <div class$="${isActiveSlot}"><slot name$="slide${index + 1}"></slot>
    `;
  });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions