Skip to content

Commit

Permalink
feat(ui): non-closeable modal support
Browse files Browse the repository at this point in the history
  • Loading branch information
sa-r-ah committed Oct 24, 2024
1 parent b6ca21e commit 01bd311
Show file tree
Hide file tree
Showing 6 changed files with 11 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>
2 changes: 1 addition & 1 deletion libs/ui/src/lib/modal/modal.component.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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="true" 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!: boolean;

@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 01bd311

Please sign in to comment.