Skip to content

Commit

Permalink
feat(esl-carousel): esl-carousel-nav default classes and attributes…
Browse files Browse the repository at this point in the history
… reworked

Co-authored-by: Anna Barmina <abarmina@exadel.com>
Co-authored-by: alesun <alesun@exadel.com>
  • Loading branch information
3 people committed Jul 23, 2024
1 parent b1df718 commit fd50c71
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 72 deletions.
8 changes: 6 additions & 2 deletions site/views/examples/carousel/centered-siblings.sample.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ order: 6
tags: carousel-sample
---
<div class="esl-carousel-nav-container">
<button class="esl-carousel-arrow inner prev hide-xs" esl-carousel-nav="group:prev">
<button type="button"
class="esl-carousel-arrow inner prev hide-xs"
esl-carousel-nav="group:prev">
<span class="sr-only">Previous Slide</span>
</button>

Expand All @@ -28,7 +30,9 @@ tags: carousel-sample
</ul>
</esl-carousel>

<button class="esl-carousel-arrow inner next hide-xs" esl-carousel-nav="group:next">
<button type="button"
class="esl-carousel-arrow inner next hide-xs"
esl-carousel-nav="group:next">
<span class="sr-only">Next Slide</span>
</button>
</div>
Expand Down
6 changes: 4 additions & 2 deletions site/views/examples/carousel/default.sample.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ order: 1
tags: carousel-sample
---
<div class="mx-6 esl-carousel-nav-container">
<button class="esl-carousel-arrow prev hide-xs"
<button type="button"
class="esl-carousel-arrow prev hide-xs"
esl-carousel-nav="group:prev"><span class="sr-only">Previous Slide</span></button>

<esl-carousel demo-options-target
Expand Down Expand Up @@ -40,7 +41,8 @@ tags: carousel-sample
</ul>
</esl-carousel>

<button class="esl-carousel-arrow next hide-xs"
<button type="button"
class="esl-carousel-arrow next hide-xs"
esl-carousel-nav="group:next"><span class="sr-only">Next Slide</span></button>
</div>
<esl-carousel-dots class="carousel-dots-wrapper" target="::prev::child(esl-carousel)" tabindex="0"></esl-carousel-dots>
6 changes: 4 additions & 2 deletions site/views/examples/carousel/multirow.sample.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ order: 4
tags: carousel-sample
---
<div class="mx-6 esl-carousel-nav-container">
<button class="esl-carousel-arrow prev hide-xs"
<button type="button"
class="esl-carousel-arrow prev hide-xs"
esl-carousel-nav="group:prev"><span class="sr-only">Previous Slide</span></button>

<esl-carousel demo-options-target
Expand Down Expand Up @@ -39,7 +40,8 @@ tags: carousel-sample
</ul>
</esl-carousel>

<button class="esl-carousel-arrow next hide-xs"
<button type="button"
class="esl-carousel-arrow next hide-xs"
esl-carousel-nav="group:next"><span class="sr-only">Next Slide</span></button>
</div>
<esl-carousel-dots class="carousel-dots-wrapper" target="::prev::find(esl-carousel)" tabindex="0"></esl-carousel-dots>
4 changes: 2 additions & 2 deletions site/views/examples/carousel/nav-carousel.sample.njk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tags: carousel-sample
</esl-carousel>
</div>
<div class="flex-column marquee-nav-carousel esl-carousel-nav-container">
<button class="esl-carousel-arrow inner prev" esl-carousel-nav="-4"></button>
<button type="button" class="esl-carousel-arrow inner prev" esl-carousel-nav="-4"></button>

<esl-carousel id="nav-carousel"
esl-carousel-touch="drag"
Expand All @@ -44,5 +44,5 @@ tags: carousel-sample
</ul>
</esl-carousel>

<button class="esl-carousel-arrow inner next" esl-carousel-nav="+4"></button>
<button type="button" class="esl-carousel-arrow inner next" esl-carousel-nav="+4"></button>
</div>
4 changes: 2 additions & 2 deletions site/views/examples/carousel/siblings.sample.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ order: 3
tags: carousel-sample
---
<div class="esl-carousel-nav-container">
<button class="esl-carousel-arrow inner prev hide-xs" esl-carousel-nav="group:prev">
<button type="button" class="esl-carousel-arrow inner prev hide-xs" esl-carousel-nav="group:prev">
<span class="sr-only">Previous Slide</span>
</button>

Expand All @@ -26,7 +26,7 @@ tags: carousel-sample
</ul>
</esl-carousel>

<button class="esl-carousel-arrow inner next hide-xs" esl-carousel-nav="group:next">
<button type="button" class="esl-carousel-arrow inner next hide-xs" esl-carousel-nav="group:next">
<span class="sr-only">Next Slide</span>
</button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions site/views/examples/carousel/single.sample.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tags: carousel-sample
---

<div class="esl-carousel-no-extra-space esl-carousel-nav-container">
<button class="esl-carousel-arrow inner prev hide-xs" esl-carousel-nav="group:prev">
<button type="button" class="esl-carousel-arrow inner prev hide-xs" esl-carousel-nav="group:prev">
<span class="sr-only">Previous Slide</span>
</button>

Expand All @@ -28,7 +28,7 @@ tags: carousel-sample
</ul>
</esl-carousel>

<button class="esl-carousel-arrow inner next hide-xs" esl-carousel-nav="group:next">
<button type="button" class="esl-carousel-arrow inner next hide-xs" esl-carousel-nav="group:next">
<span class="sr-only">Next Slide</span>
</button>

Expand Down
4 changes: 2 additions & 2 deletions site/views/examples/carousel/vertical.sample.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tags: carousel-sample
---

<div class="esl-carousel-no-extra-space esl-carousel-nav-container">
<button class="esl-carousel-arrow inner prev hide-xs" esl-carousel-nav="group:prev">
<button type="button" class="esl-carousel-arrow inner prev hide-xs" esl-carousel-nav="group:prev">
<span class="sr-only">Previous Slide</span>
</button>

Expand All @@ -30,7 +30,7 @@ tags: carousel-sample
</ul>
</esl-carousel>

<button class="esl-carousel-arrow inner next hide-xs" esl-carousel-nav="group:next">
<button type="button" class="esl-carousel-arrow inner next hide-xs" esl-carousel-nav="group:next">
<span class="sr-only">Next Slide</span>
</button>

Expand Down
119 changes: 65 additions & 54 deletions src/modules/esl-carousel/plugin/nav/esl-carousel.nav.arrows.less
Original file line number Diff line number Diff line change
@@ -1,70 +1,81 @@
/** Nav control mixin defaults */
[esl-carousel-nav]:not([active]) {
display: none;
}

[esl-carousel-nav][disabled] {
pointer-events: none;
}

:root {
// variable to make clickable area larger
--esl-carousel-arrow-size: 40px;
--esl-carousel-arrow-padding: 0px;
--esl-carousel-arrow-bg: grey;
}

/** Arrow navigation styles */
.esl-carousel-nav-container {
position: relative;
// variable to make clickable area larger
--esl-carousel-arrow-padding: 0px;
--esl-carousel-arrow-size: 40px;

/* stylelint-disable-next-line */
--esl-carousel-arrow-offset: calc((var(--esl-carousel-arrow-size) + var(--esl-carousel-arrow-padding) + var(--esl-carousel-side-space)) * -1);
--esl-carousel-arrow-bg: grey;
}

.esl-carousel-arrow {
position: absolute;
z-index: 3;
top: 50%;
transform: translateY(-50%);
padding: var(--esl-carousel-arrow-padding);

display: grid;
place-content: center;

background: none;
border: none;
cursor: pointer;
appearance: none;
filter: drop-shadow(0 0 4px var(--esl-carousel-arrow-bg));

opacity: 0.75;

&:hover {
opacity: 1;
}

&[disabled] {
opacity: 0.25;
}
&[disabled='hidden'] {
visibility: hidden;
}
}
.esl-carousel-arrow {
position: absolute;
z-index: 3;
top: 50%;
transform: translateY(-50%);
padding: var(--esl-carousel-arrow-padding);

// Positioning
.esl-carousel-arrow.prev {
left: var(--esl-carousel-arrow-offset);
display: grid;
place-content: center;

&.inner {
left: 0;
}
}
background: none;
border: none;
cursor: pointer;
appearance: none;
filter: drop-shadow(0 0 4px var(--esl-carousel-arrow-bg));

.esl-carousel-arrow.next {
right: var(--esl-carousel-arrow-offset);
opacity: 0.75;

&.inner {
right: 0;
}
&:hover {
opacity: 1;
}

.esl-carousel-arrow::before {
content: '';
display: block;
width: var(--esl-carousel-arrow-size);
height: var(--esl-carousel-arrow-size);
background: var(--esl-carousel-arrow-bg);
clip-path: polygon(20% 50%, 70% 0%, 80% 5%, 35% 50%, 80% 95%, 70% 100%);
&[disabled] {
opacity: 0.25;
}
}

// Positioning
.esl-carousel-arrow.prev {
left: var(--esl-carousel-arrow-offset);

&.inner {
left: 0;
}
}

.esl-carousel-arrow.next::before {
transform: scaleX(-1);
.esl-carousel-arrow.next {
right: var(--esl-carousel-arrow-offset);

&.inner {
right: 0;
}
}

// Arrow icon
.esl-carousel-arrow::before {
content: '';
display: block;
width: var(--esl-carousel-arrow-size);
height: var(--esl-carousel-arrow-size);
background: var(--esl-carousel-arrow-bg);
clip-path: polygon(20% 50%, 70% 0%, 80% 5%, 35% 50%, 80% 95%, 70% 100%);
}

.esl-carousel-arrow.next::before {
transform: scaleX(-1);
}
10 changes: 6 additions & 4 deletions src/modules/esl-carousel/plugin/nav/esl-carousel.nav.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ export class ESLCarouselNavMixin extends ESLMixinElement {
@ready
public override connectedCallback(): void {
super.connectedCallback();
this.$$attr('disabled', true);
if (!this.$carousel) return;
if (this.$carousel.renderer) this._onUpdate();
}

public override disconnectedCallback(): void {
super.disconnectedCallback();
memoize.clear(this, '$carousel');
this.$$attr('active', false);
this.$$attr('disabled', false);
}

/** Handles carousel state changes */
Expand All @@ -64,9 +65,10 @@ export class ESLCarouselNavMixin extends ESLMixinElement {
target: ($nav: ESLCarouselNavMixin) => $nav.$carousel
})
protected _onUpdate(): void {
const isIncomplete = !this.$carousel?.renderer || this.$carousel.incomplete;
const isDisabled = isIncomplete || !this.$carousel.canNavigate(this.command);
this.$$attr('disabled', isIncomplete ? 'hidden' : (isDisabled ? 'inactive' : false));
const isActive = !!this.$carousel?.renderer && !this.$carousel.incomplete;
const isDisabled = isActive && !this.$carousel.canNavigate(this.command);
this.$$attr('active', isActive);
this.$$attr('disabled', isDisabled);
this.$$attr('aria-controls', this.targetID);
}

Expand Down

0 comments on commit fd50c71

Please sign in to comment.