Commit b99e63f7 authored by avovchuk's avatar avovchuk

Modal backdrop #8

how to change default size? #3
AOT support #2
demo app
support bootstrap 4
custom placeholder
parent fff6f02f
# Node Files #
/node_modules/
node_modules
npm-debug.log
# IDE #
......@@ -8,6 +8,4 @@ npm-debug.log
# Compiled code #
dist
# Demo app #
demo/node_modules/
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "demo"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
# dependencies
/node_modules
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# misc
/.sass-cache
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
testem.log
/typings
# e2e
/e2e/*.js
/e2e/*.map
#System Files
.DS_Store
Thumbs.db
# Demo
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.0.0-rc.1.
## Development server
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
## Code scaffolding
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class/module`.
## Build
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
## Running unit tests
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Running end-to-end tests
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
Before running the tests make sure you are serving the app via `ng serve`.
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
import { DemoPage } from './app.po';
describe('demo App', () => {
let page: DemoPage;
beforeEach(() => {
page = new DemoPage();
});
it('should display message saying app works', () => {
page.navigateTo();
expect(page.getParagraphText()).toEqual('app works!');
});
});
import { browser, element, by } from 'protractor';
export class DemoPage {
navigateTo() {
return browser.get('/');
}
getParagraphText() {
return element(by.css('app-root h1')).getText();
}
}
{
"compilerOptions": {
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016"
],
"outDir": "../dist/out-tsc-e2e",
"module": "commonjs",
"target": "es6",
"types":[
"jasmine",
"node"
]
}
}
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['@angular/cli']
},
mime: {
'text/x-typescript': ['ts','tsx']
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
{
"name": "demo",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "^2.4.0",
"@angular/compiler": "^2.4.0",
"@angular/core": "^2.4.0",
"@angular/forms": "^2.4.0",
"@angular/http": "^2.4.0",
"@angular/platform-browser": "^2.4.0",
"@angular/platform-browser-dynamic": "^2.4.0",
"@angular/router": "^3.4.0",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"zone.js": "^0.7.6",
"ng2-bootstrap-modal":"file:../"
},
"devDependencies": {
"@angular/cli": "1.0.0-rc.1",
"@angular/compiler-cli": "^2.4.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.4.2",
"typescript": "~2.0.0"
}
}
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
},
onPrepare() {
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
import { Component } from '@angular/core';
import { DialogComponent, DialogService } from 'ng2-bootstrap-modal';
export interface AlertModel {
title: string;
message: string;
}
@Component({
selector: 'alert',
template: `<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" (click)="close()" >&times;</button>
<h4 class="modal-title">{{title || 'Alert!'}}</h4>
</div>
<div class="modal-body">
<p>{{message || 'TADAA-AM!'}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="close()">OK</button>
</div>
</div>
</div>`
})
export class AlertComponent extends DialogComponent<AlertModel, null> implements AlertModel {
title: string;
message: string;
constructor(dialogService: DialogService) {
super(dialogService);
}
}
<div class="container" >
<h1 class="text-center">ng2-bootstrap-modal demo</h1>
<br>
<br>
<div class="row">
<div class="col-sm-4 text-right">
<b>Alert example: </b>
</div>
<div class="col-sm-4">
<button class="btn btn-default btn-block" (click)=showAlert()>Show alert</button>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-sm-4 text-right">
<b>Confirm example: </b>
</div>
<div class="col-sm-4">
<button class="btn btn-default btn-block" (click)=showConfirm()>Show confirm</button>
</div>
<div class="col-sm-4" *ngIf="confirmResult != null">
<span>Result: </span>
<b [ngClass]="{'text-danger': !confirmResult, 'text-success': confirmResult}">{{confirmResult ? 'Accepted': 'Declined'}}</b>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-sm-4 text-right">
<b>Prompt example: </b>
</div>
<div class="col-sm-4">
<button class="btn btn-default btn-block" (click)=showPrompt()>Show prompt</button>
</div>
<div class="col-sm-4" *ngIf="promptMessage">
<span>Your name: </span>
<b>{{promptMessage}}</b>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-sm-4 text-right">
<b>Close dialog by click outside example: </b>
</div>
<div class="col-sm-4">
<button class="btn btn-default btn-block" (click)=showAlert2()>Show alert</button>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-sm-4 text-right">
<b>Close dialog by timeout example: </b>
</div>
<div class="col-sm-4">
<button class="btn btn-default btn-block" (click)=showAlert3()>Show alert</button>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-sm-4 text-right">
<b>Custom backdrop color example: </b>
</div>
<div class="col-sm-4">
<button class="btn btn-default btn-block" (click)=showAlert4()>Show alert</button>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-sm-4 text-right">
<b>Show dialog from dialog: </b>
</div>
<div class="col-sm-4">
<button class="btn btn-default btn-block" (click)=showParentDialog()>Show dialog</button>
</div>
</div>
</div>
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it(`should have as title 'app works!'`, async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app works!');
}));
it('should render title in a h1 tag', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('app works!');
}));
});
import { Component } from '@angular/core';
import { DialogService } from 'ng2-bootstrap-modal';
import { AlertComponent } from "./alert/alert.component";
import { ConfirmComponent } from "./confirm/confirm.component";
import { PromptComponent } from "./prompt/prompt.component";
import { ParentDialogComponent } from "./parent-dialog/parent-dialog.component";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
confirmResult:boolean = null;
promptMessage:string = '';
constructor(private dialogService:DialogService) {}
showAlert() {
this.dialogService.addDialog(AlertComponent, {title:'Alert title!', message:'Alert message!!!'});
}
showConfirm() {
this.dialogService.addDialog(ConfirmComponent, {
title:'Confirmation',
message:'Bla bla confirm some action?'})
.subscribe((isConfirmed)=>{
//Get dialog result
this.confirmResult = isConfirmed;
});
}
showPrompt() {
this.dialogService.addDialog(PromptComponent, {
title:'Name dialog',
question:'What is your name?: '})
.subscribe((message)=>{
//We get dialog result
this.promptMessage = message;
});
}
showAlert2() {
this.dialogService.addDialog(AlertComponent, { message:'Click outside to close dialog' }, { closeByClickingOutside:true });
}
showAlert3() {
this.dialogService.addDialog(AlertComponent, { message:'Wait 5 seconds and dialog will be closed automatically' }, { autoCloseTimeout:5000 });
}
showAlert4() {
this.dialogService.addDialog(AlertComponent, { message:'Dialog with red backdrop' }, { backdropColor: 'rgba(255, 0, 0, 0.5)' });
}
showParentDialog() {
this.dialogService.addDialog(ParentDialogComponent);
}
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { BootstrapModalModule } from 'ng2-bootstrap-modal';
import { AppComponent } from './app.component';
import { AlertComponent } from './alert/alert.component';
import { ConfirmComponent } from "./confirm/confirm.component";
import { PromptComponent } from "./prompt/prompt.component";
import { ParentDialogComponent } from "./parent-dialog/parent-dialog.component";
@NgModule({
declarations: [
AppComponent,
AlertComponent,
ConfirmComponent,
PromptComponent,
ParentDialogComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
BootstrapModalModule
],
entryComponents: [
AlertComponent,
ConfirmComponent,
PromptComponent,
ParentDialogComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }
import { Component } from '@angular/core';
import { DialogComponent, DialogService } from "ng2-bootstrap-modal";
export interface ConfirmModel {
title:string;
message:string;
}
@Component({
selector: 'confirm',
template: `<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" (click)="close()" >&times;</button>
<h4 class="modal-title">{{title || 'Confirm'}}</h4>
</div>
<div class="modal-body">
<p>{{message || 'Are you sure?'}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="confirm()">OK</button>
<button type="button" class="btn btn-default" (click)="cancel()">Cancel</button>
</div>
</div>
</div>`
})
export class ConfirmComponent extends DialogComponent<ConfirmModel, boolean> implements ConfirmModel {
title: string;
message: string;
constructor(dialogService: DialogService) {
super(dialogService);
}
confirm() {
// on click on confirm button we set dialog result as true,
// ten we can get dialog result from caller code
this.result = true;
this.close();
}
cancel() {
this.result = false;
this.close();
}
}
import { Component } from '@angular/core';
import { DialogComponent, DialogService } from 'ng2-bootstrap-modal';
import {ConfirmComponent} from "../confirm/confirm.component";
@Component({
selector: 'parent-dialog',
template: `<div class="modal-dialog" style="width: 800px;">
<div class="modal-content" >
<div class="modal-header">
<button type="button" class="close" (click)="close()" >&times;</button>
<h4 class="modal-title">Parent dialog</h4>
</div>
<div class="modal-body">
<p>bla-bla</p>
<p>bla-bla</p>
<p>bla-bla</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="confirm()">Close</button>
</div>
</div>
</div>`
})
export class ParentDialogComponent extends DialogComponent<null, null> {
constructor(dialogService: DialogService) {
super(dialogService);
}
confirm() {
this.dialogService.addDialog(ConfirmComponent, {title: 'Confirm', message: 'Are you sure you want close dialog?'}).subscribe((isConfirmed)=>{
if(isConfirmed) {
this.close();
}
});
}
}
import { Component } from '@angular/core';
import { DialogComponent, DialogService } from "ng2-bootstrap-modal";
export interface PromptModel {
title:string;
question:string;
}