|
1 | 1 | import {
|
2 | 2 | LitElement, html, unsafeCSS, nothing, PropertyValues, TemplateResult,
|
3 | 3 | } from 'lit';
|
4 |
| -import { property } from 'lit/decorators.js'; |
| 4 | +import { property, queryAssignedElements } from 'lit/decorators.js'; |
5 | 5 | import { ifDefined } from 'lit/directives/if-defined.js';
|
6 | 6 | import { validPropertyValues, defineCustomElement, FormControlMixin } from '@justeattakeaway/pie-webc-core';
|
7 | 7 | import {
|
@@ -41,6 +41,22 @@ export class PieButton extends FormControlMixin(LitElement) implements ButtonPro
|
41 | 41 | updated (changedProperties: PropertyValues<this>): void {
|
42 | 42 | super.updated(changedProperties);
|
43 | 43 |
|
| 44 | + // Making sure that icon passed in a slot has the correct icon size |
| 45 | + const [iconElement] = this._iconSlotElement; |
| 46 | + |
| 47 | + if (iconElement) { |
| 48 | + if (this.size === 'xsmall') { |
| 49 | + iconElement.setAttribute('size', 'xs'); |
| 50 | + } |
| 51 | + if (this.size === 'small-expressive' || this.size === 'small-productive') { |
| 52 | + iconElement.setAttribute('size', 's'); |
| 53 | + } |
| 54 | + |
| 55 | + if (this.size === 'medium' || this.size === 'large') { |
| 56 | + iconElement.setAttribute('size', 'm'); |
| 57 | + } |
| 58 | + } |
| 59 | + |
44 | 60 | if (changedProperties.has('type')) {
|
45 | 61 | // If the new type is "submit", add the keydown event listener
|
46 | 62 | if (this.type === 'submit') {
|
@@ -103,6 +119,9 @@ export class PieButton extends FormControlMixin(LitElement) implements ButtonPro
|
103 | 119 | @property({ type: String })
|
104 | 120 | public responsiveSize?: ButtonProps['responsiveSize'];
|
105 | 121 |
|
| 122 | + @queryAssignedElements({ slot: 'icon' }) |
| 123 | + _iconSlotElement!: Array<HTMLElement>; |
| 124 | + |
106 | 125 | /**
|
107 | 126 | * This method creates an invisible button of the same type as pie-button. It is then clicked, and immediately removed from the DOM.
|
108 | 127 | * This is done so that we trigger native form actions, such as submit and reset in the browser. The performance impact of adding and removing a single button to the DOM
|
|
0 commit comments