Skip to content

Commit

Permalink
feat: counter group dropdown variant #179
Browse files Browse the repository at this point in the history
  • Loading branch information
rmenner committed Jan 18, 2025
1 parent 07243d4 commit 2b1d8fd
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 48 deletions.
18 changes: 8 additions & 10 deletions components/counter/apiExamples/dropdown.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<div style="width: 300px;">
<auro-dropdown common chevron>
<div slot="trigger">Trigger</div>
<auro-counter-group style="padding: 1em; width: 400px; max-height: 400px; overflow: scroll;">
<auro-counter-group isDropdown>
<div slot="placeholder">Passengers</div>
<auro-counter>
Short label
<span slot="description">This is an example of a long sub label wrapping behavior</span>
Short label
<span slot="description">This is an example of a long sub label wrapping behavior</span>
</auro-counter>
<auro-counter>
This is an example of the wrapping behavior for a long label
<span slot="description">with short sub label text</span>
This is an example of the wrapping behavior for a long label
<span slot="description">with short sub label text</span>
</auro-counter>
<auro-counter>
This is an example of the wrapping behavior for a long label
<span slot="description">Combined with an example of a long sub label wrapping behavior</span>
This is an example of the wrapping behavior for a long label
<span slot="description">Combined with an example of a long sub label wrapping behavior</span>
</auro-counter>
</auro-counter-group>
</auro-dropdown>
</div>
15 changes: 8 additions & 7 deletions components/counter/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@

## Properties

| Property | Attribute | Type | Default | Description |
|------------|------------|----------|-------------|--------------------------------------------------|
| `max` | `max` | `number` | "undefined" | The maximum value allowed for the whole group of counters. |
| `min` | `min` | `number` | "undefined" | The minimum value allowed for the whole group of counters. |
| `total` | `total` | `number` | "undefined" | The total value of the counters. |
| `validity` | `validity` | `string` | "undefined" | Reflects the validity state. |
| `value` | `value` | `object` | "undefined" | The current individual values of the nested counters. |
| Property | Attribute | Type | Default | Description |
|--------------|--------------|-----------|-------------|--------------------------------------------------|
| `isDropdown` | `isDropdown` | `boolean` | false | Indicates if the counter group is displayed as a dropdown. |
| `max` | `max` | `number` | "undefined" | The maximum value allowed for the whole group of counters. |
| `min` | `min` | `number` | "undefined" | The minimum value allowed for the whole group of counters. |
| `total` | `total` | `number` | "undefined" | The total value of the counters. |
| `validity` | `validity` | `string` | "undefined" | Reflects the validity state. |
| `value` | `value` | `object` | "undefined" | The current individual values of the nested counters. |

## Events

Expand Down
91 changes: 72 additions & 19 deletions components/counter/src/auro-counter-group.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
/* eslint-disable lit/no-invalid-html, lit/binding-positions */

// Copyright (c) 2025 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
// See LICENSE in the project root for license information.

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

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

import styleCss from "./styles/counter-group-css.js";
import colorCss from "./styles/counter-group-color-css.js";

import AuroLibraryRuntimeUtils from "@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs";
import AuroFormValidation from "@auro-formkit/form-validation";

import { AuroDependencyVersioning } from "@aurodesignsystem/auro-library/scripts/runtime/dependencyTagVersioning.mjs";
import { AuroDropdown } from "@aurodesignsystem/auro-dropdown";
import dropdownVersion from "./dropdownVersion.js";

import './auro-counter-wrapper.js';

/**
* Auro Counter Group is a group of counter components.
*
Expand All @@ -24,6 +33,8 @@ export class AuroCounterGroup extends LitElement {
constructor() {
super();

this.isDropdown = false;

this.max = undefined;
this.min = undefined;
this.total = undefined;
Expand All @@ -39,18 +50,35 @@ export class AuroCounterGroup extends LitElement {
* @private
*/
this.validation = new AuroFormValidation();

/**
* Generate unique names for dependency components.
* @private
*/
const versioning = new AuroDependencyVersioning();

/**
* Dynamically generated dropdown tag.
* @private
* @type {string}
*/
this.dropdownTag = versioning.generateTag("auro-dropdown", dropdownVersion, AuroDropdown);
}

static get styles() {
return [
colorCss,
styleCss
];
return [styleCss];
}

static get properties() {
return {

/**
* Indicates if the counter group is displayed as a dropdown.
*/
isDropdown: {
type: Boolean
},

/**
* The maximum value allowed for the whole group of counters.
*/
Expand All @@ -67,13 +95,6 @@ export class AuroCounterGroup extends LitElement {
reflect: true,
},

/**
* The total value of the counters.
*/
total: {
type: Number,
},

/**
* Reflects the validity state.
*/
Expand All @@ -82,12 +103,19 @@ export class AuroCounterGroup extends LitElement {
reflect: true,
},

/**
* The total value of the counters.
*/
total: {
type: Number,
},

/**
* The current individual values of the nested counters.
*/
value: {
type: Object,
},
}
};
}

Expand All @@ -112,12 +140,32 @@ export class AuroCounterGroup extends LitElement {

/**
* Attaches input event listeners to all auro-counter elements within the component.
* This method selects all `auro-counter` and `[auto-counter]` elements and adds an `input` event listener to each.
* This method selects all `auro-counter` and `[auro-counter]` elements and adds an `input` event listener to each.
* The listener calls `this.updateValue()` whenever the value of a counter changes.
* @private
*/
configureCounters() {
this.counters = this.querySelectorAll("auro-counter, [auto-counter]");
this.counters = this.querySelectorAll("auro-counter, [auro-counter]");
this.counters.forEach((counter) => {
counter.addEventListener("input", () => this.updateValue());
});
}

/**
* Configures the dropdown counters by selecting all `auro-counter` elements
* and appending them to the `auro-counter-wrapper` element within the shadow DOM.
* Adds an event listener to each counter to update the value on input.
* @private
*/
configureDropdownCounters() {
const counterWrapper = this.shadowRoot.querySelector('auro-counter-wrapper');
this.counters = this.querySelectorAll("auro-counter, [auro-counter]");

this.counters.forEach((counter) => {
counterWrapper.append(counter);
});

this.counters = counterWrapper.querySelectorAll("auro-counter, [auro-counter]");
this.counters.forEach((counter) => {
counter.addEventListener("input", () => this.updateValue());
});
Expand Down Expand Up @@ -188,9 +236,14 @@ export class AuroCounterGroup extends LitElement {
// function that renders the HTML and CSS into the scope of the component
render() {
return html`
<div class="counters">
<slot @slotchange=${() => this.configureCounters()}></slot>
</div>
`;
${this.isDropdown
? html`<${this.dropdownTag} common chevron>
<div slot="trigger">${this.total}<slot name="placeholder"></slot></div>
<auro-counter-wrapper isInDropdown>
</auro-counter-wrapper>
</${this.dropdownTag}>
<slot @slotchange=${() => this.configureDropdownCounters()}></slot>`
: html`<auro-counter-wrapper><slot @slotchange=${() => this.configureCounters()}></slot></auro-counter-wrapper>`
}`;
}
}
54 changes: 54 additions & 0 deletions components/counter/src/auro-counter-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2025 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
// See LICENSE in the project root for license information.

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

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

import styleCss from "./styles/counter-wrapper-css.js";
import colorCss from "./styles/counter-wrapper-color-css.js";

import AuroLibraryRuntimeUtils from "@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs";

/**
* Auro Counter Wrapper is a group of counter components.
*
* This web component provides a flexible interface for grouping multiple counters, supporting
* validation, custom validity messages, and disabled states based on the group's value.
*
* @element auro-counter-group
* @extends LitElement
* @slot Default - Slot for counter elements.
*/
export class AuroCounterWrapper extends LitElement {

static get styles() {
return [
colorCss,
styleCss
];
}

/**
* Registers the custom element with the browser.
* @param {string} [name="auro-counter-wrapper"] - Custom element name to register.
* @example
* AuroCounterWrapper.register("custom-counter-wrapper") // registers <custom-counter-wrapper/>
*/
static register(name = "auro-counter-wrapper") {
AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroCounterWrapper);
}

// function that renders the HTML and CSS into the scope of the component
render() {
return html`<slot></slot>`;
}
}

/* istanbul ignore else */
// define the name of the custom component
if (!customElements.get("auro-counter-wrapper")) {
customElements.define("auro-counter-wrapper", AuroCounterWrapper);
}

1 change: 0 additions & 1 deletion components/counter/src/formkit/auro-dropdownVersion.js

This file was deleted.

16 changes: 6 additions & 10 deletions components/counter/src/styles/counter-group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
display: block;
}

.counters {
display: flex;
flex-direction: column;
gap: var(--ds-size-300, $ds-size-300);

::slotted(*:not(:first-child)) {
padding-top: var(--ds-size-300, $ds-size-300);
border-top-width: 1px;
border-top-style: solid;
}
[slot="trigger"] {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--ds-size-100, $ds-size-100);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/* stylelint-disable no-descending-specificity, selector-max-attribute */

.counters {
:host {
::slotted(*:not(:first-child)) {
border-color: var(--ds-color-border-divider-default, $ds-color-border-divider-default);
}
Expand Down
29 changes: 29 additions & 0 deletions components/counter/src/styles/counter-wrapper.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license.
// See LICENSE in the project root for license information.

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

// layout styles - define any layout specifications for UI that is contained WITHIN the component
// never define layout that would cause effect on element outside the scope of this component

// Support for fallback values
@import "@aurodesignsystem/design-tokens/dist/tokens/SCSSVariables";
@import '@aurodesignsystem/webcorestylesheets/src/breakpoints';

/* stylelint-disable no-descending-specificity, selector-max-attribute, selector-nest-combinators */

:host {
display: flex;
flex-direction: column;
gap: var(--ds-size-300, $ds-size-300);

::slotted(*:not(:first-child)) {
padding-top: var(--ds-size-300, $ds-size-300);
border-top-width: 1px;
border-top-style: solid;
}
}

:host([isindropdown]) {
padding: var(--ds-size-300, $ds-size-300);
}

0 comments on commit 2b1d8fd

Please sign in to comment.