Skip to content

Commit

Permalink
feat: add alert variation with description (#839) ✨
Browse files Browse the repository at this point in the history
* feat: add property description and noRadius

* fix: add test

* fix: pr suggestions

* fix: pr suggestions

---------

Co-authored-by: Madalena Campos <[email protected]>
Co-authored-by: Iury Nogueira <[email protected]>
  • Loading branch information
3 people authored Sep 29, 2023
1 parent 63024a6 commit 60bd35f
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 21 deletions.
54 changes: 35 additions & 19 deletions projects/ion/src/lib/alert/alert.component.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
<div
data-testid="ion-alert"
[class]="'ion-alert ' + type + ' closable-' + closable"
[ngClass]="{ 'without-background': hideBackground }"
[ngClass]="{
'without-background': hideBackground,
'with-description': description?.length > 0,
'no-radius': noRadius
}"
#ionAlert
>
<ion-icon
data-testid="status-icon"
class="alert-icon"
[type]="iconType"
></ion-icon>
<span *ngIf="hasPlainText; else customBody" data-testid="ion-alert-message">{{
message
}}</span>
<div class="header">
<div class="message">
<ion-icon
data-testid="status-icon"
class="alert-icon"
[type]="iconType"
></ion-icon>

<ng-template #customBody>
<ng-container [ngTemplateOutlet]="message"></ng-container>
</ng-template>
<span
*ngIf="hasPlainText; else customBody"
data-testid="ion-alert-message"
class="message-text"
>{{ message }}</span
>

<ion-icon
class="close-icon"
data-testid="close-icon"
type="close"
*ngIf="closable"
(click)="closeEvent()"
></ion-icon>
<ng-template #customBody>
<ng-container [ngTemplateOutlet]="message"></ng-container>
</ng-template>
</div>

<ion-icon
class="close-icon"
data-testid="close-icon"
type="close"
*ngIf="closable"
(click)="closeEvent()"
></ion-icon>
</div>

<span *ngIf="description?.length > 0" class="description">
{{ description }}
</span>
</div>
35 changes: 33 additions & 2 deletions projects/ion/src/lib/alert/alert.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

.ion-alert {
display: flex;
flex-direction: row;
align-items: center;
flex-direction: column;
gap: 8px;
border: 1px solid;
border-radius: 8px;
Expand All @@ -31,6 +30,18 @@
}
}

.header {
display: flex;
align-items: center;
justify-content: space-between;
}

.message {
display: flex;
align-items: center;
gap: 8px;
}

.success {
@include alert-style($positive-1, $positive-6);
}
Expand All @@ -47,11 +58,31 @@
@include alert-style($negative-1, $negative-6);
}

.with-description {
border: none !important;
background-color: $neutral-2;
padding: spacing(2) spacing(3) !important;
color: $neutral-7;
gap: 4px;

.message-text {
font-weight: 600;
}

.description {
width: 100%;
}
}

.without-background {
background-color: transparent;
border: none !important;
}

.no-radius {
border-radius: 0;
}

.closable-true {
padding: spacing(1) spacing(2);
}
Expand Down
16 changes: 16 additions & 0 deletions projects/ion/src/lib/alert/alert.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ describe('AlertComponent', () => {
expect(element).toHaveClass('without-background');
});

it('should render with description', async () => {
const description = 'Testing description';
const element = await sut({ ...defaultValue, description });
expect(element).toHaveTextContent(description);
});

it('should render with radius', async () => {
const element = await sut(defaultValue);
expect(element).not.toHaveClass('no-radius');
});

it('should render without radius', async () => {
const element = await sut({ ...defaultValue, noRadius: true });
expect(element).toHaveClass('no-radius');
});

describe('With a string provided', () => {
it('Should have an alert message', async () => {
expect(await sut()).toHaveTextContent(defaultValue.message as string);
Expand Down
2 changes: 2 additions & 0 deletions projects/ion/src/lib/alert/alert.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class IonAlertComponent implements OnInit, OnChanges {
@Input() type?: StatusType = 'success';
@Input() closable? = false;
@Input() hideBackground? = false;
@Input() noRadius? = false;
@Input() description?: string;

@ViewChild('ionAlert', { static: false }) private ionAlert: ElementRef;

Expand Down
2 changes: 2 additions & 0 deletions projects/ion/src/lib/core/types/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { StatusType } from './status';

export interface IonAlertProps {
message: string | TemplateRef<void>;
description?: string;
type?: StatusType;
closable?: boolean;
hideBackground?: boolean;
noRadius?: boolean;
}
18 changes: 18 additions & 0 deletions stories/Alert.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,21 @@ A partir do paramêtro `hideBackground` pode ser definido se o usuário quer mos
{Template.bind({})}
</Story>
</Canvas>

<Canvas>
<Story
name="type: with description"
args={{
type: 'info',
message: 'Example of alert message',
description: 'Example of description.',
}}
decorators={[
moduleMetadata({
imports: [CommonModule, IonSharedModule],
}),
]}
>
{Template.bind({})}
</Story>
</Canvas>

0 comments on commit 60bd35f

Please sign in to comment.