diff --git a/.changeset/chilled-snails-cry.md b/.changeset/chilled-snails-cry.md deleted file mode 100644 index c4144e4b8a..0000000000 --- a/.changeset/chilled-snails-cry.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@justeattakeaway/pie-icon-button": patch ---- - -[Changed] - `--btn-icon-display`, `--btn-icon-size` and `--btn-icon-size-default` to `--icon-display-override` and `--icon-size-override` variables diff --git a/.changeset/cyan-islands-compete.md b/.changeset/cyan-islands-compete.md new file mode 100644 index 0000000000..0f1f9becc1 --- /dev/null +++ b/.changeset/cyan-islands-compete.md @@ -0,0 +1,5 @@ +--- +"@justeattakeaway/pie-button": minor +--- + +[Added] - assigning size prop for the icon slot diff --git a/.changeset/fluffy-dolls-flash.md b/.changeset/fluffy-dolls-flash.md deleted file mode 100644 index 22b8c26dcf..0000000000 --- a/.changeset/fluffy-dolls-flash.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@justeattakeaway/pie-icons-webc": patch ---- - -[Changed] - `--btn-icon-size` and `--btn-icon-display` to `--icon-display-override` and `--icon-size-override` variable for display, width and height icon styles for `:host svg` diff --git a/.changeset/hip-files-wash.md b/.changeset/hip-files-wash.md deleted file mode 100644 index f7d85d3ccb..0000000000 --- a/.changeset/hip-files-wash.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@justeattakeaway/pie-button": patch ---- - -[Changed] - `--btn-icon-display` and `--btn-icon-size` to `--icon-display-override` and `--icon-size-override` variables diff --git a/packages/components/pie-button/src/index.ts b/packages/components/pie-button/src/index.ts index 5c8a74342d..7e6a67ba7a 100644 --- a/packages/components/pie-button/src/index.ts +++ b/packages/components/pie-button/src/index.ts @@ -1,7 +1,7 @@ import { LitElement, html, unsafeCSS, nothing, PropertyValues, TemplateResult, } from 'lit'; -import { property } from 'lit/decorators.js'; +import { property, queryAssignedElements } from 'lit/decorators.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { validPropertyValues, defineCustomElement, FormControlMixin } from '@justeattakeaway/pie-webc-core'; import { @@ -41,6 +41,22 @@ export class PieButton extends FormControlMixin(LitElement) implements ButtonPro updated (changedProperties: PropertyValues): void { super.updated(changedProperties); + // Making sure that icon passed in a slot has the correct icon size + const [iconElement] = this._iconSlotElement; + + if (iconElement) { + if (this.size === 'xsmall') { + iconElement.setAttribute('size', 'xs'); + } + if (this.size === 'small-expressive' || this.size === 'small-productive') { + iconElement.setAttribute('size', 's'); + } + + if (this.size === 'medium' || this.size === 'large') { + iconElement.setAttribute('size', 'm'); + } + } + if (changedProperties.has('type')) { // If the new type is "submit", add the keydown event listener if (this.type === 'submit') { @@ -103,6 +119,9 @@ export class PieButton extends FormControlMixin(LitElement) implements ButtonPro @property({ type: String }) public responsiveSize?: ButtonProps['responsiveSize']; + @queryAssignedElements({ slot: 'icon' }) + _iconSlotElement!: Array; + /** * This method creates an invisible button of the same type as pie-button. It is then clicked, and immediately removed from the DOM. * 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