Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): non-closeable modal support #236

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move the closeable check into the closeModal() method?

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
Loading