Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Add ability to specify modal size of small, medium, or large. #767

Merged
merged 7 commits into from
Jun 9, 2017
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
11 changes: 10 additions & 1 deletion src/app/components/modal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@
A Boolean property of <code>config</code> with a default of false. When set to true, the modal will become full screen.
</sky-demo-page-property>

<sky-demo-page-property
<sky-demo-page-property
propertyName="providers?"
>
A array property of <code>providers</code> This can be used to pass context values from the component launching the modal to the modal component.

</sky-demo-page-property>

<sky-demo-page-property
propertyName="size?"
defaultValue="medium"
isOptional="true"
>
Specifies a size for the modal. The valid options are <code>small</code>,
<code>medium</code>, and <code>large</code>.
</sky-demo-page-property>
</sky-demo-page-properties>

<sky-demo-page-properties sectionHeading="Modal component properties">
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/modal/modal-demo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Open modal
</button>

<button type="button" class="sky-btn sky-btn-primary" (click)="openModal('smallModal')">
Open small modal
</button>

<button type="button" class="sky-btn sky-btn-primary" (click)="openModal('largeModal')">
Open large modal
</button>

<button type="button" class="sky-btn sky-btn-secondary" (click)="openModal('fullScreenModal')">
Open Full Screen modal
</button>
4 changes: 4 additions & 0 deletions src/app/components/modal/modal-demo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class SkyModalDemoComponent {

if (type === 'fullScreenModal') {
options.fullPage = true;
} else if (type === 'smallModal') {
options.size = 'small';
} else if (type === 'largeModal') {
options.size = 'large';
}

let modalInstance = this.modal.open(SkyModalDemoFormComponent, options);
Expand Down
23 changes: 22 additions & 1 deletion src/modules/modal/fixtures/modal.component.visual-fixture.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
type="button"
class="sky-btn sky-btn-primary"
(click)="openModal()"
>
>
Open modal
</button>
<button
Expand All @@ -21,4 +21,25 @@
>
Open content modal
</button>
<button
type="button"
class="sky-btn sky-btn-primary sky-test-small-size-modal"
(click)="openSmallSizeModal()"
>
Open small modal
</button>
<button
type="button"
class="sky-btn sky-btn-primary sky-test-medium-size-modal"
(click)="openMediumSizeModal()"
>
Open medium size modal
</button>
<button
type="button"
class="sky-btn sky-btn-primary sky-test-large-size-modal"
(click)="openLargeSizeModal()"
>
Open large size modal
</button>
</div>
17 changes: 16 additions & 1 deletion src/modules/modal/fixtures/modal.component.visual-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,35 @@ class AppComponent {
constructor(public viewContainerRef: ViewContainerRef, private modal: SkyModalService) { }

public openModal() {

this.modal.open(ModalDemoComponent, { 'providers': [] });
}

public openLargeModal() {
this.modal.open(ModalLargeDemoComponent, { 'providers': [] });
}

public openFullScreenModal() {
this.modal.open(ModalFullPageDemoComponent, { 'providers': [], 'fullPage': true });
}

public openContentModal() {
this.modal.open(ModalContentDemoComponent);
}

public openSmallSizeModal() {
this.modal.open(
ModalDemoComponent, { 'providers': [], 'fullPage': false , 'size': 'small'});
}

public openMediumSizeModal() {
this.modal.open(
ModalDemoComponent, { 'providers': [], 'fullPage': false , 'size': 'medium'});
}

public openLargeSizeModal() {
this.modal.open(
ModalDemoComponent, { 'providers': [], 'fullPage': false , 'size': 'large'});
}
}

@NgModule({
Expand Down
3 changes: 2 additions & 1 deletion src/modules/modal/modal-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { Injectable } from '@angular/core';
export class SkyModalConfiguration {

public fullPage: boolean;
public size: string;

constructor() {
this.fullPage = this.fullPage;

this.size = 'medium';
}
}
5 changes: 4 additions & 1 deletion src/modules/modal/modal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
>
<div class="sky-modal"
[ngClass]="{
'sky-modal-full-page': modalFullPage
'sky-modal-full-page': modalFullPage,
'sky-modal-small' : isSmallSize,
'sky-modal-medium' : isMediumSize,
'sky-modal-large' : isLargeSize
}"
[ngStyle]="{
zIndex: modalZIndex
Expand Down
13 changes: 12 additions & 1 deletion src/modules/modal/modal.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@

@media (min-width: $sky-screen-sm-min) {
.sky-modal {
width: 600px;
margin: 0 auto;
}

.sky-modal-small {
width: 300px;
}

.sky-modal-medium {
width: 600px;
}

.sky-modal-large {
width: 900px;
}
}

.sky-modal-content {
Expand Down
49 changes: 49 additions & 0 deletions src/modules/modal/modal.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,53 @@ describe('Modal component', () => {
closeModal(modalInstance);
}));

it('should not contain small,medium, or large classes in full size mode', fakeAsync(() => {
let modalInstance = openModal(ModalTestComponent, {'fullPage': true});

expect(document.querySelector('.sky-modal-small')).not.toExist();
expect(document.querySelector('.sky-modal-medium')).not.toExist();
expect(document.querySelector('.sky-modal-large')).not.toExist();

closeModal(modalInstance);
}));

it('should default to medium size', fakeAsync(() => {
let modalInstance = openModal(ModalTestComponent, {'fullPage': false});

expect(document.querySelector('.sky-modal-small')).not.toExist();
expect(document.querySelector('.sky-modal-medium')).toExist();
expect(document.querySelector('.sky-modal-large')).not.toExist();

closeModal(modalInstance);
}));

it('should respect medium config setting size', fakeAsync(() => {
let modalInstance = openModal(ModalTestComponent, {'fullPage': false, 'size': 'medium'});

expect(document.querySelector('.sky-modal-small')).not.toExist();
expect(document.querySelector('.sky-modal-medium')).toExist();
expect(document.querySelector('.sky-modal-large')).not.toExist();

closeModal(modalInstance);
}));

it('should respect small config setting size', fakeAsync(() => {
let modalInstance = openModal(ModalTestComponent, {'fullPage': false, 'size': 'small'});

expect(document.querySelector('.sky-modal-small')).toExist();
expect(document.querySelector('.sky-modal-medium')).not.toExist();
expect(document.querySelector('.sky-modal-large')).not.toExist();

closeModal(modalInstance);
}));

it('should respect large config setting size', fakeAsync(() => {
let modalInstance = openModal(ModalTestComponent, {'fullPage': false, 'size': 'large'});

expect(document.querySelector('.sky-modal-small')).not.toExist();
expect(document.querySelector('.sky-modal-medium')).not.toExist();
expect(document.querySelector('.sky-modal-large')).toExist();

closeModal(modalInstance);
}));
});
16 changes: 16 additions & 0 deletions src/modules/modal/modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ export class SkyModalComponent implements AfterViewInit {
return this.config.fullPage;
}

public get isSmallSize() {
return !this.modalFullPage && this.isSizeEqual(this.config.size, 'small');
}

public get isMediumSize() {
return !this.modalFullPage && !(this.isSmallSize || this.isLargeSize);
}

public get isLargeSize() {
return !this.modalFullPage && this.isSizeEqual(this.config.size, 'large');
}

constructor(
private hostService: SkyModalHostService,
private config: SkyModalConfiguration,
Expand All @@ -63,4 +75,8 @@ export class SkyModalComponent implements AfterViewInit {
public windowResize() {
this.componentAdapter.handleWindowChange(this.elRef);
}

private isSizeEqual(actualSize: string, size: string) {
return actualSize && actualSize.toLowerCase() === size;
}
}
39 changes: 39 additions & 0 deletions src/modules/modal/modal.component.visual-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,43 @@ describe('Modal', function () {
checkAccessibility: true
});
});

it('should match previous small size modal screenshot', function () {
return browser
.setupTest('/modal.html')
.click('.sky-test-small-size-modal')
.moveCursorOffScreen()
.pause(1000)
.compareScreenshot({
screenshotName: 'modal_small_size',
selector: '.sky-modal',
checkAccessibility: true
});
});

it('should match previous medium size modal screenshot', function () {
return browser
.setupTest('/modal.html')
.click('.sky-test-medium-size-modal')
.moveCursorOffScreen()
.pause(1000)
.compareScreenshot({
screenshotName: 'modal_medium_size',
selector: '.sky-modal',
checkAccessibility: true
});
});

it('should match previous large size modal screenshot', function () {
return browser
.setupTest('/modal.html')
.click('.sky-test-large-size-modal')
.moveCursorOffScreen()
.pause(1000)
.compareScreenshot({
screenshotName: 'modal_large_size',
selector: '.sky-modal',
checkAccessibility: true
});
});
});
1 change: 1 addition & 0 deletions src/modules/modal/modal.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface SkyModalConfiguationInterface {
fullPage?: boolean;
size?: string;
providers?: any[];
}
2 changes: 1 addition & 1 deletion src/modules/modal/modal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class SkyModalService {
}

private getConfigFromParameter(providersOrConfig: any) {
let defaultParams: IConfig = { 'providers': [], 'fullPage': false };
let defaultParams: IConfig = { 'providers': [], 'fullPage': false, 'size': 'medium' };
let params: any = undefined;
let method: any = undefined;

Expand Down