Skip to content

Commit

Permalink
fix: add correct gradient behavior #47 #51
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-capsule42 committed Nov 5, 2024
1 parent f3086db commit 5c5b5e4
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 35 deletions.
19 changes: 18 additions & 1 deletion demo/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,21 @@ Used for all elements inside the scrolling carousel.
</auro-carousel>
```
<!-- AURO-GENERATED-CONTENT:END -->
</auro-accordion>
</auro-accordion>

### Theme Support

The component may be restyled using the following code sample and changing the values of the following token(s).

<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../../src/tokens.scss) -->
<!-- The below code snippet is automatically added from ./../../src/tokens.scss -->

```scss
@import './../node_modules/@aurodesignsystem/design-tokens/dist/tokens/SCSSVariables';

:host {
--ds-auro-carousel-gradient-color-one: var(--ds-color-background-primary-100-default, #{$ds-color-background-primary-100-default});
--ds-auro-carousel-gradient-color-two: transparent;
}
```
<!-- AURO-GENERATED-CONTENT:END -->
38 changes: 24 additions & 14 deletions demo/api.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
</head>
<body>
<main></main>

<script type="module">
<script type="module">
import 'https://cdn.jsdelivr.net/npm/marked@latest/marked.min.js';
import 'https://cdn.jsdelivr.net/npm/prismjs@latest/prism.js';
fetch('/demo/index.md')
Expand Down
38 changes: 24 additions & 14 deletions demo/index.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/partials/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,10 @@ Used for all elements inside the scrolling carousel.
<!-- AURO-GENERATED-CONTENT:END -->

</auro-accordion>

### Theme Support

The component may be restyled using the following code sample and changing the values of the following token(s).

<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../../src/tokens.scss) -->
<!-- AURO-GENERATED-CONTENT:END -->
12 changes: 10 additions & 2 deletions src/auro-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* eslint-disable max-lines, lit/no-invalid-html, lit/binding-positions */

import { LitElement, css } from "lit";
import { LitElement } from "lit";
import { html } from 'lit/static-html.js';

import { classMap } from 'lit/directives/class-map.js';
Expand All @@ -25,6 +25,8 @@ import chevronRight from '@alaskaairux/icons/dist/icons/interface/chevron-right.
import chevronLeft from '@alaskaairux/icons/dist/icons/interface/chevron-left.mjs';

import styleCss from "./style-css.js";
import colorCss from "./color-css.js";
import tokensCss from "./tokens-css.js";

// See https://git.io/JJ6SJ for "How to document your components using JSDoc"
/**
Expand Down Expand Up @@ -92,7 +94,11 @@ export class AuroCarousel extends LitElement {
}

static get styles() {
return [css`${styleCss}`];
return [
styleCss,
colorCss,
tokensCss
];
}

/**
Expand Down Expand Up @@ -380,7 +386,9 @@ export class AuroCarousel extends LitElement {
${this.generateIconHtml(chevronLeft.svg)}<span class="util_displayHiddenVisually">Scroll Left</span>
</${this.buttonTag}>
<div class="container">
<div class="gradient--left"></div>
<slot @slotchange=${this.handleSlotChange}></slot>
<div class="gradient--right"></div>
</div>
<${this.buttonTag} arialabel="chevron-right" iconOnly rounded variant="secondary" @click=${() => this.handleClick(true)} class="button button--right">
${this.generateIconHtml(chevronRight.svg)}<span class="util_displayHiddenVisually">Scroll Right</span>
Expand Down
22 changes: 22 additions & 0 deletions src/color.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2021 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
// See LICENSE in the project root for license information.

// ---------------------------------------------------------------------

/* stylelint-disable selector-class-pattern */

@import './../node_modules/@aurodesignsystem/design-tokens/dist/tokens/SCSSVariables';

:host {
.gradient {
background: var(--ds-auro-carousel-gradient-color-two);
}

.gradient--left {
background: linear-gradient(to right, var(--ds-auro-carousel-gradient-color-one), var(--ds-auro-carousel-gradient-color-two));
}

.gradient--right {
background: linear-gradient(to left, var(--ds-auro-carousel-gradient-color-one), var(--ds-auro-carousel-gradient-color-two));
}
}
22 changes: 20 additions & 2 deletions src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,39 @@
}

.button--left {
z-index: +1; // Ensure the gradient is behind the button without changing the order of the DOM elements
left: 0;
}

.button--right {
right: 0;
}

[class^='gradient'] {
position: absolute;
top: 0;
width: calc(var(--ds-size-1000, $ds-size-1000) + var(--ds-size-500, $ds-size-500) + var(--ds-size-150, $ds-size-150));
height: 100%;
}

.gradient--left {
left: 0;
}

.gradient--right {
right: 0;
}

.carousel--scrolledToStart {
.button--left {
.button--left,
.gradient--left {
display: none;
}
}

.carousel--scrolledToEnd {
.button--right {
.button--right,
.gradient--right {
display: none;
}
}
7 changes: 7 additions & 0 deletions src/tokens.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@import './../node_modules/@aurodesignsystem/design-tokens/dist/tokens/SCSSVariables';

:host {
--ds-auro-carousel-gradient-color-one: var(--ds-color-background-primary-100-default, #{$ds-color-background-primary-100-default});
--ds-auro-carousel-gradient-color-two: transparent;
}

0 comments on commit 5c5b5e4

Please sign in to comment.