Skip to content

Commit cce4acd

Browse files
committed
added prefix to css classes to prevent clash with other libs
1 parent 685de04 commit cce4acd

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

src/app/_content/modal.less

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
/* MODAL STYLES
22
-------------------------------*/
3-
modal {
3+
jw-modal {
44
/* modals are hidden by default */
55
display: none;
66

7-
.modal {
7+
.jw-modal {
88
/* modal container fixed across whole screen */
99
position: fixed;
1010
top: 0;
1111
right: 0;
1212
bottom: 0;
1313
left: 0;
1414

15-
/* z-index must be higher than .modal-background */
15+
/* z-index must be higher than .jw-modal-background */
1616
z-index: 1000;
1717

1818
/* enables scrolling for tall modals */
1919
overflow: auto;
2020

21-
.modal-body {
21+
.jw-modal-body {
2222
padding: 20px;
2323
background: #fff;
2424

@@ -27,7 +27,7 @@ modal {
2727
}
2828
}
2929

30-
.modal-background {
30+
.jw-modal-background {
3131
/* modal background fixed across whole screen */
3232
position: fixed;
3333
top: 0;
@@ -39,12 +39,12 @@ modal {
3939
background-color: #000;
4040
opacity: 0.75;
4141

42-
/* z-index must be below .modal and above everything else */
42+
/* z-index must be below .jw-modal and above everything else */
4343
z-index: 900;
4444
}
4545
}
4646

47-
body.modal-open {
47+
body.jw-modal-open {
4848
/* body overflow is hidden to hide main scrollbar when modal window is open */
4949
overflow: hidden;
5050
}

src/app/_directives/modal.component.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
import { ModalService } from '../_services';
44

55
@Component({
6-
selector: 'modal',
7-
template: '<ng-content></ng-content>'
6+
selector: 'jw-modal',
7+
template:
8+
`<div class="jw-modal">
9+
<div class="jw-modal-body">
10+
<ng-content></ng-content>
11+
</div>
12+
</div>
13+
<div class="jw-modal-background"></div>`
814
})
915

1016
export class ModalComponent implements OnInit, OnDestroy {
@@ -29,7 +35,7 @@ export class ModalComponent implements OnInit, OnDestroy {
2935

3036
// close modal on background click
3137
this.element.addEventListener('click', function (e: any) {
32-
if (e.target.className === 'modal') {
38+
if (e.target.className === 'jw-modal') {
3339
modal.close();
3440
}
3541
});
@@ -47,12 +53,12 @@ export class ModalComponent implements OnInit, OnDestroy {
4753
// open modal
4854
open(): void {
4955
this.element.style.display = 'block';
50-
document.body.classList.add('modal-open');
56+
document.body.classList.add('jw-modal-open');
5157
}
5258

5359
// close modal
5460
close(): void {
5561
this.element.style.display = 'none';
56-
document.body.classList.remove('modal-open');
62+
document.body.classList.remove('jw-modal-open');
5763
}
5864
}

src/app/app.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
<!-- credits -->
1111
<div class="credits">
12+
<p>
13+
<a href="http://jasonwatmore.com/post/2018/05/25/angular-6-custom-modal-window-dialog-box" target="_top">Angular 6 - Custom Modal Window / Dialog Box</a>
14+
</p>
1215
<p>
1316
<a href="http://jasonwatmore.com" target="_top">JasonWatmore.com</a>
1417
</p>

src/app/home/home.component.html

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,13 @@ <h1>Home</h1>
55
<button (click)="openModal('custom-modal-2')">Open Modal 2</button>
66
</div>
77

8-
<modal id="custom-modal-1">
9-
<div class="modal">
10-
<div class="modal-body">
11-
<h1>A Custom Modal!</h1>
12-
<p>
13-
Home page text: <input type="text" [(ngModel)]="bodyText" />
14-
</p>
15-
<button (click)="closeModal('custom-modal-1');">Close</button>
16-
</div>
17-
</div>
18-
<div class="modal-background"></div>
19-
</modal>
8+
<jw-modal id="custom-modal-1">
9+
<h1>A Custom Modal!</h1>
10+
<p>Home page text: <input type="text" [(ngModel)]="bodyText" /></p>
11+
<button (click)="closeModal('custom-modal-1');">Close</button>
12+
</jw-modal>
2013

21-
<modal id="custom-modal-2">
22-
<div class="modal">
23-
<div class="modal-body">
24-
<h1 style="height:1000px">A Tall Custom Modal!</h1>
25-
<button (click)="closeModal('custom-modal-2');">Close</button>
26-
</div>
27-
</div>
28-
<div class="modal-background"></div>
29-
</modal>
14+
<jw-modal id="custom-modal-2">
15+
<h1 style="height:1000px">A Tall Custom Modal!</h1>
16+
<button (click)="closeModal('custom-modal-2');">Close</button>
17+
</jw-modal>

0 commit comments

Comments
 (0)