Skip to content

Commit

Permalink
feat(pie-notification): DSW-1351 avoid content overlap close icon and…
Browse files Browse the repository at this point in the history
… regular icon
  • Loading branch information
thejfreitas committed Mar 25, 2024
1 parent 8276acc commit 41b0cda
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/components/pie-notification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export class PieNotification extends LitElement implements NotificationProps {
@state()
protected _hasIconClass = false;

@state()
protected _hasContentGutter = false;

// Renders a `CSSResult` generated from SCSS by Vite
static styles = unsafeCSS(styles);

Expand All @@ -107,11 +110,16 @@ export class PieNotification extends LitElement implements NotificationProps {
/**
* Lifecycle method executed when component is updated.
* It dispatches an event if notification is opened.
* It applies a gutter if there's no heading content in order to avoid the close button overlap the content.
*/
protected updated (_changedProperties: PropertyValues<this>): void {
if (_changedProperties.has('isOpen') && this.isOpen) {
dispatchCustomEvent(this, ON_NOTIFICATION_OPEN_EVENT, { targetNotification: this });
}

if (_changedProperties.has('heading') || _changedProperties.has('isDismissible') || _changedProperties.has('isCompact')) {
this._hasContentGutter = (this.heading === '' || this.heading === undefined) && (this.isDismissible && !this.isCompact);
}
}

/**
Expand Down Expand Up @@ -325,6 +333,7 @@ export class PieNotification extends LitElement implements NotificationProps {
leadingAction,
supportingAction,
isOpen,
_hasContentGutter,
} = this;

if (!isOpen) {
Expand All @@ -337,7 +346,7 @@ export class PieNotification extends LitElement implements NotificationProps {
<section class="${componentClass}-content-section">
${!hideIcon ? this.renderIcon(variant, _hasExternalIcon, _hasIconClass) : nothing}
<article>
<article ?hasGutter="${_hasContentGutter}">
${heading ? this.renderNotificationHeading(heading, unsafeStatic(headingLevel)) : nothing}
<slot></slot>
</article>
Expand Down
7 changes: 7 additions & 0 deletions packages/components/pie-notification/src/notification.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@
display: flex;
flex-direction: row;

article {
&[hasGutter] {
padding-inline-end: var(--dt-spacing-e);
}
}

.has-icon {
display: block ruby; // This is a hack to avoid the icon overlap the text in Firefox
margin-inline-end: var(--dt-spacing-c);
}
}
Expand Down

0 comments on commit 41b0cda

Please sign in to comment.