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

Commit

Permalink
feat: the viewer-modal can be used as a controller component
Browse files Browse the repository at this point in the history
- export `viewer-modal.component`
- add default values to inputs
- update README.md
  • Loading branch information
SimonGolms committed Feb 23, 2020
1 parent d7af54c commit 6d8fb45
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [Import](#import)
- [Component](#component)
- [Directive](#directive)
- [Controller](#controller)
- [Properties](#properties)
- [Workspace](#workspace)
- [Local Development](#local-development)
Expand Down Expand Up @@ -126,6 +127,39 @@ Add `ionImgViewer` as a directive within the `ion-img` HTML element of your modu
</ion-img>
```

### Controller

Import `ViewerModalComponent` from `ngx-ionic-image-viewer` and add it to the `ModalController`. Within the `componentProps`, all available properties can be passed, whereby `src` is always required. In addition you must add the css class `ion-img-viewer` to the property `cssClass`.
Use `cssClass: ['ion-img-viewer', 'my-custom-ion-img-viewer']`in case you want to add more css classes.

```js
import { ModalController } from '@ionic/angular';
import { ViewerModalComponent } from 'ngx-ionic-image-viewer';

export class HomePage {

constructor(public modalController: ModalController) {}

async openViewer() {
const modal = await this.modalController.create({
component: ViewerModalComponent,
componentProps: {
src: "./assets/img/demo.jpg"
},
cssClass: 'ion-img-viewer'
keyboardClose: true,
showBackdrop: true
});

return await modal.present();
}
}
```

```html
<ion-button (click)="openViewer()">Open Viewer</ion-button>
```

## Properties

<table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { NgxIonicImageViewerDirective } from './ngx-ionic-image-viewer.directive
import { ViewerModalComponent } from './viewer-modal/viewer-modal.component';

@NgModule({
declarations: [NgxIonicImageViewerComponent, ViewerModalComponent, NgxIonicImageViewerDirective],
declarations: [NgxIonicImageViewerComponent, NgxIonicImageViewerDirective, ViewerModalComponent],
imports: [CommonModule, IonicModule],
entryComponents: [ViewerModalComponent],
exports: [NgxIonicImageViewerComponent, ViewerModalComponent, NgxIonicImageViewerDirective]
exports: [NgxIonicImageViewerComponent, NgxIonicImageViewerDirective, ViewerModalComponent]
})
export class NgxIonicImageViewerModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import { ModalController, IonSlides } from '@ionic/angular';
styleUrls: ['./viewer-modal.component.scss']
})
export class ViewerModalComponent implements OnInit {
@Input() alt?: string;
@Input() scheme?: string;
@Input() slideOptions?: object;
// tslint:disable: no-inferrable-types
@Input() alt?: string = '';
@Input() scheme?: string = 'auto';
@Input() slideOptions?: object = {};
@Input() src: string;
@Input() srcFallback?: string;
@Input() srcHighRes?: string;
@Input() swipeToClose?: boolean;
@Input() text?: string;
@Input() title?: string;
@Input() titleSize?: string;
@Input() srcFallback?: string = '';
@Input() srcHighRes?: string = '';
@Input() swipeToClose?: boolean = true;
@Input() text?: string = '';
@Input() title?: string = '';
@Input() titleSize?: string = '';
// tslint:enable: no-inferrable-types

defaultSlideOptions = {
centeredSlides: true,
Expand Down
1 change: 1 addition & 0 deletions projects/ngx-ionic-image-viewer/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './lib/ngx-ionic-image-viewer.service';
export * from './lib/ngx-ionic-image-viewer.component';
export * from './lib/ngx-ionic-image-viewer.directive';
export * from './lib/ngx-ionic-image-viewer.module';
export * from './lib/viewer-modal/viewer-modal.component';

0 comments on commit 6d8fb45

Please sign in to comment.