Skip to content

Commit

Permalink
feat(ui): non-closeable modal support (#236)
Browse files Browse the repository at this point in the history
* feat(ui): non-closeable modal support

* feat: changes from PR
  • Loading branch information
sa-r-ah authored Oct 29, 2024
1 parent b6ca21e commit dc38053
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
open: false,
closeable: true,
},
} as Meta<ConfirmationModalComponent>;

Expand All @@ -38,7 +39,7 @@ export const Default = {
<br><p>All will be lost!!!</p>
</cvi-ng-confirmation-modal>
</ng-template>
<cvi-ng-button [cviNgModal]="modal" [modalTitle]="modalTitle" [open]="open" dataAttribute="test-button">Open modal</cvi-ng-button>
<cvi-ng-button [cviNgModal]="modal" [modalTitle]="modalTitle" [open]="open" [closeable]="closeable" dataAttribute="test-button">Open modal</cvi-ng-button>
`,
}),
};
Expand Down
4 changes: 2 additions & 2 deletions libs/ui/src/lib/modal/modal.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="cvi-modal__dialog" role="dialog" [attr.aria-label]="title" cdkTrapFocus>
<button class="cvi-modal__close" (click)="closeModal()" dataAttribute="close-modal-button" aria-label="Close">
<button *ngIf="closeable" class="cvi-modal__close" (click)="closeModal()" dataAttribute="close-modal-button" aria-label="Close">
<cvi-ng-icon [name]="'close'" [height]="14"></cvi-ng-icon>
</button>
<ng-template [ngTemplateOutlet]="templateRef" [ngTemplateOutletContext]="{ $implicit: this, title }"></ng-template>
</div>
<div class="cvi-modal__backdrop" dataAttribute="modal-backdrop" (click)="closeModal()"></div>
<div class="cvi-modal__backdrop" dataAttribute="modal-backdrop" (click)="closeable && closeModal()"></div>
5 changes: 4 additions & 1 deletion libs/ui/src/lib/modal/modal.component.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { ModalComponent } from './modal.component';
export default {
title: 'Angular/Modal/Modal',
component: ModalComponent,
args: {
closeable: true,
},
} as Meta<ModalComponent>;

export const Default = {
Expand All @@ -15,7 +18,7 @@ export const Default = {
<h1>{{ testModalTitle }}</h1>
<p dataAttribute="test-content">Modal content</p>
</ng-template>
<cvi-ng-button [cviNgModal]="modal" modalTitle="Some title" dataAttribute="test-button">Open modal</cvi-ng-button>
<cvi-ng-button [cviNgModal]="modal" modalTitle="Some title" [closeable]="closeable" dataAttribute="test-button">Open modal</cvi-ng-button>
`,
}),
};
Expand Down
1 change: 1 addition & 0 deletions libs/ui/src/lib/modal/modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class ModalComponent implements OnDestroy {
templateRef!: TemplateRef<any>;

title!: string;
closeable = true;

@Output() closed = new EventEmitter();

Expand Down
5 changes: 3 additions & 2 deletions libs/ui/src/lib/modal/modal.directive.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
args: {
modalTitle: 'Hey, I am Modal, how are you?',
modalOpen: false,
closeable: true,
},
} as Meta;

Expand All @@ -32,7 +33,7 @@ export const Default = {
<h2 *ngIf="testModalTitle">{{ testModalTitle }}</h2>
<p>Modal content</p>
</ng-template>
<cvi-ng-button [cviNgModal]="modal" [modalTitle]="modalTitle" [open]="modalOpen">Open modal</cvi-ng-button>
<cvi-ng-button [cviNgModal]="modal" [modalTitle]="modalTitle" [open]="modalOpen" [closeable]="closeable">Open modal</cvi-ng-button>
`,
}),
};
Expand Down Expand Up @@ -64,7 +65,7 @@ export const ModalOpenWithoutButton = {
<ng-template #modal>
<p>Modal content</p>
</ng-template>
<ng-container [cviNgModal]="modal" [open]="true"></ng-container>
<ng-container [cviNgModal]="modal" [open]="true" [closeable]="closeable"></ng-container>
`,
}),
parameters: {
Expand Down
2 changes: 2 additions & 0 deletions libs/ui/src/lib/modal/modal.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class ModalDirective implements OnInit {
@Input() cviNgModal!: TemplateRef<any>;
@Input() modalTitle!: string;
@Input() open = false;
@Input() closeable = true;

private componentRef: ComponentRef<ModalComponent> | null = null;

Expand Down Expand Up @@ -47,6 +48,7 @@ export class ModalDirective implements OnInit {
this.componentRef = this.viewContainerRef.createComponent(ModalComponent);
this.componentRef.instance.templateRef = this.cviNgModal;
this.componentRef.instance.title = this.modalTitle;
this.componentRef.instance.closeable = this.closeable;
this.componentRef.instance.closed.subscribe(() => this.hideModal());
}

Expand Down

0 comments on commit dc38053

Please sign in to comment.