Skip to content

Commit cf952f7

Browse files
committed
feat(pie-button): DSW-1539 wip assigning size prop to an icon slot
1 parent 9b80396 commit cf952f7

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

.changeset/chilled-snails-cry.md

-5
This file was deleted.

.changeset/cyan-islands-compete.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@justeattakeaway/pie-button": minor
3+
---
4+
5+
[Added] - assigning size prop for the icon slot

.changeset/fluffy-dolls-flash.md

-5
This file was deleted.

.changeset/hip-files-wash.md

-5
This file was deleted.

packages/components/pie-button/src/index.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
LitElement, html, unsafeCSS, nothing, PropertyValues, TemplateResult,
33
} from 'lit';
4-
import { property } from 'lit/decorators.js';
4+
import { property, queryAssignedElements } from 'lit/decorators.js';
55
import { ifDefined } from 'lit/directives/if-defined.js';
66
import { validPropertyValues, defineCustomElement, FormControlMixin } from '@justeattakeaway/pie-webc-core';
77
import {
@@ -41,6 +41,22 @@ export class PieButton extends FormControlMixin(LitElement) implements ButtonPro
4141
updated (changedProperties: PropertyValues<this>): void {
4242
super.updated(changedProperties);
4343

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+
4460
if (changedProperties.has('type')) {
4561
// If the new type is "submit", add the keydown event listener
4662
if (this.type === 'submit') {
@@ -103,6 +119,9 @@ export class PieButton extends FormControlMixin(LitElement) implements ButtonPro
103119
@property({ type: String })
104120
public responsiveSize?: ButtonProps['responsiveSize'];
105121

122+
@queryAssignedElements({ slot: 'icon' })
123+
_iconSlotElement!: Array<HTMLElement>;
124+
106125
/**
107126
* This method creates an invisible button of the same type as pie-button. It is then clicked, and immediately removed from the DOM.
108127
* 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

Comments
 (0)