Skip to content

Commit

Permalink
feat(pie-button): DSW-1539 wip assigning size prop to an icon slot
Browse files Browse the repository at this point in the history
  • Loading branch information
dandel10n committed Dec 22, 2023
1 parent 4969ff8 commit 0edce4c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/components/pie-button/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 } from '@justeattakeaway/pie-webc-core';
import {
Expand Down Expand Up @@ -55,6 +55,22 @@ export class PieButton extends LitElement implements ButtonProps {
updated (changedProperties: PropertyValues<this>): 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') {
Expand Down Expand Up @@ -117,6 +133,9 @@ export class PieButton extends LitElement implements ButtonProps {
@property({ type: String })
public responsiveSize?: ButtonProps['responsiveSize'];

@queryAssignedElements({ slot: 'icon' })
_iconSlotElement!: Array<HTMLElement>;

/**
* 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
Expand Down

0 comments on commit 0edce4c

Please sign in to comment.