27
27
28
28
### Installation
29
29
30
- ** step 1:** Install from NPM or YARN
30
+ ** step 1:** Install from [ npm ] ( https://www.npmjs.com/package/toppy ) or [ yarn ] ( https://yarnpkg.com/en/package/toppy )
31
31
32
32
``` sh
33
33
npm install toppy // or
@@ -68,18 +68,18 @@ export class AppComponent {
68
68
src: this .el .nativeElement
69
69
});
70
70
71
- this .overlayIns = this ._toppy
72
- .overlay (position )
73
- .host (' hello' ) // content
71
+ this .overlay = this ._toppy
72
+ .position (position )
73
+ .content (' hello' ) // content
74
74
.create ();
75
75
}
76
76
77
77
open() {
78
- this .overlayIns .open ();
78
+ this .overlay .open ();
79
79
}
80
80
81
81
close() {
82
- this .overlayIns .close ();
82
+ this .overlay .close ();
83
83
}
84
84
}
85
85
```
@@ -91,18 +91,18 @@ Toppy allows to use `string`, `html`, `TemplateRef`, `Component` as overlay cont
91
91
** Plain text**
92
92
93
93
``` typescript
94
- this .overlayIns = this ._toppy
95
- .overlay (position )
96
- .host (` some plain text content ` ) // simple text
94
+ this .overlay = this ._toppy
95
+ .position (position )
96
+ .content (` some plain text content ` ) // simple text
97
97
.create ();
98
98
```
99
99
100
100
** HTML content**
101
101
102
102
``` typescript
103
- this .overlayIns = this ._toppy
104
- .overlay (position )
105
- .host (` <div>any HTML content</div> ` , { hasHTML: true }) // html
103
+ this .overlay = this ._toppy
104
+ .position (position )
105
+ .content (` <div>any HTML content</div> ` , { hasHTML: true }) // html
106
106
.create ();
107
107
```
108
108
@@ -115,9 +115,9 @@ this.overlayIns = this._toppy
115
115
``` typescript
116
116
@ViewChild (' tpl' ) tpl :TemplateRef < any > ;
117
117
118
- this .overlayIns = this ._toppy
119
- .overlay (position )
120
- .host (this .tpl ) // template ref
118
+ this .overlay = this ._toppy
119
+ .position (position )
120
+ .content (this .tpl ) // template ref
121
121
.create ();
122
122
```
123
123
@@ -132,9 +132,9 @@ export class HelloComponent {}
132
132
```
133
133
134
134
``` typescript
135
- this .overlayIns = this ._toppy
136
- .overlay (position )
137
- .host (HelloComponent ) // <==
135
+ this .overlay = this ._toppy
136
+ .position (position )
137
+ .content (HelloComponent ) // <==
138
138
.create ();
139
139
```
140
140
@@ -152,8 +152,8 @@ Overlay position that is relative to specific element. These are used in `toolti
152
152
new RelativePosition ({
153
153
src: HTMLElement , // target element
154
154
placement: OutsidePlacement , // location of the content
155
- hostWidth : string | number , // content width eg, `auto`, 150, `30%`
156
- hostHeight : string | number , // content height eg, `auto`, 150, `30%`
155
+ width : string | number , // content width eg, `auto`, 150, `30%`
156
+ height : string | number , // content height eg, `auto`, 150, `30%`
157
157
autoUpdate: boolean // update position when window scroll/resize/drag
158
158
});
159
159
```
@@ -182,8 +182,8 @@ Overlay position that is relative to window viewport. These are used in `modals`
182
182
``` typescript
183
183
new GlobalPosition ({
184
184
placement: InsidePlacement , // location of the content.
185
- hostWidth : string | number , // content width eg, `auto`, `150`, `30%`
186
- hostHeight : string | number , // content height eg, `auto`, 150, `30%`
185
+ width : string | number , // content width eg, `auto`, `150`, `30%`
186
+ height : string | number , // content height eg, `auto`, 150, `30%`
187
187
offset: number // oustide space of the content, in px
188
188
});
189
189
```
@@ -232,28 +232,29 @@ new FullScreenPosition();
232
232
233
233
``` typescript
234
234
this .toppy
235
- .overlay (position , configuration )
236
- .host (' hello' )
235
+ .position (position :Position )
236
+ .config (configuration :ToppyConfig = {})
237
+ .content (' hello' )
237
238
.create ();
238
239
```
239
240
240
- | ` property ` | ` default ` | ` supported values ` |
241
- | -------------------------- | ------------------- | ------------------ |
242
- | ** backdrop** | _ false_ | boolean |
243
- | ** containerClass** | _ 'toppy-container'_ | string |
244
- | ** wrapperClass** | _ 'toppy-wrapper'_ | string |
245
- | ** backdropClass** | _ 'toppy-backdrop'_ | string |
246
- | ** bodyClassNameOnOpen** | _ ''_ | string |
247
- | ** dismissOnDocumentClick** | _ true_ | boolean |
248
- | ** closeOnEsc** | _ false_ | boolean |
249
- | ** parentElement** | _ null_ | HTMLElement |
250
- | ** watchDocClick** | _ true_ | boolean |
251
- | ** watchWindowResize** | _ true_ | boolean |
252
- | ** windowResizeCallback** | _ null_ | function |
253
- | ** docClickCallback** | _ null_ | function |
241
+ | ` property ` | ` for ` |
242
+ | ------------------------ | -------------------------------------------------------------------------------------- |
243
+ | ** backdrop** | ` boolean ` · ; whether to show backdrop layer · ; default: ` false ` |
244
+ | ** closeOnEsc** | ` boolean ` · ; clicking Escape button will close overlay · ; default: ` false ` |
245
+ | ** closeOnDocClick** | ` boolean ` · ; dismiss on clicking outside of content · ; default: ` false ` |
246
+ | ** listenWindowEvents** | ` boolean ` · ; auto adjust the position on scroll/resize · ; default: ` true ` |
247
+ | ** containerClass** | ` string ` · ; overlay container class name · ; default: ` t-overlay ` |
248
+ | ** wrapperClass** | ` string ` · ; overlay wrapper class name · ; default: ` '' ` |
249
+ | ** backdropClass** | ` string ` · ; overlay backdrop class name · ; default: ` '' ` |
250
+ | ** bodyClass** | ` string ` · ; body class when overlay is open · ; default: ` t-open ` |
251
+ | ** windowResizeCallback** | ` function ` · ; triggered on window scroll |
252
+ | ** docClickCallback** | ` function ` · ; triggered on document click |
254
253
255
254
### Component communication
256
255
256
+ #### Component Data
257
+
257
258
When you host a component, you can control the overlay through ` CurrentOverlay ` service. As of now, this service has only one method called ` close ` to close the overlay from the host component. But, soon more API will be added to this service.
258
259
259
260
``` typescript
@@ -273,9 +274,9 @@ export class HostComponent {
273
274
You can also set properties to component when creating the overlay.
274
275
275
276
``` typescript
276
- this .overlayIns = this ._toppy
277
- .overlay (position )
278
- .host (HelloComponent , { propName: ' toppy-test-prop' })
277
+ this .overlay = this ._toppy
278
+ .position (position )
279
+ .content (HelloComponent , { propName: ' toppy-test-prop' })
279
280
.create ();
280
281
```
281
282
@@ -294,64 +295,95 @@ export class HostComponent {
294
295
}
295
296
```
296
297
298
+ #### Template Data
299
+
300
+ This is very similar to above one. When you use template as a content, you can pass additional data to it.
301
+
302
+ ``` typescript
303
+ this .overlay = this ._toppy
304
+ .position (position )
305
+ .content (template , { name: ' Johny' })
306
+ .create ();
307
+ ```
308
+
309
+ Then in your template you can refer the data like this,
310
+
311
+ ``` html
312
+ <ng-template #tpl let-toppy >
313
+ <div >Hello <span [innerText] =" toppy.name" ></span > !</div >
314
+ <button (click) =" toppy.close()" >Close</button >
315
+ </ng-template >
316
+ ```
317
+
318
+ Method ` close ` is automatically binded.
319
+
320
+ #### Plain text
321
+
322
+ When you use Plain text as a content, optionally you can able to set a class name to that ` div ` block.
323
+
324
+ ``` typescript
325
+ this .overlay = this ._toppy
326
+ .position (position )
327
+ .content (' some content' , { class: ' tooltip' })
328
+ .create ();
329
+ ```
330
+
297
331
### API
298
332
299
- > ``` typescript
300
- > Toppy .overlay (position :Position , config :ToppyConfig ):Toppy
301
- > ` ` `
333
+ ``` typescript
334
+
335
+ /* Toppy */
336
+
337
+ Toppy .position (position :Position ):Toppy
338
+
339
+ Toppy .config (config :ToppyConfig ):Toppy
340
+
341
+ Toppy .content (data : ContentData , props : ContentProps = {}):Toppy
302
342
303
- > ` ` ` typescript
304
- > Toppy .host (
305
- > content : string | TemplateRef < any > | ComponentType < any > ,
306
- > props : { [x : string ]: any } = {}
307
- > ):Toppy
308
- > ` ` `
343
+ Toppy .create (position :Position ,config :ToppyConfig ):ToppyControl
309
344
310
- > ` ` ` typescript
311
- > Toppy .create (position :Position , config :ToppyConfig ):ToppyRef
312
- > ` ` `
345
+ Toppy .getCtrl (id :string ):ToppyControl
346
+
347
+ Toppy .destroy ():void
348
+ ```
349
+
350
+ ``` typescript
313
351
314
- ---
352
+ /* ToppyControl */
315
353
316
- > ` ` ` typescript
317
- > ToppyRef .open ():void
318
- > ` ` `
354
+ ToppyControl .open ():void
319
355
320
- > ` ` ` typescript
321
- > ToppyRef .close ():void
322
- > ` ` `
356
+ ToppyControl .close ():void
323
357
324
- > ` ` ` typescript
325
- > ToppyRef .toggle ():void
326
- > ` ` `
358
+ ToppyControl .toggle ():void
327
359
328
- > ` ` ` typescript
329
- > ToppyRef .onDocumentClick ():Observable
330
- > ` ` `
360
+ ToppyControl .onDocumentClick ():Observable < any >
331
361
332
- > ` ` ` typescript
333
- > ToppyRef .onWindowResize ():Observable
334
- > ` ` `
362
+ ToppyControl .onWindowResize ():Observable < any >
335
363
336
- > ` ` ` typescript
337
- > ToppyRef .getConfig ():ToppyConfig
338
- > ` ` `
364
+ ToppyControl .changePosition (newPosition : Position ): void
339
365
340
- > ` ` ` typescript
341
- > ToppyRef .updateHost (
342
- > content : string | TemplateRef < any > | ComponentType < any > ,
343
- > props : { [x : string ]: any } = {}
344
- > ):ToppyRef
345
- > ` ` `
366
+ ToppyControl .updateContent (content : ContentData , props : ContentProps = {}):void
346
367
347
- > ` ` ` typescript
348
- > ToppyRef .updatePosition (config :object ):ToppyRef
349
- > ` ` `
368
+ ToppyControl .updatePosition (config :object ):ToppyControl
369
+
370
+ ToppyControl .listen (eventName :string ):Observable < any >
371
+ ```
372
+
373
+ ``` typescript
374
+ /* events */
375
+
376
+ ` t_open ` , ` t_close ` , ` t_dynpos ` , ` t_detach ` , ` t_posupdate ` ;
377
+ ```
350
378
351
379
### Contribution
352
380
353
381
Any kind of contributions ( Typo fix, documentation, code quality, performance, refactor, pipeline, etc., ) are welcome. :)
354
382
383
+ ### Credits
384
+
385
+ - Icons from [ openmoji] ( http://openmoji.org )
386
+
355
387
### Issues
356
388
357
389
Found a bug? Have some idea? Or do you have questions? File it [ here] ( https://github.com/lokesh-coder/toppy/issues )
0 commit comments