Skip to content

Commit b8550c8

Browse files
authored
feat: access custom props in Component, Template and Plain text contents
2 parents 60fddf7 + 10a3fd8 commit b8550c8

File tree

116 files changed

+3519
-23881
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+3519
-23881
lines changed

.releaserc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[
55
"@semantic-release/exec",
66
{
7-
"prepareCmd": "npm run archive:app -- ${nextRelease.version} && chmod a+x ./bin/version.sh && ./bin/version.sh ${nextRelease.version} && cp -r ./README.md ./dist/toppy && npx json -I -f package.json -e 'this.version=\"${nextRelease.version}\"'",
7+
"prepareCmd": "npm run archive:app -- ${nextRelease.version} && chmod a+x ./scripts/version.sh && ./scripts/version.sh ${nextRelease.version} && cp -r ./README.md ./dist/toppy && npx json -I -f package.json -e 'this.version=\"${nextRelease.version}\"'",
88
"successCmd": "npm run postpublish -- ${nextRelease.version}"
99
}
1010
],

README.md

Lines changed: 113 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
### Installation
2929

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)
3131

3232
```sh
3333
npm install toppy // or
@@ -68,18 +68,18 @@ export class AppComponent {
6868
src: this.el.nativeElement
6969
});
7070

71-
this.overlayIns = this._toppy
72-
.overlay(position)
73-
.host('hello') // content
71+
this.overlay = this._toppy
72+
.position(position)
73+
.content('hello') // content
7474
.create();
7575
}
7676

7777
open() {
78-
this.overlayIns.open();
78+
this.overlay.open();
7979
}
8080

8181
close() {
82-
this.overlayIns.close();
82+
this.overlay.close();
8383
}
8484
}
8585
```
@@ -91,18 +91,18 @@ Toppy allows to use `string`, `html`, `TemplateRef`, `Component` as overlay cont
9191
**Plain text**
9292

9393
```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
9797
.create();
9898
```
9999

100100
**HTML content**
101101

102102
```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
106106
.create();
107107
```
108108

@@ -115,9 +115,9 @@ this.overlayIns = this._toppy
115115
```typescript
116116
@ViewChild('tpl') tpl:TemplateRef<any>;
117117

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
121121
.create();
122122
```
123123

@@ -132,9 +132,9 @@ export class HelloComponent {}
132132
```
133133

134134
```typescript
135-
this.overlayIns = this._toppy
136-
.overlay(position)
137-
.host(HelloComponent) // <==
135+
this.overlay = this._toppy
136+
.position(position)
137+
.content(HelloComponent) // <==
138138
.create();
139139
```
140140

@@ -152,8 +152,8 @@ Overlay position that is relative to specific element. These are used in `toolti
152152
new RelativePosition({
153153
src: HTMLElement, // target element
154154
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%`
157157
autoUpdate: boolean // update position when window scroll/resize/drag
158158
});
159159
```
@@ -182,8 +182,8 @@ Overlay position that is relative to window viewport. These are used in `modals`
182182
```typescript
183183
new GlobalPosition({
184184
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%`
187187
offset: number // oustide space of the content, in px
188188
});
189189
```
@@ -232,28 +232,29 @@ new FullScreenPosition();
232232

233233
```typescript
234234
this.toppy
235-
.overlay(position, configuration)
236-
.host('hello')
235+
.position(position:Position)
236+
.config(configuration:ToppyConfig = {})
237+
.content('hello')
237238
.create();
238239
```
239240

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` &middot; whether to show backdrop layer &middot; default: `false` |
244+
| **closeOnEsc** | `boolean` &middot; clicking Escape button will close overlay &middot; default: `false` |
245+
| **closeOnDocClick** | `boolean` &middot; dismiss on clicking outside of content &middot; default: `false` |
246+
| **listenWindowEvents** | `boolean` &middot; auto adjust the position on scroll/resize &middot; default: `true` |
247+
| **containerClass** | `string` &middot; overlay container class name &middot; default: `t-overlay` |
248+
| **wrapperClass** | `string` &middot; overlay wrapper class name &middot; default: `''` |
249+
| **backdropClass** | `string` &middot; overlay backdrop class name &middot; default: `''` |
250+
| **bodyClass** | `string` &middot; body class when overlay is open &middot; default: `t-open` |
251+
| **windowResizeCallback** | `function` &middot; triggered on window scroll |
252+
| **docClickCallback** | `function` &middot; triggered on document click |
254253

255254
### Component communication
256255

256+
#### Component Data
257+
257258
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.
258259

259260
```typescript
@@ -273,9 +274,9 @@ export class HostComponent {
273274
You can also set properties to component when creating the overlay.
274275

275276
```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' })
279280
.create();
280281
```
281282

@@ -294,64 +295,95 @@ export class HostComponent {
294295
}
295296
```
296297

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+
297331
### API
298332

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
302342

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
309344

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
313351

314-
---
352+
/* ToppyControl */
315353

316-
> ```typescript
317-
> ToppyRef.open():void
318-
> ```
354+
ToppyControl.open():void
319355

320-
> ```typescript
321-
> ToppyRef.close():void
322-
> ```
356+
ToppyControl.close():void
323357

324-
> ```typescript
325-
> ToppyRef.toggle():void
326-
> ```
358+
ToppyControl.toggle():void
327359

328-
> ```typescript
329-
> ToppyRef.onDocumentClick():Observable
330-
> ```
360+
ToppyControl.onDocumentClick():Observable<any>
331361

332-
> ```typescript
333-
> ToppyRef.onWindowResize():Observable
334-
> ```
362+
ToppyControl.onWindowResize():Observable<any>
335363

336-
> ```typescript
337-
> ToppyRef.getConfig():ToppyConfig
338-
> ```
364+
ToppyControl.changePosition(newPosition: Position): void
339365

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
346367

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+
```
350378

351379
### Contribution
352380

353381
Any kind of contributions ( Typo fix, documentation, code quality, performance, refactor, pipeline, etc., ) are welcome. :)
354382

383+
### Credits
384+
385+
- Icons from [openmoji](http://openmoji.org)
386+
355387
### Issues
356388

357389
Found a bug? Have some idea? Or do you have questions? File it [here](https://github.com/lokesh-coder/toppy/issues)

0 commit comments

Comments
 (0)