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

Update value structure to support auro-form #226

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion components/checkbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-checkbox__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-checkbox__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-checkbox use cases
Expand Down
8 changes: 4 additions & 4 deletions components/combobox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-input__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-menu__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-combobox__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-input__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-menu__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-combobox__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-combobox use cases
Expand Down
2 changes: 1 addition & 1 deletion components/counter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-counter__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-counter__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-counter use cases
Expand Down
18 changes: 9 additions & 9 deletions components/counter/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

## Methods

| Method | Type | Description |
|--------------------|---------------------------------------|--------------------------------------------------|
| `decrement` | `(value?: number \| undefined): void` | Decrements the value of the counter by 1. If a value is provided, it decrements by that amount.<br /><br />**value**: The amount to decrement by. |
| `handleSlotChange` | `(): void` | |
| `increment` | `(value?: number \| undefined): void` | Increments the counter value by 1. If a value is provided, it increments by that amount.<br /><br />**value**: The amount to increment by. |
| Method | Type | Description |
|-------------|---------------------------------------|--------------------------------------------------|
| `decrement` | `(value?: number \| undefined): void` | Decrements the value of the counter by 1. If a value is provided, it decrements by that amount.<br /><br />**value**: The amount to decrement by. |
| `increment` | `(value?: number \| undefined): void` | Increments the counter value by 1. If a value is provided, it increments by that amount.<br /><br />**value**: The amount to increment by. |

## Events

Expand All @@ -40,14 +39,15 @@
|------------|------------|----------|-------------|--------------------------------------------------|
| `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` | `number` | "undefined" | The current value. |
| `value` | `value` | `object` | "undefined" | The current individual values of the nested counters. |

## Events

| Event | Type |
|---------|------------------------------------------------|
| `input` | `CustomEvent<{ value: number \| undefined; }>` |
| Event | Type |
|---------|--------------------------------------------------|
| `input` | `CustomEvent<{ total: number \| undefined; value: {} \| undefined; }>` |

## Slots

Expand Down
41 changes: 30 additions & 11 deletions components/counter/src/auro-counter-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ export class AuroCounterGroup extends LitElement {

this.max = undefined;
this.min = undefined;
this.total = undefined;
this.validity = undefined;
this.value = undefined;

/**
* @private
*/
this.counters = undefined;

/**
* @private
*/
Expand Down Expand Up @@ -61,6 +67,13 @@ export class AuroCounterGroup extends LitElement {
reflect: true,
},

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

/**
* Reflects the validity state.
*/
Expand All @@ -70,10 +83,10 @@ export class AuroCounterGroup extends LitElement {
},

/**
* The current value.
* The current individual values of the nested counters.
*/
value: {
type: Number,
type: Object,
},
};
}
Expand All @@ -90,23 +103,22 @@ export class AuroCounterGroup extends LitElement {
counter.disableMax = false;
counter.disableMin = false;

if (this.value <= this.min) {
if (this.total <= this.min) {
counter.disableMin = true;
} else if (this.value >= this.max) {
} else if (this.total >= this.max) {
counter.disableMax = true;
}
}


/**
* 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.
* The listener calls `this.updateValue()` whenever the value of a counter changes.
* @private
*/
configureCounters() {
const counters = this.querySelectorAll("auro-counter, [auto-counter]");
counters.forEach((counter) => {
this.counters = this.querySelectorAll("auro-counter, [auto-counter]");
this.counters.forEach((counter) => {
counter.addEventListener("input", () => this.updateValue());
});
}
Expand All @@ -129,12 +141,18 @@ export class AuroCounterGroup extends LitElement {
* @private
*/
updateValue() {
const counters = this.querySelectorAll("auro-counter, [auro-counter]");
this.value = Array.from(counters).reduce(
this.value = Array.from(this.counters).reduce((acc, counter, index) => {
const name = counter.hasAttribute('name') ? counter.getAttribute('name') : `counter-${index}`;
acc[name] = this.safeNumberConversion(counter.value);
return acc;
}, {});

this.total = Array.from(this.counters).reduce(
(total, counter) => total + this.safeNumberConversion(counter.value),
0,
);
counters.forEach((counter) => {

this.counters.forEach((counter) => {
this.manageDisabled(counter);
});
}
Expand All @@ -145,7 +163,8 @@ export class AuroCounterGroup extends LitElement {
this.dispatchEvent(
new CustomEvent("input", {
detail: {
value: this.value,
total: this.total,
value: this.value
},
}),
{
Expand Down
6 changes: 6 additions & 0 deletions components/counter/src/auro-counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ export class AuroCounter extends LitElement {
}
}

/**
* Handles the slot change event.
* This method is called when the slot content changes.
* It triggers the checkSlots method to update the component state based on the new slot content.
* @private
*/
handleSlotChange() {
this.checkSlots();
}
Expand Down
8 changes: 4 additions & 4 deletions components/datepicker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-input__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-popover__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-datepicker__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-input__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-popover__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-datepicker__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-datepicker use cases
Expand Down
2 changes: 1 addition & 1 deletion components/dropdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-dropdown__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-dropdown use cases
Expand Down
2 changes: 1 addition & 1 deletion components/form/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-form__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-form__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-form use cases
Expand Down
2 changes: 1 addition & 1 deletion components/input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-input__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-input__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-input use cases
Expand Down
2 changes: 1 addition & 1 deletion components/menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-menu__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-menu__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-menu use cases
Expand Down
2 changes: 1 addition & 1 deletion components/radio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-radio__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-radio__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-radio use cases
Expand Down
6 changes: 3 additions & 3 deletions components/select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-menu__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].12/dist/auro-select__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-menu__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].13/dist/auro-select__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-select use cases
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

Loading